Search in sources :

Example 41 with SqlSession

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

the class HierarchicalJava5Test method testPKFieldsBlobsSelectByExampleWithBlobs.

@Test
public void testPKFieldsBlobsSelectByExampleWithBlobs() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
        PkfieldsblobsWithBLOBs record = new PkfieldsblobsWithBLOBs(3, 4, "Jeff", "Smith", generateRandomBlob());
        mapper.insert(record);
        record = new PkfieldsblobsWithBLOBs(5, 6, "Scott", "Jones", generateRandomBlob());
        mapper.insert(record);
        PkfieldsblobsExample example = new PkfieldsblobsExample();
        example.createCriteria().andId2EqualTo(6);
        List<PkfieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        PkfieldsblobsWithBLOBs newRecord = answer.get(0);
        assertEquals(record.getId1(), newRecord.getId1());
        assertEquals(record.getId2(), newRecord.getId2());
        assertEquals(record.getFirstname(), newRecord.getFirstname());
        assertEquals(record.getLastname(), newRecord.getLastname());
        assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsblobsExample(mbg.test.mb3.generated.hierarchical.immutable.model.PkfieldsblobsExample) PkfieldsblobsWithBLOBs(mbg.test.mb3.generated.hierarchical.immutable.model.PkfieldsblobsWithBLOBs) PkfieldsblobsMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.PkfieldsblobsMapper) Test(org.junit.Test)

Example 42 with SqlSession

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

the class HierarchicalJava5Test method testPKFieldsDeleteByExample.

@Test
public void testPKFieldsDeleteByExample() {
    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);
        PkfieldsExample example = new PkfieldsExample();
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
        example = new PkfieldsExample();
        example.createCriteria().andLastnameLike("J%");
        int rows = mapper.deleteByExample(example);
        assertEquals(1, rows);
        example = new PkfieldsExample();
        answer = mapper.selectByExample(example);
        assertEquals(1, 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 43 with SqlSession

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

the class HierarchicalJava5Test method testFieldsBlobsSelectByExampleWithBlobs.

@Test
public void testFieldsBlobsSelectByExampleWithBlobs() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        FieldsblobsMapper mapper = sqlSession.getMapper(FieldsblobsMapper.class);
        FieldsblobsWithBLOBs record = new FieldsblobsWithBLOBs("Jeff", "Smith", generateRandomBlob(), generateRandomBlob(), null);
        mapper.insert(record);
        record = new FieldsblobsWithBLOBs("Scott", "Jones", generateRandomBlob(), generateRandomBlob(), null);
        mapper.insert(record);
        FieldsblobsExample example = new FieldsblobsExample();
        example.createCriteria().andFirstnameLike("S%");
        List<FieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        FieldsblobsWithBLOBs newRecord = answer.get(0);
        assertEquals(record.getFirstname(), newRecord.getFirstname());
        assertEquals(record.getLastname(), newRecord.getLastname());
        assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
        assertTrue(blobsAreEqual(record.getBlob2(), newRecord.getBlob2()));
    } finally {
        sqlSession.close();
    }
}
Also used : FieldsblobsWithBLOBs(mbg.test.mb3.generated.hierarchical.immutable.model.FieldsblobsWithBLOBs) SqlSession(org.apache.ibatis.session.SqlSession) FieldsblobsExample(mbg.test.mb3.generated.hierarchical.immutable.model.FieldsblobsExample) FieldsblobsMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.FieldsblobsMapper) Test(org.junit.Test)

Example 44 with SqlSession

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

the class HierarchicalJava5Test method testPKOnlySelectByExample.

@Test
public void testPKOnlySelectByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        PkonlyKey key = new PkonlyKey(1, 3);
        mapper.insert(key);
        key = new PkonlyKey(5, 6);
        mapper.insert(key);
        key = new PkonlyKey(7, 8);
        mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        example.createCriteria().andIdGreaterThan(4);
        List<PkonlyKey> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.hierarchical.immutable.model.PkonlyExample) PkonlyKey(mbg.test.mb3.generated.hierarchical.immutable.model.PkonlyKey) Test(org.junit.Test)

Example 45 with SqlSession

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

the class HierarchicalJava5Test method testPKFieldsUpdateByPrimaryKey.

@Test
public void testPKFieldsUpdateByPrimaryKey() {
    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.setFirstname("Scott");
        record.setLastname("Jones");
        int rows = mapper.updateByPrimaryKey(record);
        assertEquals(1, rows);
        PkfieldsKey key = new PkfieldsKey();
        key.setId1(1);
        key.setId2(2);
        Pkfields record2 = mapper.selectByPrimaryKey(key);
        assertEquals(record.getFirstname(), record2.getFirstname());
        assertEquals(record.getLastname(), record2.getLastname());
        assertEquals(record.getId1(), record2.getId1());
        assertEquals(record.getId2(), record2.getId2());
    } 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) PkfieldsKey(mbg.test.mb3.generated.hierarchical.immutable.model.PkfieldsKey) 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