use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldFetchComplexBlogs.
@Test
public void shouldFetchComplexBlogs() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
MappedStatement selectBlog = ExecutorTestHelper.prepareComplexSelectBlogMappedStatement(config);
MappedStatement selectPosts = ExecutorTestHelper.prepareSelectPostsForBlogMappedStatement(config);
config.addMappedStatement(selectBlog);
config.addMappedStatement(selectPosts);
List<Blog> blogs = executor.query(selectBlog, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
executor.flushStatements();
assertEquals(1, blogs.size());
assertNotNull(blogs.get(0).getPosts());
assertEquals(2, blogs.get(0).getPosts().size());
assertEquals(1, blogs.get(0).getPosts().get(1).getBlog().getPosts().get(1).getBlog().getId());
executor.rollback(true);
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldFetchOneOrphanedPostWithNoBlog.
@Test
public void shouldFetchOneOrphanedPostWithNoBlog() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
MappedStatement selectBlog = ExecutorTestHelper.prepareComplexSelectBlogMappedStatement(config);
MappedStatement selectPost = ExecutorTestHelper.prepareSelectPostMappedStatement(config);
config.addMappedStatement(selectBlog);
config.addMappedStatement(selectPost);
List<Post> posts = executor.query(selectPost, 5, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
executor.flushStatements();
executor.rollback(true);
assertEquals(1, posts.size());
Post post = posts.get(0);
assertNull(post.getBlog());
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldInsertNewAuthorUsingSimpleNonPreparedStatements.
@Test
public void shouldInsertNewAuthorUsingSimpleNonPreparedStatements() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
Author author = new Author(99, "someone", "******", "someone@apache.org", null, null);
MappedStatement insertStatement = ExecutorTestHelper.createInsertAuthorWithIDof99MappedStatement(config);
MappedStatement selectStatement = ExecutorTestHelper.createSelectAuthorWithIDof99MappedStatement(config);
int rows = executor.update(insertStatement, null);
List<Author> authors = executor.query(selectStatement, 99, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
executor.flushStatements();
executor.rollback(true);
assertEquals(1, authors.size());
assertEquals(author.toString(), authors.get(0).toString());
assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
} finally {
executor.rollback(true);
executor.close(false);
}
}
Aggregations