use of mbg.test.mb3.generated.dsql.model.Pkfields in project generator by mybatis.
the class DynamicSqlTest method testPKFieldscount.
@Test
public void testPKFieldscount() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
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);
long rows = mapper.count(dsl -> dsl.where(pkfieldstable.lastname, isLike("J%")));
assertEquals(1, rows);
rows = mapper.count(dsl -> dsl);
assertEquals(2, rows);
}
}
use of mbg.test.mb3.generated.dsql.model.Pkfields in project generator by mybatis.
the class DynamicSqlTest method testPKFieldsSelectByExampleNoCriteria.
@Test
public void testPKFieldsSelectByExampleNoCriteria() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
Pkfields record = new Pkfields();
record.setFirstname("Fred");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(1);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Wilma");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(2);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Pebbles");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(3);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Barney");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(1);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Betty");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(2);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Bamm Bamm");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(3);
mapper.insert(record);
List<Pkfields> answer = mapper.select(SelectDSLCompleter.allRowsOrderedBy(pkfieldstable.id1, pkfieldstable.id2));
assertEquals(6, answer.size());
}
}
use of mbg.test.mb3.generated.dsql.model.Pkfields in project generator by mybatis.
the class DynamicSqlTest method testPKFieldsSelectByExampleNoCriteriaWithMultiInsert.
@Test
public void testPKFieldsSelectByExampleNoCriteriaWithMultiInsert() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
Collection<Pkfields> records = new ArrayList<>();
Pkfields record = new Pkfields();
record.setFirstname("Fred");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(1);
records.add(record);
record = new Pkfields();
record.setFirstname("Wilma");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(2);
records.add(record);
record = new Pkfields();
record.setFirstname("Pebbles");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(3);
records.add(record);
record = new Pkfields();
record.setFirstname("Barney");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(1);
records.add(record);
record = new Pkfields();
record.setFirstname("Betty");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(2);
records.add(record);
record = new Pkfields();
record.setFirstname("Bamm Bamm");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(3);
records.add(record);
int rowsInserted = mapper.insertMultiple(records);
assertEquals(6, rowsInserted);
List<Pkfields> answer = mapper.select(SelectDSLCompleter.allRowsOrderedBy(pkfieldstable.id1, pkfieldstable.id2));
assertEquals(6, answer.size());
}
}
use of mbg.test.mb3.generated.dsql.model.Pkfields in project generator by mybatis.
the class DynamicSqlTest method testPKFieldsUpdateByPrimaryKeySelective.
@Test
public void testPKFieldsUpdateByPrimaryKeySelective() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
Pkfields record = new Pkfields();
record.setFirstname("Jeff");
record.setLastname("Smith");
record.setDecimal60field(5);
record.setId1(1);
record.setId2(2);
mapper.insert(record);
Pkfields newRecord = new Pkfields();
newRecord.setId1(1);
newRecord.setId2(2);
newRecord.setFirstname("Scott");
newRecord.setDecimal60field(4);
int rows = mapper.updateByPrimaryKeySelective(newRecord);
assertEquals(1, rows);
Optional<Pkfields> returnedRecord = mapper.selectByPrimaryKey(2, 1);
assertThat(returnedRecord).hasValueSatisfying(rr -> {
assertEquals(record.getDatefield(), rr.getDatefield());
assertEquals(record.getDecimal100field(), rr.getDecimal100field());
assertEquals(record.getDecimal155field(), rr.getDecimal155field());
assertEquals(record.getDecimal30field(), rr.getDecimal30field());
assertEquals(newRecord.getDecimal60field(), rr.getDecimal60field());
assertEquals(newRecord.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());
});
}
}
use of mbg.test.mb3.generated.dsql.model.Pkfields in project generator by mybatis.
the class DynamicSqlTest method testPKFieldsUpdateByPrimaryKey.
@Test
public void testPKFieldsUpdateByPrimaryKey() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
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);
Optional<Pkfields> record2 = mapper.selectByPrimaryKey(2, 1);
assertThat(record2).hasValueSatisfying(r2 -> {
assertEquals(record.getFirstname(), r2.getFirstname());
assertEquals(record.getLastname(), r2.getLastname());
assertEquals(record.getId1(), r2.getId1());
assertEquals(record.getId2(), r2.getId2());
});
}
}
Aggregations