Search in sources :

Example 16 with DefaultObjectFactory

use of org.apache.ibatis.reflection.factory.DefaultObjectFactory in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldSerializeAProxyForABeanWithoutDefaultConstructorAndUnloadedProperties.

@Test
public void shouldSerializeAProxyForABeanWithoutDefaultConstructorAndUnloadedProperties() throws Exception {
    AuthorWithoutDefaultConstructor author = new AuthorWithoutDefaultConstructor(999, "someone", "!@#@!#!@#", "someone@somewhere.com", "blah", Section.NEWS);
    ArrayList<Class<?>> argTypes = new ArrayList<Class<?>>();
    argTypes.add(Integer.class);
    argTypes.add(String.class);
    argTypes.add(String.class);
    argTypes.add(String.class);
    argTypes.add(String.class);
    argTypes.add(Section.class);
    ArrayList<Object> argValues = new ArrayList<Object>();
    argValues.add(999);
    argValues.add("someone");
    argValues.add("!@#@!#!@#");
    argValues.add("someone@somewhere.com");
    argValues.add("blah");
    argValues.add(Section.NEWS);
    ResultLoaderMap loader = new ResultLoaderMap();
    loader.addLoader("id", null, null);
    Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), argTypes, argValues);
    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) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with DefaultObjectFactory

use of org.apache.ibatis.reflection.factory.DefaultObjectFactory in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldLetReadALoadedPropertyAfterSerialization.

@Test
public void shouldLetReadALoadedPropertyAfterSerialization() throws Exception {
    Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    byte[] ser = serialize((Serializable) proxy);
    Author author2 = (Author) deserialize(ser);
    assertEquals(999, 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 18 with DefaultObjectFactory

use of org.apache.ibatis.reflection.factory.DefaultObjectFactory in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldSerializeAProxyForABeanWithoutDefaultConstructor.

@Test
public void shouldSerializeAProxyForABeanWithoutDefaultConstructor() throws Exception {
    AuthorWithoutDefaultConstructor author = new AuthorWithoutDefaultConstructor(999, "someone", "!@#@!#!@#", "someone@somewhere.com", "blah", Section.NEWS);
    ArrayList<Class<?>> argTypes = new ArrayList<Class<?>>();
    argTypes.add(Integer.class);
    argTypes.add(String.class);
    argTypes.add(String.class);
    argTypes.add(String.class);
    argTypes.add(String.class);
    argTypes.add(Section.class);
    ArrayList<Object> argValues = new ArrayList<Object>();
    argValues.add(999);
    argValues.add("someone");
    argValues.add("!@#@!#!@#");
    argValues.add("someone@somewhere.com");
    argValues.add("blah");
    argValues.add(Section.NEWS);
    Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), argTypes, argValues);
    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) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with DefaultObjectFactory

use of org.apache.ibatis.reflection.factory.DefaultObjectFactory in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldSerizaliceAFullLoadedObjectToOriginalClass.

@Test
public void shouldSerizaliceAFullLoadedObjectToOriginalClass() 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.getClass(), proxy2.getClass());
}
Also used : Serializable(java.io.Serializable) Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Test(org.junit.Test)

Aggregations

DefaultObjectFactory (org.apache.ibatis.reflection.factory.DefaultObjectFactory)19 Test (org.junit.Test)19 Author (org.apache.ibatis.domain.blog.Author)13 Configuration (org.apache.ibatis.session.Configuration)13 ArrayList (java.util.ArrayList)7 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 CglibProxyFactory (org.apache.ibatis.executor.loader.cglib.CglibProxyFactory)2 Method (java.lang.reflect.Method)1 Proxy (javassist.util.proxy.Proxy)1 Factory (net.sf.cglib.proxy.Factory)1 JavassistProxyFactory (org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory)1