Search in sources :

Example 61 with MappedStatement

use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldFetchPostWithBlogWithCompositeKey.

@Test
public void shouldFetchPostWithBlogWithCompositeKey() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectBlog = ExecutorTestHelper.prepareSelectBlogByIdAndAuthor(config);
        MappedStatement selectPost = ExecutorTestHelper.prepareSelectPostWithBlogByAuthorMappedStatement(config);
        config.addMappedStatement(selectBlog);
        config.addMappedStatement(selectPost);
        List<Post> posts = executor.query(selectPost, 2, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        assertEquals(1, posts.size());
        Post post = posts.get(0);
        assertNotNull(post.getBlog());
        assertEquals(101, post.getBlog().getAuthor().getId());
        executor.rollback(true);
    } 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 62 with MappedStatement

use of org.apache.ibatis.mapping.MappedStatement 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 63 with MappedStatement

use of org.apache.ibatis.mapping.MappedStatement 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 64 with MappedStatement

use of org.apache.ibatis.mapping.MappedStatement 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)

Example 65 with MappedStatement

use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.

the class XmlMapperBuilderTest method mappedStatementWithOptions.

@Test
public void mappedStatementWithOptions() throws Exception {
    Configuration configuration = new Configuration();
    String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
    builder.parse();
    MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptions");
    assertThat(mappedStatement.getFetchSize(), is(200));
    assertThat(mappedStatement.getTimeout(), is(10));
    assertThat(mappedStatement.getStatementType(), is(StatementType.PREPARED));
    assertThat(mappedStatement.getResultSetType(), is(ResultSetType.SCROLL_SENSITIVE));
    assertThat(mappedStatement.isFlushCacheRequired(), is(false));
    assertThat(mappedStatement.isUseCache(), is(false));
}
Also used : Configuration(org.apache.ibatis.session.Configuration) InputStream(java.io.InputStream) XMLMapperBuilder(org.apache.ibatis.builder.xml.XMLMapperBuilder) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Test(org.junit.Test)

Aggregations

MappedStatement (org.apache.ibatis.mapping.MappedStatement)73 Test (org.junit.Test)27 Author (org.apache.ibatis.domain.blog.Author)19 BaseDataTest (org.apache.ibatis.BaseDataTest)18 JdbcTransaction (org.apache.ibatis.transaction.jdbc.JdbcTransaction)18 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)17 Configuration (org.apache.ibatis.session.Configuration)17 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)17 ArrayList (java.util.ArrayList)15 ResultMap (org.apache.ibatis.mapping.ResultMap)12 BoundSql (org.apache.ibatis.mapping.BoundSql)11 Statement (java.sql.Statement)10 StatementHandler (org.apache.ibatis.executor.statement.StatementHandler)10 ParameterMap (org.apache.ibatis.mapping.ParameterMap)9 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)9 Section (org.apache.ibatis.domain.blog.Section)8 SqlSource (org.apache.ibatis.mapping.SqlSource)8 RowBounds (org.apache.ibatis.session.RowBounds)8 ResultMapping (org.apache.ibatis.mapping.ResultMapping)7 MetaObject (org.apache.ibatis.reflection.MetaObject)7