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/09/12 20:17:23 UTC
svn commit: r280409 - in /incubator/graffito/trunk/jcr-mapping/src:
java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/
test-config/ test/org/apache/portals/graffito/jcr/persistence/impl/
test/org/apache/portals/graffito/jcr/testmodel/
Author: clombart
Date: Mon Sep 12 13:17:13 2005
New Revision: 280409
URL: http://svn.apache.org/viewcvs?rev=280409&view=rev
Log:
* Manage null values for the atomic types
* Add more unit test on atomic types
Added:
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java
Modified:
incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java
incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java
incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java?rev=280409&r1=280408&r2=280409&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java Mon Sep 12 13:17:13 2005
@@ -31,9 +31,6 @@
import javax.jcr.ValueFactory;
import javax.jcr.ValueFormatException;
-
-
-
/**
* According to the Flyweight pattern you can register new atomic types (flyweights)
* in this factory.
@@ -46,225 +43,408 @@
* @ToDo: The types itself should also be specified in the XML file.
*
*/
-public class AtomicTypeConverterFactory {
- private AtomicTypeConverter stringTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_STRING;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- return this.getValueFactory().createValue((String) propValue);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- return node.getProperty(jcrPropName).getString();
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={String.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter binaryTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_BINARY;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- return this.getValueFactory().createValue((InputStream) propValue);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- return node.getProperty(jcrPropName).getStream();
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={InputStream.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter intTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_LONG;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- long value = ((Integer) propValue).intValue();
- return this.getValueFactory().createValue(value);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- int beanPropValue = (int) node.getProperty(jcrPropName).getLong();
- return new Integer(beanPropValue);
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={Integer.class, int.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter longTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_LONG;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- long value = ((Long) propValue).longValue();
- return this.getValueFactory().createValue(value);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- long beanPropValue = node.getProperty(jcrPropName).getLong();
- return new Long(beanPropValue);
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={Long.class, long.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter doubleTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_DOUBLE;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- double value = ((Double) propValue).doubleValue();
- return this.getValueFactory().createValue(value);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- double beanPropValue = node.getProperty(jcrPropName).getDouble();
- return new Double(beanPropValue);
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={Double.class, double.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter calendarTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_DATE;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- return this.getValueFactory().createValue((Calendar) propValue);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- return node.getProperty(jcrPropName).getDate();
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={Calendar.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter utilDateTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_DATE;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- Calendar calendar = Calendar.getInstance();
- calendar.setTime((java.util.Date)propValue);
- return this.getValueFactory().createValue(calendar);
- }
-
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- Calendar calendar = node.getProperty(jcrPropName).getDate();
- Date date = calendar.getTime();
- return date;
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={java.util.Date.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter booleanTypeConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_BOOLEAN;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- boolean value = ((Boolean) propValue).booleanValue();
- return this.getValueFactory().createValue(value);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- boolean aBoolean= node.getProperty(jcrPropName).getBoolean();
- return new Boolean(aBoolean);
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={Boolean.class, boolean.class};
- return javaTypes;
- }
- };
- private AtomicTypeConverter byteArrayConverter = new AtomicTypeConverter(){
- public String getPropertyType(){
- return PropertyType.TYPENAME_STRING;
- }
- public Value getJcrValueFromJavaObject(Object propValue){
- if (propValue==null) return null;
- String value = new String((byte[]) propValue);
- return getValueFactory().createValue(value);
- }
- public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
- byte[] value = node.getProperty(jcrPropName).getString().getBytes();
- return value;
- }
- public Class[] getJavaTypes() {
- Class[] javaTypes ={byte[].class};
- return javaTypes;
- }
- };
-
-
- private Map typeConverterMap = new HashMap();
-
- private static AtomicTypeConverterFactory thisInstance;
-
- private ValueFactory valueFactory;
-
- private AtomicTypeConverterFactory(ValueFactory aValueFactory){
- this.valueFactory=aValueFactory; //it's needed for the registration
- this.registerTypeConverter(stringTypeConverter);
- this.registerTypeConverter(binaryTypeConverter);
- this.registerTypeConverter(longTypeConverter);
- this.registerTypeConverter(intTypeConverter);
- this.registerTypeConverter(doubleTypeConverter);
- this.registerTypeConverter(booleanTypeConverter);
- this.registerTypeConverter(calendarTypeConverter);
- this.registerTypeConverter(utilDateTypeConverter);
- this.registerTypeConverter(byteArrayConverter);
- }
-
- public void registerTypeConverter(AtomicTypeConverter converter){
- Class[] javaTypes = converter.getAndCheckJavaTypes();
- for (int i=0; i<converter.getJavaTypes().length; i++){
- if (this.typeConverterMap.containsKey(javaTypes[i])){
- throw new RuntimeException("The java type '"+javaTypes[i]+"' has already been registered.");
- }else {
- this.typeConverterMap.put(javaTypes[i],converter);
- }
- converter.setValueFactory(this.valueFactory);
- }
- }
-
- public AtomicTypeConverter getJCRTypeConverter(Class javaType){
- if(!this.typeConverterMap.containsKey(javaType)){
- throw new RuntimeException("The java type '"+javaType+"' is not registered.");
- }
- return (AtomicTypeConverter) this.typeConverterMap.get(javaType);
- }
-
- /**
- * @param session
- * @return
- * @throws UnsupportedRepositoryOperationException - if writing to the repository is not supported.
- * @throws RepositoryException - if another error occurs.
- */
- public static AtomicTypeConverterFactory getInstance(ValueFactory aValueFactory) throws UnsupportedRepositoryOperationException, RepositoryException{
- if (AtomicTypeConverterFactory.thisInstance==null){
- AtomicTypeConverterFactory.thisInstance=new AtomicTypeConverterFactory(aValueFactory);
- }
- return AtomicTypeConverterFactory.thisInstance;
- }
-
- public boolean isTypeRegistered(Class type){
- return this.typeConverterMap.containsKey(type);
- }
-
- public String getJCRPropertyType(Class javaType){
- AtomicTypeConverter typeConverter = (AtomicTypeConverter) this.typeConverterMap.get(javaType);
- return typeConverter.getPropertyType();
- }
+public class AtomicTypeConverterFactory
+{
+ private AtomicTypeConverter stringTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_STRING;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ return this.getValueFactory().createValue((String) propValue);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ return node.getProperty(jcrPropName).getString();
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { String.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter binaryTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_BINARY;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ return this.getValueFactory().createValue((InputStream) propValue);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ return node.getProperty(jcrPropName).getStream();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { InputStream.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter intTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_LONG;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ long value = ((Integer) propValue).intValue();
+ return this.getValueFactory().createValue(value);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ int beanPropValue = (int) node.getProperty(jcrPropName).getLong();
+ return new Integer(beanPropValue);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { Integer.class, int.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter longTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_LONG;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ long value = ((Long) propValue).longValue();
+ return this.getValueFactory().createValue(value);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ long beanPropValue = node.getProperty(jcrPropName).getLong();
+ return new Long(beanPropValue);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { Long.class, long.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter doubleTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_DOUBLE;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ double value = ((Double) propValue).doubleValue();
+ return this.getValueFactory().createValue(value);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ double beanPropValue = node.getProperty(jcrPropName).getDouble();
+ return new Double(beanPropValue);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { Double.class, double.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter calendarTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_DATE;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ return this.getValueFactory().createValue((Calendar) propValue);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ return node.getProperty(jcrPropName).getDate();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { Calendar.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter utilDateTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_DATE;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime((java.util.Date) propValue);
+ return this.getValueFactory().createValue(calendar);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ Calendar calendar = node.getProperty(jcrPropName).getDate();
+ Date date = calendar.getTime();
+ return date;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { java.util.Date.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter booleanTypeConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_BOOLEAN;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ boolean value = ((Boolean) propValue).booleanValue();
+ return this.getValueFactory().createValue(value);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ boolean aBoolean = node.getProperty(jcrPropName).getBoolean();
+ return new Boolean(aBoolean);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { Boolean.class, boolean.class };
+ return javaTypes;
+ }
+ };
+
+ private AtomicTypeConverter byteArrayConverter = new AtomicTypeConverter()
+ {
+ public String getPropertyType()
+ {
+ return PropertyType.TYPENAME_STRING;
+ }
+
+ public Value getJcrValueFromJavaObject(Object propValue)
+ {
+ if (propValue == null)
+ return null;
+ String value = new String((byte[]) propValue);
+ return getValueFactory().createValue(value);
+ }
+
+ public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException,
+ RepositoryException
+ {
+ if (node.hasProperty(jcrPropName) == true)
+ {
+ byte[] value = node.getProperty(jcrPropName).getString().getBytes();
+ return value;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Class[] getJavaTypes()
+ {
+ Class[] javaTypes =
+ { byte[].class };
+ return javaTypes;
+ }
+ };
+
+ private Map typeConverterMap = new HashMap();
+
+ private static AtomicTypeConverterFactory thisInstance;
+
+ private ValueFactory valueFactory;
+
+ private AtomicTypeConverterFactory(ValueFactory aValueFactory)
+ {
+ this.valueFactory = aValueFactory; //it's needed for the registration
+ this.registerTypeConverter(stringTypeConverter);
+ this.registerTypeConverter(binaryTypeConverter);
+ this.registerTypeConverter(longTypeConverter);
+ this.registerTypeConverter(intTypeConverter);
+ this.registerTypeConverter(doubleTypeConverter);
+ this.registerTypeConverter(booleanTypeConverter);
+ this.registerTypeConverter(calendarTypeConverter);
+ this.registerTypeConverter(utilDateTypeConverter);
+ this.registerTypeConverter(byteArrayConverter);
+ }
+
+ public void registerTypeConverter(AtomicTypeConverter converter)
+ {
+ Class[] javaTypes = converter.getAndCheckJavaTypes();
+ for (int i = 0; i < converter.getJavaTypes().length; i++)
+ {
+ if (this.typeConverterMap.containsKey(javaTypes[i]))
+ {
+ throw new RuntimeException("The java type '" + javaTypes[i] + "' has already been registered.");
+ }
+ else
+ {
+ this.typeConverterMap.put(javaTypes[i], converter);
+ }
+ converter.setValueFactory(this.valueFactory);
+ }
+ }
+
+ public AtomicTypeConverter getJCRTypeConverter(Class javaType)
+ {
+ if (!this.typeConverterMap.containsKey(javaType))
+ {
+ throw new RuntimeException("The java type '" + javaType + "' is not registered.");
+ }
+ return (AtomicTypeConverter) this.typeConverterMap.get(javaType);
+ }
+
+ /**
+ * @param session
+ * @return
+ * @throws UnsupportedRepositoryOperationException - if writing to the repository is not supported.
+ * @throws RepositoryException - if another error occurs.
+ */
+ public static AtomicTypeConverterFactory getInstance(ValueFactory aValueFactory)
+ throws UnsupportedRepositoryOperationException, RepositoryException
+ {
+ if (AtomicTypeConverterFactory.thisInstance == null)
+ {
+ AtomicTypeConverterFactory.thisInstance = new AtomicTypeConverterFactory(aValueFactory);
+ }
+ return AtomicTypeConverterFactory.thisInstance;
+ }
+
+ public boolean isTypeRegistered(Class type)
+ {
+ return this.typeConverterMap.containsKey(type);
+ }
+
+ public String getJCRPropertyType(Class javaType)
+ {
+ AtomicTypeConverter typeConverter = (AtomicTypeConverter) this.typeConverterMap.get(javaType);
+ return typeConverter.getPropertyType();
+ }
}
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=280409&r1=280408&r2=280409&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml Mon Sep 12 13:17:13 2005
@@ -13,8 +13,11 @@
<field-descriptor fieldName="integerObject" jcrName="integerObject" />
<field-descriptor fieldName="intPrimitive" jcrName="intPrimitive" />
<field-descriptor fieldName="byteArray" jcrName="byteArray" />
- <field-descriptor fieldName="calandar" jcrName="calandar" />
+ <field-descriptor fieldName="calendar" jcrName="calendar" />
<field-descriptor fieldName="date" jcrName="date" />
+ <field-descriptor fieldName="doubleObject" jcrName="doubleObject" />
+ <field-descriptor fieldName="doublePrimitive" jcrName="doublePrimitive" />
+ <field-descriptor fieldName="inputStream" jcrName="inputStream" />
</class-descriptor>
Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java?rev=280409&r1=280408&r2=280409&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java Mon Sep 12 13:17:13 2005
@@ -16,6 +16,7 @@
*/
package org.apache.portals.graffito.jcr.persistence.impl;
+import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@@ -83,7 +84,12 @@
a.setDate(new Date());
byte[] content = "Test Byte".getBytes();
a.setByteArray(content);
- a.setCalandar(Calendar.getInstance());
+ a.setCalendar(Calendar.getInstance());
+ a.setDoubleObject(new Double(2.12));
+ a.setDoublePrimitive(1.23);
+
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes());
+ a.setInputStream(byteArrayInputStream);
getPersistenceManager().insert("/test", a);
@@ -106,9 +112,13 @@
assertTrue("Incorrect byte object", new String(a.getByteArray()).equals("Test Byte"));
assertNotNull("date object is null", a.getDate());
- assertNotNull("calendar object is null", a.getCalandar());
+ assertNotNull("calendar object is null", a.getCalendar());
-
+ assertNotNull("Double object is null", a.getDoubleObject());
+ assertTrue("Incorrect double object", a.getDoubleObject().doubleValue() == 2.12);
+ assertTrue("Incorrect double primitive", a.getDoublePrimitive() == 1.23);
+
+ assertNotNull("Incorrect input stream primitive", a.getInputStream());
}
Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java?rev=280409&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java Mon Sep 12 13:17:13 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.impl;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+
+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.testmodel.A;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+import org.apache.portals.graffito.jcr.testmodel.B;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.Folder;
+
+/**
+ * Test Atomic perisstence fields
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class NullAtomicTest extends TestBase
+{
+ private final static Log log = LogFactory.getLog(NullAtomicTest.class);
+
+ /**
+ * <p>Defines the test case name for junit.</p>
+ * @param testName The test case name.
+ */
+ public NullAtomicTest(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ // All methods starting with "test" will be executed in the test suite.
+ return new TestSuite(NullAtomicTest.class);
+ }
+
+ public void testNullValueAtomicFields()
+ {
+ try
+ {
+
+ if (getPersistenceManager().itemExists("/test"))
+ {
+ getPersistenceManager().remove("/test");
+ }
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object graph in the repository
+ // --------------------------------------------------------------------------------
+ Atomic a = new Atomic();
+ a.setBooleanPrimitive(true);
+ a.setIntegerObject(new Integer(100));
+ a.setIntPrimitive(200);
+ a.setDate(new Date());
+ byte[] content = "Test Byte".getBytes();
+ a.setByteArray(content);
+ a.setCalendar(Calendar.getInstance());
+ a.setDoubleObject(new Double(2.12));
+ a.setDoublePrimitive(1.23);
+
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes());
+ a.setInputStream(byteArrayInputStream);
+
+ getPersistenceManager().insert("/test", a);
+
+
+ // --------------------------------------------------------------------------------
+ // Get the object
+ // --------------------------------------------------------------------------------
+ a = null;
+ a = (Atomic) getPersistenceManager().getObject(Atomic.class, "/test");
+ assertNotNull("a is null", a);
+ assertNull("Boolean object is not null", a.getBooleanObject());
+
+ assertTrue("Incorrect boolean primitive", a.isBooleanPrimitive());
+ assertNotNull("Integer Object is null", a.getIntegerObject());
+ assertTrue("Incorrect Integer object", a.getIntegerObject().intValue() == 100);
+ assertTrue("Incorrect int primitive", a.getIntPrimitive() == 200);
+ assertNull("String object is not null", a.getString());
+ assertNotNull("Byte array object is null", a.getByteArray());
+ assertTrue("Incorrect byte object", new String(a.getByteArray()).equals("Test Byte"));
+
+ assertNotNull("date object is null", a.getDate());
+ assertNotNull("calendar object is null", a.getCalendar());
+
+ assertNotNull("Double object is null", a.getDoubleObject());
+ assertTrue("Incorrect double object", a.getDoubleObject().doubleValue() == 2.12);
+ assertTrue("Incorrect double primitive", a.getDoublePrimitive() == 1.23);
+
+ assertNotNull("Incorrect input stream primitive", a.getInputStream());
+
+
+ }
+ 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=280409&r1=280408&r2=280409&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 Sep 12 13:17:13 2005
@@ -15,6 +15,7 @@
*/
package org.apache.portals.graffito.jcr.testmodel;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@@ -34,8 +35,12 @@
private Integer integerObject;
private int intPrimitive;
private byte[] byteArray;
- private Calendar calandar;
+ private Calendar calendar;
private Date date;
+ private Double doubleObject;
+ private double doublePrimitive;
+ private InputStream inputStream;
+
public Boolean getBooleanObject()
{
@@ -85,13 +90,13 @@
{
this.byteArray = byteArray;
}
- public Calendar getCalandar()
+ public Calendar getCalendar()
{
- return calandar;
+ return calendar;
}
- public void setCalandar(Calendar calandar)
+ public void setCalendar(Calendar calandar)
{
- this.calandar = calandar;
+ this.calendar = calandar;
}
public Date getDate()
{
@@ -100,6 +105,30 @@
public void setDate(Date date)
{
this.date = date;
+ }
+ public Double getDoubleObject()
+ {
+ return doubleObject;
+ }
+ public void setDoubleObject(Double doubleObject)
+ {
+ this.doubleObject = doubleObject;
+ }
+ public double getDoublePrimitive()
+ {
+ return doublePrimitive;
+ }
+ public void setDoublePrimitive(double doublePrimitive)
+ {
+ this.doublePrimitive = doublePrimitive;
+ }
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+ public void setInputStream(InputStream inputStream)
+ {
+ this.inputStream = inputStream;
}