Search in sources :

Example 36 with AwfulTableMapper

use of mbg.test.mb3.generated.flat.mapper.AwfulTableMapper in project generator by mybatis.

the class DynamicSqlTest method testAwfulTablecount.

@Test
public void testAwfulTablecount() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("fred2@fred.com");
        record.setEmailaddress("alsofred2@fred.com");
        record.setFirstFirstName("fred11");
        record.setFrom("from from field");
        record.setId1(11);
        record.setId2(22);
        record.setId5(55);
        record.setId6(66);
        record.setId7(77);
        record.setSecondFirstName("fred22");
        record.setThirdFirstName("fred33");
        mapper.insert(record);
        long rows = mapper.count(dsl -> dsl.where(awfulTable.eMail, isLike("fred@%")));
        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) AwfulTableMapper(mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.dsql.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Example 37 with AwfulTableMapper

use of mbg.test.mb3.generated.flat.mapper.AwfulTableMapper in project generator by mybatis.

the class DynamicSqlTest method testAwfulTableSelectByPrimaryKey.

@Test
public void testAwfulTableSelectByPrimaryKey() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        AwfulTable record1 = new AwfulTable();
        record1.seteMail("fred2@fred.com");
        record1.setEmailaddress("alsofred2@fred.com");
        record1.setFirstFirstName("fred11");
        record1.setFrom("from from field");
        record1.setId1(11);
        record1.setId2(22);
        record1.setId5(55);
        record1.setId6(66);
        record1.setId7(77);
        record1.setSecondFirstName("fred22");
        record1.setThirdFirstName("fred33");
        mapper.insert(record1);
        Integer generatedKey = record1.getCustomerId();
        Optional<AwfulTable> returnedRecord = mapper.selectByPrimaryKey(generatedKey);
        assertThat(returnedRecord).hasValueSatisfying(rr -> {
            assertEquals(record1.getCustomerId(), rr.getCustomerId());
            assertEquals(record1.geteMail(), rr.geteMail());
            assertEquals(record1.getEmailaddress(), rr.getEmailaddress());
            assertEquals(record1.getFirstFirstName(), rr.getFirstFirstName());
            assertEquals(record1.getFrom(), rr.getFrom());
            assertEquals(record1.getId1(), rr.getId1());
            assertEquals(record1.getId2(), rr.getId2());
            assertEquals(record1.getId5(), rr.getId5());
            assertEquals(record1.getId6(), rr.getId6());
            assertEquals(record1.getId7(), rr.getId7());
            assertEquals(record1.getSecondFirstName(), rr.getSecondFirstName());
            assertEquals(record1.getThirdFirstName(), rr.getThirdFirstName());
        });
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.dsql.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Example 38 with AwfulTableMapper

use of mbg.test.mb3.generated.flat.mapper.AwfulTableMapper in project generator by mybatis.

the class DynamicSqlTest method testAwfulTableSelectByExampleNoCriteria.

@Test
public void testAwfulTableSelectByExampleNoCriteria() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("wilma@wilma.com");
        record.setEmailaddress("alsoWilma@wilma.com");
        record.setFirstFirstName("wilma1");
        record.setFrom("from field");
        record.setId1(11);
        record.setId2(22);
        record.setId5(55);
        record.setId6(66);
        record.setId7(77);
        record.setSecondFirstName("wilma2");
        record.setThirdFirstName("wilma3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("pebbles@pebbles.com");
        record.setEmailaddress("alsoPebbles@pebbles.com");
        record.setFirstFirstName("pebbles1");
        record.setFrom("from field");
        record.setId1(111);
        record.setId2(222);
        record.setId5(555);
        record.setId6(666);
        record.setId7(777);
        record.setSecondFirstName("pebbles2");
        record.setThirdFirstName("pebbles3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("barney@barney.com");
        record.setEmailaddress("alsoBarney@barney.com");
        record.setFirstFirstName("barney1");
        record.setFrom("from field");
        record.setId1(1111);
        record.setId2(2222);
        record.setId5(5555);
        record.setId6(6666);
        record.setId7(7777);
        record.setSecondFirstName("barney2");
        record.setThirdFirstName("barney3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("betty@betty.com");
        record.setEmailaddress("alsoBetty@betty.com");
        record.setFirstFirstName("betty1");
        record.setFrom("from field");
        record.setId1(11111);
        record.setId2(22222);
        record.setId5(55555);
        record.setId6(66666);
        record.setId7(77777);
        record.setSecondFirstName("betty2");
        record.setThirdFirstName("betty3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("bammbamm@bammbamm.com");
        record.setEmailaddress("alsoBammbamm@bammbamm.com");
        record.setFirstFirstName("bammbamm1");
        record.setFrom("from field");
        record.setId1(111111);
        record.setId2(222222);
        record.setId5(555555);
        record.setId6(666666);
        record.setId7(777777);
        record.setSecondFirstName("bammbamm2");
        record.setThirdFirstName("bammbamm3");
        mapper.insert(record);
        List<AwfulTable> answer = mapper.select(SelectDSLCompleter.allRowsOrderedBy(awfulTable.customerId.descending()));
        assertEquals(6, answer.size());
        AwfulTable returnedRecord = answer.get(0);
        assertEquals(111111, returnedRecord.getId1().intValue());
        returnedRecord = answer.get(1);
        assertEquals(11111, returnedRecord.getId1().intValue());
        returnedRecord = answer.get(2);
        assertEquals(1111, returnedRecord.getId1().intValue());
        returnedRecord = answer.get(3);
        assertEquals(111, returnedRecord.getId1().intValue());
        returnedRecord = answer.get(4);
        assertEquals(11, returnedRecord.getId1().intValue());
        returnedRecord = answer.get(5);
        assertEquals(1, returnedRecord.getId1().intValue());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.dsql.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Example 39 with AwfulTableMapper

use of mbg.test.mb3.generated.flat.mapper.AwfulTableMapper in project generator by mybatis.

the class FlatJava5Test method testAwfulTableCountByExample.

@Test
public void testAwfulTableCountByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("fred2@fred.com");
        record.setEmailaddress("alsofred2@fred.com");
        record.setFirstFirstName("fred11");
        record.setFrom("from from field");
        record.setId1(11);
        record.setId2(22);
        record.setId5(55);
        record.setId6(66);
        record.setId7(77);
        record.setSecondFirstName("fred22");
        record.setThirdFirstName("fred33");
        mapper.insert(record);
        AwfulTableExample example = new AwfulTableExample();
        example.createCriteria().andEMailLike("fred@%");
        long rows = mapper.countByExample(example);
        assertEquals(1, rows);
        example.clear();
        rows = mapper.countByExample(example);
        assertEquals(2, rows);
    } finally {
        sqlSession.close();
    }
}
Also used : AwfulTableExample(mbg.test.mb3.generated.annotated.flat.model.AwfulTableExample) SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.annotated.flat.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.annotated.flat.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Example 40 with AwfulTableMapper

use of mbg.test.mb3.generated.flat.mapper.AwfulTableMapper in project generator by mybatis.

the class FlatJava5Test method testAwfulTableUpdateByPrimaryKey.

@Test
public void testAwfulTableUpdateByPrimaryKey() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        Integer generatedCustomerId = record.getCustomerId();
        record.setId1(11);
        record.setId2(22);
        int rows = mapper.updateByPrimaryKey(record);
        assertEquals(1, rows);
        AwfulTable returnedRecord = mapper.selectByPrimaryKey(generatedCustomerId);
        assertEquals(generatedCustomerId, returnedRecord.getCustomerId());
        assertEquals(record.geteMail(), returnedRecord.geteMail());
        assertEquals(record.getEmailaddress(), returnedRecord.getEmailaddress());
        assertEquals(record.getFirstFirstName(), returnedRecord.getFirstFirstName());
        assertEquals(record.getFrom(), returnedRecord.getFrom());
        assertEquals(record.getId1(), returnedRecord.getId1());
        assertEquals(record.getId2(), returnedRecord.getId2());
        assertEquals(record.getId5(), returnedRecord.getId5());
        assertEquals(record.getId6(), returnedRecord.getId6());
        assertEquals(record.getId7(), returnedRecord.getId7());
        assertEquals(record.getSecondFirstName(), returnedRecord.getSecondFirstName());
        assertEquals(record.getThirdFirstName(), returnedRecord.getThirdFirstName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.annotated.flat.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.annotated.flat.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)163 Test (org.junit.jupiter.api.Test)163 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)17 AwfulTable (mbg.test.mb3.generated.dsql.model.AwfulTable)17 AwfulTableMapper (mbg.test.mb3.generated.annotated.conditional.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.annotated.conditional.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.annotated.flat.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.annotated.flat.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.annotated.hierarchical.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.annotated.hierarchical.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.conditional.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.conditional.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.flat.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.flat.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.hierarchical.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.hierarchical.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.mixed.conditional.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.mixed.conditional.model.AwfulTable)16 AwfulTableMapper (mbg.test.mb3.generated.mixed.flat.mapper.AwfulTableMapper)16 AwfulTable (mbg.test.mb3.generated.mixed.flat.model.AwfulTable)16