Search in sources :

Example 16 with SqlSession

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

the class UpdateByExampleTest method testFieldsOnlyUpdateByExampleSelective.

@Test
public void testFieldsOnlyUpdateByExampleSelective() {
    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);
        record = new Fieldsonly(null, 99d, null);
        FieldsonlyExample example = new FieldsonlyExample();
        example.createCriteria().andIntegerfieldGreaterThan(5);
        int rows = mapper.updateByExampleSelective(record, example);
        assertEquals(2, rows);
        example.clear();
        example.createCriteria().andIntegerfieldEqualTo(5);
        List<Fieldsonly> answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        record = answer.get(0);
        assertEquals(record.getDoublefield(), 11.22, 0.0);
        assertEquals(record.getFloatfield(), 33.44, 0.0);
        assertEquals(record.getIntegerfield().intValue(), 5);
        example.clear();
        example.createCriteria().andIntegerfieldEqualTo(8);
        answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        record = answer.get(0);
        assertEquals(record.getDoublefield(), 99d, 0.0);
        assertEquals(record.getFloatfield(), 66.77, 0.0);
        assertEquals(record.getIntegerfield().intValue(), 8);
        example.clear();
        example.createCriteria().andIntegerfieldEqualTo(9);
        answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
        record = answer.get(0);
        assertEquals(record.getDoublefield(), 99d, 0.0);
        assertEquals(record.getFloatfield(), 100.111, 0.0);
        assertEquals(record.getIntegerfield().intValue(), 9);
    } 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 17 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);
        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);
        record = new Fieldsonly(22, null, null);
        FieldsonlyExample example = new FieldsonlyExample();
        example.createCriteria().andIntegerfieldEqualTo(5);
        int rows = mapper.updateByExample(record, example);
        assertEquals(1, rows);
        example.clear();
        example.createCriteria().andIntegerfieldEqualTo(22);
        List<Fieldsonly> 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 : 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 18 with SqlSession

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

the class UpdateByExampleTest method testPKOnlyUpdateByExampleSelective.

@Test
public void testPKOnlyUpdateByExampleSelective() {
    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);
        key = new PkonlyKey(null, 3);
        int rows = mapper.updateByExampleSelective(key, example);
        assertEquals(2, rows);
        example.clear();
        example.createCriteria().andIdEqualTo(5).andSeqNumEqualTo(3);
        long returnedRows = mapper.countByExample(example);
        assertEquals(1, returnedRows);
        example.clear();
        example.createCriteria().andIdEqualTo(7).andSeqNumEqualTo(3);
        returnedRows = mapper.countByExample(example);
        assertEquals(1, returnedRows);
    } 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 19 with SqlSession

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

the class UpdateByExampleTest method testPKFieldsBlobsUpdateByExampleWithoutBLOBs.

@Test
public void testPKFieldsBlobsUpdateByExampleWithoutBLOBs() {
    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);
        Pkfieldsblobs newRecord = new Pkfieldsblobs(5, 8, "Fred", null);
        PkfieldsblobsExample example = new PkfieldsblobsExample();
        example.createCriteria().andId1EqualTo(5);
        int rows = mapper.updateByExample(newRecord, example);
        assertEquals(1, rows);
        List<PkfieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
        assertEquals(1, answer.size());
        PkfieldsblobsWithBLOBs returnedRecord = answer.get(0);
        assertEquals(newRecord.getId1(), returnedRecord.getId1());
        assertEquals(newRecord.getId2(), returnedRecord.getId2());
        assertEquals(newRecord.getFirstname(), returnedRecord.getFirstname());
        assertNull(returnedRecord.getLastname());
        assertTrue(blobsAreEqual(record.getBlob1(), returnedRecord.getBlob1()));
    } finally {
        sqlSession.close();
    }
}
Also used : Pkfieldsblobs(mbg.test.mb3.generated.hierarchical.immutable.model.Pkfieldsblobs) 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 20 with SqlSession

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

the class UpdateByExampleTest method testPKFieldsUpdateByExampleSelective.

@Test
public void testPKFieldsUpdateByExampleSelective() {
    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);
        record = new Pkfields();
        record.setFirstname("Fred");
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andLastnameLike("J%");
        int rows = mapper.updateByExampleSelective(record, example);
        assertEquals(1, rows);
        example.clear();
        example.createCriteria().andFirstnameEqualTo("Fred").andLastnameEqualTo("Jones").andId1EqualTo(3).andId2EqualTo(4);
        long returnedRows = mapper.countByExample(example);
        assertEquals(1, returnedRows);
    } 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