Search in sources :

Example 81 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class SqlProviderTest method methodNotFound.

@Test
public void methodNotFound() throws NoSuchMethodException {
    expectedException.expect(BuilderException.class);
    expectedException.expectMessage(is("Error creating SqlSource for SqlProvider. Method 'methodNotFound' not found in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'."));
    new ProviderSqlSource(new Configuration(), ErrorMapper.class.getMethod("methodNotFound").getAnnotation(SelectProvider.class));
}
Also used : SelectProvider(org.apache.ibatis.annotations.SelectProvider) Configuration(org.apache.ibatis.session.Configuration) ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) Test(org.junit.Test)

Example 82 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class MultipleCrossIncludeTest method getSqlSessionFactoryJavaConfig.

private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
    initDb(c);
    Configuration configuration = new Configuration();
    Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
    configuration.setEnvironment(environment);
    configuration.addMapper(MultipleCrossIncludePersonMapper.class);
    configuration.addMapper(MultipleCrossIncludePetMapper.class);
    return new SqlSessionFactoryBuilder().build(configuration);
}
Also used : UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) Configuration(org.apache.ibatis.session.Configuration) Connection(java.sql.Connection) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)

Example 83 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class MultipleCrossIncludeTest method testMappedStatementCache.

@Test
public void testMappedStatementCache() throws Exception {
    Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MultipleCrossIncludeMapperConfig.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.MultipleCrossIncludePetMapper.select");
    MappedStatement selectPersonStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.MultipleCrossIncludePersonMapper.select");
    Cache cache = selectPetStatement.getCache();
    assertEquals("org.apache.ibatis.submitted.xml_external_ref.MultipleCrossIncludePetMapper", 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 84 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class MultipleIncludeTest method getSqlSessionFactoryJavaConfig.

private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
    initDb(c);
    Configuration configuration = new Configuration();
    Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
    configuration.setEnvironment(environment);
    configuration.addMapper(MultipleIncludePersonMapper.class);
    return new SqlSessionFactoryBuilder().build(configuration);
}
Also used : UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) Configuration(org.apache.ibatis.session.Configuration) Connection(java.sql.Connection) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)

Example 85 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class SubstitutionInAnnotsTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", "");
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(c);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    c.commit();
    reader.close();
    Configuration configuration = new Configuration();
    Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
    configuration.setEnvironment(environment);
    configuration.addMapper(SubstitutionInAnnotsMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) Configuration(org.apache.ibatis.session.Configuration) Connection(java.sql.Connection) Reader(java.io.Reader) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

Configuration (org.apache.ibatis.session.Configuration)118 Test (org.junit.Test)85 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)30 Environment (org.apache.ibatis.mapping.Environment)19 Reader (java.io.Reader)18 BaseDataTest (org.apache.ibatis.BaseDataTest)17 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)17 BoundSql (org.apache.ibatis.mapping.BoundSql)16 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)16 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)16 Connection (java.sql.Connection)15 MappedStatement (org.apache.ibatis.mapping.MappedStatement)15 DefaultObjectFactory (org.apache.ibatis.reflection.factory.DefaultObjectFactory)13 SqlSession (org.apache.ibatis.session.SqlSession)13 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)13 Properties (java.util.Properties)12 IfSqlNode (org.apache.ibatis.scripting.xmltags.IfSqlNode)12 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 WhereSqlNode (org.apache.ibatis.scripting.xmltags.WhereSqlNode)10 Statement (java.sql.Statement)9