jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r544291 - in /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src: main/java/org/apache/jackrabbit/ocm/persistence/ main/java/org/apache/jackrabbit/ocm/persistence/impl/ test/java/org/apache/jackrabbit/ocm/persistence/lock/ test...
Date Mon, 04 Jun 2007 21:54:00 GMT
Author: clombart
Date: Mon Jun  4 14:53:59 2007
New Revision: 544291

URL: http://svn.apache.org/viewvc?view=rev&rev=544291
Log:
work on JCR-922 : 
Review method lock in the PersistenceManager. Now it returns a Lock object.
Add unit test. See the data value object 'Lockable' in the pck testmodel. 

Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/PersistenceManager.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/impl/PersistenceManagerImpl.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/persistence/lock/PersistenceManagerLockTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/jcrmapping.xml
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/nodetypes/custom_nodetypes.xml

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/PersistenceManager.java?view=diff&rev=544291&r1=544290&r2=544291
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/PersistenceManager.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/PersistenceManager.java
Mon Jun  4 14:53:59 2007
@@ -19,10 +19,12 @@
 import java.util.Collection;
 import java.util.Iterator;
 
+import javax.jcr.Session;
 import javax.jcr.version.VersionException;
 
 import org.apache.jackrabbit.ocm.exception.IllegalUnlockException;
 import org.apache.jackrabbit.ocm.exception.LockedException;
+import org.apache.jackrabbit.ocm.lock.Lock;
 import org.apache.jackrabbit.ocm.exception.PersistenceException;
 import org.apache.jackrabbit.ocm.query.Query;
 import org.apache.jackrabbit.ocm.query.QueryManager;
@@ -306,12 +308,12 @@
      *            is lock deep? See JCR spec: 8.4.3 Shallow and Deep Locks
      * @param isSessionScoped
      *            is lock session scoped? See JCR spec: Session-scoped and Open-scoped Locks
-     * @return lock token - see JCR spec: 8.4.6 Lock Token; Other user  with this token can
perform unlock
+     * @return lock - Wrapper object for a JCR lock
      * 
      * @throws LockedException
      *             if path is locked (cannot lock same path again)
      */
-    public String lock(String path, boolean isDeep, boolean isSessionScoped) throws LockedException;
+    public Lock lock(String path, boolean isDeep, boolean isSessionScoped) throws LockedException;
     
     /**
      * Unlock object stored on {@param path }.
@@ -342,7 +344,7 @@
     public QueryManager getQueryManager();
     
     /**
-     * Refrsh the underlying jcr session (see the jcr spec)
+     * Refresh the underlying jcr session (see the jcr spec)
      * @param keepChanges
      */
     public void refresh(boolean keepChanges);
@@ -367,4 +369,9 @@
      */
     public void copy(String srcPath, String destPath) throws PersistenceException; 
         
+    /**
+     * This method returns the JCR session. The JCR session could be used to make some JCR
specific calls.
+     * @return the associated JCR session 
+     */
+    public Session getSession();
 }

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/impl/PersistenceManagerImpl.java?view=diff&rev=544291&r1=544290&r2=544291
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/impl/PersistenceManagerImpl.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/impl/PersistenceManagerImpl.java
Mon Jun  4 14:53:59 2007
@@ -32,7 +32,6 @@
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Workspace;
-import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.query.InvalidQueryException;
@@ -62,7 +61,7 @@
 import org.apache.jackrabbit.ocm.query.impl.QueryManagerImpl;
 import org.apache.jackrabbit.ocm.version.Version;
 import org.apache.jackrabbit.ocm.version.VersionIterator;
-
+import org.apache.jackrabbit.ocm.lock.Lock;
 /**
  *
  * Default implementation for {@link org.apache.jackrabbit.ocm.persistence.PersistenceManager}
@@ -898,7 +897,7 @@
      *
      * @see org.apache.jackrabbit.ocm.persistence.PersistenceManager#lock(java.lang.String,
java.lang.Object, boolean, boolean)
      */
-    public String lock(final String absPath, final boolean isDeep, final boolean isSessionScoped)

+    public Lock lock(final String absPath, final boolean isDeep, final boolean isSessionScoped)

     throws LockedException {
         try {
 
@@ -907,9 +906,9 @@
             checkIfNodeLocked(absPath);
 
             Node node = getNode(absPath);
-            Lock lock = node.lock(isDeep, isSessionScoped);
+            javax.jcr.lock.Lock lock = node.lock(isDeep, isSessionScoped);
 
-            return lock.getLockToken();
+            return new Lock(lock);
         } 
         catch (LockException e) {
             // Only one case with LockException remains: if node is not mix:lockable, propably
error in custom node types definitions
@@ -938,7 +937,7 @@
                 return;
             }
 
-            Lock lock = node.getLock();
+            javax.jcr.lock.Lock lock = node.getLock();
             lockOwner = lock.getLockOwner();
 
             node.unlock();
@@ -999,7 +998,7 @@
 
         // Node can hold nock or can be locked with precedencor
         if (node.isLocked()) {
-            Lock lock = node.getLock();
+            javax.jcr.lock.Lock lock = node.getLock();
             String lockOwner = lock.getLockOwner();
             
             if (! session.getUserID().equals(lockOwner))
@@ -1118,10 +1117,10 @@
 	 * @see org.apache.jackrabbit.ocm.persistence.PersistenceManager#move(java.lang.String,
java.lang.String)
 	 */
     public void move(String srcPath, String destPath){
-        //Workspace workspace = session.getWorkspace();
+        Workspace workspace = session.getWorkspace();
         try {
             
-        	session.move(srcPath,destPath);
+        	workspace.move(srcPath,destPath);
             
         }catch(javax.jcr.nodetype.ConstraintViolationException cve){
             throw new PersistenceException(

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/persistence/lock/PersistenceManagerLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/persistence/lock/PersistenceManagerLockTest.java?view=diff&rev=544291&r1=544290&r2=544291
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/persistence/lock/PersistenceManagerLockTest.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/persistence/lock/PersistenceManagerLockTest.java
Mon Jun  4 14:53:59 2007
@@ -26,11 +26,12 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
 import org.apache.jackrabbit.ocm.TestBase;
+import org.apache.jackrabbit.ocm.lock.Lock;
 import org.apache.jackrabbit.ocm.persistence.PersistenceManager;
 import org.apache.jackrabbit.ocm.testmodel.A;
 import org.apache.jackrabbit.ocm.testmodel.B;
 import org.apache.jackrabbit.ocm.testmodel.C;
-import org.apache.jackrabbit.ocm.testmodel.Discriminator;
+import org.apache.jackrabbit.ocm.testmodel.Lockable;
 
 /**
  * Test Persistence Manager lock feature
@@ -63,7 +64,11 @@
      */
     public void tearDown() throws Exception
     {
-
+    	if (getPersistenceManager().objectExists("/test"))
+    	{
+    	   getPersistenceManager().remove("/test");
+    	   getPersistenceManager().save();
+    	}
         super.tearDown();
     }
     
@@ -123,7 +128,9 @@
             // --------------------------------------------------------------------------------
             // Lock the object
             // --------------------------------------------------------------------------------
          
-            String lockToken = persistenceManager.lock("/test", true, false);
+            
+            Lock lock = persistenceManager.lock("/test", true, false);
+            assertTrue("the Lock owner is not correct", lock.getLockOwner().equals("superuser"));
             
             // --------------------------------------------------------------------------------
             // Check if the object is locked
@@ -133,7 +140,7 @@
             // --------------------------------------------------------------------------------
             // Unlock the object
             // --------------------------------------------------------------------------------
          
-            persistenceManager.unlock("/test", lockToken);
+            persistenceManager.unlock("/test", lock.getLockToken());
 
             // --------------------------------------------------------------------------------
             // Check if the object is locked
@@ -143,12 +150,12 @@
             // --------------------------------------------------------------------------------
             // Lock & update 
             // --------------------------------------------------------------------------------
-            lockToken = persistenceManager.lock("/test", true, false);
+            lock = persistenceManager.lock("/test", true, false);
             a = (A) persistenceManager.getObject("/test");
             a.setA1("new a1 Value");
             persistenceManager.update(a);
             persistenceManager.save();
-            persistenceManager.unlock("/test", lockToken);
+            persistenceManager.unlock("/test", lock.getLockToken());
             
             
             // --------------------------------------------------------------------------------
@@ -166,4 +173,86 @@
         
     }        
 
+    /**
+     *  Lock object which is assigned to a custome node type. This jcr node type inherits
from mix:lockable
+     *
+     */
+    public void testLockWithNodeType()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+
+            // --------------------------------------------------------------------------------
+            // Create an object which is associated to the 
+            // --------------------------------------------------------------------------------
+            Lockable lockable = new Lockable();
+            lockable.setPath("/test");
+            lockable.setA1("a1");
+            lockable.setA2("a2");
+            persistenceManager.insert(lockable);
+            persistenceManager.save();
+            
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            lockable = (Lockable) persistenceManager.getObject("/test");
+            assertNotNull("a is null", lockable);
+            
+            // --------------------------------------------------------------------------------
+            // Check if the object is locked
+            // --------------------------------------------------------------------------------
+            assertFalse("the object is locked", persistenceManager.isLocked("/test"));
+            assertNull("Attribute lockowner is not null", lockable.getLockOwner());
+            // --------------------------------------------------------------------------------
+            // Lock the object
+            // --------------------------------------------------------------------------------
                      
+            Lock lock = 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", lock.getLockToken());
+
+            // --------------------------------------------------------------------------------
+            // Check if the object is locked
+            // --------------------------------------------------------------------------------
+            assertFalse("the object is locked", persistenceManager.isLocked("/test"));
+
+
+            // --------------------------------------------------------------------------------
+            // Lock & update 
+            // --------------------------------------------------------------------------------
+            lock = persistenceManager.lock("/test", true, false);
+            assertTrue("the object is not locked", persistenceManager.isLocked("/test"));
+            lockable = (Lockable) persistenceManager.getObject("/test");
+            assertNotNull("Attribute lockowner is null", lockable.getLockOwner());
+            lockable.setA1("new a1 Value");
+            persistenceManager.update(lockable);
+            persistenceManager.save();
+            persistenceManager.unlock("/test", lock.getLockToken());
+            
+            
+            // --------------------------------------------------------------------------------
+            // Remove the object
+            // --------------------------------------------------------------------------------
          
+            persistenceManager.remove(lockable);
+            persistenceManager.save();
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }        
+    
 }

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/jcrmapping.xml?view=diff&rev=544291&r1=544290&r2=544291
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/jcrmapping.xml
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/jcrmapping.xml
Mon Jun  4 14:53:59 2007
@@ -4,11 +4,10 @@
 <jackrabbit-ocm>
     
   
-
 	<!--
 		The following classes are used to test object associations
 		A has an assocition (1..1) with B (field b) => B is mapped as subnode in A
-		A has a collection of C (field "collection" ) => there are n subnodes used to map the
"C" collection 
+		A has a collection of C (field "collection") => there are n subnodes used to map the
"C" collection 
 		
 	-->
 	<class-descriptor
@@ -59,6 +58,14 @@
 		<field-descriptor fieldName="name" jcrName="ocm:name" />
 	</class-descriptor>
 
+	<class-descriptor className="org.apache.jackrabbit.ocm.testmodel.Lockable" jcrNodeType="ocm:TestLockable"
>		
+		<field-descriptor fieldName="path" path="true" />
+		<field-descriptor fieldName="a1" jcrName="ocm:a1" />
+		<field-descriptor fieldName="a2" jcrName="ocm:a2" />
+		
+		<!--  lockOwner is null is the object is not locked -->
+    	<field-descriptor fieldName="lockOwner" jcrName="jcr:lockOwner" />
+	</class-descriptor>
 
 	<class-descriptor className="org.apache.jackrabbit.ocm.testmodel.Page" jcrNodeType="ocm:page"
discriminator="false" >
 		<field-descriptor fieldName="path" path="true" />

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/nodetypes/custom_nodetypes.xml?view=diff&rev=544291&r1=544290&r2=544291
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/nodetypes/custom_nodetypes.xml
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/test-config/nodetypes/custom_nodetypes.xml
Mon Jun  4 14:53:59 2007
@@ -20,8 +20,26 @@
 	xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
 	xmlns:test="http://www.apache.org/jackrabbit/test"
 	xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
-	xmlns:ocm="http://jackrabbit.apache.org/ocm">
-	<nodeType name="ocm:C" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+	xmlns:ocm="http://jackrabbit.apache.org/ocm">
+	
+   <nodeType name="ocm:discriminator" isMixin="true">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDefinition name="ocm:classname" requiredType="String" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
+  </nodeType>
+
+  <nodeType name="ocm:TestLockable" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mix:lockable</supertype>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
+    <propertyDefinition name="ocm:a1" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
+	<propertyDefinition name="ocm:a2" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
+  </nodeType>
+  	
+  <nodeType name="ocm:C" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
     <supertypes>
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
@@ -137,15 +155,6 @@
     <propertyDefinition name="ocm:content" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
   </nodeType>
   
-
-   <nodeType name="ocm:discriminator" isMixin="true">
-    <supertypes>
-      <supertype>nt:base</supertype>
-    </supertypes>
-    <propertyDefinition name="ocm:classname" requiredType="String" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
-  </nodeType>
-   
-
    <nodeType name="ocm:cmsobject" isMixin="true">
     <supertypes>
       <supertype>nt:base</supertype>



Mime
View raw message