Search in sources :

Example 56 with Pkfields

use of mbg.test.mb3.generated.hierarchical.model.Pkfields in project generator by mybatis.

the class UpdateByExampleTest method testPKFieldsUpdateAllRows.

@Test
public void testPKFieldsUpdateAllRows() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setId1(1);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Bob");
        record.setLastname("Jones");
        record.setId1(3);
        record.setId2(4);
        mapper.insert(record);
        record = new Pkfields();
        record.setLastname("Cooper");
        int rows = mapper.updateByExampleSelective(record, null);
        assertEquals(2, rows);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andLastnameEqualTo("Cooper");
        long returnedRows = mapper.countByExample(example);
        assertEquals(2, returnedRows);
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.annotated.hierarchical.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.annotated.hierarchical.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.annotated.hierarchical.model.PkfieldsExample) Test(org.junit.jupiter.api.Test)

Example 57 with Pkfields

use of mbg.test.mb3.generated.hierarchical.model.Pkfields in project generator by mybatis.

the class DynamicSqlTest method testPKFieldscount.

@Test
public void testPKFieldscount() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setId1(1);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Bob");
        record.setLastname("Jones");
        record.setId1(3);
        record.setId2(4);
        mapper.insert(record);
        long rows = mapper.count(dsl -> dsl.where(pkfieldstable.lastname, isLike("J%")));
        assertEquals(1, rows);
        rows = mapper.count(dsl -> dsl);
        assertEquals(2, 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) SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.dsql.model.Pkfields) Test(org.junit.jupiter.api.Test)

Example 58 with Pkfields

use of mbg.test.mb3.generated.hierarchical.model.Pkfields in project generator by mybatis.

the class DynamicSqlTest method testPKFieldsSelectByExampleNoCriteria.

@Test
public void testPKFieldsSelectByExampleNoCriteria() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        mapper.insert(record);
        List<Pkfields> answer = mapper.select(SelectDSLCompleter.allRowsOrderedBy(pkfieldstable.id1, pkfieldstable.id2));
        assertEquals(6, answer.size());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.dsql.model.Pkfields) Test(org.junit.jupiter.api.Test)

Example 59 with Pkfields

use of mbg.test.mb3.generated.hierarchical.model.Pkfields in project generator by mybatis.

the class DynamicSqlTest method testPKFieldsSelectByExampleNoCriteriaWithMultiInsert.

@Test
public void testPKFieldsSelectByExampleNoCriteriaWithMultiInsert() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Collection<Pkfields> records = new ArrayList<>();
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        records.add(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        records.add(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        records.add(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        records.add(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        records.add(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        records.add(record);
        int rowsInserted = mapper.insertMultiple(records);
        assertEquals(6, rowsInserted);
        List<Pkfields> answer = mapper.select(SelectDSLCompleter.allRowsOrderedBy(pkfieldstable.id1, pkfieldstable.id2));
        assertEquals(6, answer.size());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsMapper) ArrayList(java.util.ArrayList) Pkfields(mbg.test.mb3.generated.dsql.model.Pkfields) Test(org.junit.jupiter.api.Test)

Example 60 with Pkfields

use of mbg.test.mb3.generated.hierarchical.model.Pkfields in project generator by mybatis.

the class DynamicSqlTest method testPKFieldsUpdateByPrimaryKeySelective.

@Test
public void testPKFieldsUpdateByPrimaryKeySelective() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setDecimal60field(5);
        record.setId1(1);
        record.setId2(2);
        mapper.insert(record);
        Pkfields newRecord = new Pkfields();
        newRecord.setId1(1);
        newRecord.setId2(2);
        newRecord.setFirstname("Scott");
        newRecord.setDecimal60field(4);
        int rows = mapper.updateByPrimaryKeySelective(newRecord);
        assertEquals(1, rows);
        Optional<Pkfields> returnedRecord = mapper.selectByPrimaryKey(2, 1);
        assertThat(returnedRecord).hasValueSatisfying(rr -> {
            assertEquals(record.getDatefield(), rr.getDatefield());
            assertEquals(record.getDecimal100field(), rr.getDecimal100field());
            assertEquals(record.getDecimal155field(), rr.getDecimal155field());
            assertEquals(record.getDecimal30field(), rr.getDecimal30field());
            assertEquals(newRecord.getDecimal60field(), rr.getDecimal60field());
            assertEquals(newRecord.getFirstname(), rr.getFirstname());
            assertEquals(record.getId1(), rr.getId1());
            assertEquals(record.getId2(), rr.getId2());
            assertEquals(record.getLastname(), rr.getLastname());
            assertEquals(record.getTimefield(), rr.getTimefield());
            assertEquals(record.getTimestampfield(), rr.getTimestampfield());
        });
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.dsql.model.Pkfields) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)267 SqlSession (org.apache.ibatis.session.SqlSession)243 ArrayList (java.util.ArrayList)39 Pkfields (mbg.test.mb3.generated.annotated.flat.model.Pkfields)23 Pkfields (mbg.test.mb3.generated.dsql.model.Pkfields)23 Pkfields (mbg.test.mb3.generated.flat.model.Pkfields)23 Pkfields (mbg.test.mb3.generated.mixed.flat.model.Pkfields)23 PkfieldsMapper (mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper)17 Pkfields (mbg.test.mb3.generated.annotated.conditional.model.Pkfields)17 PkfieldsMapper (mbg.test.mb3.generated.annotated.flat.mapper.PkfieldsMapper)17 PkfieldsMapper (mbg.test.mb3.generated.conditional.mapper.PkfieldsMapper)17 Pkfields (mbg.test.mb3.generated.conditional.model.Pkfields)17 PkfieldsMapper (mbg.test.mb3.generated.flat.mapper.PkfieldsMapper)17 PkfieldsMapper (mbg.test.mb3.generated.mixed.conditional.mapper.PkfieldsMapper)17 Pkfields (mbg.test.mb3.generated.mixed.conditional.model.Pkfields)17 PkfieldsMapper (mbg.test.mb3.generated.mixed.flat.mapper.PkfieldsMapper)17 SQLException (java.sql.SQLException)16 PkfieldsDAO (mbg.test.ib2j2.generated.hierarchical.dao.PkfieldsDAO)16 Pkfields (mbg.test.ib2j2.generated.hierarchical.model.Pkfields)16 PkfieldsDAO (mbg.test.ib2j5.generated.hierarchical.dao.PkfieldsDAO)16