Search in sources :

Example 26 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();
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setBlob1(generateRandomBlob());
        record.setBlob2(generateRandomBlob());
        mapper.insert(record);
        record = new FieldsblobsWithBLOBs();
        record.setFirstname("Scott");
        record.setLastname("Jones");
        record.setBlob1(generateRandomBlob());
        record.setBlob2(generateRandomBlob());
        mapper.insert(record);
        FieldsblobsWithBLOBs newRecord = new FieldsblobsWithBLOBs();
        newRecord.setLastname("Doe");
        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.model.FieldsblobsWithBLOBs) SqlSession(org.apache.ibatis.session.SqlSession) FieldsblobsExample(mbg.test.mb3.generated.hierarchical.model.FieldsblobsExample) FieldsblobsMapper(mbg.test.mb3.generated.hierarchical.mapper.FieldsblobsMapper) Test(org.junit.Test)

Example 27 with SqlSession

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

the class UpdateByExampleTest method testFieldsOnlyUpdateByExample.

@Test
public void testFieldsOnlyUpdateByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        FieldsOnlyMapper mapper = sqlSession.getMapper(FieldsOnlyMapper.class);
        FieldsOnlyEntity record = new FieldsOnlyEntity();
        record.setDoublefield(11.22);
        record.setFloatfield(33.44);
        record.setIntegerfield(5);
        mapper.insert(record);
        record = new FieldsOnlyEntity();
        record.setDoublefield(44.55);
        record.setFloatfield(66.77);
        record.setIntegerfield(8);
        mapper.insert(record);
        record = new FieldsOnlyEntity();
        record.setDoublefield(88.99);
        record.setFloatfield(100.111);
        record.setIntegerfield(9);
        mapper.insert(record);
        record = new FieldsOnlyEntity();
        record.setIntegerfield(22);
        FieldsOnlyEntityExample example = new FieldsOnlyEntityExample();
        example.createCriteria().andIntegerfieldEqualTo(5);
        int rows = mapper.updateByExample(record, example);
        assertEquals(1, rows);
        example.clear();
        example.createCriteria().andIntegerfieldEqualTo(22);
        List<FieldsOnlyEntity> answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        record = answer.get(0);
        assertNull(record.getDoublefield());
        assertNull(record.getFloatfield());
        assertEquals(record.getIntegerfield().intValue(), 22);
    } finally {
        sqlSession.close();
    }
}
Also used : FieldsOnlyEntityExample(mbg.test.mb3.generated.hierarchical.model.subpackage.FieldsOnlyEntityExample) SqlSession(org.apache.ibatis.session.SqlSession) FieldsOnlyEntity(mbg.test.mb3.generated.hierarchical.model.subpackage.FieldsOnlyEntity) FieldsOnlyMapper(mbg.test.mb3.generated.hierarchical.mapper.different.subpackage.FieldsOnlyMapper) Test(org.junit.Test)

Example 28 with SqlSession

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

the class HierarchicalJava5Test method testPKFieldsBlobsUpdateByPrimaryKeyWithoutBLOBs.

@Test
public void testPKFieldsBlobsUpdateByPrimaryKeyWithoutBLOBs() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
        PkfieldsblobsWithBLOBs record = new PkfieldsblobsWithBLOBs(3, 4, "Jeff", "Smith", generateRandomBlob());
        mapper.insert(record);
        Pkfieldsblobs updateRecord = new Pkfieldsblobs(3, 4, "Scott", "Jones");
        int rows = mapper.updateByPrimaryKey(updateRecord);
        assertEquals(1, rows);
        PkfieldsblobsKey key = new PkfieldsblobsKey(3, 4);
        PkfieldsblobsWithBLOBs newRecord = mapper.selectByPrimaryKey(key);
        assertEquals(updateRecord.getFirstname(), newRecord.getFirstname());
        assertEquals(updateRecord.getLastname(), newRecord.getLastname());
        assertEquals(record.getId1(), newRecord.getId1());
        assertEquals(record.getId2(), newRecord.getId2());
        assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
    } finally {
        sqlSession.close();
    }
}
Also used : Pkfieldsblobs(mbg.test.mb3.generated.hierarchical.immutable.model.Pkfieldsblobs) PkfieldsblobsKey(mbg.test.mb3.generated.hierarchical.immutable.model.PkfieldsblobsKey) SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsblobsWithBLOBs(mbg.test.mb3.generated.hierarchical.immutable.model.PkfieldsblobsWithBLOBs) PkfieldsblobsMapper(mbg.test.mb3.generated.hierarchical.immutable.mapper.PkfieldsblobsMapper) Test(org.junit.Test)

Example 29 with SqlSession

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

the class HierarchicalJava5Test method testPKBlobsSelectByExampleWithoutBlobs.

@Test
public void testPKBlobsSelectByExampleWithoutBlobs() {
    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();
        example.createCriteria().andIdGreaterThan(4);
        List<PkblobsKey> answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        PkblobsKey key = answer.get(0);
        assertFalse(key instanceof PkblobsWithBLOBs);
        assertEquals(6, key.getId().intValue());
    } 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 30 with SqlSession

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

the class HierarchicalJava5Test method testPKFieldsSelectByExampleLike.

@Test
public void testPKFieldsSelectByExampleLike() {
    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().andFirstnameLike("B%");
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(3, answer.size());
        Pkfields returnedRecord = answer.get(0);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(1, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(2, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(2);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
    } 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)

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