Search in sources :

Example 71 with SqlSession

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

the class ConditionalJava5Test method testFieldsBlobsInsert.

@Test
public void testFieldsBlobsInsert() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        FieldsblobsMapper mapper = sqlSession.getMapper(FieldsblobsMapper.class);
        FieldsblobsWithBLOBs record = new FieldsblobsWithBLOBs();
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setBlob1(generateRandomBlob());
        record.setBlob2(generateRandomBlob());
        mapper.insert(record);
        record = new FieldsblobsWithBLOBs();
        record.setFirstname("Bob");
        record.setLastname("Smith");
        record.setBlob1(generateRandomBlob());
        record.setBlob2(generateRandomBlob());
        mapper.insert(record);
        FieldsblobsExample example = new FieldsblobsExample();
        example.createCriteria().andFirstnameEqualTo("Bob");
        List<FieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        FieldsblobsWithBLOBs returnedRecord = answer.get(0);
        assertEquals(record.getFirstname(), returnedRecord.getFirstname());
        assertEquals(record.getLastname(), returnedRecord.getLastname());
        assertTrue(blobsAreEqual(record.getBlob1(), returnedRecord.getBlob1()));
        assertTrue(blobsAreEqual(record.getBlob2(), returnedRecord.getBlob2()));
    } finally {
        sqlSession.close();
    }
}
Also used : FieldsblobsWithBLOBs(mbg.test.mb3.generated.annotated.conditional.model.FieldsblobsWithBLOBs) SqlSession(org.apache.ibatis.session.SqlSession) FieldsblobsExample(mbg.test.mb3.generated.annotated.conditional.model.FieldsblobsExample) FieldsblobsMapper(mbg.test.mb3.generated.annotated.conditional.mapper.FieldsblobsMapper) Test(org.junit.jupiter.api.Test)

Example 72 with SqlSession

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

the class ConditionalJava5Test method testPKFieldsSelectByPrimaryKey.

@Test
public void testPKFieldsSelectByPrimaryKey() {
    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);
        PkfieldsKey key = new PkfieldsKey();
        key.setId1(3);
        key.setId2(4);
        Pkfields newRecord = mapper.selectByPrimaryKey(key);
        assertNotNull(newRecord);
        assertEquals(record.getFirstname(), newRecord.getFirstname());
        assertEquals(record.getLastname(), newRecord.getLastname());
        assertEquals(record.getId1(), newRecord.getId1());
        assertEquals(record.getId2(), newRecord.getId2());
    } 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) PkfieldsKey(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsKey) Test(org.junit.jupiter.api.Test)

Example 73 with SqlSession

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

the class ConditionalJava5Test method testFieldsOnlySelectByExampleNoCriteria.

@Test
public void testFieldsOnlySelectByExampleNoCriteria() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        FieldsonlyMapper mapper = sqlSession.getMapper(FieldsonlyMapper.class);
        Fieldsonly record = new Fieldsonly();
        record.setDoublefield(11.22);
        record.setFloatfield(33.44);
        record.setIntegerfield(5);
        mapper.insert(record);
        record = new Fieldsonly();
        record.setDoublefield(44.55);
        record.setFloatfield(66.77);
        record.setIntegerfield(8);
        mapper.insert(record);
        record = new Fieldsonly();
        record.setDoublefield(88.99);
        record.setFloatfield(100.111);
        record.setIntegerfield(9);
        mapper.insert(record);
        FieldsonlyExample example = new FieldsonlyExample();
        example.createCriteria();
        List<Fieldsonly> answer = mapper.selectByExample(example);
        assertEquals(3, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : FieldsonlyExample(mbg.test.mb3.generated.annotated.conditional.model.FieldsonlyExample) SqlSession(org.apache.ibatis.session.SqlSession) FieldsonlyMapper(mbg.test.mb3.generated.annotated.conditional.mapper.FieldsonlyMapper) Fieldsonly(mbg.test.mb3.generated.annotated.conditional.model.Fieldsonly) Test(org.junit.jupiter.api.Test)

Example 74 with SqlSession

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

the class ConditionalJava5Test method testAwfulTableSelectByExampleLike.

@Test
public void testAwfulTableSelectByExampleLike() {
    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().andFirstFirstNameLike("b%");
        example.setOrderByClause("\"A_CuStOmEr iD\"");
        List<AwfulTable> answer = mapper.selectByExample(example);
        assertEquals(3, answer.size());
        AwfulTable returnedRecord = answer.get(0);
        assertEquals(1111, returnedRecord.getId1().intValue());
        assertEquals(2222, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(11111, returnedRecord.getId1().intValue());
        assertEquals(22222, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(2);
        assertEquals(111111, returnedRecord.getId1().intValue());
        assertEquals(222222, 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 75 with SqlSession

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

the class GeneratedAlwaysTest method testUpdateByPrimaryKeyWithBlobs.

@Test
public void testUpdateByPrimaryKeyWithBlobs() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
        Generatedalwaystest gaTest = new Generatedalwaystest();
        gaTest.setId(1);
        gaTest.setName("fred");
        // should be ignored
        gaTest.setIdPlus1(55);
        // should be ignored
        gaTest.setIdPlus2(66);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        int rows = mapper.insert(gaTest);
        assertEquals(1, rows);
        gaTest.setName("barney");
        // should be ignored
        gaTest.setIdPlus1(77);
        // should be ignored
        gaTest.setIdPlus2(88);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        rows = mapper.updateByPrimaryKey(gaTest);
        assertEquals(1, rows);
        List<Generatedalwaystest> returnedRecords = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(1, returnedRecords.size());
        Generatedalwaystest returnedRecord = returnedRecords.get(0);
        assertEquals(1, returnedRecord.getId().intValue());
        assertEquals(2, returnedRecord.getIdPlus1().intValue());
        assertEquals(3, returnedRecord.getIdPlus2().intValue());
        assertEquals("barney", returnedRecord.getName());
        assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) SqlSession(org.apache.ibatis.session.SqlSession) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) 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