use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper in project generator by mybatis.
the class UpdateByExampleTest method testPKFieldsUpdateByExample.
@Test
public void testPKFieldsUpdateByExample() {
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");
record.setId1(3);
record.setId2(4);
PkfieldsExample example = new PkfieldsExample();
example.createCriteria().andId1EqualTo(3).andId2EqualTo(4);
int rows = mapper.updateByExample(record, example);
assertEquals(1, rows);
example.clear();
example.createCriteria().andFirstnameEqualTo("Fred").andLastnameIsNull().andId1EqualTo(3).andId2EqualTo(4);
long returnedRows = mapper.countByExample(example);
assertEquals(1, returnedRows);
} finally {
sqlSession.close();
}
}
use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper in project generator by mybatis.
the class UpdateByExampleTest method testPKFieldsUpdateAllRows.
@Test
public void testPKFieldsUpdateAllRows() {
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.setLastname("Cooper");
int rows = mapper.updateByExampleSelective(record, null);
assertEquals(2, rows);
PkfieldsExample example = new PkfieldsExample();
example.createCriteria().andLastnameEqualTo("Cooper");
long returnedRows = mapper.countByExample(example);
assertEquals(2, returnedRows);
} finally {
sqlSession.close();
}
}
use of mbg.test.mb3.generated.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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.annotated.hierarchical.Immutable.Mapper.PkfieldsMapper 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());
}
}
Aggregations