use of mbg.test.mb3.generated.dsql.miscellaneous.model.MyObject in project generator by mybatis.
the class MiscellaneousTest method testMyObjectUpdateByExample.
@Test
public void testMyObjectUpdateByExample() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MyObjectMapper mapper = sqlSession.getMapper(MyObjectMapper.class);
MyObject record = new MyObject();
FirstName fn = new FirstName();
fn.setValue("Jeff");
record.setFirstname(fn);
record.setLastname("Smith");
record.setId1(1);
record.setId2(2);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Bob");
record.setFirstname(fn);
record.setLastname("Jones");
record.setId1(3);
record.setId2(4);
mapper.insert(record);
MyObject newRecord = new MyObject();
newRecord.setLastname("Barker");
newRecord.setId1(3);
newRecord.setId2(4);
MyObjectCriteria example = new MyObjectCriteria();
example.createCriteria().andId1EqualTo(3).andId2EqualTo(4);
int rows = mapper.updateByExample(newRecord, example);
assertEquals(1, rows);
List<MyObject> answer = mapper.selectByExample(example);
assertEquals(1, answer.size());
MyObject returnedRecord = answer.get(0);
assertEquals(newRecord.getLastname(), returnedRecord.getLastname());
assertNull(returnedRecord.getFirstname());
assertEquals(newRecord.getId1(), returnedRecord.getId1());
assertEquals(newRecord.getId2(), returnedRecord.getId2());
} finally {
sqlSession.close();
}
}
use of mbg.test.mb3.generated.dsql.miscellaneous.model.MyObject in project generator by mybatis.
the class MiscellaneousTest method testMyObjectDeleteByExample.
@Test
public void testMyObjectDeleteByExample() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MyObjectMapper mapper = sqlSession.getMapper(MyObjectMapper.class);
MyObject record = new MyObject();
FirstName fn = new FirstName();
fn.setValue("Jeff");
record.setFirstname(fn);
record.setLastname("Smith");
record.setId1(1);
record.setId2(2);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Bob");
record.setFirstname(fn);
record.setLastname("Jones");
record.setId1(3);
record.setId2(4);
mapper.insert(record);
MyObjectCriteria example = new MyObjectCriteria();
List<MyObject> answer = mapper.selectByExample(example);
assertEquals(2, answer.size());
example = new MyObjectCriteria();
example.createCriteria().andLastnameLike("J%");
int rows = mapper.deleteByExample(example);
assertEquals(1, rows);
example = new MyObjectCriteria();
answer = mapper.selectByExample(example);
assertEquals(1, answer.size());
} finally {
sqlSession.close();
}
}
use of mbg.test.mb3.generated.dsql.miscellaneous.model.MyObject in project generator by mybatis.
the class MiscellaneousTest method testMyObjectSelectByExampleLike.
@Test
public void testMyObjectSelectByExampleLike() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
MyObjectMapper mapper = sqlSession.getMapper(MyObjectMapper.class);
MyObject record = new MyObject();
FirstName fn = new FirstName();
fn.setValue("Fred");
record.setFirstname(fn);
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(1);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Wilma");
record.setFirstname(fn);
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(2);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Pebbles");
record.setFirstname(fn);
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(3);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Barney");
record.setFirstname(fn);
record.setLastname("Rubble");
record.setId1(2);
record.setId2(1);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Betty");
record.setFirstname(fn);
record.setLastname("Rubble");
record.setId1(2);
record.setId2(2);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Bamm Bamm");
record.setFirstname(fn);
record.setLastname("Rubble");
record.setId1(2);
record.setId2(3);
mapper.insert(record);
FirstName fn1 = new FirstName();
fn1.setValue("B%");
List<MyObject> answer = mapper.select(dsl -> dsl.where(myObject.firstname, isLike(fn1)).orderBy(myObject.id1, myObject.id2));
assertEquals(3, answer.size());
MyObject returnedRecord = answer.get(0);
assertEquals(2, returnedRecord.getId1().intValue());
assertEquals(1, returnedRecord.getId2().intValue());
returnedRecord = answer.get(1);
assertEquals(2, returnedRecord.getId1().intValue());
assertEquals(2, returnedRecord.getId2().intValue());
returnedRecord = answer.get(2);
assertEquals(2, returnedRecord.getId1().intValue());
assertEquals(3, returnedRecord.getId2().intValue());
}
}
use of mbg.test.mb3.generated.dsql.miscellaneous.model.MyObject in project generator by mybatis.
the class MiscellaneousTest method testMyObjectUpdateByExample.
@Test
public void testMyObjectUpdateByExample() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
MyObjectMapper mapper = sqlSession.getMapper(MyObjectMapper.class);
MyObject record = new MyObject();
FirstName fn = new FirstName();
fn.setValue("Jeff");
record.setFirstname(fn);
record.setLastname("Smith");
record.setId1(1);
record.setId2(2);
mapper.insert(record);
record = new MyObject();
fn = new FirstName();
fn.setValue("Bob");
record.setFirstname(fn);
record.setLastname("Jones");
record.setId1(3);
record.setId2(4);
mapper.insert(record);
MyObject newRecord = new MyObject();
newRecord.setLastname("Barker");
newRecord.setId1(3);
newRecord.setId2(4);
int rows = mapper.update(dsl -> MyObjectMapper.updateAllColumns(newRecord, dsl).where(myObject.id1, isEqualTo(3), and(myObject.id2, isEqualTo(4))));
assertEquals(1, rows);
List<MyObject> answer = mapper.select(dsl -> dsl.where(myObject.id1, isEqualTo(3), and(myObject.id2, isEqualTo(4))));
assertEquals(1, answer.size());
MyObject returnedRecord = answer.get(0);
assertEquals(newRecord.getLastname(), returnedRecord.getLastname());
assertNull(returnedRecord.getFirstname());
assertEquals(newRecord.getId1(), returnedRecord.getId1());
assertEquals(newRecord.getId2(), returnedRecord.getId2());
}
}
use of mbg.test.mb3.generated.dsql.miscellaneous.model.MyObject in project generator by mybatis.
the class MiscellaneousTest method testMyObjectinsertMyObject.
@Test
public void testMyObjectinsertMyObject() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
MyObjectMapper mapper = sqlSession.getMapper(MyObjectMapper.class);
MyObject record = new MyObject();
record.setStartDate(new Date());
record.setDecimal100field(10L);
record.setDecimal155field(15.12345);
record.setDecimal60field(6);
FirstName fn = new FirstName();
fn.setValue("Jeff");
record.setFirstname(fn);
record.setId1(1);
record.setId2(2);
record.setLastname("Butler");
MyTime myTime = new MyTime();
myTime.setHours(12);
myTime.setMinutes(34);
myTime.setSeconds(5);
record.setTimefield(myTime);
record.setTimestampfield(new Date());
mapper.insert(record);
Optional<MyObject> returnedRecord = mapper.selectByPrimaryKey(2, 1);
assertThat(returnedRecord).hasValueSatisfying(rr -> {
assertTrue(datesAreEqual(record.getStartDate(), rr.getStartDate()));
assertEquals(record.getDecimal100field(), rr.getDecimal100field());
assertEquals(record.getDecimal155field(), rr.getDecimal155field());
assertEquals(record.getDecimal60field(), rr.getDecimal60field());
assertEquals(record.getFirstname(), rr.getFirstname());
assertEquals(record.getId1(), rr.getId1());
assertEquals(record.getId2(), rr.getId2());
assertEquals(record.getLastname(), rr.getLastname());
assertEquals(record.getTimefield(), rr.getTimefield());
assertEquals(record.getTimestampfield(), rr.getTimestampfield());
});
}
}
Aggregations