use of mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper 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 mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper in project generator by mybatis.
the class ConditionalJava5Test method testPKFieldsSelectByExampleEscapedFields.
@Test
public void testPKFieldsSelectByExampleEscapedFields() {
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);
record.setWierdField(11);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Wilma");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(2);
record.setWierdField(22);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Pebbles");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(3);
record.setWierdField(33);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Barney");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(1);
record.setWierdField(44);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Betty");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(2);
record.setWierdField(55);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Bamm Bamm");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(3);
record.setWierdField(66);
mapper.insert(record);
List<Integer> values = new ArrayList<Integer>();
values.add(11);
values.add(22);
PkfieldsExample example = new PkfieldsExample();
example.createCriteria().andWierdFieldLessThan(40).andWierdFieldIn(values);
example.setOrderByClause("ID1, ID2");
List<Pkfields> answer = mapper.selectByExample(example);
assertEquals(2, answer.size());
} finally {
sqlSession.close();
}
}
use of mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper in project generator by mybatis.
the class ConditionalJava5Test 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();
}
}
use of mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper in project generator by mybatis.
the class ConditionalJava5Test method testPKFieldsSelectByExampleDateTimeFields.
@Test
public void testPKFieldsSelectByExampleDateTimeFields() {
SqlSession sqlSession = sqlSessionFactory.openSession();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2009);
calendar.set(Calendar.MONTH, Calendar.JUNE);
calendar.set(Calendar.DAY_OF_MONTH, 15);
calendar.set(Calendar.HOUR, 10);
calendar.set(Calendar.MINUTE, 10);
calendar.set(Calendar.SECOND, 10);
try {
PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
Pkfields record = new Pkfields();
record.setId1(1);
record.setId2(1);
record.setDatefield(calendar.getTime());
record.setTimefield(calendar.getTime());
mapper.insert(record);
record = new Pkfields();
record.setId1(1);
record.setId2(2);
calendar.set(Calendar.DAY_OF_MONTH, 16);
calendar.set(Calendar.MINUTE, 11);
record.setDatefield(calendar.getTime());
record.setTimefield(calendar.getTime());
mapper.insert(record);
record = new Pkfields();
record.setId1(1);
record.setId2(3);
calendar.set(Calendar.DAY_OF_MONTH, 17);
calendar.set(Calendar.MINUTE, 12);
record.setDatefield(calendar.getTime());
record.setTimefield(calendar.getTime());
mapper.insert(record);
record = new Pkfields();
record.setId1(2);
record.setId2(1);
calendar.set(Calendar.DAY_OF_MONTH, 18);
calendar.set(Calendar.MINUTE, 13);
record.setDatefield(calendar.getTime());
record.setTimefield(calendar.getTime());
mapper.insert(record);
record = new Pkfields();
record.setId1(2);
record.setId2(2);
calendar.set(Calendar.DAY_OF_MONTH, 19);
calendar.set(Calendar.MINUTE, 14);
record.setDatefield(calendar.getTime());
record.setTimefield(calendar.getTime());
mapper.insert(record);
record = new Pkfields();
record.setId1(2);
record.setId2(3);
calendar.set(Calendar.DAY_OF_MONTH, 20);
calendar.set(Calendar.MINUTE, 15);
record.setDatefield(calendar.getTime());
record.setTimefield(calendar.getTime());
mapper.insert(record);
PkfieldsExample example = new PkfieldsExample();
example.createCriteria().andDatefieldEqualTo(calendar.getTime());
example.setOrderByClause("ID1, ID2");
List<Pkfields> answer = mapper.selectByExample(example);
assertEquals(1, answer.size());
example.clear();
example.createCriteria().andDatefieldLessThan(calendar.getTime());
answer = mapper.selectByExample(example);
assertEquals(5, answer.size());
calendar.set(Calendar.MINUTE, 12);
example.clear();
example.createCriteria().andTimefieldEqualTo(calendar.getTime());
answer = mapper.selectByExample(example);
assertEquals(1, answer.size());
example.clear();
example.createCriteria().andTimefieldGreaterThan(calendar.getTime());
answer = mapper.selectByExample(example);
assertEquals(3, answer.size());
} finally {
sqlSession.close();
}
}
use of mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper in project generator by mybatis.
the class UpdateByExampleTest method testPKFieldsUpdateByExampleSelective.
@Test
public void testPKFieldsUpdateByExampleSelective() {
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);
record = new Pkfields();
record.setFirstname("Fred");
PkfieldsExample example = new PkfieldsExample();
example.createCriteria().andLastnameLike("J%");
int rows = mapper.updateByExampleSelective(record, example);
assertEquals(1, rows);
example.clear();
example.createCriteria().andFirstnameEqualTo("Fred").andLastnameEqualTo("Jones").andId1EqualTo(3).andId2EqualTo(4);
long returnedRows = mapper.countByExample(example);
assertEquals(1, returnedRows);
} finally {
sqlSession.close();
}
}
Aggregations