Search in sources :

Example 96 with PkonlyMapper

use of mbg.test.mb3.generated.conditional.immutable.mapper.PkonlyMapper in project generator by mybatis.

the class ConditionalJava5Test method testPKOnlyInsert.

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

Example 97 with PkonlyMapper

use of mbg.test.mb3.generated.conditional.immutable.mapper.PkonlyMapper in project generator by mybatis.

the class DynamicSqlTest method testPKOnlycount.

@Test
public void testPKOnlycount() {
    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);
        long rows = mapper.count(dsl -> dsl.where(pkonly.id, isGreaterThan(4)));
        assertEquals(2, rows);
        rows = mapper.count(dsl -> dsl);
        assertEquals(3, rows);
    }
}
Also used : FieldsblobsDynamicSqlSupport.fieldsblobs(mbg.test.mb3.generated.dsql.mapper.FieldsblobsDynamicSqlSupport.fieldsblobs) FieldsonlyDynamicSqlSupport.fieldsonly(mbg.test.mb3.generated.dsql.mapper.FieldsonlyDynamicSqlSupport.fieldsonly) Arrays(java.util.Arrays) SqlBuilder(org.mybatis.dynamic.sql.SqlBuilder) Pkfieldsblobs(mbg.test.mb3.generated.dsql.model.Pkfieldsblobs) SelectDSLCompleter(org.mybatis.dynamic.sql.select.SelectDSLCompleter) TestUtilities.generateRandomBlob(mbg.test.common.util.TestUtilities.generateRandomBlob) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Pkonly(mbg.test.mb3.generated.dsql.model.Pkonly) LocalDateTime(java.time.LocalDateTime) PkonlyMapper(mbg.test.mb3.generated.dsql.mapper.PkonlyMapper) Pkblobs(mbg.test.mb3.generated.dsql.model.Pkblobs) TranslationMapper(mbg.test.mb3.generated.dsql.mapper.mbgtest.sub.TranslationMapper) CountDSLCompleter(org.mybatis.dynamic.sql.select.CountDSLCompleter) Fieldsblobs(mbg.test.mb3.generated.dsql.model.Fieldsblobs) PkonlyDynamicSqlSupport.pkonly(mbg.test.mb3.generated.dsql.mapper.PkonlyDynamicSqlSupport.pkonly) ArrayList(java.util.ArrayList) Id(mbg.test.mb3.generated.dsql.model.mbgtest.Id) BigDecimal(java.math.BigDecimal) AwfulTableDynamicSqlSupport.awfulTable(mbg.test.mb3.generated.dsql.mapper.AwfulTableDynamicSqlSupport.awfulTable) PkblobsDynamicSqlSupport.pkblobs(mbg.test.mb3.generated.dsql.mapper.PkblobsDynamicSqlSupport.pkblobs) LocalTime(java.time.LocalTime) 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) Collection(java.util.Collection) AwfulTable(mbg.test.mb3.generated.dsql.model.AwfulTable) Assertions.within(org.assertj.core.api.Assertions.within) Fieldsonly(mbg.test.mb3.generated.dsql.model.Fieldsonly) Translation(mbg.test.mb3.generated.dsql.model.mbgtest.sub.Translation) IdMapper(mbg.test.mb3.generated.dsql.mapper.mbgtest.IdMapper) 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) ChronoUnit(java.time.temporal.ChronoUnit) FieldsonlyMapper(mbg.test.mb3.generated.dsql.mapper.FieldsonlyMapper) Pkfields(mbg.test.mb3.generated.dsql.model.Pkfields) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) 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)

Example 98 with PkonlyMapper

use of mbg.test.mb3.generated.conditional.immutable.mapper.PkonlyMapper in project generator by mybatis.

the class ConditionalJava5Test method testPKOnlySelectByExample.

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

Example 99 with PkonlyMapper

use of mbg.test.mb3.generated.conditional.immutable.mapper.PkonlyMapper in project generator by mybatis.

the class UpdateByExampleTest method testPKOnlyUpdateByExample.

@Test
public void testPKOnlyUpdateByExample() {
    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(22, 3);
        int rows = mapper.update(dsl -> PkonlyMapper.updateAllColumns(updateKey, dsl).where(pkonly.id, isEqualTo(7)));
        assertEquals(1, rows);
        long returnedRows = mapper.count(dsl -> dsl.where(pkonly.id, isEqualTo(22)).and(pkonly.seqNum, isEqualTo(3)));
        assertEquals(1, returnedRows);
    }
}
Also used : 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)

Example 100 with PkonlyMapper

use of mbg.test.mb3.generated.conditional.immutable.mapper.PkonlyMapper in project generator by mybatis.

the class UpdateByExampleTest method testPKOnlyUpdateByExampleSelective.

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

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)117 Test (org.junit.jupiter.api.Test)117 PkonlyMapper (mbg.test.mb3.generated.annotated.conditional.mapper.PkonlyMapper)8 PkonlyExample (mbg.test.mb3.generated.annotated.conditional.model.PkonlyExample)8 PkonlyKey (mbg.test.mb3.generated.annotated.conditional.model.PkonlyKey)8 PkonlyMapper (mbg.test.mb3.generated.annotated.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.annotated.flat.model.Pkonly)8 PkonlyMapper (mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkonlyMapper)8 PkonlyExample (mbg.test.mb3.generated.annotated.hierarchical.Immutable.Model.PkonlyExample)8 PkonlyKey (mbg.test.mb3.generated.annotated.hierarchical.Immutable.Model.PkonlyKey)8 PkonlyMapper (mbg.test.mb3.generated.annotated.hierarchical.mapper.PkonlyMapper)8 PkonlyExample (mbg.test.mb3.generated.annotated.hierarchical.model.PkonlyExample)8 PkonlyKey (mbg.test.mb3.generated.annotated.hierarchical.model.PkonlyKey)8 PkonlyMapper (mbg.test.mb3.generated.conditional.immutable.mapper.PkonlyMapper)8 PkonlyExample (mbg.test.mb3.generated.conditional.immutable.model.PkonlyExample)8 PkonlyKey (mbg.test.mb3.generated.conditional.immutable.model.PkonlyKey)8 PkonlyMapper (mbg.test.mb3.generated.conditional.mapper.PkonlyMapper)8 PkonlyExample (mbg.test.mb3.generated.conditional.model.PkonlyExample)8 PkonlyKey (mbg.test.mb3.generated.conditional.model.PkonlyKey)8 PkonlyMapper (mbg.test.mb3.generated.dsql.mapper.PkonlyMapper)8