Search in sources :

Example 16 with Configuration

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

the class DynamicSqlSourceTest method shouldTrimWHEREORWithTABForFirstCondition.

@Test
public void shouldTrimWHEREORWithTABForFirstCondition() throws Exception {
    final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
    DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode("   or\t ID = ?  ")), "true"))));
    BoundSql boundSql = source.getBoundSql(null);
    assertEquals(expected, boundSql.getSql());
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) Configuration(org.apache.ibatis.session.Configuration) BoundSql(org.apache.ibatis.mapping.BoundSql) WhereSqlNode(org.apache.ibatis.scripting.xmltags.WhereSqlNode) IfSqlNode(org.apache.ibatis.scripting.xmltags.IfSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 17 with Configuration

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

the class DynamicSqlSourceTest method createDynamicSqlSource.

private DynamicSqlSource createDynamicSqlSource(SqlNode... contents) throws IOException, SQLException {
    createBlogDataSource();
    final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
    final Reader reader = Resources.getResourceAsReader(resource);
    SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
    Configuration configuration = sqlMapper.getConfiguration();
    MixedSqlNode sqlNode = mixedContents(contents);
    return new DynamicSqlSource(configuration, sqlNode);
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) Configuration(org.apache.ibatis.session.Configuration) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) MixedSqlNode(org.apache.ibatis.scripting.xmltags.MixedSqlNode)

Example 18 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 19 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)

Example 20 with Configuration

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

the class WrongNamespacesTest method shouldFailForMissingNamespace.

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

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