Search in sources :

Example 61 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class ConditionalJava5Test method testPKFieldsSelectByExampleNotLike.

@Test
public void testPKFieldsSelectByExampleNotLike() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        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);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andFirstnameNotLike("B%");
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(3, answer.size());
        Pkfields returnedRecord = answer.get(0);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(1, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(2, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(2);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.annotated.conditional.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsExample) Test(org.junit.jupiter.api.Test)

Example 62 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class ConditionalJava5Test method testPKFieldsSelectByExampleDateTimeFields.

@Test
public void testPKFieldsSelectByExampleDateTimeFields() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2009);
    calendar.set(Calendar.MONTH, Calendar.JUNE);
    calendar.set(Calendar.DAY_OF_MONTH, 15);
    calendar.set(Calendar.HOUR, 10);
    calendar.set(Calendar.MINUTE, 10);
    calendar.set(Calendar.SECOND, 10);
    try {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setId1(1);
        record.setId2(1);
        record.setDatefield(calendar.getTime());
        record.setTimefield(calendar.getTime());
        mapper.insert(record);
        record = new Pkfields();
        record.setId1(1);
        record.setId2(2);
        calendar.set(Calendar.DAY_OF_MONTH, 16);
        calendar.set(Calendar.MINUTE, 11);
        record.setDatefield(calendar.getTime());
        record.setTimefield(calendar.getTime());
        mapper.insert(record);
        record = new Pkfields();
        record.setId1(1);
        record.setId2(3);
        calendar.set(Calendar.DAY_OF_MONTH, 17);
        calendar.set(Calendar.MINUTE, 12);
        record.setDatefield(calendar.getTime());
        record.setTimefield(calendar.getTime());
        mapper.insert(record);
        record = new Pkfields();
        record.setId1(2);
        record.setId2(1);
        calendar.set(Calendar.DAY_OF_MONTH, 18);
        calendar.set(Calendar.MINUTE, 13);
        record.setDatefield(calendar.getTime());
        record.setTimefield(calendar.getTime());
        mapper.insert(record);
        record = new Pkfields();
        record.setId1(2);
        record.setId2(2);
        calendar.set(Calendar.DAY_OF_MONTH, 19);
        calendar.set(Calendar.MINUTE, 14);
        record.setDatefield(calendar.getTime());
        record.setTimefield(calendar.getTime());
        mapper.insert(record);
        record = new Pkfields();
        record.setId1(2);
        record.setId2(3);
        calendar.set(Calendar.DAY_OF_MONTH, 20);
        calendar.set(Calendar.MINUTE, 15);
        record.setDatefield(calendar.getTime());
        record.setTimefield(calendar.getTime());
        mapper.insert(record);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andDatefieldEqualTo(calendar.getTime());
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        example.clear();
        example.createCriteria().andDatefieldLessThan(calendar.getTime());
        answer = mapper.selectByExample(example);
        assertEquals(5, answer.size());
        calendar.set(Calendar.MINUTE, 12);
        example.clear();
        example.createCriteria().andTimefieldEqualTo(calendar.getTime());
        answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        example.clear();
        example.createCriteria().andTimefieldGreaterThan(calendar.getTime());
        answer = mapper.selectByExample(example);
        assertEquals(3, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper) Calendar(java.util.Calendar) Pkfields(mbg.test.mb3.generated.annotated.conditional.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsExample) Test(org.junit.jupiter.api.Test)

Example 63 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class ConditionalJava5Test method testPKFieldsBlobsDeleteByPrimaryKey.

@Test
public void testPKFieldsBlobsDeleteByPrimaryKey() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
        Pkfieldsblobs record = new Pkfieldsblobs();
        record.setId1(3);
        record.setId2(4);
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setBlob1(generateRandomBlob());
        mapper.insert(record);
        record = new Pkfieldsblobs();
        record.setId1(5);
        record.setId2(6);
        record.setFirstname("Scott");
        record.setLastname("Jones");
        record.setBlob1(generateRandomBlob());
        mapper.insert(record);
        PkfieldsblobsExample example = new PkfieldsblobsExample();
        List<Pkfieldsblobs> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
        PkfieldsblobsKey key = new PkfieldsblobsKey();
        key.setId1(5);
        key.setId2(6);
        int rows = mapper.deleteByPrimaryKey(key);
        assertEquals(1, rows);
        example = new PkfieldsblobsExample();
        answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : Pkfieldsblobs(mbg.test.mb3.generated.annotated.conditional.model.Pkfieldsblobs) PkfieldsblobsKey(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsblobsKey) SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsblobsExample(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsblobsExample) PkfieldsblobsMapper(mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsblobsMapper) Test(org.junit.jupiter.api.Test)

Example 64 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class ConditionalJava5Test method testAwfulTableSelectByExampleNotLike.

@Test
public void testAwfulTableSelectByExampleNotLike() {
    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("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);
        AwfulTableExample example = new AwfulTableExample();
        example.createCriteria().andFirstFirstNameNotLike("b%");
        example.setOrderByClause("\"A_CuStOmEr iD\"");
        List<AwfulTable> answer = mapper.selectByExample(example);
        assertEquals(3, answer.size());
        AwfulTable returnedRecord = answer.get(0);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(2, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(11, returnedRecord.getId1().intValue());
        assertEquals(22, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(2);
        assertEquals(111, returnedRecord.getId1().intValue());
        assertEquals(222, returnedRecord.getId2().intValue());
    } finally {
        sqlSession.close();
    }
}
Also used : AwfulTableExample(mbg.test.mb3.generated.annotated.conditional.model.AwfulTableExample) SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.annotated.conditional.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.annotated.conditional.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Example 65 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class ConditionalJava5Test method testPKFieldsSelectByExampleBetween.

@Test
public void testPKFieldsSelectByExampleBetween() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        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);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andId2Between(1, 3);
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(6, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.annotated.conditional.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsExample) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)2117 Test (org.junit.jupiter.api.Test)1845 BaseDataTest (org.apache.ibatis.BaseDataTest)593 Test (org.junit.Test)127 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)104 Reader (java.io.Reader)97 User (com.github.pagehelper.model.User)87 ArrayList (java.util.ArrayList)84 UserMapper (com.github.pagehelper.mapper.UserMapper)75 Connection (java.sql.Connection)68 FirstName (mbg.test.common.FirstName)60 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)60 HashMap (java.util.HashMap)59 BeforeClass (org.junit.BeforeClass)56 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)54 RowBounds (org.apache.ibatis.session.RowBounds)36 Map (java.util.Map)34 Date (java.util.Date)33 List (java.util.List)24 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)23