labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
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 GMT
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<String> 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<Modification> mods = new ArrayList<Modification>();
+	
+	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<MethodDef> 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


Mime
View raw message