Java Code Examples for org.apache.ibatis.reflection.factory.ObjectFactory

The following examples show how to use org.apache.ibatis.reflection.factory.ObjectFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mybaties   Source File: MetaObject.java    License: Apache License 2.0 6 votes vote down vote up
private MetaObject(Object object, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory) {
  this.originalObject = object;
  this.objectFactory = objectFactory;
  this.objectWrapperFactory = objectWrapperFactory;

  if (object instanceof ObjectWrapper) {
      //如果对象本身已经是ObjectWrapper型,则直接赋给objectWrapper
    this.objectWrapper = (ObjectWrapper) object;
  } else if (objectWrapperFactory.hasWrapperFor(object)) {
      //如果有包装器,调用ObjectWrapperFactory.getWrapperFor
    this.objectWrapper = objectWrapperFactory.getWrapperFor(this, object);
  } else if (object instanceof Map) {
      //如果是Map型,返回MapWrapper
    this.objectWrapper = new MapWrapper(this, (Map) object);
  } else if (object instanceof Collection) {
      //如果是Collection型,返回CollectionWrapper
    this.objectWrapper = new CollectionWrapper(this, (Collection) object);
  } else {
      //除此以外,返回BeanWrapper
    this.objectWrapper = new BeanWrapper(this, object);
  }
}
 
Example 2
Source Project: mybatis   Source File: MetaObject.java    License: Apache License 2.0 6 votes vote down vote up
private MetaObject(Object object, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory) {
  this.originalObject = object;
  this.objectFactory = objectFactory;
  this.objectWrapperFactory = objectWrapperFactory;

  if (object instanceof ObjectWrapper) {
      //如果对象本身已经是ObjectWrapper型,则直接赋给objectWrapper
    this.objectWrapper = (ObjectWrapper) object;
  } else if (objectWrapperFactory.hasWrapperFor(object)) {
      //如果有包装器,调用ObjectWrapperFactory.getWrapperFor
    this.objectWrapper = objectWrapperFactory.getWrapperFor(this, object);
  } else if (object instanceof Map) {
      //如果是Map型,返回MapWrapper
    this.objectWrapper = new MapWrapper(this, (Map) object);
  } else if (object instanceof Collection) {
      //如果是Collection型,返回CollectionWrapper
    this.objectWrapper = new CollectionWrapper(this, (Collection) object);
  } else {
      //除此以外,返回BeanWrapper
    this.objectWrapper = new BeanWrapper(this, object);
  }
}
 
Example 3
private void objectFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties properties = context.getChildrenAsProperties();
    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
    factory.setProperties(properties);
    configuration.setObjectFactory(factory);
  }
}
 
Example 4
Source Project: QuickProject   Source File: XMLConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void objectFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties properties = context.getChildrenAsProperties();
    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
    factory.setProperties(properties);
    configuration.setObjectFactory(factory);
  }
}
 
Example 5
Source Project: mybaties   Source File: BeanWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetaObject instantiatePropertyValue(String name, PropertyTokenizer prop, ObjectFactory objectFactory) {
  MetaObject metaValue;
  Class<?> type = getSetterType(prop.getName());
  try {
    Object newObject = objectFactory.create(type);
    metaValue = MetaObject.forObject(newObject, metaObject.getObjectFactory(), metaObject.getObjectWrapperFactory());
    set(prop, newObject);
  } catch (Exception e) {
    throw new ReflectionException("Cannot set value of property '" + name + "' because '" + name + "' is null and cannot be instantiated on instance of " + type.getName() + ". Cause:" + e.toString(), e);
  }
  return metaValue;
}
 
Example 6
Source Project: mybaties   Source File: MetaObject.java    License: Apache License 2.0 5 votes vote down vote up
public static MetaObject forObject(Object object, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory) {
  if (object == null) {
      //处理一下null,将null包装起来
    return SystemMetaObject.NULL_META_OBJECT;
  } else {
    return new MetaObject(object, objectFactory, objectWrapperFactory);
  }
}
 
Example 7
Source Project: mybaties   Source File: XMLConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void objectFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties properties = context.getChildrenAsProperties();
    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
    factory.setProperties(properties);
    configuration.setObjectFactory(factory);
  }
}
 
Example 8
Source Project: mybaties   Source File: AbstractSerialStateHolder.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractSerialStateHolder(
        final Object userBean,
        final Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        final ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) {
  this.userBean = userBean;
  this.unloadedProperties = new HashMap<String, ResultLoaderMap.LoadPair>(unloadedProperties);
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes.toArray(new Class<?>[constructorArgTypes.size()]);
  this.constructorArgs = constructorArgs.toArray(new Object[constructorArgs.size()]);
}
 
Example 9
Source Project: mybaties   Source File: JavassistSerialStateHolder.java    License: Apache License 2.0 5 votes vote down vote up
public JavassistSerialStateHolder(
        final Object userBean,
        final Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        final ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) {
  super(userBean, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
}
 
Example 10
Source Project: mybaties   Source File: JavassistProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
private EnhancedResultObjectProxyImpl(Class<?> type, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  this.type = type;
  this.lazyLoader = lazyLoader;
  this.aggressive = configuration.isAggressiveLazyLoading();
  this.lazyLoadTriggerMethods = configuration.getLazyLoadTriggerMethods();
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes;
  this.constructorArgs = constructorArgs;
}
 
Example 11
Source Project: mybaties   Source File: JavassistProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedResultObjectProxyImpl callback = new EnhancedResultObjectProxyImpl(type, lazyLoader, configuration, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 12
Source Project: mybaties   Source File: JavassistProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, Map<String, ResultLoaderMap.LoadPair> unloadedProperties, ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedDeserializationProxyImpl callback = new EnhancedDeserializationProxyImpl(type, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 13
Source Project: mybaties   Source File: CglibSerialStateHolder.java    License: Apache License 2.0 5 votes vote down vote up
public CglibSerialStateHolder(
        final Object userBean,
        final Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        final ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) {
  super(userBean, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
}
 
Example 14
Source Project: mybaties   Source File: CglibProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
private EnhancedResultObjectProxyImpl(Class<?> type, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  this.type = type;
  this.lazyLoader = lazyLoader;
  this.aggressive = configuration.isAggressiveLazyLoading();
  this.lazyLoadTriggerMethods = configuration.getLazyLoadTriggerMethods();
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes;
  this.constructorArgs = constructorArgs;
}
 
Example 15
Source Project: mybaties   Source File: CglibProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedResultObjectProxyImpl callback = new EnhancedResultObjectProxyImpl(type, lazyLoader, configuration, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 16
Source Project: mybaties   Source File: CglibProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, Map<String, ResultLoaderMap.LoadPair> unloadedProperties, ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedDeserializationProxyImpl callback = new EnhancedDeserializationProxyImpl(type, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 17
protected AbstractEnhancedDeserializationProxy(Class<?> type, Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  this.type = type;
  this.unloadedProperties = unloadedProperties;
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes;
  this.constructorArgs = constructorArgs;
  this.reloadingPropertyLock = new Object();
  this.reloadingProperty = false;
}
 
Example 18
Source Project: mybaties   Source File: DefaultMapResultHandler.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public DefaultMapResultHandler(String mapKey, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory) {
  this.objectFactory = objectFactory;
  this.objectWrapperFactory = objectWrapperFactory;
  this.mappedResults = objectFactory.create(Map.class);
  this.mapKey = mapKey;
}
 
Example 19
Source Project: mybatis   Source File: BeanWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MetaObject instantiatePropertyValue(String name, PropertyTokenizer prop, ObjectFactory objectFactory) {
  MetaObject metaValue;
  Class<?> type = getSetterType(prop.getName());
  try {
    Object newObject = objectFactory.create(type);
    metaValue = MetaObject.forObject(newObject, metaObject.getObjectFactory(), metaObject.getObjectWrapperFactory());
    set(prop, newObject);
  } catch (Exception e) {
    throw new ReflectionException("Cannot set value of property '" + name + "' because '" + name + "' is null and cannot be instantiated on instance of " + type.getName() + ". Cause:" + e.toString(), e);
  }
  return metaValue;
}
 
Example 20
Source Project: mybatis   Source File: MetaObject.java    License: Apache License 2.0 5 votes vote down vote up
public static MetaObject forObject(Object object, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory) {
  if (object == null) {
      //处理一下null,将null包装起来
    return SystemMetaObject.NULL_META_OBJECT;
  } else {
    return new MetaObject(object, objectFactory, objectWrapperFactory);
  }
}
 
Example 21
Source Project: mybatis   Source File: XMLConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void objectFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties properties = context.getChildrenAsProperties();
    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
    factory.setProperties(properties);
    configuration.setObjectFactory(factory);
  }
}
 
Example 22
Source Project: mybatis   Source File: AbstractSerialStateHolder.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractSerialStateHolder(
        final Object userBean,
        final Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        final ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) {
  this.userBean = userBean;
  this.unloadedProperties = new HashMap<String, ResultLoaderMap.LoadPair>(unloadedProperties);
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes.toArray(new Class<?>[constructorArgTypes.size()]);
  this.constructorArgs = constructorArgs.toArray(new Object[constructorArgs.size()]);
}
 
Example 23
Source Project: mybatis   Source File: JavassistSerialStateHolder.java    License: Apache License 2.0 5 votes vote down vote up
public JavassistSerialStateHolder(
        final Object userBean,
        final Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        final ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) {
  super(userBean, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
}
 
Example 24
Source Project: mybatis   Source File: JavassistProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
private EnhancedResultObjectProxyImpl(Class<?> type, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  this.type = type;
  this.lazyLoader = lazyLoader;
  this.aggressive = configuration.isAggressiveLazyLoading();
  this.lazyLoadTriggerMethods = configuration.getLazyLoadTriggerMethods();
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes;
  this.constructorArgs = constructorArgs;
}
 
Example 25
Source Project: mybatis   Source File: JavassistProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedResultObjectProxyImpl callback = new EnhancedResultObjectProxyImpl(type, lazyLoader, configuration, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 26
Source Project: mybatis   Source File: JavassistProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, Map<String, ResultLoaderMap.LoadPair> unloadedProperties, ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedDeserializationProxyImpl callback = new EnhancedDeserializationProxyImpl(type, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 27
Source Project: mybatis   Source File: CglibSerialStateHolder.java    License: Apache License 2.0 5 votes vote down vote up
public CglibSerialStateHolder(
        final Object userBean,
        final Map<String, ResultLoaderMap.LoadPair> unloadedProperties,
        final ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes,
        List<Object> constructorArgs) {
  super(userBean, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
}
 
Example 28
Source Project: mybatis   Source File: CglibProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
private EnhancedResultObjectProxyImpl(Class<?> type, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  this.type = type;
  this.lazyLoader = lazyLoader;
  this.aggressive = configuration.isAggressiveLazyLoading();
  this.lazyLoadTriggerMethods = configuration.getLazyLoadTriggerMethods();
  this.objectFactory = objectFactory;
  this.constructorArgTypes = constructorArgTypes;
  this.constructorArgs = constructorArgs;
}
 
Example 29
Source Project: mybatis   Source File: CglibProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedResultObjectProxyImpl callback = new EnhancedResultObjectProxyImpl(type, lazyLoader, configuration, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}
 
Example 30
Source Project: mybatis   Source File: CglibProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Object createProxy(Object target, Map<String, ResultLoaderMap.LoadPair> unloadedProperties, ObjectFactory objectFactory,
        List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
  final Class<?> type = target.getClass();
  EnhancedDeserializationProxyImpl callback = new EnhancedDeserializationProxyImpl(type, unloadedProperties, objectFactory, constructorArgTypes, constructorArgs);
  Object enhanced = crateProxy(type, callback, constructorArgTypes, constructorArgs);
  PropertyCopier.copyBeanProperties(type, target, enhanced);
  return enhanced;
}