Search in sources :

Example 6 with JdbcTransaction

use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldFetchPostsForBlog.

@Test
public void shouldFetchPostsForBlog() 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<Post> posts = executor.query(selectPosts, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        assertEquals(2, posts.size());
        assertTrue(posts.get(1) instanceof Proxy);
        assertNotNull(posts.get(1).getBlog());
        assertEquals(1, posts.get(1).getBlog().getId());
        executor.rollback(true);
    } finally {
        executor.rollback(true);
        executor.close(false);
    }
}
Also used : Proxy(javassist.util.proxy.Proxy) 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 7 with JdbcTransaction

use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldClearDeferredLoads.

@Test
public void shouldClearDeferredLoads() 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);
        MappedStatement selectAuthor = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        MappedStatement insertAuthor = ExecutorTestHelper.prepareInsertAuthorMappedStatement(config);
        //generate DeferredLoads
        executor.query(selectPosts, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        Author author = new Author(-1, "someone", "******", "someone@apache.org", null, Section.NEWS);
        executor.update(insertAuthor, author);
        executor.query(selectAuthor, -1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        executor.rollback(true);
    } 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)

Example 8 with JdbcTransaction

use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldSelectAuthorViaOutParams.

@Test
public void shouldSelectAuthorViaOutParams() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectAuthorViaOutParams(config);
        Author author = new Author(102, null, null, null, null, null);
        executor.query(selectStatement, author, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        assertEquals("sally", author.getUsername());
        assertEquals("********", author.getPassword());
        assertEquals("sally@ibatis.apache.org", author.getEmail());
        assertEquals(null, author.getBio());
    } catch (ExecutorException e) {
        if (executor instanceof CachingExecutor) {
            // TODO see issue #464. Fail is OK.
            assertTrue(e.getMessage().contains("OUT params is not supported"));
        } else {
            throw e;
        }
    } 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)

Example 9 with JdbcTransaction

use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldInsertNewAuthorByProc.

@Test
public void shouldInsertNewAuthorByProc() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(97, "someone", "******", "someone@apache.org", null, null);
        MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorProc(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(insertStatement, author);
        List<Author> authors = executor.query(selectStatement, 97, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        executor.rollback(true);
        assertEquals(1, authors.size());
        assertEquals(author.toString(), authors.get(0).toString());
    } 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)

Example 10 with JdbcTransaction

use of org.apache.ibatis.transaction.jdbc.JdbcTransaction in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldInsertNewAuthor.

@Test
public void shouldInsertNewAuthor() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(99, "someone", "******", "someone@apache.org", null, Section.NEWS);
        MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorMappedStatement(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(insertStatement, author);
        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