Search in sources :

Example 31 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly 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 32 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly 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 33 with Pkonly

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

the class FlatJava5Test method testPKOnlyDeleteByPrimaryKey.

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

Example 34 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.annotated.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.annotated.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.annotated.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 35 with Pkonly

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

the class DynamicSqlTest method testPKOnlyInsert.

@Test
public void testPKOnlyInsert() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly(1, 3);
        mapper.insert(key);
        List<Pkonly> answer = mapper.select(SelectDSLCompleter.allRows());
        assertThat(answer.size()).isEqualTo(1);
        Pkonly returnedRecord = answer.get(0);
        assertThat(returnedRecord.getId()).isEqualTo(key.getId());
        assertThat(returnedRecord.getSeqNum()).isEqualTo(key.getSeqNum());
    }
}
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)

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