Search in sources :

Example 6 with Configuration

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

the class SerializableProxyTest method shouldNotCreateAProxyForAFullyLoadedBean.

@Test
public void shouldNotCreateAProxyForAFullyLoadedBean() throws Exception {
    Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Author author2 = (Author) deserialize(serialize((Serializable) proxy));
    assertEquals(author.getClass(), author2.getClass());
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 7 with Configuration

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

the class SerializableProxyTest method shouldNotLetReadUnloadedPropertyAfterSerialization.

@Test(expected = ExecutorException.class)
public void shouldNotLetReadUnloadedPropertyAfterSerialization() throws Exception {
    ResultLoaderMap loader = new ResultLoaderMap();
    loader.addLoader("id", null, null);
    Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Author author2 = (Author) deserialize(serialize((Serializable) proxy));
    author2.getId();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 8 with Configuration

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

the class DefaultResultSetHandlerTest method getMappedStatement.

MappedStatement getMappedStatement() {
    final Configuration config = new Configuration();
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    return new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps(new ArrayList<ResultMap>() {

        {
            add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() {

                {
                    add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build());
                }
            }).build());
        }
    }).build();
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) Configuration(org.apache.ibatis.session.Configuration) ResultMapping(org.apache.ibatis.mapping.ResultMapping) ArrayList(java.util.ArrayList) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Example 9 with Configuration

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

the class DynamicSqlSourceTest method shouldIterateOnceForEachItemInCollection.

@Test
public void shouldIterateOnceForEachItemInCollection() throws Exception {
    final HashMap<String, String[]> parameterObject = new HashMap<String, String[]>() {

        {
            put("array", new String[] { "one", "two", "three" });
        }
    };
    final String expected = "SELECT * FROM BLOG WHERE ID in (  one = ? AND two = ? AND three = ? )";
    DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG WHERE ID in"), new ForEachSqlNode(new Configuration(), mixedContents(new TextSqlNode("${item} = #{item}")), "array", "index", "item", "(", ")", "AND"));
    BoundSql boundSql = source.getBoundSql(parameterObject);
    assertEquals(expected, boundSql.getSql());
    assertEquals(3, boundSql.getParameterMappings().size());
    assertEquals("__frch_item_0", boundSql.getParameterMappings().get(0).getProperty());
    assertEquals("__frch_item_1", boundSql.getParameterMappings().get(1).getProperty());
    assertEquals("__frch_item_2", boundSql.getParameterMappings().get(2).getProperty());
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) Configuration(org.apache.ibatis.session.Configuration) HashMap(java.util.HashMap) BoundSql(org.apache.ibatis.mapping.BoundSql) ForEachSqlNode(org.apache.ibatis.scripting.xmltags.ForEachSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 10 with Configuration

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

the class DynamicSqlSourceTest method shouldTrimWHEREInsteadOfANDForBothConditions.

@Test
public void shouldTrimWHEREInsteadOfANDForBothConditions() throws Exception {
    final String expected = "SELECT * FROM BLOG WHERE  ID = ?   OR NAME = ?";
    DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode("   and ID = ?   ")), "true"), new IfSqlNode(mixedContents(new TextSqlNode("OR NAME = ?  ")), "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)

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