use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKFieldsBlobsSelectByExampleWithBlobs.
@Test
public void testPKFieldsBlobsSelectByExampleWithBlobs() {
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);
PkfieldsblobsExample example = new PkfieldsblobsExample();
example.createCriteria().andId2EqualTo(6);
List<PkfieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
assertEquals(1, answer.size());
PkfieldsblobsWithBLOBs newRecord = answer.get(0);
assertEquals(record.getId1(), newRecord.getId1());
assertEquals(record.getId2(), newRecord.getId2());
assertEquals(record.getFirstname(), newRecord.getFirstname());
assertEquals(record.getLastname(), newRecord.getLastname());
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 testPKFieldsDeleteByExample.
@Test
public void testPKFieldsDeleteByExample() {
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);
PkfieldsExample example = new PkfieldsExample();
List<Pkfields> answer = mapper.selectByExample(example);
assertEquals(2, answer.size());
example = new PkfieldsExample();
example.createCriteria().andLastnameLike("J%");
int rows = mapper.deleteByExample(example);
assertEquals(1, rows);
example = new PkfieldsExample();
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 testFieldsBlobsSelectByExampleWithBlobs.
@Test
public void testFieldsBlobsSelectByExampleWithBlobs() {
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);
FieldsblobsExample example = new FieldsblobsExample();
example.createCriteria().andFirstnameLike("S%");
List<FieldsblobsWithBLOBs> answer = mapper.selectByExampleWithBLOBs(example);
assertEquals(1, answer.size());
FieldsblobsWithBLOBs newRecord = answer.get(0);
assertEquals(record.getFirstname(), newRecord.getFirstname());
assertEquals(record.getLastname(), newRecord.getLastname());
assertTrue(blobsAreEqual(record.getBlob1(), newRecord.getBlob1()));
assertTrue(blobsAreEqual(record.getBlob2(), newRecord.getBlob2()));
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKOnlySelectByExample.
@Test
public void testPKOnlySelectByExample() {
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);
List<PkonlyKey> answer = mapper.selectByExample(example);
assertEquals(2, answer.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class HierarchicalJava5Test method testPKFieldsUpdateByPrimaryKey.
@Test
public void testPKFieldsUpdateByPrimaryKey() {
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.setFirstname("Scott");
record.setLastname("Jones");
int rows = mapper.updateByPrimaryKey(record);
assertEquals(1, rows);
PkfieldsKey key = new PkfieldsKey();
key.setId1(1);
key.setId2(2);
Pkfields record2 = mapper.selectByPrimaryKey(key);
assertEquals(record.getFirstname(), record2.getFirstname());
assertEquals(record.getLastname(), record2.getLastname());
assertEquals(record.getId1(), record2.getId1());
assertEquals(record.getId2(), record2.getId2());
} finally {
sqlSession.close();
}
}
Aggregations