Search in sources :

Example 31 with Configuration

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

the class ProviderTest method shouldUseProvider.

@Test
public void shouldUseProvider() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/ProviderConfig.xml");
    DefaultSqlSessionFactory sqlSessionFactory = (DefaultSqlSessionFactory) new SqlSessionFactoryBuilder().build(reader);
    Configuration c = sqlSessionFactory.getConfiguration();
    assertEquals("translated", c.getDatabaseId());
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.Test)

Example 32 with Configuration

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

the class InvalidNamedConstructorArgsTest method missingRequiredJavaType.

@Test
public void missingRequiredJavaType() {
    ex.expect(BuilderException.class);
    ex.expectMessage(allOf(containsString("'org.apache.ibatis.submitted.named_constructor_args.InvalidNamedConstructorArgsTest$ConstructorMissingRequiresJavaType.select-void'"), containsString("'org.apache.ibatis.submitted.named_constructor_args.User'"), containsString("[id]")));
    Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.addMapper(ConstructorMissingRequiresJavaType.class);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Test(org.junit.Test)

Example 33 with Configuration

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

the class NamedConstructorArgsTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.setUseActualParamName(false);
    configuration.addMapper(Mapper.class);
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 34 with Configuration

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

the class WrongMapperTest method shouldFailForBothOneAndMany.

@Test(expected = RuntimeException.class)
public void shouldFailForBothOneAndMany() throws Exception {
    Configuration configuration = new Configuration();
    configuration.addMapper(MapperWithOneAndMany.class);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Test(org.junit.Test)

Example 35 with Configuration

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

the class WrongNamespacesTest method shouldFailForWrongNamespace.

@Test(expected = RuntimeException.class)
public void shouldFailForWrongNamespace() throws Exception {
    Configuration configuration = new Configuration();
    configuration.addMapper(WrongNamespaceMapper.class);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.ibatis.session.Configuration)121 Test (org.junit.Test)85 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)30 Environment (org.apache.ibatis.mapping.Environment)19 Reader (java.io.Reader)18 BoundSql (org.apache.ibatis.mapping.BoundSql)18 BaseDataTest (org.apache.ibatis.BaseDataTest)17 MappedStatement (org.apache.ibatis.mapping.MappedStatement)17 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)17 Connection (java.sql.Connection)16 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)16 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)16 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 StatementHandler (org.apache.ibatis.executor.statement.StatementHandler)10 WhereSqlNode (org.apache.ibatis.scripting.xmltags.WhereSqlNode)10