Search in sources :

Example 11 with SqlSession

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

the class HierarchicalJava5Test method testFieldsOnlySelectByExample.

@Test
public void testFieldsOnlySelectByExample() {
    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().andIntegerfieldGreaterThan(5);
        List<Fieldsonly> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
        example = new FieldsonlyExample();
        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 12 with SqlSession

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

the class HierarchicalJava5Test method testPKOnlyCountByExample.

@Test
public void testPKOnlyCountByExample() {
    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);
        long rows = mapper.countByExample(example);
        assertEquals(2, rows);
        example.clear();
        rows = mapper.countByExample(example);
        assertEquals(3, rows);
    } 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 13 with SqlSession

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

the class UpdateByExampleTest method testPKBlobsUpdateByExampleWithoutBLOBs.

@Test
public void testPKBlobsUpdateByExampleWithoutBLOBs() {
    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 newRecord = new PkblobsKey(8);
        PkblobsExample example = new PkblobsExample();
        example.createCriteria().andIdGreaterThan(4);
        int rows = mapper.updateByExample(newRecord, example);
        assertEquals(1, rows);
        List<PkblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        PkblobsWithBLOBs returnedRecord = answer.get(0);
        assertEquals(8, returnedRecord.getId().intValue());
        assertTrue(blobsAreEqual(record.getBlob1(), returnedRecord.getBlob1()));
        assertTrue(blobsAreEqual(record.getBlob2(), returnedRecord.getBlob2()));
        assertEquals(record.getCharacterlob(), returnedRecord.getCharacterlob());
    } 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 14 with SqlSession

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

the class UpdateByExampleTest method testPKFieldsBlobsUpdateByExampleSelective.

@Test
public void testPKFieldsBlobsUpdateByExampleSelective() {
    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);
        PkfieldsblobsWithBLOBs newRecord = new PkfieldsblobsWithBLOBs(null, null, "Fred", null, null);
        PkfieldsblobsExample example = new PkfieldsblobsExample();
        example.createCriteria().andId1NotEqualTo(3);
        int rows = mapper.updateByExampleSelective(newRecord, example);
        assertEquals(1, rows);
        List<PkfieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        PkfieldsblobsWithBLOBs returnedRecord = answer.get(0);
        assertEquals(record.getId1(), returnedRecord.getId1());
        assertEquals(record.getId2(), returnedRecord.getId2());
        assertEquals(newRecord.getFirstname(), returnedRecord.getFirstname());
        assertEquals(record.getLastname(), returnedRecord.getLastname());
        assertTrue(blobsAreEqual(record.getBlob1(), returnedRecord.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 15 with SqlSession

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

the class UpdateByExampleTest method testFieldsBlobsUpdateByExampleSelective.

@Test
public void testFieldsBlobsUpdateByExampleSelective() {
    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);
        FieldsblobsWithBLOBs newRecord = new FieldsblobsWithBLOBs(null, "Doe", null, null, null);
        FieldsblobsExample example = new FieldsblobsExample();
        example.createCriteria().andFirstnameLike("S%");
        int rows = mapper.updateByExampleSelective(newRecord, example);
        assertEquals(1, rows);
        List<FieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        FieldsblobsWithBLOBs returnedRecord = answer.get(0);
        assertEquals(record.getFirstname(), returnedRecord.getFirstname());
        assertEquals(newRecord.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.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)

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