use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKBlobsDeleteByExample.
@Test
public void testPKBlobsDeleteByExample() {
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();
List<PkblobsKey> answer = mapper.selectByExample(example);
assertEquals(2, answer.size());
example = new PkblobsExample();
example.createCriteria().andIdLessThan(4);
int rows = mapper.deleteByExample(example);
assertEquals(1, rows);
example = new PkblobsExample();
answer = mapper.selectByExample(example);
assertEquals(1, answer.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKBlobsSelectByPrimaryKey.
@Test
public void testPKBlobsSelectByPrimaryKey() {
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 key = new PkblobsKey(6);
PkblobsWithBLOBs newRecord = mapper.selectByPrimaryKey(key);
assertNotNull(newRecord);
assertEquals(record.getId(), newRecord.getId());
assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
assertTrue(blobsAreEqual(record.getBlob2(), newRecord.getBlob2()));
assertEquals(record.getCharacterlob(), newRecord.getCharacterlob());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testFieldsOnlySelectByExampleNoCriteria.
@Test
public void testFieldsOnlySelectByExampleNoCriteria() {
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();
List<Fieldsonly> answer = mapper.selectByExample(example);
assertEquals(3, answer.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKFieldsSelectByExampleBetween.
@Test
public void testPKFieldsSelectByExampleBetween() {
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().andId2Between(1, 3);
example.setOrderByClause("ID1, ID2");
List<Pkfields> answer = mapper.selectByExample(example);
assertEquals(6, answer.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKBlobsUpdateByPrimaryKeyWithBLOBs.
@Test
public void testPKBlobsUpdateByPrimaryKeyWithBLOBs() {
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(3, generateRandomBlob(), generateRandomBlob(), "Long String 2");
int rows = mapper.updateByPrimaryKeyWithBLOBs(record);
assertEquals(1, rows);
PkblobsKey key = new PkblobsKey(3);
PkblobsWithBLOBs newRecord = mapper.selectByPrimaryKey(key);
assertNotNull(newRecord);
assertEquals(record.getId(), newRecord.getId());
assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
assertTrue(blobsAreEqual(record.getBlob2(), newRecord.getBlob2()));
assertEquals(record.getCharacterlob(), newRecord.getCharacterlob());
} finally {
sqlSession.close();
}
}
Aggregations