Search in sources :

Example 11 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class FlatJava5Test method testPKOnlyInsert.

@Test
public void testPKOnlyInsert() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly();
        key.setId(1);
        key.setSeqNum(3);
        mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        List<Pkonly> answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        Pkonly returnedRecord = answer.get(0);
        assertEquals(key.getId(), returnedRecord.getId());
        assertEquals(key.getSeqNum(), returnedRecord.getSeqNum());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.mixed.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.mixed.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.mixed.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 12 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class FlatJava5Test method testPKOnlyCountByExample.

@Test
public void testPKOnlyCountByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly();
        key.setId(1);
        key.setSeqNum(3);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(5);
        key.setSeqNum(6);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(7);
        key.setSeqNum(8);
        mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        example.createCriteria().andIdGreaterThan(4);
        long rows = mapper.countByExample(example);
        assertEquals(2, rows);
        example.clear();
        rows = mapper.countByExample(example);
        assertEquals(3, rows);
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 13 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class FlatJava5Test method testPKOnlySelectByExample.

@Test
public void testPKOnlySelectByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly();
        key.setId(1);
        key.setSeqNum(3);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(5);
        key.setSeqNum(6);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(7);
        key.setSeqNum(8);
        mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        example.createCriteria().andIdGreaterThan(4);
        List<Pkonly> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 14 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class FlatJava5Test method testPKOnlyDeleteByExample.

@Test
public void testPKOnlyDeleteByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly();
        key.setId(1);
        key.setSeqNum(3);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(5);
        key.setSeqNum(6);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(7);
        key.setSeqNum(8);
        mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        example.createCriteria().andIdGreaterThan(4);
        int rows = mapper.deleteByExample(example);
        assertEquals(2, rows);
        example = new PkonlyExample();
        List<Pkonly> answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 15 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class UpdateByExampleTest method testPKOnlyUpdateByExampleSelective.

@Test
public void testPKOnlyUpdateByExampleSelective() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly(1, 3);
        mapper.insert(key);
        key = new Pkonly(5, 6);
        mapper.insert(key);
        key = new Pkonly(7, 8);
        mapper.insert(key);
        Pkonly updateKey = new Pkonly(null, 3);
        int rows = mapper.update(dsl -> PkonlyMapper.updateSelectiveColumns(updateKey, dsl).where(pkonly.id, isGreaterThan(4)));
        assertEquals(2, rows);
        long returnedRows = mapper.count(dsl -> dsl.where(pkonly.id, isEqualTo(5)).and(pkonly.seqNum, isEqualTo(3)));
        assertEquals(1, returnedRows);
        returnedRows = mapper.count(dsl -> dsl.where(pkonly.id, isEqualTo(7)).and(pkonly.seqNum, isEqualTo(3)));
        assertEquals(1, returnedRows);
    }
}
Also used : FieldsblobsDynamicSqlSupport.fieldsblobs(mbg.test.mb3.generated.dsql.mapper.FieldsblobsDynamicSqlSupport.fieldsblobs) FieldsonlyDynamicSqlSupport.fieldsonly(mbg.test.mb3.generated.dsql.mapper.FieldsonlyDynamicSqlSupport.fieldsonly) SqlBuilder(org.mybatis.dynamic.sql.SqlBuilder) Pkfieldsblobs(mbg.test.mb3.generated.dsql.model.Pkfieldsblobs) TestUtilities.generateRandomBlob(mbg.test.common.util.TestUtilities.generateRandomBlob) Pkonly(mbg.test.mb3.generated.dsql.model.Pkonly) PkonlyMapper(mbg.test.mb3.generated.dsql.mapper.PkonlyMapper) Pkblobs(mbg.test.mb3.generated.dsql.model.Pkblobs) Fieldsblobs(mbg.test.mb3.generated.dsql.model.Fieldsblobs) PkonlyDynamicSqlSupport.pkonly(mbg.test.mb3.generated.dsql.mapper.PkonlyDynamicSqlSupport.pkonly) AwfulTableDynamicSqlSupport.awfulTable(mbg.test.mb3.generated.dsql.mapper.AwfulTableDynamicSqlSupport.awfulTable) PkblobsDynamicSqlSupport.pkblobs(mbg.test.mb3.generated.dsql.mapper.PkblobsDynamicSqlSupport.pkblobs) PkfieldsblobsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsblobsMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsMapper) TestUtilities.blobsAreEqual(mbg.test.common.util.TestUtilities.blobsAreEqual) PkfieldsblobsDynamicSqlSupport.pkfieldsblobs(mbg.test.mb3.generated.dsql.mapper.PkfieldsblobsDynamicSqlSupport.pkfieldsblobs) AwfulTable(mbg.test.mb3.generated.dsql.model.AwfulTable) Fieldsonly(mbg.test.mb3.generated.dsql.model.Fieldsonly) Test(org.junit.jupiter.api.Test) PkblobsMapper(mbg.test.mb3.generated.dsql.mapper.PkblobsMapper) List(java.util.List) AwfulTableMapper(mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper) FieldsonlyMapper(mbg.test.mb3.generated.dsql.mapper.FieldsonlyMapper) Pkfields(mbg.test.mb3.generated.dsql.model.Pkfields) Assertions(org.junit.jupiter.api.Assertions) PkfieldsDynamicSqlSupport.pkfieldstable(mbg.test.mb3.generated.dsql.mapper.PkfieldsDynamicSqlSupport.pkfieldstable) FieldsblobsMapper(mbg.test.mb3.generated.dsql.mapper.FieldsblobsMapper) PkonlyMapper(mbg.test.mb3.generated.dsql.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) Pkonly(mbg.test.mb3.generated.dsql.model.Pkonly) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)37 Test (org.junit.jupiter.api.Test)37 PkonlyMapper (mbg.test.mb3.generated.dsql.mapper.PkonlyMapper)11 Pkonly (mbg.test.mb3.generated.dsql.model.Pkonly)11 PkonlyMapper (mbg.test.mb3.generated.annotated.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.annotated.flat.model.Pkonly)8 PkonlyExample (mbg.test.mb3.generated.annotated.flat.model.PkonlyExample)8 PkonlyMapper (mbg.test.mb3.generated.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.flat.model.Pkonly)8 PkonlyExample (mbg.test.mb3.generated.flat.model.PkonlyExample)8 PkonlyMapper (mbg.test.mb3.generated.mixed.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.mixed.flat.model.Pkonly)8 PkonlyExample (mbg.test.mb3.generated.mixed.flat.model.PkonlyExample)8 List (java.util.List)2 TestUtilities.blobsAreEqual (mbg.test.common.util.TestUtilities.blobsAreEqual)2 TestUtilities.generateRandomBlob (mbg.test.common.util.TestUtilities.generateRandomBlob)2 AwfulTableDynamicSqlSupport.awfulTable (mbg.test.mb3.generated.dsql.mapper.AwfulTableDynamicSqlSupport.awfulTable)2 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)2 FieldsblobsDynamicSqlSupport.fieldsblobs (mbg.test.mb3.generated.dsql.mapper.FieldsblobsDynamicSqlSupport.fieldsblobs)2 FieldsblobsMapper (mbg.test.mb3.generated.dsql.mapper.FieldsblobsMapper)2