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/03/07 21:18:53 UTC
svn commit: r515771 - in /incubator/graffito/trunk/jcr/jcr-mapping/src:
java/org/apache/portals/graffito/jcr/persistence/
java/org/apache/portals/graffito/jcr/persistence/impl/ test-config/
test/org/apache/portals/graffito/jcr/persistence/uuid/ test/or...
Author: clombart
Date: Wed Mar 7 13:18:52 2007
New Revision: 515771
URL: http://svn.apache.org/viewvc?view=rev&rev=515771
Log:
continue to work on GRFT-40 :
* Add the class ReferenceBeanConverter : map a Reference jcr property into a bean field (readonly).
* Add more unit tests on uuid & reference support.
Added:
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Ancestor.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B2.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Descendant.java
Modified:
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-uuid.xml
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/uuid/PersistenceManagerUuidTest.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/A.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B.java
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java?view=diff&rev=515771&r1=515770&r2=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java Wed Mar 7 13:18:52 2007
@@ -85,6 +85,15 @@
/**
* Get an object from the JCR repository
+ * @param the object uuid
+ * @return the object found or null
+ *
+ * @throws PersistenceException when it is not possible to retrieve the object
+ */
+ public Object getObjectByUuid( String uuid) throws PersistenceException;
+
+ /**
+ * Get an object from the JCR repository
* @param path the object path
* @param versionNumber The desired object version number
* @return the object found or null
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?view=diff&rev=515771&r1=515770&r2=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java Wed Mar 7 13:18:52 2007
@@ -196,6 +196,30 @@
}
+
+ /**
+ * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(java.lang.Class, java.lang.String)
+ * @throws org.apache.portals.graffito.jcr.exception.RepositoryException if the underlying repository
+ * has thrown a javax.jcr.RepositoryException
+ * @throws JcrMappingException if the mapping for the class is not correct
+ * @throws PersistenceException if the object cannot be retrieved from the path
+ */
+ public Object getObjectByUuid( String uuid) {
+
+ try
+ {
+ Node node = session.getNodeByUUID(uuid);
+ return objectConverter.getObject(session, node.getPath());
+
+ }
+ catch(RepositoryException e) {
+ throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
+ "Impossible to get the object with uuid : " + uuid, e);
+ }
+
+
+
+ }
/**
* @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(java.lang.Class, java.lang.String, java.lang.String)
*/
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-uuid.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-uuid.xml?view=diff&rev=515771&r1=515770&r2=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-uuid.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-uuid.xml Wed Mar 7 13:18:52 2007
@@ -13,7 +13,23 @@
className="org.apache.portals.graffito.jcr.testmodel.uuid.B" jcrNodeType="nt:unstructured" >
<field-descriptor fieldName="path" path="true" />
<field-descriptor fieldName="reference2A" jcrName="reference2A" converter="org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.ReferenceTypeConverterImpl" />
+ </class-descriptor>
+ <class-descriptor
+ className="org.apache.portals.graffito.jcr.testmodel.uuid.B2" jcrNodeType="nt:unstructured" >
+ <field-descriptor fieldName="path" path="true" />
+ <bean-descriptor fieldName="a" jcrName="a" converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.ReferenceBeanConverterImpl" />
+ </class-descriptor>
+
+
+ <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.uuid.Ancestor" abstract="true" jcrMixinTypes="mix:referenceable">
+ <field-descriptor fieldName="path" path="true" />
+ <field-descriptor fieldName="uuid" uuid="true" />
</class-descriptor>
+
+ <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.uuid.Descendant" jcrMixinTypes="mix:referenceable"
+ extend="org.apache.portals.graffito.jcr.testmodel.uuid.Ancestor">
+ <field-descriptor fieldName="stringData" jcrName="stringData" />
+ </class-descriptor >
</graffito-jcr>
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/uuid/PersistenceManagerUuidTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/uuid/PersistenceManagerUuidTest.java?view=diff&rev=515771&r1=515770&r2=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/uuid/PersistenceManagerUuidTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/uuid/PersistenceManagerUuidTest.java Wed Mar 7 13:18:52 2007
@@ -26,10 +26,12 @@
import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
import org.apache.portals.graffito.jcr.testmodel.uuid.A;
import org.apache.portals.graffito.jcr.testmodel.uuid.B;
+import org.apache.portals.graffito.jcr.testmodel.uuid.B2;
+import org.apache.portals.graffito.jcr.testmodel.uuid.Descendant;
/**
- * Test JcrSession
+ * Test on UUID & references
*
* @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
*/
@@ -65,16 +67,28 @@
getPersistenceManager().save();
}
+ if (getPersistenceManager().objectExists("/testB2"))
+ {
+ getPersistenceManager().remove("/testB2");
+ getPersistenceManager().save();
+ }
+
if (getPersistenceManager().objectExists("/test"))
{
getPersistenceManager().remove("/test");
getPersistenceManager().save();
}
+ if (getPersistenceManager().objectExists("/descendant"))
+ {
+ getPersistenceManager().remove("/descendant");
+ getPersistenceManager().save();
+ }
+
super.tearDown();
}
- public void testClassA()
+ public void testUuid()
{
try
{
@@ -114,7 +128,63 @@
assertTrue("The uuid has been modified", uuidA.equals(a.getUuid()));
// --------------------------------------------------------------------------------
- // Create and store an object B in the repository which has a reference on A
+ // Get the object with the uuid
+ // --------------------------------------------------------------------------------
+ a = (A) persistenceManager.getObjectByUuid(uuidA);
+ assertNotNull("a is null", a);
+ assertTrue("Invalid object found with the uuid ", "testdata2".equals(a.getStringData()));
+
+ // --------------------------------------------------------------------------------
+ // Get the object with an invalid uuid
+ // --------------------------------------------------------------------------------
+ try
+ {
+ a = (A) persistenceManager.getObjectByUuid("1234");
+ fail("Exception not throw");
+ }
+ catch(Exception e)
+ {
+ //Throws an exception due to an invalid uuid
+ System.out.println(e);
+
+ }
+
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception occurs during the unit test : " + e);
+ }
+
+ }
+
+ public void testFieldReference()
+ {
+ try
+ {
+ PersistenceManager persistenceManager = getPersistenceManager();
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object A in the repository
+ // --------------------------------------------------------------------------------
+ A a = new A();
+ a.setPath("/test");
+ a.setStringData("testdata");
+ persistenceManager.insert(a);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Get the object
+ // --------------------------------------------------------------------------------
+ a = (A) persistenceManager.getObject( "/test");
+ assertNotNull("a is null", a);
+ String uuidA = a.getUuid();
+ assertNotNull("uuid is null", uuidA);
+ System.out.println("UUID : " + uuidA);
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object B in the repository which has a reference to A
// --------------------------------------------------------------------------------
B b = new B();
b.setReference2A(uuidA);
@@ -123,9 +193,15 @@
persistenceManager.save();
// --------------------------------------------------------------------------------
+ // Retrieve the object B with an invalid reference
+ // --------------------------------------------------------------------------------
+ b = (B) persistenceManager.getObject("/testB");
+ assertNotNull("b is null", b);
+ assertTrue("Invalid uuid property", b.getReference2A().equals(uuidA));
+
+ // --------------------------------------------------------------------------------
// Update the object B with an invalid reference
// --------------------------------------------------------------------------------
- b = (B) persistenceManager.getObject("/testB");
b.setReference2A("1245");
try
{
@@ -134,7 +210,7 @@
}
catch(Exception e)
{
- //Exception has to triggered due to an invalid uuid
+ //Throws an exception due to an invalid uuid
System.out.println("Invalid uuid : " + e);
}
@@ -148,7 +224,132 @@
}
}
+
+ public void testBeanReference()
+ {
+ try
+ {
+ PersistenceManager persistenceManager = getPersistenceManager();
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object A in the repository
+ // --------------------------------------------------------------------------------
+ A a = new A();
+ a.setPath("/test");
+ a.setStringData("testdata");
+ persistenceManager.insert(a);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Get the object a
+ // --------------------------------------------------------------------------------
+ a = (A) persistenceManager.getObject( "/test");
+ assertNotNull("a is null", a);
+ String uuidA = a.getUuid();
+ assertNotNull("uuid is null", uuidA);
+ System.out.println("UUID : " + uuidA);
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object B in the repository which has a reference to A
+ // --------------------------------------------------------------------------------
+ B2 b = new B2();
+ b.setA(a);
+ b.setPath("/testB2");
+ persistenceManager.insert(b);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Retrieve object B
+ // --------------------------------------------------------------------------------
+ b = (B2) persistenceManager.getObject("/testB2");
+ a = b.getA();
+ assertNotNull("a is null", a);
+ assertTrue("Invalid object a", a.getStringData().equals("testdata"));
+ assertTrue("Invalid uuid property", a.getUuid().equals(uuidA));
+
+ // --------------------------------------------------------------------------------
+ // Update object B with an null value
+ // --------------------------------------------------------------------------------
+ b.setA(null);
+ persistenceManager.update(b);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Retrieve object B
+ // --------------------------------------------------------------------------------
+ b = (B2) persistenceManager.getObject("/testB2");
+ a = b.getA();
+ assertNull("a is not null", a);
+
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception occurs during the unit test : " + e);
+ }
+
+ }
+
+ /**
+ * Test on uuid field defined in an ancestor class
+ *
+ */
+ public void testDescendantAncestor()
+ {
+ try
+ {
+ PersistenceManager persistenceManager = getPersistenceManager();
+
+
+ // --------------------------------------------------------------------------------
+ // Create and store an object A in the repository
+ // --------------------------------------------------------------------------------
+ Descendant a = new Descendant();
+ a.setPath("/descendant");
+ a.setStringData("testdata");
+ persistenceManager.insert(a);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Get the object
+ // --------------------------------------------------------------------------------
+ a = (Descendant) persistenceManager.getObject( "/descendant");
+ assertNotNull("a is null", a);
+ String uuidA = a.getUuid();
+ assertNotNull("uuid is null", uuidA);
+ System.out.println("UUID : " + uuidA);
+
+ // --------------------------------------------------------------------------------
+ // Update the object
+ // --------------------------------------------------------------------------------
+ a.setStringData("testdata2");
+ persistenceManager.update(a);
+ persistenceManager.save();
+
+ // --------------------------------------------------------------------------------
+ // Get the object
+ // --------------------------------------------------------------------------------
+ a = (Descendant) persistenceManager.getObject("/descendant");
+ assertNotNull("a is null", a);
+ assertTrue("The uuid has been modified", uuidA.equals(a.getUuid()));
+
+ // --------------------------------------------------------------------------------
+ // Get the object with the uuid
+ // --------------------------------------------------------------------------------
+ a = (Descendant) persistenceManager.getObjectByUuid(uuidA);
+ assertNotNull("a is null", a);
+ assertTrue("Invalid object found with the uuid ", "testdata2".equals(a.getStringData()));
+
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception occurs during the unit test : " + e);
+ }
+ }
}
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/A.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/A.java?view=diff&rev=515771&r1=515770&r2=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/A.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/A.java Wed Mar 7 13:18:52 2007
@@ -19,7 +19,7 @@
/**
*
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
* @version $Id: Exp $
*/
public class A
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Ancestor.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Ancestor.java?view=auto&rev=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Ancestor.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Ancestor.java Wed Mar 7 13:18:52 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.testmodel.uuid;
+
+
+/**
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class Ancestor
+{
+ private String path;
+ private String uuid;
+
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public void setPath(String path)
+ {
+ this.path = path;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+}
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B.java?view=diff&rev=515771&r1=515770&r2=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B.java Wed Mar 7 13:18:52 2007
@@ -19,7 +19,7 @@
/**
*
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
* @version $Id: Exp $
*/
public class B
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B2.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B2.java?view=auto&rev=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B2.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/B2.java Wed Mar 7 13:18:52 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.testmodel.uuid;
+
+
+/**
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class B2
+{
+ private String path;
+ private A a; // This attribute is mapped to a reference jcr property
+
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public void setPath(String path)
+ {
+ this.path = path;
+ }
+
+ public A getA() {
+ return a;
+ }
+
+ public void setA(A a) {
+ this.a = a;
+ }
+
+
+
+}
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Descendant.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Descendant.java?view=auto&rev=515771
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Descendant.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/uuid/Descendant.java Wed Mar 7 13:18:52 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.testmodel.uuid;
+
+
+/**
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class Descendant extends Ancestor
+{
+
+ private String stringData;
+
+
+ public String getStringData() {
+ return stringData;
+ }
+
+ public void setStringData(String stringData) {
+ this.stringData = stringData;
+ }
+
+
+
+
+}