Search in sources :

Example 1 with Configuration

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

the class SerializableProxyTest method shouldNotGenerateWriteReplaceItThereIsAlreadyOne.

@Test
public void shouldNotGenerateWriteReplaceItThereIsAlreadyOne() throws Exception {
    AuthorWithWriteReplaceMethod beanWithWriteReplace = new AuthorWithWriteReplaceMethod(999, "someone", "!@#@!#!@#", "someone@somewhere.com", "blah", Section.NEWS);
    try {
        beanWithWriteReplace.getClass().getDeclaredMethod("writeReplace");
    } catch (NoSuchMethodException e) {
        fail("Bean should declare a writeReplace method");
    }
    Object proxy = proxyFactory.createProxy(beanWithWriteReplace, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Class<?>[] interfaces = proxy.getClass().getInterfaces();
    boolean ownInterfaceFound = false;
    for (Class<?> i : interfaces) {
        if (i.equals(WriteReplaceInterface.class)) {
            ownInterfaceFound = true;
            break;
        }
    }
    assertFalse(ownInterfaceFound);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Test(org.junit.Test)

Example 2 with Configuration

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

the class SerializableProxyTest method shouldSerializeAProxyForABeanWithDefaultConstructor.

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

Example 3 with Configuration

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

the class SerializableProxyTest method shouldNotLetReadUnloadedPropertyAfterTwoSerializations.

@Test(expected = ExecutorException.class)
public void shouldNotLetReadUnloadedPropertyAfterTwoSerializations() 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(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 4 with Configuration

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

the class SerializableProxyTest method shouldKeepGenericTypes.

@Test
public void shouldKeepGenericTypes() throws Exception {
    for (int i = 0; i < 10000; i++) {
        Author pc = new Author();
        Author proxy = (Author) proxyFactory.createProxy(pc, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
        proxy.getBio();
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) ArrayList(java.util.ArrayList) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 5 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)

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