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);
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
Aggregations