Search in sources :

Example 16 with JdbcTransaction

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);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 17 with JdbcTransaction

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);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) Post(org.apache.ibatis.domain.blog.Post) MappedStatement(org.apache.ibatis.mapping.MappedStatement) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 18 with JdbcTransaction

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);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) Author(org.apache.ibatis.domain.blog.Author) MappedStatement(org.apache.ibatis.mapping.MappedStatement) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

BaseDataTest (org.apache.ibatis.BaseDataTest)18 MappedStatement (org.apache.ibatis.mapping.MappedStatement)18 JdbcTransaction (org.apache.ibatis.transaction.jdbc.JdbcTransaction)18 Test (org.junit.Test)18 Author (org.apache.ibatis.domain.blog.Author)12 Post (org.apache.ibatis.domain.blog.Post)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 List (java.util.List)1 Proxy (javassist.util.proxy.Proxy)1 Blog (org.apache.ibatis.domain.blog.Blog)1 RowBounds (org.apache.ibatis.session.RowBounds)1