Ejemplo n.º 1
0
 public void load() {
   Object value = null;
   @SuppressWarnings("unchecked") // we suppose we get back a List
   List<Object> list = (List<Object>) localCache.getObject(key);
   Class<?> targetType = resultObject.getSetterType(property);
   if (targetType.isAssignableFrom(list.getClass())) {
     value = list;
   } else if (objectFactory.isCollection(targetType)) {
     value = objectFactory.create(targetType);
     MetaObject metaObject = configuration.newMetaObject(value);
     metaObject.addAll(list);
   } else if (targetType.isArray()) {
     Object[] array = (Object[]) Array.newInstance(targetType.getComponentType(), list.size());
     value = list.toArray(array);
   } else {
     if (list != null && list.size() > 1) {
       throw new ExecutorException(
           "Statement returned more than one row, where no more than one was expected.");
     } else if (list != null && list.size() == 1) {
       value = list.get(0);
     }
   }
   resultObject.setValue(property, value);
 }
Ejemplo n.º 2
0
 private <E> Object convertToDeclaredCollection(Configuration config, List<E> list) {
   Object collection = config.getObjectFactory().create(method.getReturnType());
   MetaObject metaObject = config.newMetaObject(collection);
   metaObject.addAll(list);
   return collection;
 }