Return-Path: Delivered-To: apmail-labs-commits-archive@minotaur.apache.org Received: (qmail 71473 invoked from network); 7 Apr 2009 16:50:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Apr 2009 16:50:01 -0000 Received: (qmail 24916 invoked by uid 500); 7 Apr 2009 16:50:00 -0000 Delivered-To: apmail-labs-commits-archive@labs.apache.org Received: (qmail 24776 invoked by uid 500); 7 Apr 2009 16:50:00 -0000 Mailing-List: contact commits-help@labs.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: labs@labs.apache.org Delivered-To: mailing list commits@labs.apache.org Received: (qmail 24767 invoked by uid 99); 7 Apr 2009 16:50:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2009 16:50:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2009 16:49:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 98FE22388970; Tue, 7 Apr 2009 16:49:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r762844 - in /labs/magma/trunk: foundation-beans/src/main/java/org/apache/magma/beans/ foundation-conversion/src/main/java/org/apache/magma/conversion/ Date: Tue, 07 Apr 2009 16:49:39 -0000 To: commits@labs.apache.org From: simoneg@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090407164939.98FE22388970@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: simoneg Date: Tue Apr 7 16:49:39 2009 New Revision: 762844 URL: http://svn.apache.org/viewvc?rev=762844&view=rev Log: LABS-335 : don't preload nested objects and collections Added: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/CollectionHandler.java Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeanHandler.java labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeanHandler.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeanHandler.java?rev=762844&r1=762843&r2=762844&view=diff ============================================================================== --- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeanHandler.java (original) +++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeanHandler.java Tue Apr 7 16:49:39 2009 @@ -106,6 +106,15 @@ PropertyInfo property = data.getProperty(field); if (property == null) throw new MagmaException("Cannot find a proprty named {0} in class {1}", field, bean.getClass().getName()); if (!property.isReadable()) throw new MagmaException("Property {0} is not readable in class {1}", field, bean.getClass().getName()); + if (!values.containsKey(field)) { + Object val = null; + try { + val = PropertyUtils.getProperty(bean, field); + } catch (Exception e) { + throw new MagmaException(e, "Error while fecthing property {0} from {1}", field, bean.getClass().getName()); + } + values.put(field, val); + } return values.get(field); } @@ -119,7 +128,7 @@ Set names = data.getPropertyNames(); for (String name : names) { PropertyInfo property = data.getProperty(name); - if (property.isReadable()) { + if (property.isReadable() && property.isBasicType()) { Object val = null; try { val = PropertyUtils.getProperty(bean, name); @@ -157,8 +166,8 @@ * @param property */ public void updated(PropertyInfo property) { - if (property.isReadable()) { - String name = property.getName(); + String name = property.getName(); + if (property.isReadable() && (property.isBasicType() || values.containsKey(name))) { Object val = null; try { val = PropertyUtils.getProperty(bean, name); Added: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/CollectionHandler.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/CollectionHandler.java?rev=762844&view=auto ============================================================================== --- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/CollectionHandler.java (added) +++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/CollectionHandler.java Tue Apr 7 16:49:39 2009 @@ -0,0 +1,27 @@ +package org.apache.magma.beans; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class CollectionHandler { + + private Collection mycollection; + + private List mods = new ArrayList(); + + public CollectionHandler(Collection coll) { + this.mycollection = coll; + } + + public void rollback() { + + } + + class Modification { + public Object targetId; + } + + + +} Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java?rev=762844&r1=762843&r2=762844&view=diff ============================================================================== --- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java (original) +++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java Tue Apr 7 16:49:39 2009 @@ -20,6 +20,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.Set; @@ -76,6 +77,11 @@ * If content of this property is rendered as a string, the maximum size of this string. */ private int maxStringSize = -1; + + /** + * If the type is a basic type, that is a primitive type, a wrapper, one of java.math numbers, or Date. + */ + private boolean isBasicType; /** * @return true if this property is readable from the bean, false otherwise @@ -118,6 +124,13 @@ } /** + * @return true if the type is a basic type, that is a primitive type, a wrapper, one of java.math numbers, or Date. + */ + public boolean isBasicType() { + return this.isBasicType; + } + + /** * Initializes this class, parsing the {@link PropertyDescriptor} and eventually annotations found on the getter or setter methods. * * This is the method to hook to when implementing additional parsing, like validation and conversion does. @@ -129,9 +142,18 @@ this.beanClass = beanClass; this.name = descriptor.getName(); this.type = descriptor.getPropertyType(); + this.readable = descriptor.getReadMethod() != null; + this.writeable = descriptor.getWriteMethod() != null; if (this.type != null) { this.isCollection = Collection.class.isAssignableFrom(this.type); - if (this.isCollection && descriptor.getReadMethod() != null) { + if (!this.isCollection) { + this.isBasicType = + this.type.isPrimitive() || + this.type.getName().startsWith("java.lang") || + this.type.getName().startsWith("java.math") || + Date.class.isAssignableFrom(this.type); + + } else if (descriptor.getReadMethod() != null) { GenericClass returnType = GenericClass.forReturnType(descriptor.getReadMethod()); // It must have an add method List methods = returnType.findMethods("add", new Class[] {null}); @@ -139,8 +161,6 @@ this.collectionClass = methods.get(0).getParameterTypes()[0].getBaseClass(); } } - this.readable = descriptor.getReadMethod() != null; - this.writeable = descriptor.getWriteMethod() != null; } /** Modified: labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj?rev=762844&r1=762843&r2=762844&view=diff ============================================================================== --- labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj (original) +++ labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj Tue Apr 7 16:49:39 2009 @@ -50,6 +50,10 @@ PropertyInfo property = data.getProperty(field); if (property == null) throw new MagmaException("Cannot find a proprty named {0} in class {1}", field, bean.getClass().getName()); if (!property.isReadable()) throw new MagmaException("Property {0} is not readable in class {1}", field, bean.getClass().getName()); + if (!stringValues.containsKey(field)) { + Object val = getValue(field); + loadConverted(property, val); + } return stringValues.get(field); } @@ -65,22 +69,27 @@ for (String name : names) { PropertyInfo property = this.data.getProperty(name); Object val = this.values.get(name); - if (val != null) { - Converter conv = property.getConverter(); - if (conv != null) { - this.stringValues.put(name, conv.toString(val)); + loadConverted(property, val); + } + } + + private void BeanHandler.loadConverted(PropertyInfo property, Object val) { + String name = property.getName(); + if (val != null) { + Converter conv = property.getConverter(); + if (conv != null) { + this.stringValues.put(name, conv.toString(val)); + } else { + if (val instanceof String) { + this.stringValues.put(name, (String)val); } else { - if (val instanceof String) { - this.stringValues.put(name, (String)val); - } else { - this.stringValues.put(name, "N/A"); - this.nonConverted.add(name); - //throw new MagmaException("Property {0}.{1} is not a string but does not have a convertor", this.data.getBeanClass().getName(), name); - } + this.stringValues.put(name, "N/A"); + this.nonConverted.add(name); + //throw new MagmaException("Property {0}.{1} is not a string but does not have a convertor", this.data.getBeanClass().getName(), name); } - } else { - this.stringValues.put(name, null); } + } else { + this.stringValues.put(name, null); } } @@ -134,21 +143,7 @@ public void BeanHandler.updatedStringValue(String name) { PropertyInfo property = this.data.getProperty(name); Object val = this.values.get(name); - if (val != null) { - Converter conv = property.getConverter(); - if (conv != null) { - this.stringValues.put(name, conv.toString(val)); - } else { - if (val instanceof String) { - this.stringValues.put(name, (String)val); - } else { - this.stringValues.put(name, "N/A"); - //throw new MagmaException("Property {0}.{1} is not a string but does not have a convertor", this.data.getBeanClass().getName(), name); - } - } - } else { - this.stringValues.put(name, null); - } + loadConverted(property, val); this.explicitlySet.remove(name); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org For additional commands, e-mail: commits-help@labs.apache.org