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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations