Search in sources :

Example 26 with MappedStatement

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

the class SimpleExecutor method doQueryCursor.

@Override
protected <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql) throws SQLException {
    Configuration configuration = ms.getConfiguration();
    StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, null, boundSql);
    Statement stmt = prepareStatement(handler, ms.getStatementLog());
    return handler.<E>queryCursor(stmt);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler)

Example 27 with MappedStatement

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

the class SimpleExecutor method doUpdate.

@Override
public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {
    Statement stmt = null;
    try {
        Configuration configuration = ms.getConfiguration();
        StatementHandler handler = configuration.newStatementHandler(this, ms, parameter, RowBounds.DEFAULT, null, null);
        stmt = prepareStatement(handler, ms.getStatementLog());
        return handler.update(stmt);
    } finally {
        closeStatement(stmt);
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler)

Example 28 with MappedStatement

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

the class XmlExternalRefTest method testMappedStatementCache.

@Test
public void testMappedStatementCache() throws Exception {
    Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MapperConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
    configReader.close();
    Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.getMappedStatementNames();
    MappedStatement selectPetStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.PetMapper.select");
    MappedStatement selectPersonStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.PersonMapper.select");
    Cache cache = selectPetStatement.getCache();
    assertEquals("org.apache.ibatis.submitted.xml_external_ref.PetMapper", cache.getId());
    assertSame(cache, selectPersonStatement.getCache());
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Cache(org.apache.ibatis.cache.Cache) Test(org.junit.Test)

Example 29 with MappedStatement

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

the class ShortNameTest method ambiguousShortNameShouldFail.

@Test(expected = IllegalArgumentException.class)
public void ambiguousShortNameShouldFail() throws Exception {
    Configuration configuration = getConfiguration();
    // ambiguous short name should throw an exception.
    MappedStatement ambiguousStatement = configuration.getMappedStatement("select");
    fail("If there are multiple statements with the same name, an exception should be thrown.");
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Test(org.junit.Test)

Example 30 with MappedStatement

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

the class CacheOrderTest method shouldResolveACacheRefNotYetRead.

@Test
public void shouldResolveACacheRefNotYetRead() {
    MappedStatement ms = sqlSessionFactory.getConfiguration().getMappedStatement("getUser");
    Cache cache = ms.getCache();
    assertEquals("org.apache.ibatis.submitted.cacheorder.Mapper2", cache.getId());
}
Also used : MappedStatement(org.apache.ibatis.mapping.MappedStatement) Cache(org.apache.ibatis.cache.Cache) Test(org.junit.Test)

Aggregations

MappedStatement (org.apache.ibatis.mapping.MappedStatement)69 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 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)17 ArrayList (java.util.ArrayList)15 Configuration (org.apache.ibatis.session.Configuration)15 ResultMap (org.apache.ibatis.mapping.ResultMap)12 Statement (java.sql.Statement)10 StatementHandler (org.apache.ibatis.executor.statement.StatementHandler)9 ParameterMap (org.apache.ibatis.mapping.ParameterMap)9 Section (org.apache.ibatis.domain.blog.Section)8 BoundSql (org.apache.ibatis.mapping.BoundSql)8 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)8 ResultMapping (org.apache.ibatis.mapping.ResultMapping)7 SqlSource (org.apache.ibatis.mapping.SqlSource)7 RowBounds (org.apache.ibatis.session.RowBounds)7 Post (org.apache.ibatis.domain.blog.Post)6