Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 public Object intercept(Object enhanced, Method method, Object[] args, MethodProxy methodProxy)
     throws Throwable {
   final String methodName = method.getName();
   try {
     synchronized (lazyLoader) {
       if (WRITE_REPLACE_METHOD.equals(methodName)) {
         Object original = null;
         if (constructorArgTypes.isEmpty()) {
           original = objectFactory.create(type);
         } else {
           original = objectFactory.create(type, constructorArgTypes, constructorArgs);
         }
         PropertyCopier.copyBeanProperties(type, enhanced, original);
         if (lazyLoader.size() > 0) {
           return new CglibSerialStateHolder(
               original,
               lazyLoader.getProperties(),
               objectFactory,
               constructorArgTypes,
               constructorArgs);
         } else {
           return original;
         }
       } else {
         if (lazyLoader.size() > 0 && !FINALIZE_METHOD.equals(methodName)) {
           if (aggressive || lazyLoadTriggerMethods.contains(methodName)) {
             lazyLoader.loadAll();
           } else if (PropertyNamer.isProperty(methodName)) {
             final String property = PropertyNamer.methodToProperty(methodName);
             if (lazyLoader.hasLoader(property)) {
               lazyLoader.load(property);
             }
           }
         }
       }
     }
     return methodProxy.invokeSuper(enhanced, args);
   } catch (Throwable t) {
     throw ExceptionUtil.unwrapThrowable(t);
   }
 }