Search in sources :

Example 36 with SqlSession

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

the class HierarchicalJava5Test method testPKBlobsDeleteByExample.

@Test
public void testPKBlobsDeleteByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkblobsMapper mapper = sqlSession.getMapper(PkblobsMapper.class);
        PkblobsWithBLOBs record = new PkblobsWithBLOBs(3, generateRandomBlob(), generateRandomBlob(), "Long String 1");
        mapper.insert(record);
        record = new PkblobsWithBLOBs(6, generateRandomBlob(), generateRandomBlob(), "Long String 2");
        mapper.insert(record);
        PkblobsExample example = new PkblobsExample();
        List<PkblobsKey> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
        example = new PkblobsExample();
        example.createCriteria().andIdLessThan(4);
        int rows = mapper.deleteByExample(example);
        assertEquals(1, rows);
        example = new PkblobsExample();
        answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkblobsExample(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsExample) PkblobsWithBLOBs(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsWithBLOBs) PkblobsKey(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsKey) SqlSession(org.apache.ibatis.session.SqlSession) PkblobsMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.PkblobsMapper) Test(org.junit.Test)

Example 37 with SqlSession

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

the class HierarchicalJava5Test method testPKBlobsSelectByPrimaryKey.

@Test
public void testPKBlobsSelectByPrimaryKey() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkblobsMapper mapper = sqlSession.getMapper(PkblobsMapper.class);
        PkblobsWithBLOBs record = new PkblobsWithBLOBs(3, generateRandomBlob(), generateRandomBlob(), "Long String 1");
        mapper.insert(record);
        record = new PkblobsWithBLOBs(6, generateRandomBlob(), generateRandomBlob(), "Long String 2");
        mapper.insert(record);
        PkblobsKey key = new PkblobsKey(6);
        PkblobsWithBLOBs newRecord = mapper.selectByPrimaryKey(key);
        assertNotNull(newRecord);
        assertEquals(record.getId(), newRecord.getId());
        assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
        assertTrue(blobsAreEqual(record.getBlob2(), newRecord.getBlob2()));
        assertEquals(record.getCharacterlob(), newRecord.getCharacterlob());
    } finally {
        sqlSession.close();
    }
}
Also used : PkblobsWithBLOBs(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsWithBLOBs) PkblobsKey(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsKey) SqlSession(org.apache.ibatis.session.SqlSession) PkblobsMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.PkblobsMapper) Test(org.junit.Test)

Example 38 with SqlSession

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

the class HierarchicalJava5Test method testFieldsOnlySelectByExampleNoCriteria.

@Test
public void testFieldsOnlySelectByExampleNoCriteria() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        FieldsonlyMapper mapper = sqlSession.getMapper(FieldsonlyMapper.class);
        Fieldsonly record = new Fieldsonly(5, 11.22, 33.44);
        mapper.insert(record);
        record = new Fieldsonly(8, 44.55, 66.77);
        mapper.insert(record);
        record = new Fieldsonly(9, 88.99, 100.111);
        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.hierarchical.immutable.model.FieldsonlyExample) SqlSession(org.apache.ibatis.session.SqlSession) FieldsonlyMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.FieldsonlyMapper) Fieldsonly(mbg.test.mb3.generated.hierarchical.immutable.model.Fieldsonly) Test(org.junit.Test)

Example 39 with SqlSession

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

the class HierarchicalJava5Test 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.hierarchical.immutable.mapper.PkfieldsMapper) Pkfields(mbg.test.mb3.generated.hierarchical.immutable.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.hierarchical.immutable.model.PkfieldsExample) Test(org.junit.Test)

Example 40 with SqlSession

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

the class HierarchicalJava5Test method testPKBlobsUpdateByPrimaryKeyWithBLOBs.

@Test
public void testPKBlobsUpdateByPrimaryKeyWithBLOBs() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkblobsMapper mapper = sqlSession.getMapper(PkblobsMapper.class);
        PkblobsWithBLOBs record = new PkblobsWithBLOBs(3, generateRandomBlob(), generateRandomBlob(), "Long String 1");
        mapper.insert(record);
        record = new PkblobsWithBLOBs(3, generateRandomBlob(), generateRandomBlob(), "Long String 2");
        int rows = mapper.updateByPrimaryKeyWithBLOBs(record);
        assertEquals(1, rows);
        PkblobsKey key = new PkblobsKey(3);
        PkblobsWithBLOBs newRecord = mapper.selectByPrimaryKey(key);
        assertNotNull(newRecord);
        assertEquals(record.getId(), newRecord.getId());
        assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
        assertTrue(blobsAreEqual(record.getBlob2(), newRecord.getBlob2()));
        assertEquals(record.getCharacterlob(), newRecord.getCharacterlob());
    } finally {
        sqlSession.close();
    }
}
Also used : PkblobsWithBLOBs(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsWithBLOBs) PkblobsKey(mbg.test.mb3.generated.hierarchical.immutable.model.PkblobsKey) SqlSession(org.apache.ibatis.session.SqlSession) PkblobsMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.PkblobsMapper) Test(org.junit.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)1671 Test (org.junit.Test)1561 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)85 Reader (java.io.Reader)83 Connection (java.sql.Connection)75 Country (com.github.pagehelper.model.Country)71 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)69 BeforeClass (org.junit.BeforeClass)62 ArrayList (java.util.ArrayList)59 CountryMapper (com.github.pagehelper.mapper.CountryMapper)57 BaseDataTest (org.apache.ibatis.BaseDataTest)48 HashMap (java.util.HashMap)47 FirstName (mbg.test.common.FirstName)45 RowBounds (org.apache.ibatis.session.RowBounds)31 Map (java.util.Map)28 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)27 Date (java.util.Date)26 Blog (org.apache.ibatis.domain.blog.Blog)13 AwfulTableMapper (mbg.test.mb3.generated.annotated.hierarchical.mapper.AwfulTableMapper)11 AwfulTable (mbg.test.mb3.generated.annotated.hierarchical.model.AwfulTable)11