Search in sources :

Example 36 with PkfieldsMapper

use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper in project generator by mybatis.

the class UpdateByExampleTest method testPKFieldsUpdateByExample.

@Test
public void testPKFieldsUpdateByExample() {
    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.setFirstname("Fred");
        record.setId1(3);
        record.setId2(4);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andId1EqualTo(3).andId2EqualTo(4);
        int rows = mapper.updateByExample(record, example);
        assertEquals(1, rows);
        example.clear();
        example.createCriteria().andFirstnameEqualTo("Fred").andLastnameIsNull().andId1EqualTo(3).andId2EqualTo(4);
        long returnedRows = mapper.countByExample(example);
        assertEquals(1, 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 37 with PkfieldsMapper

use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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 38 with PkfieldsMapper

use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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 39 with PkfieldsMapper

use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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 40 with PkfieldsMapper

use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)243 Test (org.junit.jupiter.api.Test)243 ArrayList (java.util.ArrayList)28 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 Pkfields (mbg.test.mb3.generated.annotated.flat.model.Pkfields)17 PkfieldsMapper (mbg.test.mb3.generated.annotated.hierarchical.mapper.PkfieldsMapper)17 Pkfields (mbg.test.mb3.generated.annotated.hierarchical.model.Pkfields)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 Pkfields (mbg.test.mb3.generated.flat.model.Pkfields)17 PkfieldsMapper (mbg.test.mb3.generated.hierarchical.mapper.PkfieldsMapper)17 Pkfields (mbg.test.mb3.generated.hierarchical.model.Pkfields)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 Pkfields (mbg.test.mb3.generated.mixed.flat.model.Pkfields)17 PkfieldsMapper (mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper)16