You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2005/10/10 22:00:30 UTC
svn commit: r312759 - in /incubator/graffito/trunk/jcr-mapping/src:
java/org/apache/portals/graffito/jcr/mapper/model/
java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/
java/org/apache/portals/graffito/jcr/persistence/atomictypeconv...
Author: clombart
Date: Mon Oct 10 15:00:01 2005
New Revision: 312759
URL: http://svn.apache.org/viewcvs?rev=312759&view=rev
Log:
* Refactor the search capabilities in order to use the appropriate converter classe in the search filder object
* Add support for multiValue properties - I'm going to add new unit test for searching on multivalue properties
Added:
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/MultiValue.java
Modified:
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/hashmap/HashMapElement.java
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java Mon Oct 10 15:00:01 2005
@@ -30,6 +30,7 @@
private String jcrName;
private ClassDescriptor classDescriptor;
private boolean id;
+
/**
@@ -78,6 +79,4 @@
{
this.id = id;
}
-
-
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter;
-import javax.jcr.Node;
import javax.jcr.Value;
import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
@@ -46,13 +45,20 @@
public Value getValue(Object object) throws IncorrectAtomicTypeException;
/**
- * Convert a jcr property into an object
+ * Convert a jcr property value into an object
*
- * @param node The jcr node
- * @param jcrPropName the node property name
+ * @param value The JCR property value
* @return the matching object
* @throws IncorrectAtomicTypeException when it is not possible to convert the JCR property
*/
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException;
+ public Object getObject(Value value) throws IncorrectAtomicTypeException;
+
+ /**
+ * Get the string converted value
+ * @param object The object value
+ * @return The string converted value
+ * @throws IncorrectAtomicTypeException when it is not possible to convert the object value into String
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException;
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -16,7 +16,6 @@
*/
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -47,11 +46,11 @@
public abstract Value getValue(Object propValue) throws IncorrectAtomicTypeException;
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public abstract Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException;
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+ */
+ public abstract Object getObject(Value value) throws IncorrectAtomicTypeException;
/**
* Set the JCR value factory
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -19,7 +19,6 @@
import java.io.InputStream;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -59,27 +58,30 @@
*
* @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
*/
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
{
-
- try
- {
-
- if (node.hasProperty(jcrPropName) == true)
- {
- return node.getProperty(jcrPropName).getStream();
- }
- else
- {
- return null;
- }
+ try
+ {
+ return value.getStream();
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName , e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString() , e);
}
}
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ throw new IncorrectAtomicTypeException("Bynary cannot be convert into string");
+ }
+
+
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -52,28 +51,30 @@
return this.getValueFactory().createValue(value);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
- try
- {
- if (node.hasProperty(jcrPropName) == true)
- {
- boolean aBoolean = node.getProperty(jcrPropName).getBoolean();
- return new Boolean(aBoolean);
- }
- else
- {
- return null;
- }
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
+ try
+ {
+ return new Boolean(value.getBoolean());
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString() , e);
}
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return ((Boolean) object).booleanValue() ? "true()" : "false()";
}
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -53,29 +52,30 @@
return getValueFactory().createValue(value);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- byte[] value = node.getProperty(jcrPropName).getString().getBytes();
- return value;
- }
- else
- {
- return null;
- }
+ return value.getString().getBytes();
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString() , e);
}
}
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return "'" + object.toString() + "'";
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -19,7 +19,6 @@
import java.util.Calendar;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -54,29 +53,33 @@
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
{
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(node.getProperty(jcrPropName).getLong());
- return calendar;
- }
- else
- {
- return null;
- }
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(value.getLong());
+ return calendar;
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
}
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ Calendar calendar = (Calendar) object;
+ return new Long(calendar.getTimeInMillis()).toString();
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -52,29 +51,32 @@
return this.getValueFactory().createValue(value);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- double beanPropValue = node.getProperty(jcrPropName).getDouble();
- return new Double(beanPropValue);
- }
- else
- {
- return null;
- }
+ double beanPropValue = value.getDouble();
+ return new Double(beanPropValue);
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
}
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return object.toString();
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -52,29 +51,31 @@
return this.getValueFactory().createValue(value);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node,
- * java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- int beanPropValue = (int) node.getProperty(jcrPropName).getLong();
- return new Integer(beanPropValue);
- }
- else
- {
- return null;
- }
+ int beanPropValue = (int) value.getLong();
+ return new Integer(beanPropValue);
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return object.toString();
}
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -54,30 +53,31 @@
return this.getValueFactory().createValue(value);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- long beanPropValue = node.getProperty(jcrPropName).getLong();
- return new Long(beanPropValue);
- }
- else
- {
- return null;
- }
+ long beanPropValue = value.getLong();
+ return new Long(beanPropValue);
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
}
-
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return object.toString();
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,7 +17,6 @@
package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -48,28 +47,31 @@
return this.getValueFactory().createValue((String) propValue);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- return node.getProperty(jcrPropName).getString();
- }
- else
- {
- return null;
- }
+ return value.getString();
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
}
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return "'" + object.toString() + "'";
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -19,7 +19,6 @@
import java.sql.Timestamp;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -53,28 +52,31 @@
return this.getValueFactory().createValue(value);
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- long beanPropValue = node.getProperty(jcrPropName).getLong();
- return new Timestamp(beanPropValue);
- }
- else
- {
- return null;
- }
+ long beanPropValue = value.getLong();
+ return new Timestamp(beanPropValue);
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
}
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return new Long(((Timestamp) object).getTime()).toString();
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -19,7 +19,6 @@
import java.util.Date;
-import javax.jcr.Node;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
@@ -53,32 +52,33 @@
return this.getValueFactory().createValue(((java.util.Date) propValue).getTime());
}
- /**
- *
- * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
- */
- public Object getObject(Node node, String jcrPropName) throws IncorrectAtomicTypeException
- {
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Node, java.lang.String)
+ */
+ public Object getObject(Value value) throws IncorrectAtomicTypeException
+ {
try
{
- if (node.hasProperty(jcrPropName) == true)
- {
- long time = node.getProperty(jcrPropName).getLong();
- Date date = new Date(time);
-
- return date;
- }
- else
- {
- return null;
- }
+ long time = value.getLong();
+ return new Date(time);
}
catch (Exception e)
{
- throw new IncorrectAtomicTypeException("Impossible to convert the property : " + jcrPropName, e);
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
}
}
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+ */
+ public String getStringValue(Object object) throws IncorrectAtomicTypeException
+ {
+
+ return new Long(((java.util.Date) object).getTime()).toString();
+ }
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java Mon Oct 10 15:00:01 2005
@@ -30,5 +30,7 @@
public Iterator getIterator();
+ public int getSize();
+
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -16,6 +16,8 @@
package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
+import java.util.Map;
+
import org.apache.portals.graffito.jcr.mapper.Mapper;
import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
@@ -26,12 +28,14 @@
*/
public abstract class AbstractCollectionConverterImpl
{
- protected ObjectConverter objectConverter;
+ protected Map atomicTypeConverters;
+ protected ObjectConverter objectConverter;
protected Mapper mapper;
- public AbstractCollectionConverterImpl(ObjectConverter objectConverter, Mapper mapper)
+ public AbstractCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter, Mapper mapper)
{
+ this.atomicTypeConverters = atomicTypeConverters;
this.objectConverter = objectConverter;
this.mapper = mapper;
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -69,9 +70,9 @@
private static final String COLLECTION_ELEMENT_NAME = "collection-element";
- public DefaultCollectionConverterImpl(ObjectConverter objectConverter, Mapper mapper)
+ public DefaultCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter, Mapper mapper)
{
- super(objectConverter, mapper);
+ super(atomicTypeConverters, objectConverter, mapper);
}
/**
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java Mon Oct 10 15:00:01 2005
@@ -42,4 +42,12 @@
return this.iterator();
}
+ public int getSize()
+ {
+
+ return this.size();
+ }
+
+
+
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java Mon Oct 10 15:00:01 2005
@@ -16,8 +16,8 @@
package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
-import java.util.ArrayList;
import java.util.Iterator;
+import java.util.Vector;
import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
@@ -27,7 +27,7 @@
* @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
*
*/
-public class ManageableVector extends ArrayList implements ManageableCollection
+public class ManageableVector extends Vector implements ManageableCollection
{
public void addObject(Object object)
@@ -39,5 +39,12 @@
{
return this.iterator();
}
+
+ public int getSize()
+ {
+
+ return this.size();
+ }
+
}
Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java?rev=312759&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import javax.jcr.Value;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollectionUtil;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+
+/**
+ * Collection Mapping/convertion implementation for multi values properties
+ *
+ * This collection mapping strategy maps a collection into a JCR multi value property
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class MultiValueCollectionConverterImpl extends AbstractCollectionConverterImpl implements CollectionConverter
+{
+
+ public MultiValueCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter, Mapper mapper)
+ {
+ super(atomicTypeConverters, objectConverter, mapper);
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#insertCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
+ */
+ public void insertCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+ ManageableCollection collection) throws JcrMappingException
+ {
+
+ try
+ {
+
+ if (collection == null)
+ {
+ return;
+ }
+
+ String jcrName = collectionDescriptor.getJcrName();
+
+ if (jcrName == null)
+ {
+ throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor : "
+ + collectionDescriptor.getCollectionConverterClassName());
+ }
+
+ Value[] values = new Value[collection.getSize()];
+ Iterator collectionIterator = collection.getIterator();
+ for (int i=0; i<collection.getSize();i++)
+ {
+ Object fieldValue = collectionIterator.next();
+ AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(fieldValue.getClass());
+ values[i] = atomicTypeConverter.getValue(fieldValue);
+ }
+
+ parentNode.setProperty(jcrName, values);
+ }
+ catch (Exception e)
+ {
+ throw new JcrMappingException("Impossible to insert the collection field : " + collectionDescriptor.getFieldName()
+ + "for " + collectionDescriptor.getElementClassName(), e);
+ }
+
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#updateCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
+ */
+ public void updateCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+ ManageableCollection collection) throws JcrMappingException
+ {
+ try
+ {
+ String jcrName = collectionDescriptor.getJcrName();
+
+ if (collection == null)
+ {
+ if (parentNode.hasProperty(jcrName))
+ {
+ parentNode.setProperty(jcrName, (Value[]) null);
+ }
+ return;
+ }
+
+ if (jcrName == null)
+ {
+ throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor : "
+ + collectionDescriptor.getCollectionConverterClassName());
+ }
+
+ // Delete existing values
+ parentNode.setProperty(jcrName, (Value[]) null);
+
+ // Add all collection element into an Value array
+ Value[] values = new Value[collection.getSize()];
+ Iterator collectionIterator = collection.getIterator();
+ for (int i=0; i<collection.getSize();i++)
+ {
+ Object fieldValue = collectionIterator.next();
+ AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(fieldValue.getClass());
+ values[i] = atomicTypeConverter.getValue(fieldValue);
+ }
+
+ parentNode.setProperty(jcrName, values);
+ }
+ catch (Exception e)
+ {
+ throw new JcrMappingException("Impossible to insert the collection field : " + collectionDescriptor.getFieldName()
+ + "for " + collectionDescriptor.getElementClassName(), e);
+ }
+
+ }
+
+ /**
+ * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#getCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, java.lang.Class)
+ */
+ public ManageableCollection getCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+ Class collectionFieldClass) throws JcrMappingException
+ {
+ try
+ {
+ String jcrName = collectionDescriptor.getJcrName();
+ if( ! parentNode.hasProperty(jcrName))
+ {
+ return null;
+ }
+ Property property = parentNode.getProperty(jcrName);
+ Value[] values = property.getValues();
+
+ ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
+ for (int i=0;i<values.length;i++)
+ {
+ String elementClassName = collectionDescriptor.getElementClassName();
+ AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(Class.forName(elementClassName));
+ collection.addObject(atomicTypeConverter.getObject(values[i]));
+ }
+
+ return collection;
+
+ }
+ catch (Exception e)
+ {
+ throw new JcrMappingException("Impossible to get the collection field : " + collectionDescriptor.getFieldName()
+ + "for " + collectionDescriptor.getElementClassName(), e);
+ }
+ }
+
+}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -68,9 +69,9 @@
private static final String COLLECTION_ELEMENT_NAME = "collection-element";
- public NTCollectionConverterImpl(ObjectConverter objectConverter, Mapper mapper)
+ public NTCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter, Mapper mapper)
{
- super(objectConverter, mapper);
+ super(atomicTypeConverters, objectConverter, mapper);
}
/**
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java Mon Oct 10 15:00:01 2005
@@ -82,5 +82,7 @@
* @throws JcrMappingException when it is not possible to update the object
*/
public void update(Session session, Node parentNode, String nodeName, Object object) throws JcrMappingException;
+
+
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java Mon Oct 10 15:00:01 2005
@@ -231,9 +231,11 @@
String propertyName = fieldDescriptor.getJcrName();
AtomicTypeConverter converter = (AtomicTypeConverter) atomicTypeConverters.get(PropertyUtils.getPropertyType(object, fieldName));
- Object fieldValue = converter.getObject(node, propertyName);
-
- PropertyUtils.setNestedProperty(object, fieldName, fieldValue);
+ if (node.hasProperty(propertyName))
+ {
+ Object fieldValue = converter.getObject(node.getProperty(propertyName).getValue());
+ PropertyUtils.setNestedProperty(object, fieldName, fieldValue);
+ }
}
}
@@ -437,12 +439,12 @@
String className = collectionDescriptor.getCollectionConverterClassName();
if (className == null)
{
- return new DefaultCollectionConverterImpl(this, this.mapper);
+ return new DefaultCollectionConverterImpl(this.atomicTypeConverters, this, this.mapper);
}
else
{
Class converterClass = Class.forName(className);
- Object[] param = {this, this.mapper};
+ Object[] param = {this.atomicTypeConverters, this, this.mapper};
return (CollectionConverter) ConstructorUtils.invokeConstructor(converterClass, param);
}
}
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java Mon Oct 10 15:00:01 2005
@@ -16,6 +16,8 @@
*/
package org.apache.portals.graffito.jcr.query;
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
/**
*
@@ -56,32 +58,31 @@
* @scope either a a jcr node or propserty. If a node is used, all properties of this node are searche (following the internal index
* @param fullTextSearch The full text search string
*/
- public void addContains(String scope, String fullTextSearch);
-
+ public void addContains(String scope, String fullTextSearch) throws IncorrectAtomicTypeException;
- public void addBetween(String arg0, Object arg1, Object arg2);
+ public void addBetween(String arg0, Object arg1, Object arg2) throws IncorrectAtomicTypeException;
- public void addEqualTo(String arg0, Object arg1);
+ public void addEqualTo(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addGreaterOrEqualThan(String arg0, Object arg1);
+ public void addGreaterOrEqualThan(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addGreaterThan(String arg0, Object arg1);
+ public void addGreaterThan(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addLessOrEqualThan(String arg0, Object arg1);
+ public void addLessOrEqualThan(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addLessThan(String arg0, Object arg1);
+ public void addLessThan(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addLike(String arg0, Object arg1);
+ public void addLike(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addNotEqualTo(String arg0, Object arg1);
+ public void addNotEqualTo(String arg0, Object arg1) throws IncorrectAtomicTypeException;
- public void addNotNull(String arg0);
+ public void addNotNull(String arg0) throws IncorrectAtomicTypeException;
- public void addIsNull(String arg0);
+ public void addIsNull(String arg0) throws IncorrectAtomicTypeException;
- public void addOrFilter(Filter arg0);
+ public void addOrFilter(Filter arg0) throws IncorrectAtomicTypeException;
- public void addJCRExpression(String jcrExpression);
+ public void addJCRExpression(String jcrExpression) throws IncorrectAtomicTypeException;
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java Mon Oct 10 15:00:01 2005
@@ -17,20 +17,16 @@
package org.apache.portals.graffito.jcr.query.impl;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
import java.util.Iterator;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
import org.apache.portals.graffito.jcr.query.Filter;
/**
@@ -46,20 +42,19 @@
private String scope = "";
private ArrayList jcrExpressions = new ArrayList();
- private Mapper mapper;
- private ClassDescriptor classDescriptor;
+ private ClassDescriptor classDescriptor;
+ private Map atomicTypeConverters;
private String orJcrExpression;
private final static Log log = LogFactory.getLog(FilterImpl.class);
- public FilterImpl(Mapper mapper, Class clazz) throws JcrMappingException
- {
- this.mapper = mapper;
+ public FilterImpl(ClassDescriptor classDescriptor, Map atomicTypeConverters, Class clazz) throws JcrMappingException
+ {
this.claszz = clazz;
-
- classDescriptor = mapper.getClassDescriptor(clazz);
+ this.atomicTypeConverters = atomicTypeConverters;
+ this.classDescriptor = classDescriptor;
}
@@ -91,7 +86,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addContains(java.lang.String)
*/
- public void addContains(String scope, String fullTextSearch)
+ public void addContains(String scope, String fullTextSearch) throws IncorrectAtomicTypeException
{
String jcrExpression = null;
if (scope.equals("."))
@@ -109,7 +104,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addBetween(java.lang.String, java.lang.Object, java.lang.Object)
*/
- public void addBetween(String fieldAttributeName, Object value1, Object value2)
+ public void addBetween(String fieldAttributeName, Object value1, Object value2) throws IncorrectAtomicTypeException
{
String jcrExpression = "( @" + this.getJcrFieldName(fieldAttributeName) + " >= " + this.getStringValue(value1) +
" and @" + this.getJcrFieldName(fieldAttributeName) + " <= " + this.getStringValue(value2) + ")";
@@ -120,7 +115,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addEqualTo(java.lang.String, java.lang.Object)
*/
- public void addEqualTo(String fieldAttributeName, Object value)
+ public void addEqualTo(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " = " + this.getStringValue(value);
jcrExpressions.add(jcrExpression);
@@ -129,7 +124,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addGreaterOrEqualThan(java.lang.String, java.lang.Object)
*/
- public void addGreaterOrEqualThan(String fieldAttributeName, Object value)
+ public void addGreaterOrEqualThan(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " >= " + this.getStringValue(value);
@@ -140,7 +135,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addGreaterThan(java.lang.String, java.lang.Object)
*/
- public void addGreaterThan(String fieldAttributeName, Object value)
+ public void addGreaterThan(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " > " + this.getStringValue(value);
jcrExpressions.add(jcrExpression);
@@ -151,7 +146,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String, java.lang.Object)
*/
- public void addLessOrEqualThan(String fieldAttributeName, Object value)
+ public void addLessOrEqualThan(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " <= " + this.getStringValue(value);
jcrExpressions.add(jcrExpression);
@@ -161,7 +156,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addLessOrEqualThan(java.lang.String, java.lang.Object)
*/
- public void addLessThan(String fieldAttributeName, Object value)
+ public void addLessThan(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " < " + this.getStringValue(value);
jcrExpressions.add(jcrExpression);
@@ -171,7 +166,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addLike(java.lang.Object, java.lang.Object)
*/
- public void addLike(String fieldAttributeName, Object value)
+ public void addLike(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "jcr:like(" + "@" + this.getJcrFieldName(fieldAttributeName) + ", '" + value + "')";
jcrExpressions.add(jcrExpression);
@@ -181,7 +176,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addNotEqualTo(java.lang.String, java.lang.Object)
*/
- public void addNotEqualTo(String fieldAttributeName, Object value)
+ public void addNotEqualTo(String fieldAttributeName, Object value) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " != " + this.getStringValue(value);
jcrExpressions.add(jcrExpression);
@@ -191,7 +186,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addNotNull(java.lang.String)
*/
- public void addNotNull(String fieldAttributeName)
+ public void addNotNull(String fieldAttributeName) throws IncorrectAtomicTypeException
{
String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName);
jcrExpressions.add(jcrExpression);
@@ -201,7 +196,7 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addIsNull(java.lang.String)
*/
- public void addIsNull(String fieldAttributeName)
+ public void addIsNull(String fieldAttributeName) throws IncorrectAtomicTypeException
{
String jcrExpression = "not(@" + this.getJcrFieldName(fieldAttributeName)+")";
jcrExpressions.add(jcrExpression);
@@ -211,20 +206,20 @@
/**
* @see org.apache.portals.graffito.jcr.query.Filter#addOrFilter(org.apache.portals.graffito.jcr.query.Filter)
*/
- public void addOrFilter(Filter filter)
+ public void addOrFilter(Filter filter) throws IncorrectAtomicTypeException
{
orJcrExpression = ((FilterImpl)filter).getJcrExpression();
}
- public void addJCRExpression(String jcrExpression)
+ public void addJCRExpression(String jcrExpression) throws IncorrectAtomicTypeException
{
jcrExpressions.add(jcrExpression);
}
- private String getJcrFieldName(String fieldAttribute)
+ private String getJcrFieldName(String fieldAttribute) throws IncorrectAtomicTypeException
{
String jcrFieldName = classDescriptor.getJcrName(fieldAttribute);
if (jcrFieldName == null)
@@ -235,43 +230,13 @@
}
- private String getStringValue (Object value)
+ private String getStringValue (Object value) throws IncorrectAtomicTypeException
{
- if (value instanceof String)
- {
- return "'" + value + "'";
- }
- else
- {
-
- if (value instanceof Boolean)
- {
-
- return ((Boolean) value).booleanValue() ? "true()" : "false()";
- }
- else
- {
- if ((value instanceof Calendar))
- {
- Calendar calendar = (Calendar) value;
- return new Long(calendar.getTimeInMillis()).toString();
- }
- else
- {
- if (value instanceof Date)
- {
- Date date = (Date) value;
- return new Long(date.getTime()).toString();
-
- }
-
- return value.toString();
- }
- }
- }
+ AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(value.getClass());
+ return atomicTypeConverter.getStringValue(value);
}
- public String getJcrExpression()
+ public String getJcrExpression() throws IncorrectAtomicTypeException
{
if (orJcrExpression == null || orJcrExpression.equals(""))
{
@@ -284,7 +249,7 @@
}
- private String buildJcrExpression()
+ private String buildJcrExpression() throws IncorrectAtomicTypeException
{
int count = 1;
String jcrExp = "";
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java Mon Oct 10 15:00:01 2005
@@ -1,6 +1,6 @@
package org.apache.portals.graffito.jcr.query.impl;
-import java.util.Iterator;
+import java.util.Map;
import org.apache.portals.graffito.jcr.exception.JcrMappingException;
import org.apache.portals.graffito.jcr.mapper.Mapper;
@@ -13,16 +13,17 @@
{
private Mapper mapper;
-
- public QueryManagerImpl(Mapper mapper)
+ private Map atomicTypeConverters;
+ public QueryManagerImpl(Mapper mapper, Map atomicTypeConverters)
{
this.mapper = mapper;
+ this.atomicTypeConverters = atomicTypeConverters;
}
public Filter createFilter(Class classQuery) throws JcrMappingException
{
- return new FilterImpl(mapper, classQuery);
+ return new FilterImpl(mapper.getClassDescriptor(classQuery), atomicTypeConverters, classQuery);
}
public Query createQuery(Filter filter) throws JcrMappingException
Modified: incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml Mon Oct 10 15:00:01 2005
@@ -18,9 +18,21 @@
<field-descriptor fieldName="doubleObject" jcrName="doubleObject" />
<field-descriptor fieldName="doublePrimitive" jcrName="doublePrimitive" />
<field-descriptor fieldName="inputStream" jcrName="inputStream" />
- <field-descriptor fieldName="timestamp" jcrName="timestamp" />
-
+ <field-descriptor fieldName="timestamp" jcrName="timestamp" />
</class-descriptor>
+
+ <class-descriptor
+ className="org.apache.portals.graffito.jcr.testmodel.MultiValue" jcrNodeType="nt:unstructured">
+ <collection-descriptor fieldName="multiValues" jcrName="multiValue" proxy="false"
+ elementClassName="java.lang.String"
+ collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.MultiValueCollectionConverterImpl" />
+
+ <collection-descriptor fieldName="nullMultiValues" jcrName="nullMultiValue" proxy="false"
+ elementClassName="java.lang.String"
+ collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.MultiValueCollectionConverterImpl" />
+
+
+ </class-descriptor>
<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Folder" jcrNodeType="nt:unstructured">
Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java Mon Oct 10 15:00:01 2005
@@ -24,6 +24,7 @@
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.HashMap;
import javax.jcr.ImportUUIDBehavior;
@@ -96,7 +97,7 @@
session = RepositoryUtil.login(repository, "superuser", "superuser");
// TODO : After Spring integration, move the following code into the assembly script
- queryManager = new QueryManagerImpl(mapper);
+
HashMap atomicTypeConverters = new HashMap();
atomicTypeConverters.put(String.class, new StringTypeConverterImpl(session.getValueFactory()));
@@ -108,12 +109,13 @@
atomicTypeConverters.put(double.class, new DoubleTypeConverterImpl(session.getValueFactory()));
atomicTypeConverters.put(Double.class, new DoubleTypeConverterImpl(session.getValueFactory()));
atomicTypeConverters.put(boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
- atomicTypeConverters.put(Boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
+ atomicTypeConverters.put(Boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
atomicTypeConverters.put(Calendar.class, new CalendarTypeConverterImpl(session.getValueFactory()));
+ atomicTypeConverters.put(GregorianCalendar.class, new CalendarTypeConverterImpl(session.getValueFactory()));
atomicTypeConverters.put(Date.class, new UtilDateTypeConverterImpl(session.getValueFactory()));
atomicTypeConverters.put(byte[].class, new ByteArrayTypeConverterImpl(session.getValueFactory()));
atomicTypeConverters.put(Timestamp.class, new TimestampTypeConverterImpl(session.getValueFactory()));
-
+ queryManager = new QueryManagerImpl(mapper, atomicTypeConverters);
persistenceManager = new PersistenceManagerImpl(mapper, atomicTypeConverters, queryManager, session);
Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java?rev=312759&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java Mon Oct 10 15:00:01 2005
@@ -0,0 +1,130 @@
+/* ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================================
+ */
+package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.A;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.MultiValue;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+/**
+ * Test NTCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class MultiValueCollectionConverterImplTest extends TestBase
+{
+ private final static Log log = LogFactory.getLog(MultiValueCollectionConverterImplTest.class);
+
+ /**
+ * <p>Defines the test case name for junit.</p>
+ * @param testName The test case name.
+ */
+ public MultiValueCollectionConverterImplTest(String testName) throws Exception
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ // All methods starting with "test" will be executed in the test suite.
+ return new TestSuite(MultiValueCollectionConverterImplTest.class);
+ }
+
+ public void testMultiValue()
+ {
+ try
+ {
+ PersistenceManager persistenceManager = getPersistenceManager();
+
+ if (persistenceManager.itemExists("/test"))
+ {
+ persistenceManager.remove("/test");
+ persistenceManager.save();
+ }
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object graph in the repository
+ // --------------------------------------------------------------------------------
+
+ MultiValue multiValue = new MultiValue();
+ ArrayList values = new ArrayList();
+ values.add("Value1");
+ values.add("Value2");
+ values.add("Value3");
+ values.add("Value4");
+ multiValue.setMultiValues(values);
+
+ persistenceManager.insert("/test", multiValue);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Get the object
+ // --------------------------------------------------------------------------------
+ multiValue = (MultiValue) persistenceManager.getObject(MultiValue.class, "/test");
+ assertNotNull("Object is null", multiValue);
+ assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues());
+ assertTrue("Incorrect number of values", multiValue.getMultiValues().size() == 4);
+ assertTrue("Incorrect collection element", ((String) multiValue.getMultiValues().iterator().next()).equals("Value1"));
+
+ // --------------------------------------------------------------------------------
+ // Update the object
+ // --------------------------------------------------------------------------------
+ values = new ArrayList();
+ values.add("Value1");
+ values.add("Value2");
+ values.add("Value3");
+ values.add("Value4");
+ values.add("Value5");
+ multiValue.setMultiValues(values);
+
+ persistenceManager.update("/test", multiValue);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Get the object
+ // --------------------------------------------------------------------------------
+
+ multiValue = (MultiValue) persistenceManager.getObject(MultiValue.class, "/test");
+ assertNotNull("Object is null", multiValue);
+ assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues());
+ assertTrue("Incorrect number of values", multiValue.getMultiValues().size() == 5);
+ assertTrue("Incorrect collection element", ((String) multiValue.getMultiValues().iterator().next()).equals("Value1"));
+
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception occurs during the unit test : " + e);
+ }
+
+ }
+
+
+}
\ No newline at end of file
Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java Mon Oct 10 15:00:01 2005
@@ -42,6 +42,7 @@
private double doublePrimitive;
private InputStream inputStream;
private Timestamp timestamp;
+ private Collection multiValue;
public Boolean getBooleanObject()
@@ -140,6 +141,15 @@
{
this.timestamp = timestamp;
}
+
+ public Collection getMultiValue()
+ {
+ return multiValue;
+ }
+ public void setMultiValue(Collection multiValue)
+ {
+ this.multiValue = multiValue;
+ }
}
Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/MultiValue.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/MultiValue.java?rev=312759&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/MultiValue.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/MultiValue.java Mon Oct 10 15:00:01 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.testmodel;
+
+import java.util.Collection;
+
+/**
+ *
+ * Simple object used to test multivalue properties
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart
+ * Christophe </a>
+ * @version $Id: Exp $
+ */
+public class MultiValue
+{
+ private Collection multiValues;
+
+ private Collection nullMultiValues;
+
+ /**
+ * @return Returns the multiValues.
+ */
+ public Collection getMultiValues()
+ {
+ return multiValues;
+ }
+
+ /**
+ * @param multiValues
+ * The multiValues to set.
+ */
+ public void setMultiValues(Collection multiValues)
+ {
+ this.multiValues = multiValues;
+ }
+
+ /**
+ * @return Returns the nullMultiValues.
+ */
+ public Collection getNullMultiValues()
+ {
+ return nullMultiValues;
+ }
+
+ /**
+ * @param nullMultiValues
+ * The nullMultiValues to set.
+ */
+ public void setNullMultiValues(Collection nullMultiValues)
+ {
+ this.nullMultiValues = nullMultiValues;
+ }
+
+}
Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/hashmap/HashMapElement.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/hashmap/HashMapElement.java?rev=312759&r1=312758&r2=312759&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/hashmap/HashMapElement.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/hashmap/HashMapElement.java Mon Oct 10 15:00:01 2005
@@ -47,5 +47,12 @@
{
return this.values().iterator();
}
+
+ public int getSize()
+ {
+
+ return this.size();
+ }
+
}