Search in sources :

Example 51 with Configuration

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

the class SerializableProxyTest method shouldGenerateWriteReplace.

@Test
public void shouldGenerateWriteReplace() throws Exception {
    try {
        author.getClass().getDeclaredMethod("writeReplace");
        fail("Author should not have a writeReplace method");
    } catch (NoSuchMethodException e) {
    // ok
    }
    Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Method m = proxy.getClass().getDeclaredMethod("writeReplace");
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 52 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 53 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 54 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 55 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)

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