use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class DynamicSqlTest method testPKBlobsSelectByPrimaryKey.
@Test
public void testPKBlobsSelectByPrimaryKey() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
PkblobsMapper mapper = sqlSession.getMapper(PkblobsMapper.class);
Pkblobs record = new Pkblobs();
record.setId(3);
record.setBlob1(generateRandomBlob());
record.setBlob2(generateRandomBlob());
mapper.insert(record);
Pkblobs record1 = new Pkblobs();
record1.setId(6);
record1.setBlob1(generateRandomBlob());
record1.setBlob2(generateRandomBlob());
mapper.insert(record1);
Optional<Pkblobs> newRecord = mapper.selectByPrimaryKey(6);
assertThat(newRecord).hasValueSatisfying(nr -> {
assertEquals(record1.getId(), nr.getId());
assertTrue(blobsAreEqual(record1.getBlob1(), nr.getBlob1()));
assertTrue(blobsAreEqual(record1.getBlob2(), nr.getBlob2()));
});
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class DynamicSqlTest method testFieldsOnlySelectByExampleNoCriteria.
@Test
public void testFieldsOnlySelectByExampleNoCriteria() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
FieldsonlyMapper mapper = sqlSession.getMapper(FieldsonlyMapper.class);
Fieldsonly record = new Fieldsonly();
record.setDoublefield(11.22);
record.setFloatfield(33.44);
record.setIntegerfield(5);
mapper.insert(record);
record = new Fieldsonly();
record.setDoublefield(44.55);
record.setFloatfield(66.77);
record.setIntegerfield(8);
mapper.insert(record);
record = new Fieldsonly();
record.setDoublefield(88.99);
record.setFloatfield(100.111);
record.setIntegerfield(9);
mapper.insert(record);
List<Fieldsonly> answer = mapper.select(SelectDSLCompleter.allRows());
assertThat(answer.size()).isEqualTo(3);
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class DynamicSqlTest method testPKFieldsBlobsSelectByPrimaryKey.
@Test
public void testPKFieldsBlobsSelectByPrimaryKey() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
Pkfieldsblobs record = new Pkfieldsblobs();
record.setId1(3);
record.setId2(4);
record.setFirstname("Jeff");
record.setLastname("Smith");
record.setBlob1(generateRandomBlob());
mapper.insert(record);
Pkfieldsblobs record1 = new Pkfieldsblobs();
record1.setId1(5);
record1.setId2(6);
record1.setFirstname("Scott");
record1.setLastname("Jones");
record1.setBlob1(generateRandomBlob());
mapper.insert(record1);
List<Pkfieldsblobs> answer = mapper.select(SelectDSLCompleter.allRows());
assertEquals(2, answer.size());
Optional<Pkfieldsblobs> newRecord = mapper.selectByPrimaryKey(5, 6);
assertThat(newRecord).hasValueSatisfying(nr -> {
assertEquals(record1.getId1(), nr.getId1());
assertEquals(record1.getId2(), nr.getId2());
assertEquals(record1.getFirstname(), nr.getFirstname());
assertEquals(record1.getLastname(), nr.getLastname());
assertTrue(blobsAreEqual(record1.getBlob1(), nr.getBlob1()));
});
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class DynamicSqlTest method testPKFieldsBlobsInsert.
@Test
public void testPKFieldsBlobsInsert() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
Pkfieldsblobs record = new Pkfieldsblobs();
record.setId1(3);
record.setId2(4);
record.setFirstname("Jeff");
record.setLastname("Smith");
record.setBlob1(generateRandomBlob());
mapper.insert(record);
List<Pkfieldsblobs> answer = mapper.select(SelectDSLCompleter.allRows());
assertEquals(1, answer.size());
Pkfieldsblobs returnedRecord = answer.get(0);
assertEquals(record.getId1(), returnedRecord.getId1());
assertEquals(record.getId2(), returnedRecord.getId2());
assertEquals(record.getFirstname(), returnedRecord.getFirstname());
assertEquals(record.getLastname(), returnedRecord.getLastname());
assertTrue(blobsAreEqual(record.getBlob1(), returnedRecord.getBlob1()));
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class DynamicSqlTest method testAwfulTableDeleteByPrimaryKey.
@Test
public void testAwfulTableDeleteByPrimaryKey() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
AwfulTable record = new AwfulTable();
record.seteMail("fred@fred.com");
record.setEmailaddress("alsofred@fred.com");
record.setFirstFirstName("fred1");
record.setFrom("from field");
record.setId1(1);
record.setId2(2);
record.setId5(5);
record.setId6(6);
record.setId7(7);
record.setSecondFirstName("fred2");
record.setThirdFirstName("fred3");
mapper.insert(record);
Integer generatedCustomerId = record.getCustomerId();
int rows = mapper.deleteByPrimaryKey(generatedCustomerId);
assertEquals(1, rows);
List<AwfulTable> answer = mapper.select(SelectDSLCompleter.allRows());
assertEquals(0, answer.size());
}
}
Aggregations