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 2007/02/15 20:13:49 UTC
svn commit: r508120 - in /incubator/graffito/trunk/jcr/jcr-mapping/src:
java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/
test-config/ test/org/apache/portals/graffito/jcr/persistence/atomic/
test/org/apache/portals/graffito/jc...
Author: clombart
Date: Thu Feb 15 12:13:48 2007
New Revision: 508120
URL: http://svn.apache.org/viewvc?view=rev&rev=508120
Log:
Starting issue GRFT-40 : add support for property type NAME and PATH.
They are is suppored with new atomic type converters.
They are mapped into the java String type.
Check the jcrmapping-atomic.xml file to see how to specify those new converters
Added:
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/NameTypeConverterImpl.java
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/PathTypeConverterImpl.java
Modified:
incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/NameTypeConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/NameTypeConverterImpl.java?view=auto&rev=508120
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/NameTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/NameTypeConverterImpl.java Thu Feb 15 12:13:48 2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.atomictypeconverter.impl;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+
+/**
+ *
+ * Name Type Converter
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class NameTypeConverterImpl implements AtomicTypeConverter
+{
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+ */
+ public Value getValue(ValueFactory valueFactory, Object propValue)
+ {
+ try
+ {
+ if (propValue == null)
+ {
+ return null;
+ }
+ return valueFactory.createValue((String) propValue, PropertyType.NAME);
+ }
+ catch (RepositoryException e)
+ {
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + propValue.toString(), e);
+ }
+
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+ */
+ public Object getObject(Value value)
+ {
+ try
+ {
+ return value.getString();
+ }
+ catch (RepositoryException 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)
+ {
+ return "'" + object.toString() + "'";
+ }
+}
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/PathTypeConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/PathTypeConverterImpl.java?view=auto&rev=508120
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/PathTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/PathTypeConverterImpl.java Thu Feb 15 12:13:48 2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.atomictypeconverter.impl;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+
+/**
+ *
+ * Name Type Converter
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class PathTypeConverterImpl implements AtomicTypeConverter
+{
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+ */
+ public Value getValue(ValueFactory valueFactory, Object propValue)
+ {
+ try
+ {
+ if (propValue == null)
+ {
+ return null;
+ }
+ return valueFactory.createValue((String) propValue, PropertyType.PATH);
+ }
+ catch (RepositoryException e)
+ {
+ throw new IncorrectAtomicTypeException("Impossible to convert the value : " + propValue.toString(), e);
+ }
+
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+ */
+ public Object getObject(Value value)
+ {
+ try
+ {
+ return value.getString();
+ }
+ catch (RepositoryException 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)
+ {
+ return "'" + object.toString() + "'";
+ }
+}
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml?view=diff&rev=508120&r1=508119&r2=508120
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml Thu Feb 15 12:13:48 2007
@@ -18,6 +18,8 @@
<field-descriptor fieldName="inputStream" jcrName="inputStream" />
<field-descriptor fieldName="timestamp" jcrName="timestamp" />
<field-descriptor fieldName="int2boolean" jcrName="int2boolean" converter="org.apache.portals.graffito.jcr.persistence.atomic.Int2BooleanTypeConverterImpl" />
+ <field-descriptor fieldName="namedProperty" jcrName="namedProperty" converter="org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.NameTypeConverterImpl" />
+ <field-descriptor fieldName="pathProperty" jcrName="pathProperty" converter="org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.PathTypeConverterImpl" />
</class-descriptor>
<class-descriptor
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java?view=diff&rev=508120&r1=508119&r2=508120
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java Thu Feb 15 12:13:48 2007
@@ -100,6 +100,8 @@
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes());
a.setInputStream(byteArrayInputStream);
+ a.setNamedProperty("graffito:test");
+ a.setPathProperty("/node1/node2");
persistenceManager.insert(a);
persistenceManager.save();
@@ -137,6 +139,44 @@
assertNotNull("Incorrect timestamp", a.getTimestamp());
assertTrue("Invalid timestamp value ", a.getTimestamp().getTime() == now);
assertTrue("Invalid int2boolean value ", a.isInt2boolean());
+
+ assertTrue("Invalid namedProperty value ", a.getNamedProperty().equals("graffito:test"));
+ assertTrue("Invalid pathProperty value ", a.getPathProperty().equals("/node1/node2"));
+
+ // --------------------------------------------------------------------------------
+ // Update the property "namedProperty" with an invalid value
+ // --------------------------------------------------------------------------------
+ try
+ {
+ // update with an incorrect namespace - Should throws an exception
+ a.setNamedProperty("unknown:test");
+ persistenceManager.update(a);
+ fail("Exception was not triggered with an invalid namespace");
+ persistenceManager.save();
+ }
+ catch (Exception e)
+ {
+
+
+ }
+
+ // --------------------------------------------------------------------------------
+ // Update the property "pathProperty" with an invalid value
+ // --------------------------------------------------------------------------------
+ try
+ {
+ // update with an incorrect namespace - Should throws an exception
+ a.setPathProperty("//node1");
+ persistenceManager.update(a);
+ fail("Exception was not triggered with an invalid path");
+ persistenceManager.save();
+ }
+ catch (Exception e)
+ {
+
+
+ }
+
}
catch (Exception e)
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java?view=diff&rev=508120&r1=508119&r2=508120
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java Thu Feb 15 12:13:48 2007
@@ -47,6 +47,9 @@
private boolean int2boolean;
private Collection multiValue;
+ private String namedProperty;
+ private String pathProperty; // used to refer another node
+
public String getPath() {
@@ -171,6 +174,25 @@
{
this.multiValue = multiValue;
}
+
+ public String getNamedProperty() {
+ return namedProperty;
+ }
+ public void setNamedProperty(String namedProperty)
+ {
+ this.namedProperty = namedProperty;
+ }
+
+ public String getPathProperty()
+ {
+ return pathProperty;
+ }
+
+ public void setPathProperty(String pathProperty)
+ {
+ this.pathProperty = pathProperty;
+ }
+
}