incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r465344 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ test-config/ test/org/apache/portals/graffito/jcr/persistence/inheritance/ test/org/apache/portals/graffito/j...
Date Wed, 18 Oct 2006 19:24:00 GMT
Author: clombart
Date: Wed Oct 18 12:23:59 2006
New Revision: 465344

URL: http://svn.apache.org/viewvc?view=rev&rev=465344
Log:
* Review the method retrieveSimpleFields which contains bad field convertions (see GRFT-103).
* Add unit tests.

Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Descendant.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?view=diff&rev=465344&r1=465343&r2=465344
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
Wed Oct 18 12:23:59 2006
@@ -536,55 +536,89 @@
 	 * @throws JcrMappingException
 	 * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
 	 */
-	private Object retrieveSimpleFields(Session session, ClassDescriptor classDescriptor, Node
node, Object object) {
+	private Object retrieveSimpleFields(Session session, ClassDescriptor classDescriptor, Node
node, Object object) 
+	{
 		Object initializedBean = object;
-		try {
+		try 
+		{
 			Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
 
-			while (fieldDescriptorIterator.hasNext()) {
+			while (fieldDescriptorIterator.hasNext()) 
+			{
 				FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
 
 				String fieldName = fieldDescriptor.getFieldName();
 				String propertyName = fieldDescriptor.getJcrName();
 
-				if (fieldDescriptor.isPath()) {
-					// HINT: lazy initialize target bean - The bean can be null
-					// when it is inline
-					if (null == initializedBean) {
+				if (fieldDescriptor.isPath()) 
+				{
+					// HINT: lazy initialize target bean - The bean can be null when it is inline
+					if (null == initializedBean) 
+					{
 						initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
 					}
 
 					ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath());
-
-				} else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && classDescriptor.hasDiscriminator())
{
-
-					if (node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) {
-						if (null == initializedBean) {
-							initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-						}
-						String value = node.getProperty(propertyName).getValue().getString();
-						ReflectionUtils.setNestedProperty(initializedBean, fieldName, value);
-					} else {
-						throw new PersistenceException("Class '" + classDescriptor.getClassName()
-								+ "' have not a discriminator property.");
+					
+				} 
+				else
+				{
+					if (classDescriptor.usesNodeTypePerHierarchyStrategy() && classDescriptor.hasDiscriminator())

+					{
+						if ( ! node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) 
+						{
+							throw new PersistenceException("Class '" + classDescriptor.getClassName() + "' has
not a discriminator property.");
+						}					
 					}
-				} else {
-					if (node.hasProperty(propertyName)) {
+					if (node.hasProperty(propertyName)) 
+					{
 						Value propValue = node.getProperty(propertyName).getValue();
-						// HINT: lazy initialize target bean - The bean can be
-						// null when it is inline
+						// HINT: lazy initialize target bean - The bean can be null when it is inline
 						if (null != propValue && null == initializedBean) {
 							initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
 						}
 
 						AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, initializedBean,
fieldName);
-
 						Object fieldValue = converter.getObject(propValue);
 						ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
-					} else {
+					} 
+					else 
+					{
 						log.warn("Class '" + classDescriptor.getClassName() + "' has an unmapped property :
" + propertyName);
 					}
 				}
+				
+//				} else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && classDescriptor.hasDiscriminator())
{
+//
+//					if (node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) {
+//						if (null == initializedBean) {
+//							initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+//						}
+//						Value propValue = node.getProperty(propertyName).getValue();
+//						AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, initializedBean,
fieldName);
+//						Object fieldValue = converter.getObject(propValue);
+//						ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
+//						
+//					} else {
+//						throw new PersistenceException("Class '" + classDescriptor.getClassName()
+//								+ "' have not a discriminator property.");
+//					}
+//				} else {
+//					if (node.hasProperty(propertyName)) {
+//						Value propValue = node.getProperty(propertyName).getValue();
+//						// HINT: lazy initialize target bean - The bean can be
+//						// null when it is inline
+//						if (null != propValue && null == initializedBean) {
+//							initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+//						}
+//
+//						AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, initializedBean,
fieldName);
+//						Object fieldValue = converter.getObject(propValue);
+//						ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
+//					} else {
+//						log.warn("Class '" + classDescriptor.getClassName() + "' has an unmapped property
: " + propertyName);
+//					}
+//				}
 			}
 		} catch (ValueFormatException vfe) {
 			throw new PersistenceException("Cannot retrieve properties of object " + object + " from
node " + node, vfe);

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml?view=diff&rev=465344&r1=465343&r2=465344
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml Wed
Oct 18 12:23:59 2006
@@ -35,7 +35,9 @@
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant"

 	                                   extend="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor">
 	    <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.AnotherInterface"
/>
+	    	    
 		<field-descriptor fieldName="descendantField" jcrName="descendantField" />  
+		<field-descriptor fieldName="intField" jcrName="intField" />  
 	</class-descriptor >
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant"


Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java?view=diff&rev=465344&r1=465343&r2=465344
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java
Wed Oct 18 12:23:59 2006
@@ -77,6 +77,7 @@
 			Descendant descendant = new Descendant();
 			descendant.setDescendantField("descendantValue");
 			descendant.setAncestorField("ancestorValue");
+			descendant.setIntField(200);
 			descendant.setPath("/test");
 			persistenceManager.insert(descendant);
 			persistenceManager.save();
@@ -88,12 +89,14 @@
 			descendant = (Descendant) persistenceManager.getObject(	 "/test");
 			assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
 			assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "ancestorValue");
-			assertEquals("Descendant descendantField is invalid", descendant	.getDescendantField(),
"descendantValue");
+			assertEquals("Descendant descendantField is invalid", descendant.getDescendantField(),
"descendantValue");
+			assertEquals("Descendant intField is invalid", descendant.getIntField(), 200);
 
 			//---------------------------------------------------------------------------------------------------------
 			// Update  a descendant object
 			//---------------------------------------------------------------------------------------------------------
					
 			descendant.setAncestorField("anotherAncestorValue");
+			descendant.setIntField(123);
 			persistenceManager.update(descendant);
 			persistenceManager.save();
 
@@ -105,6 +108,7 @@
 			assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
 			assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "anotherAncestorValue");
 			assertEquals("Descendant descendantField is invalid", descendant	.getDescendantField(),
"descendantValue");
+			assertEquals("Descendant intField is invalid", descendant.getIntField(), 123);
 
 			Ancestor ancestor = (Ancestor) persistenceManager.getObject("/test");
 			assertTrue("Invalid object instance", ancestor instanceof Descendant );

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Descendant.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Descendant.java?view=diff&rev=465344&r1=465343&r2=465344
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Descendant.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Descendant.java
Wed Oct 18 12:23:59 2006
@@ -20,7 +20,7 @@
 public class Descendant extends Ancestor implements AnotherInterface {
 
 	protected String descendantField;
-
+	protected int intField;
 	
 
 	public String getDescendantField() {
@@ -29,6 +29,14 @@
 
 	public void setDescendantField(String descendantField) {
 		this.descendantField = descendantField;
+	}
+
+	public int getIntField() {
+		return intField;
+	}
+
+	public void setIntField(int intField) {
+		this.intField = intField;
 	}
 
 



Mime
View raw message