use of org.apache.ibatis.executor.BatchResult in project mybatis-3 by mybatis.
the class FlushTest method invokeFlushStatementsViaMapper.
@Test
public void invokeFlushStatementsViaMapper() {
SqlSession session = sqlSessionFactory.openSession();
try {
BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
Author author = new Author(-1, "cbegin", "******", "cbegin@nowhere.com", "N/A", Section.NEWS);
List<Integer> ids = new ArrayList<Integer>();
mapper.insertAuthor(author);
ids.add(author.getId());
mapper.insertAuthor(author);
ids.add(author.getId());
mapper.insertAuthor(author);
ids.add(author.getId());
mapper.insertAuthor(author);
ids.add(author.getId());
mapper.insertAuthor(author);
ids.add(author.getId());
// test
List<BatchResult> results = mapper.flush();
assertThat(results.size(), is(1));
assertThat(results.get(0).getUpdateCounts().length, is(ids.size()));
for (int id : ids) {
Author selectedAuthor = mapper.selectAuthor(id);
assertNotNull(id + " is not found.", selectedAuthor);
}
session.rollback();
} finally {
session.close();
}
}
use of org.apache.ibatis.executor.BatchResult in project mybatis-3 by mybatis.
the class InsertTest method testInsertMappedBatch.
// Not supported yet in PostgreSQL
@Ignore
@Test
public void testInsertMappedBatch() throws Exception {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
Name name = new Name();
name.setFirstName("Fred");
name.setLastName("Flintstone");
mapper.insertNameMapped(name);
Name name2 = new Name();
name2.setFirstName("Wilma");
name2.setLastName("Flintstone");
mapper.insertNameMapped(name2);
List<BatchResult> batchResults = sqlSession.flushStatements();
assertNotNull(name.getId());
assertNotNull(name2.getId());
assertEquals(1, batchResults.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.executor.BatchResult in project mybatis-3 by mybatis.
the class NoParamTypeTest method shouldAcceptDifferentTypeInTheSameBatch.
@Test
public void shouldAcceptDifferentTypeInTheSameBatch() {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
ObjA a = new ObjA();
a.setId(1);
a.setName(111);
sqlSession.insert("insertUser", a);
ObjB b = new ObjB();
b.setId(2);
b.setName("222");
sqlSession.insert("insertUser", b);
List<BatchResult> batchResults = sqlSession.flushStatements();
batchResults.clear();
sqlSession.clearCache();
sqlSession.commit();
List<User> users = sqlSession.selectList("selectUser");
assertEquals(2, users.size());
} finally {
sqlSession.close();
}
}
Aggregations