incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r468111 - in /incubator/graffito/trunk/jcr/jcr-mapping: src/test-config/ src/test/org/apache/portals/graffito/jcr/ src/test/org/apache/portals/graffito/jcr/persistence/lock/ xdocs/api/
Date Thu, 26 Oct 2006 20:05:58 GMT
Author: clombart
Date: Thu Oct 26 13:05:57 2006
New Revision: 468111

URL: http://svn.apache.org/viewvc?view=rev&rev=468111
Log:
* Add unit test on lock 
* add xdoc

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/PersistenceManagerLockTest.java
Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/xdocs/api/locking.xml

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml?view=diff&rev=468111&r1=468110&r2=468111
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml Thu Oct 26 13:05:57
2006
@@ -13,7 +13,7 @@
 	-->
 	<class-descriptor
 		className="org.apache.portals.graffito.jcr.testmodel.A"
-		jcrNodeType="nt:unstructured">
+		jcrNodeType="nt:unstructured" jcrMixinTypes="mix:lockable" >
 		<!-- Field-descriptor is used to map simple attributes to jcr property -->
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="a1" jcrName="a1" />

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java?view=diff&rev=468111&r1=468110&r2=468111
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java
Thu Oct 26 13:05:57 2006
@@ -48,6 +48,7 @@
         suite.addTest(org.apache.portals.graffito.jcr.persistence.proxy.AllTests.buildSuite());
         suite.addTest(org.apache.portals.graffito.jcr.persistence.query.AllTests.buildSuite());
         suite.addTest(org.apache.portals.graffito.jcr.persistence.version.AllTests.buildSuite());
+        suite.addTest(org.apache.portals.graffito.jcr.persistence.lock.AllTests.buildSuite());
         suite.addTest(org.apache.portals.graffito.jcr.querymanager.AllTests.buildSuite());
         suite.addTest(org.apache.portals.graffito.jcr.repository.AllTests.buildSuite());
         return suite;

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/AllTests.java?view=auto&rev=468111
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/AllTests.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/AllTests.java
Thu Oct 26 13:05:57 2006
@@ -0,0 +1,44 @@
+/* ========================================================================
+ * 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.lock;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+
+
+/**
+ * Package level tests.
+ * 
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class AllTests {
+
+    public static Test suite() {
+        return new RepositoryLifecycleTestSetup(buildSuite());
+    }
+
+    public static Test buildSuite() {
+        TestSuite suite= new TestSuite("Test for org.apache.portals.graffito.jcr.persistence.basic");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(PersistenceManagerLockTest.class);
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/PersistenceManagerLockTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/PersistenceManagerLockTest.java?view=auto&rev=468111
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/PersistenceManagerLockTest.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/lock/PersistenceManagerLockTest.java
Thu Oct 26 13:05:57 2006
@@ -0,0 +1,158 @@
+/* ========================================================================
+ * 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.lock;
+
+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.RepositoryLifecycleTestSetup;
+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.B;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.Discriminator;
+
+/**
+ * Test Persistence Manager lock feature
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerLockTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerLockTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerLockTest(String testName)  throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(
+                new TestSuite(PersistenceManagerLockTest.class));
+    }
+
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+
+        super.tearDown();
+    }
+    
+    public void testBasicLock()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setPath("/test");
+            a.setA1("a1");
+            a.setA2("a2");
+            B b = new B();
+            b.setB1("b1");
+            b.setB2("b2");
+            a.setB(b);
+            
+            C c1 = new C();
+            c1.setId("first");
+            c1.setName("First Element");
+            C c2 = new C();
+            c2.setId("second");
+            c2.setName("Second Element");
+            
+            C c3 = new C();
+            c3.setId("third");
+            c3.setName("Third Element");
+            
+            
+            Collection collection = new ArrayList();
+            collection.add(c1);
+            collection.add(c2);
+            collection.add(c3);
+            
+            a.setCollection(collection);
+            
+            persistenceManager.insert(a);
+            persistenceManager.save();
+            
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            a = (A) persistenceManager.getObject( "/test");
+            assertNotNull("a is null", a);
+            
+            // --------------------------------------------------------------------------------
+            // Check if the object is locked
+            // --------------------------------------------------------------------------------
+            assertFalse("the object is locked", persistenceManager.isLocked("/test"));
+            
+            // --------------------------------------------------------------------------------
+            // Lock the object
+            // --------------------------------------------------------------------------------
          
+            String lockToken = persistenceManager.lock("/test", true, false);
+            
+            // --------------------------------------------------------------------------------
+            // Check if the object is locked
+            // --------------------------------------------------------------------------------
+            assertTrue("the object is not locked", persistenceManager.isLocked("/test"));
+            
+            // --------------------------------------------------------------------------------
+            // Unlock the object
+            // --------------------------------------------------------------------------------
          
+            persistenceManager.unlock("/test", lockToken);
+
+            // --------------------------------------------------------------------------------
+            // Check if the object is locked
+            // --------------------------------------------------------------------------------
+            assertFalse("the object is locked", persistenceManager.isLocked("/test"));
+            
+            // --------------------------------------------------------------------------------
+            // Remove the object
+            // --------------------------------------------------------------------------------
          
+            persistenceManager.remove(a);
+            persistenceManager.save();
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }        
+
+}
\ No newline at end of file

Modified: incubator/graffito/trunk/jcr/jcr-mapping/xdocs/api/locking.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/xdocs/api/locking.xml?view=diff&rev=468111&r1=468110&r2=468111
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/xdocs/api/locking.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/xdocs/api/locking.xml Thu Oct 26 13:05:57 2006
@@ -1,32 +1,112 @@
 <?xml version="1.0"?>
 <!-- 
-     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.
-     -->
+	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.
+-->
 <document>
 	<properties>
-		<author email="christophe.lombart@gmail.com">Christophe Lombart</author>
+		<author email="christophe.lombart@gmail.com">
+			Christophe Lombart
+		</author>
 		<title>The Persistence Manager API</title>
 	</properties>
 	<body>
-		
-		<section name="">
-			<subsection name="Locks">
-				<p>TO DO </p>
-				
+
+		<section name="Managing Locks">
+			<subsection name="Overview">
+				<p>
+					Following the Jcr specification, it is possible to lock nodes and their children (see
section 8.4).
+					You can see on this page the OCM API used to lock on the object level. 
+					In order to lock an object, its matching node has to implement the jcr mixin type "mix:lockable".
+					You can be specify this node type in the class descriptor like the following example
: 
+				</p>	
+				<source><![CDATA[ 					
+<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.A"
+		          jcrNodeType="nt:unstructured" jcrMixinTypes="mix:lockable" >
+		          
+		          
+		          <!-- Add here field, bean and collection desctipors -->
+		          
+		          
+</class-descriptor>							
+				]]></source>
+			</subsection>		
+			<subsection name="A basic example">
+				<source>
+// --------------------------------------------------------------------------------
+// Create and store an object graph in the repository
+// --------------------------------------------------------------------------------
+A a = new A();
+a.setPath("/test");
+a.setA1("a1");
+a.setA2("a2");
+B b = new B();
+b.setB1("b1");
+b.setB2("b2");
+a.setB(b);
+            
+C c1 = new C();
+c1.setId("first");
+c1.setName("First Element");
+C c2 = new C();
+c2.setId("second");
+c2.setName("Second Element");
+            
+C c3 = new C();
+c3.setId("third");
+c3.setName("Third Element");
+                        
+Collection collection = new ArrayList();
+collection.add(c1);
+collection.add(c2);
+collection.add(c3);
+            
+a.setCollection(collection);
+            
+persistenceManager.insert(a);
+persistenceManager.save();
+            
+
+// --------------------------------------------------------------------------------
+// Check if the object is not locked
+// --------------------------------------------------------------------------------
+if (persistenceManager.isLocked("/test"))
+{
+   System.out.println("Error : The object is locked- humm ??");
+}
+            
+// --------------------------------------------------------------------------------
+// Lock the object
+// --------------------------------------------------------------------------------     
     
+String lockToken = persistenceManager.lock("/test", true, false);
+            
+// --------------------------------------------------------------------------------
+// Check if the object is not locked
+// --------------------------------------------------------------------------------
+if (! persistenceManager.isLocked("/test"))
+{
+   System.out.println("Error : The object is not locked- humm ??");
+}            
+ 
+// --------------------------------------------------------------------------------
+// Unlock the object
+// --------------------------------------------------------------------------------     
     
+persistenceManager.unlock("/test", lockToken);
+				</source>			
 			</subsection>
+		
 		</section>
 	</body>
 </document>



Mime
View raw message