use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class GeneratedAlwaysTest method testUpdateByPrimaryKey.
@Test
public void testUpdateByPrimaryKey() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
Generatedalwaystest gaTest = new Generatedalwaystest();
gaTest.setId(1);
gaTest.setName("fred");
// should be ignored
gaTest.setIdPlus1(55);
// should be ignored
gaTest.setIdPlus2(66);
gaTest.setBlob1(TestUtilities.generateRandomBlob());
int rows = mapper.insert(gaTest);
assertEquals(1, rows);
gaTest.setName("barney");
// should be ignored
gaTest.setIdPlus1(77);
// should be ignored
gaTest.setIdPlus2(88);
gaTest.setBlob1(TestUtilities.generateRandomBlob());
rows = mapper.updateByPrimaryKey(gaTest);
assertEquals(1, rows);
List<Generatedalwaystest> returnedRecords = mapper.select(SelectDSLCompleter.allRows());
assertEquals(1, returnedRecords.size());
Generatedalwaystest returnedRecord = returnedRecords.get(0);
assertEquals(1, returnedRecord.getId().intValue());
assertEquals(2, returnedRecord.getIdPlus1().intValue());
assertEquals(3, returnedRecord.getIdPlus2().intValue());
assertEquals("barney", returnedRecord.getName());
assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class GeneratedAlwaysTest method testUpdateByPrimaryKeySelective.
@Test
public void testUpdateByPrimaryKeySelective() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
Generatedalwaystest gaTest = new Generatedalwaystest();
gaTest.setId(1);
gaTest.setName("fred");
// should be ignored
gaTest.setIdPlus1(55);
// should be ignored
gaTest.setIdPlus2(66);
gaTest.setBlob1(TestUtilities.generateRandomBlob());
int rows = mapper.insert(gaTest);
assertEquals(1, rows);
gaTest.setName(null);
// should be ignored
gaTest.setIdPlus1(77);
// should be ignored
gaTest.setIdPlus2(88);
gaTest.setBlob1(TestUtilities.generateRandomBlob());
rows = mapper.updateByPrimaryKeySelective(gaTest);
assertEquals(1, rows);
List<Generatedalwaystest> returnedRecords = mapper.select(SelectDSLCompleter.allRows());
assertEquals(1, returnedRecords.size());
Generatedalwaystest returnedRecord = returnedRecords.get(0);
assertEquals(1, returnedRecord.getId().intValue());
assertEquals(2, returnedRecord.getIdPlus1().intValue());
assertEquals(3, returnedRecord.getIdPlus2().intValue());
assertEquals("fred", returnedRecord.getName());
assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class ConditionalJava5Test method testPKFieldsInsert.
@Test
public void testPKFieldsInsert() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
Pkfields record = new Pkfields();
record.setDatefield(new Date());
record.setDecimal100field(10L);
record.setDecimal155field(new BigDecimal("15.12345"));
record.setDecimal30field((short) 3);
record.setDecimal60field(6);
record.setFirstname("Jeff");
record.setId1(1);
record.setId2(2);
record.setLastname("Butler");
record.setTimefield(new Date());
record.setTimestampfield(new Date());
mapper.insert(record);
PkfieldsKey key = new PkfieldsKey();
key.setId1(1);
key.setId2(2);
Pkfields returnedRecord = mapper.selectByPrimaryKey(key);
assertNotNull(returnedRecord);
assertTrue(datesAreEqual(record.getDatefield(), returnedRecord.getDatefield()));
assertEquals(record.getDecimal100field(), returnedRecord.getDecimal100field());
assertEquals(record.getDecimal155field(), returnedRecord.getDecimal155field());
assertEquals(record.getDecimal30field(), returnedRecord.getDecimal30field());
assertEquals(record.getDecimal60field(), returnedRecord.getDecimal60field());
assertEquals(record.getFirstname(), returnedRecord.getFirstname());
assertEquals(record.getId1(), returnedRecord.getId1());
assertEquals(record.getId2(), returnedRecord.getId2());
assertEquals(record.getLastname(), returnedRecord.getLastname());
assertTrue(timesAreEqual(record.getTimefield(), returnedRecord.getTimefield()));
assertEquals(record.getTimestampfield(), returnedRecord.getTimestampfield());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSession in project generator by mybatis.
the class ConditionalJava5Test method testPKOnlyDeleteByExample.
@Test
public void testPKOnlyDeleteByExample() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
PkonlyKey key = new PkonlyKey();
key.setId(1);
key.setSeqNum(3);
mapper.insert(key);
key = new PkonlyKey();
key.setId(5);
key.setSeqNum(6);
mapper.insert(key);
key = new PkonlyKey();
key.setId(7);
key.setSeqNum(8);
mapper.insert(key);
PkonlyExample example = new PkonlyExample();
example.createCriteria().andIdGreaterThan(4);
int rows = mapper.deleteByExample(example);
assertEquals(2, rows);
example = new PkonlyExample();
List<PkonlyKey> 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 ConditionalJava5Test method testAwfulTableInsert.
@Test
public void testAwfulTableInsert() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
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");
int rows = mapper.insert(record);
assertEquals(1, rows);
Integer generatedCustomerId = record.getCustomerId();
assertEquals(57, generatedCustomerId.intValue());
AwfulTable returnedRecord = mapper.selectByPrimaryKey(generatedCustomerId);
assertEquals(generatedCustomerId, returnedRecord.getCustomerId());
assertEquals(record.geteMail(), returnedRecord.geteMail());
assertEquals(record.getEmailaddress(), returnedRecord.getEmailaddress());
assertEquals(record.getFirstFirstName(), returnedRecord.getFirstFirstName());
assertEquals(record.getFrom(), returnedRecord.getFrom());
assertEquals(record.getId1(), returnedRecord.getId1());
assertEquals(record.getId2(), returnedRecord.getId2());
assertEquals(record.getId5(), returnedRecord.getId5());
assertEquals(record.getId6(), returnedRecord.getId6());
assertEquals(record.getId7(), returnedRecord.getId7());
assertEquals(record.getSecondFirstName(), returnedRecord.getSecondFirstName());
assertEquals(record.getThirdFirstName(), returnedRecord.getThirdFirstName());
} finally {
sqlSession.close();
}
}
Aggregations