jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r513279 [2/3] - in /jackrabbit/trunk/contrib/spi/jcr2spi: ./ src/main/java/org/apache/jackrabbit/jcr2spi/ src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ src/main/java/org/apache/jackrabbit/jcr2spi/lock/ src/main/java/org/apache/jack...
Date Thu, 01 Mar 2007 11:17:33 GMT
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java Thu Mar  1 03:17:22 2007
@@ -51,6 +51,7 @@
 
 /**
  * <code>LockManagerImpl</code>...
+ * TODO: TOBEFIXED. Lock objects obtained through this mgr are not informed if another session is or becomes lock-holder and removes the lock again.
  */
 public class LockManagerImpl implements LockManager, SessionListener {
 
@@ -207,9 +208,9 @@
      * If the lock addressed by the token is session-scoped, this method will
      * throw a LockException, such as defined by JSR170 v.1.0.1 for
      * {@link Session#removeLockToken(String)}.<br>Otherwise the call is
-     * delegated to {@link WorkspaceManager#removeLockToken(String)} and
-     * all locks stored in the local lock map are notified by the removed
-     * token in order to give them the chance to update their lock information.
+     * delegated to {@link WorkspaceManager#removeLockToken(String)}.
+     * All locks stored in the local lock map are notified by the removed
+     * token in order have them updated their lock information.
      *
      * @see LockManager#removeLockToken(String)
      */
@@ -232,13 +233,8 @@
             }
         }
 
-        if (!found) {
-            String msg = "Unable to remove lock token: lock is held by another session.";
-            log.warn(msg);
-            throw new RepositoryException(msg);
-        }
-
-        // remove lock token from sessionInfo
+        // remove lock token from sessionInfo. call will fail, if the session
+        // is not lock holder.
         wspManager.removeLockToken(lt);
         // inform about this lt being removed from this session
         notifyTokenRemoved(lt);
@@ -290,7 +286,9 @@
      * be affected by the lock present on an ancestor state.
      * Note, that in certain cases it might not be possible to detect a lock
      * being present due to the fact that the hierarchy might be imcomplete or
-     * not even readable completely.
+     * not even readable completely. For this reason it seem equally reasonable
+     * to search for jcr:lockIsDeep property only and omitting all kind of
+     * verification regarding nodetypes present.
      *
      * @param nodeState <code>NodeState</code> from which searching starts.
      * Note, that the given state must not have an overlayed state.
@@ -298,11 +296,6 @@
      * given state nor any of its ancestors is locked.
      */
     private NodeState getLockHoldingState(NodeState nodeState) {
-        /**
-         * TODO: should not only rely on existence of jcr:lockIsDeep property
-         * but also verify that node.isNodeType("mix:lockable")==true;
-         * this would have a negative impact on performance though...
-         */
         NodeEntry entry = nodeState.getNodeEntry();
         while (!entry.hasPropertyEntry(QName.JCR_LOCKISDEEP)) {
             NodeEntry parent = entry.getParent();
@@ -324,17 +317,18 @@
     }
 
     private LockState buildLockState(NodeState nodeState) throws RepositoryException {
+        NodeId nId = nodeState.getNodeId();
         NodeState lockHoldingState = null;
         LockInfo lockInfo;
         try {
-            lockInfo = wspManager.getLockInfo(nodeState.getNodeId());
+            lockInfo = wspManager.getLockInfo(nId);
         } catch (LockException e) {
             // no lock present
             return null;
         }
 
         NodeId lockNodeId = lockInfo.getNodeId();
-        if (lockNodeId.equals(nodeState.getId())) {
+        if (lockNodeId.equals(nId)) {
             lockHoldingState = nodeState;
         } else {
             HierarchyEntry lockedEntry = wspManager.getHierarchyManager().getHierarchyEntry(lockNodeId);
@@ -372,20 +366,30 @@
      */
     private LockImpl getLockImpl(NodeState nodeState, boolean lazyLockDiscovery) throws RepositoryException {
         nodeState.checkIsSessionState();
+        NodeState nState = nodeState;
+        // access first non-NEW state
+        while (nState.getStatus() == Status.NEW) {
+            try {
+                nState = nState.getParent();
+            } catch (ItemStateException e) {
+                // should never occur, since NEW states must have an accessible parent
+                throw new RepositoryException("Intenal error", e);
+            }
+        }
 
         // shortcut: check if a given state holds a lock, which has been
-        // accessed before (thus is known to the manager) irrespective if the
-        // current session is the lock holder or not.
-        if (lockMap.containsKey(nodeState)) {
-            return (LockImpl) lockMap.get(nodeState);
+        // store in the lock map. see below (LockImpl) for the conditions that
+        // must be met in order a lock can be stored.
+        if (lockMap.containsKey(nState)) {
+            return (LockImpl) lockMap.get(nState);
         }
 
         LockState lState;
         if (lazyLockDiscovery) {
             // try to retrieve a state (ev. a parent state) that holds a lock.
-            NodeState lockHoldingState = getLockHoldingState(nodeState);
+            NodeState lockHoldingState = getLockHoldingState(nState);
             if (lockHoldingState == null) {
-                // no lock
+                // assume no lock is present (might not be correct due to incomplete hierarchy)
                 return null;
             } else {
                 // check lockMap again with the lockholding state
@@ -395,18 +399,31 @@
                 lState = buildLockState(lockHoldingState);
             }
         } else {
-            lState = buildLockState(nodeState);
+            // need correct information about lock status -> retrieve lockInfo
+            // from the persistent layer.
+            lState = buildLockState(nState);
         }
 
-        // Lock has never been access -> build the lock object
-        // retrieve lock holding node. note that this may fail if the session
-        // does not have permission to see this node.
-        if (lState != null && lState.appliesToNodeState(nodeState)) {
-            Item lockHoldingNode = itemManager.getItem(lState.lockHoldingState.getHierarchyEntry());
-            return new LockImpl(lState, (Node)lockHoldingNode);
+        if (lState != null) {
+            // Test again if a Lock object is stored in the lockmap. Otherwise
+            // build the lock object and retrieve lock holding node. note that this
+            // may fail if the session does not have permission to see this node.
+            LockImpl lock;
+            if (lockMap.containsKey(lState.lockHoldingState)) {
+                lock = (LockImpl) lockMap.get(lState.lockHoldingState);
+                lock.lockState.lockInfo = lState.lockInfo;
+            } else {
+                Item lockHoldingNode = itemManager.getItem(lState.lockHoldingState.getHierarchyEntry());
+                lock = new LockImpl(lState, (Node)lockHoldingNode);
+            }
+            // test if lock applies to the original nodestate
+            if (lState.appliesToNodeState(nodeState)) {
+                return lock;
+            } else {
+                return null; // lock exists but doesn't apply to the given state
+            }
         } else {
-            // lock exists but does not apply to the given node state
-            // passed to this method.
+            // no lock at all
             return null;
         }
     }
@@ -586,7 +603,10 @@
             if (cacheBehaviour == CacheBehaviour.OBSERVATION) {
                 lockMap.put(lockState.lockHoldingState, this);
                 lockState.startListening();
-            } else if (isSessionScoped() && isHoldBySession()) {
+            } else if (isHoldBySession()) {
+                // TODO: TOBEFIXED. since another session may become lock-holder for
+                // an open-scoped lock, the map entry and the lock information
+                // stored therein may become outdated.
                 lockMap.put(lockState.lockHoldingState, this);
             }
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java Thu Mar  1 03:17:22 2007
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.NodeId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -36,10 +37,9 @@
 
     private static Logger log = LoggerFactory.getLogger(AbstractCopy.class);
 
+    final NodeState destParentState;
     private final NodeState srcState;
-    private final NodeState destParentState;
     private final QName destName;
-    
     private final String srcWorkspaceName;
 
     /**
@@ -77,7 +77,7 @@
     //----------------------------------------------------------< Operation >---
     /**
      * Invalidate the destination parent <code>NodeState</code>.
-     * 
+     *
      * @see Operation#persisted(CacheBehaviour)
      * @param cacheBehaviour
      */
@@ -92,12 +92,12 @@
         return srcWorkspaceName;
     }
 
-    public NodeState getNodeState() {
-        return srcState;
+    public NodeId getNodeId() {
+        return srcState.getNodeId();
     }
 
-    public NodeState getDestinationParentState() {
-        return destParentState;
+    public NodeId getDestinationParentId() {
+        return destParentState.getNodeId();
     }
 
     public QName getDestinationName() {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddLabel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddLabel.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddLabel.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddLabel.java Thu Mar  1 03:17:22 2007
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -84,12 +85,12 @@
         }
     }
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getVersionHistoryState() {
-        return versionHistoryState;
+    public NodeId getVersionHistoryId() {
+        return versionHistoryState.getNodeId();
     }
 
-    public NodeState getVersionState() {
-        return versionState;
+    public NodeId getVersionId() {
+        return versionState.getNodeId();
     }
 
     public QName getLabel() {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddNode.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddNode.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddNode.java Thu Mar  1 03:17:22 2007
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.NodeId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -38,12 +39,14 @@
 
     private static Logger log = LoggerFactory.getLogger(AddNode.class);
 
+    private final NodeId parentId;
     private final NodeState parentState;
     private final QName nodeName;
     private final QName nodeTypeName;
     private final String uuid;
 
     private AddNode(NodeState parentState, QName nodeName, QName nodeTypeName, String uuid) {
+        this.parentId = parentState.getNodeId();
         this.parentState = parentState;
         this.nodeName = nodeName;
         this.nodeTypeName = nodeTypeName;
@@ -71,6 +74,10 @@
         throw new UnsupportedOperationException("persisted() not implemented for transient modification.");
     }
     //----------------------------------------< Access Operation Parameters >---
+    public NodeId getParentId() {
+        return parentId;
+    }
+
     public NodeState getParentState() {
         return parentState;
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java Thu Mar  1 03:17:22 2007
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
@@ -36,6 +37,7 @@
  */
 public class AddProperty extends AbstractOperation {
 
+    private final NodeId parentId;
     private final NodeState parentState;
     private final QName propertyName;
     private final int propertyType;
@@ -44,6 +46,7 @@
     private final QPropertyDefinition definition;
 
     private AddProperty(NodeState parentState, QName propName, int propertyType, QValue[] values, QPropertyDefinition definition) {
+        this.parentId = parentState.getNodeId();
         this.parentState = parentState;
         this.propertyName = propName;
         this.propertyType = propertyType;
@@ -72,6 +75,10 @@
         throw new UnsupportedOperationException("persisted() not implemented for transient modification.");
     }
     //----------------------------------------< Access Operation Parameters >---
+    public NodeId getParentId() {
+        return parentId;
+    }
+
     public NodeState getParentState() {
         return parentState;
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java Thu Mar  1 03:17:22 2007
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.jcr2spi.version.VersionManager;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
+import org.apache.jackrabbit.spi.NodeId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -84,8 +85,8 @@
      *
      * @return The nodeState to be checked in.
      */
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     //------------------------------------------------------------< Factory >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkout.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkout.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkout.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkout.java Thu Mar  1 03:17:22 2007
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.jcr2spi.version.VersionManager;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
+import org.apache.jackrabbit.spi.NodeId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -83,8 +84,8 @@
      *
      * @return
      */
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     //------------------------------------------------------------< Factory >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java Thu Mar  1 03:17:22 2007
@@ -67,7 +67,7 @@
         if (cacheBehaviour == CacheBehaviour.INVALIDATE) {
             if (removeExisting) {
                 // invalidate the complete tree -> find root-hierarchy-entry
-                HierarchyEntry he = getDestinationParentState().getHierarchyEntry();
+                HierarchyEntry he = destParentState.getHierarchyEntry();
                 while (he.getParent() != null) {
                     he = he.getParent();
                 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockOperation.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockOperation.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockOperation.java Thu Mar  1 03:17:22 2007
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.spi.LockInfo;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -69,8 +70,8 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     public boolean isDeep() {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java Thu Mar  1 03:17:22 2007
@@ -22,6 +22,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.version.VersionException;
 import javax.jcr.nodetype.ConstraintViolationException;
@@ -57,8 +58,8 @@
     }
     
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     //------------------------------------------------------------< Factory >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRelease.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRelease.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRelease.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRelease.java Thu Mar  1 03:17:22 2007
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -72,8 +73,8 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     //------------------------------------------------------------< Factory >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java Thu Mar  1 03:17:22 2007
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.jcr2spi.version.VersionManager;
 import org.apache.jackrabbit.spi.IdIterator;
+import org.apache.jackrabbit.spi.NodeId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -80,8 +81,8 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     public String getSourceWorkspaceName() {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java Thu Mar  1 03:17:22 2007
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
+import org.apache.jackrabbit.jcr2spi.state.NoSuchItemStateException;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
@@ -47,17 +48,21 @@
     private static Logger log = LoggerFactory.getLogger(Move.class);
 
     private final NodeId srcId;
+    private final NodeId destParentId;
+    private final QName destName;
+
     private final NodeState srcState;
     private final NodeState srcParentState;
     private final NodeState destParentState;
-    private final QName destName;
 
     private Move(NodeState srcNodeState, NodeState srcParentState, NodeState destParentState, QName destName) {
         this.srcId = (NodeId) srcNodeState.getId();
+        this.destParentId = destParentState.getNodeId();
+        this.destName = destName;
+
         this.srcState = srcNodeState;
         this.srcParentState = srcParentState;
         this.destParentState = destParentState;
-        this.destName = destName;
         
         addAffectedItemState(srcNodeState);
         addAffectedItemState(srcParentState);
@@ -83,13 +88,16 @@
      */
     public void persisted(CacheBehaviour cacheBehaviour) {
         if (cacheBehaviour == CacheBehaviour.INVALIDATE) {
-            if (srcState.isWorkspaceState()) {
-                // non-recursive invalidation
+            // non-recursive invalidation
+            try {
+                srcState.getNodeEntry().move(destName, destParentState.getNodeEntry(), false);
+                // TODO: TOBEFIXED. moved state ev. got a new definition.
+            } catch (RepositoryException e) {
+                // should not occure
+                log.error("Internal error", e);
                 srcParentState.getHierarchyEntry().invalidate(false);
                 destParentState.getHierarchyEntry().invalidate(false);
                 srcState.getHierarchyEntry().invalidate(false);
-            } else {
-                throw new UnsupportedOperationException("persisted() not implemented for transient modification.");
             }
         }
     }
@@ -98,6 +106,10 @@
         return srcId;
     }
 
+    public NodeId getDestinationParentId() {
+        return destParentId;
+    }
+
     public NodeState getSourceState() {
         return srcState;
     }
@@ -151,6 +163,9 @@
         NodeState destParentState = getNodeState(destPath.getAncestor(1), hierMgr, nsResolver);
         QName destName = destElement.getName();
 
+        // lazy check for existing items at destination. since the hierarchy
+        // may not be complete it is possible that an conflict is only detected
+        // upon saving the 'move'.
         NodeEntry destEntry = (NodeEntry) destParentState.getHierarchyEntry();
         if (destEntry.hasPropertyEntry(destName)) {
             throw new ItemExistsException("Move destination already exists (Property).");
@@ -160,6 +175,8 @@
                 if (!existing.getNodeState().getDefinition().allowsSameNameSiblings()) {
                     throw new ItemExistsException("Node existing at move destination does not allow same name siblings.");
                 }
+            } catch (NoSuchItemStateException e) {
+                // existing apparent not valid any more -> probably no conflict
             } catch (ItemStateException e) {
                 throw new RepositoryException(e);
             }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java Thu Mar  1 03:17:22 2007
@@ -75,4 +75,6 @@
     public void visit(RemoveLabel operation) throws VersionException, RepositoryException;
 
     public void visit(RemoveVersion operation) throws VersionException, AccessDeniedException, ReferentialIntegrityException, RepositoryException;
+
+    public void visit(WorkspaceImport operation) throws RepositoryException;    
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java Thu Mar  1 03:17:22 2007
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.ItemId;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
@@ -31,10 +32,12 @@
  */
 public class Remove extends AbstractOperation {
 
+    private ItemId removeId;
     protected ItemState removeState;
     protected NodeState parent;
 
     protected Remove(ItemState removeState, NodeState parent) {
+        this.removeId = removeState.getId();
         this.removeState = removeState;
         this.parent = parent;
 
@@ -61,6 +64,9 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
+    public ItemId getRemoveId() {
+        return removeId;
+    }
 
     public ItemState getRemoveState() {
         return removeState;
@@ -73,15 +79,9 @@
     //------------------------------------------------------------< Factory >---
     public static Operation create(ItemState state) throws RepositoryException {
         try {
-            Remove rm = new Remove(state, state.getParent());
-            return rm;
+            return new Remove(state, state.getParent());
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
         }
-    }
-
-    public static Operation create(ItemState state, NodeState parent) {
-        Remove rm = new Remove(state, parent);
-        return rm;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveLabel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveLabel.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveLabel.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveLabel.java Thu Mar  1 03:17:22 2007
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -82,12 +83,12 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getVersionHistoryState() {
-        return versionHistoryState;
+    public NodeId getVersionHistoryId() {
+        return versionHistoryState.getNodeId();
     }
 
-    public NodeState getVersionState() {
-        return versionState;
+    public NodeId getVersionId() {
+        return versionState.getNodeId();
     }
 
     public QName getLabel() {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ReorderNodes.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ReorderNodes.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ReorderNodes.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ReorderNodes.java Thu Mar  1 03:17:22 2007
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NoSuchItemStateException;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.AccessDeniedException;
@@ -33,6 +34,10 @@
  */
 public class ReorderNodes extends AbstractOperation {
 
+    private final NodeId parentId;
+    private final NodeId insertId;
+    private final NodeId beforeId;
+
     private final NodeState parentState;
     private final NodeState insert;
     private final NodeState before;
@@ -41,6 +46,11 @@
         this.parentState = parentState;
         this.insert = insert;
         this.before = before;
+
+        this.parentId = parentState.getNodeId();
+        this.insertId = insert.getNodeId();
+        this.beforeId = (before == null) ? null : before.getNodeId();
+
         addAffectedItemState(parentState);
     }
 
@@ -63,6 +73,19 @@
         throw new UnsupportedOperationException("persisted() not implemented for transient modification.");
     }
     //----------------------------------------< Access Operation Parameters >---
+
+    public NodeId getParentId() {
+        return parentId;
+    }
+
+    public NodeId getInsertId() {
+        return insertId;
+    }
+
+    public NodeId getBeforeId() {
+        return beforeId;
+    }
+
     public NodeState getParentState() {
         return parentState;
     }
@@ -81,7 +104,6 @@
                                    Path.PathElement beforeName) throws NoSuchItemStateException, ItemStateException {
         NodeState insert = parentState.getChildNodeState(srcName.getName(), srcName.getNormalizedIndex());
         NodeState before = (beforeName == null) ? null : parentState.getChildNodeState(beforeName.getName(), beforeName.getNormalizedIndex());
-        Operation op = new ReorderNodes(parentState, insert, before);
-        return op;
+        return new ReorderNodes(parentState, insert, before);
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ResolveMergeConflict.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ResolveMergeConflict.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ResolveMergeConflict.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ResolveMergeConflict.java Thu Mar  1 03:17:22 2007
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -36,14 +37,17 @@
 public class ResolveMergeConflict extends AbstractOperation {
 
     private final NodeState nodeState;
-    private final NodeState versionState;
+    private final NodeId[] mergeFailedIds;
+    private final NodeId[] predecessorIds;
     private final boolean resolveDone;
 
-    private ResolveMergeConflict(NodeState nodeState, NodeState versionState, boolean resolveDone) {
+    private ResolveMergeConflict(NodeState nodeState, NodeId[] mergeFailedIds, NodeId[] predecessorIds, boolean resolveDone) {
         this.nodeState = nodeState;
-        this.versionState = versionState;
+        this.mergeFailedIds = mergeFailedIds;
+        this.predecessorIds = predecessorIds;
         this.resolveDone = resolveDone;
 
+
         // NOTE: affected-states only needed for transient modifications
     }
 
@@ -74,12 +78,16 @@
         }
     }
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
+    }
+
+    public NodeId[] getMergeFailedIds() {
+        return mergeFailedIds;
     }
 
-    public NodeState getVersionState() {
-        return versionState;
+    public NodeId[] getPredecessorIds() {
+        return predecessorIds;
     }
 
     public boolean resolveDone() {
@@ -93,8 +101,8 @@
      * @param versionState
      * @param resolveDone
      */
-    public static Operation create(NodeState nodeState, NodeState versionState, boolean resolveDone) {
-        ResolveMergeConflict up = new ResolveMergeConflict(nodeState, versionState, resolveDone);
+    public static Operation create(NodeState nodeState, NodeId[] mergeFailedIds, NodeId[] predecessorIds, boolean resolveDone) {
+        ResolveMergeConflict up = new ResolveMergeConflict(nodeState, mergeFailedIds, predecessorIds, resolveDone);
         return up;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java Thu Mar  1 03:17:22 2007
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ItemExistsException;
@@ -86,13 +87,13 @@
     //----------------------------------------< Access Operation Parameters >---
 
     /**
-     * Returns state or the closest existing state of the restore target or
+     * Returns id of state or the closest existing state of the restore target or
      * <code>null</code> in case of a {@link javax.jcr.Workspace#restore(Version[], boolean)}
      *
      * @return
      */
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return (nodeState == null) ? null : nodeState.getNodeId();
     }
 
     /**
@@ -106,8 +107,12 @@
         return relQPath;
     }
 
-    public NodeState[] getVersionStates() {
-        return versionStates;
+    public NodeId[] getVersionIds() {
+        NodeId[] versionIds = new NodeId[versionStates.length];
+        for (int i = 0; i < versionStates.length; i++) {
+            versionIds[i] = versionStates[i].getNodeId();
+        }
+        return versionIds;
     }
 
     public boolean removeExisting() {
@@ -123,7 +128,7 @@
      */
     public static Operation create(NodeState nodeState, Path relQPath, NodeState versionState, boolean removeExisting) {
         if (nodeState == null || versionState == null) {
-            throw new IllegalArgumentException("Neither nodeId nor versionState must be null.");
+            throw new IllegalArgumentException("Neither nodeState nor versionState must be null.");
         }
         Restore up = new Restore(nodeState, relQPath, new NodeState[] {versionState}, removeExisting);
         return up;
@@ -135,7 +140,7 @@
      * @return
      */
     public static Operation create(NodeState[] versionStates, boolean removeExisting) {
-        if (versionStates == null) {
+        if (versionStates == null || versionStates.length == 0) {
             throw new IllegalArgumentException("Version states must not be null.");
         }
         Restore up = new Restore(null, null, versionStates, removeExisting);

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetMixin.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetMixin.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetMixin.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetMixin.java Thu Mar  1 03:17:22 2007
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -34,11 +35,13 @@
  */
 public class SetMixin extends AbstractOperation {
 
+    private final NodeId nodeId;
     private final NodeState nodeState;
     private final QName[] mixinNames;
 
     private SetMixin(NodeState nodeState, QName[] mixinNames) {
         this.nodeState = nodeState;
+        this.nodeId = nodeState.getNodeId();
         this.mixinNames = mixinNames;
 
         // remember node state as affected state
@@ -80,6 +83,10 @@
         return nodeState;
     }
 
+    public NodeId getNodeId() {
+        return nodeId;
+    }
+    
     public QName[] getMixinNames() {
         return mixinNames;
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java Thu Mar  1 03:17:22 2007
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.PropertyId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
@@ -36,13 +37,16 @@
  */
 public class SetPropertyValue extends AbstractOperation {
 
+    private final PropertyId propertyId;
     private final PropertyState propertyState;
     private final QValue[] values;
-    private final int propertyType;
+    private final int valueType;
 
-    private SetPropertyValue(PropertyState propertyState, int propertyType, QValue[] values) {
+    private SetPropertyValue(PropertyState propertyState, int valueType, QValue[] values) {
         this.propertyState = propertyState;
-        this.propertyType = propertyType;
+
+        propertyId = propertyState.getPropertyId();
+        this.valueType = valueType;
         this.values = values;
 
         addAffectedItemState(propertyState);
@@ -69,12 +73,20 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
+    public PropertyId getPropertyId() {
+        return propertyId;
+    }
+
     public PropertyState getPropertyState() {
         return propertyState;
     }
 
-    public int getPropertyType() {
-        return propertyType;
+    public boolean isMultiValued() {
+        return propertyState.isMultiValued();
+    }
+
+    public int getValueType() {
+        return valueType;
     }
 
     public QValue[] getValues() {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Update.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Update.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Update.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Update.java Thu Mar  1 03:17:22 2007
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.spi.NodeId;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
@@ -64,8 +65,8 @@
     }
 
     //----------------------------------------< Access Operation Parameters >---
-    public NodeState getNodeState() {
-        return nodeState;
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
     }
 
     public String getSourceWorkspaceName() {

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/WorkspaceImport.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/WorkspaceImport.java?view=auto&rev=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/WorkspaceImport.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/WorkspaceImport.java Thu Mar  1 03:17:22 2007
@@ -0,0 +1,95 @@
+package org.apache.jackrabbit.jcr2spi.operation;
+
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
+import org.apache.jackrabbit.spi.NodeId;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.version.VersionException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import java.io.InputStream;
+
+/**
+ * <code>WorkspaceImport</code>...
+ */
+public class WorkspaceImport extends AbstractOperation {
+
+    private final NodeState nodeState;
+    private final InputStream xmlStream;
+    private final int uuidBehaviour;
+
+    private WorkspaceImport(NodeState nodeState, InputStream xmlStream, int uuidBehaviour) {
+        if (nodeState == null || xmlStream == null) {
+            throw new IllegalArgumentException();
+        }
+        this.nodeState = nodeState;
+        this.xmlStream = xmlStream;
+        this.uuidBehaviour = uuidBehaviour;
+
+        // NOTE: affected-states only needed for transient modifications
+    }
+
+    //----------------------------------------------------------< Operation >---
+    /**
+     * @see Operation#accept(OperationVisitor)
+     */
+    public void accept(OperationVisitor visitor) throws RepositoryException, ConstraintViolationException, AccessDeniedException, ItemExistsException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException {
+        visitor.visit(this);
+    }
+
+    /**
+     * Invalidates the <code>NodeState</code> that has been updated and all
+     * its decendants.
+     *
+     * @see Operation#persisted(CacheBehaviour)
+     * @param cacheBehaviour
+     */
+    public void persisted(CacheBehaviour cacheBehaviour) {
+        if (cacheBehaviour == CacheBehaviour.INVALIDATE) {
+            NodeEntry entry;
+            if (uuidBehaviour == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING ||
+                uuidBehaviour == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING) {
+                // invalidate the complete tree
+                entry = nodeState.getNodeEntry();
+                while (entry.getParent() != null) {
+                    entry = entry.getParent();
+                }
+                entry.invalidate(true);
+            } else {
+                // import only added new items below the import target. therefore
+                // recursive invalidation is not required. // TODO correct?
+                nodeState.getNodeEntry().invalidate(false);
+            }
+        }
+    }
+
+    //----------------------------------------< Access Operation Parameters >---
+    public NodeId getNodeId() {
+        return nodeState.getNodeId();
+    }
+
+    public InputStream getXmlStream() {
+        return xmlStream;
+    }
+
+    public int getUuidBehaviour() {
+        return uuidBehaviour;
+    }
+
+    //------------------------------------------------------------< Factory >---
+    /**
+     *
+     * @param nodeState
+     * @param xmlStream
+     * @return
+     */
+    public static Operation create(NodeState nodeState, InputStream xmlStream, int uuidBehaviour) {
+        return new WorkspaceImport(nodeState, xmlStream, uuidBehaviour);
+    }
+}

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java Thu Mar  1 03:17:22 2007
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.name.QName;
+import org.apache.commons.collections.iterators.IteratorChain;
 
 import javax.jcr.nodetype.ConstraintViolationException;
 import java.util.Iterator;
@@ -30,6 +31,8 @@
 import java.util.LinkedHashSet;
 import java.util.HashSet;
 import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Registers changes made to states and references and consolidates
@@ -54,7 +57,7 @@
     private final Set deletedStates = new LinkedHashSet();
 
     /**
-     * Type of operation this changelog is collection state modifications for.
+     * Set of operations
      */
     private Set operations = new LinkedHashSet();
 
@@ -124,6 +127,18 @@
         target.persisted(this, cacheBehaviour);
     }
 
+    /**
+     * Revert the changes listed within this changelog
+     */
+    public void undo() throws ItemStateException {
+        // TODO: check if states are reverted in the correct order
+        Iterator[] its = new Iterator[] {addedStates(), deletedStates(), modifiedStates()};
+        IteratorChain chain = new IteratorChain(its);
+        while (chain.hasNext()) {
+            ItemState state = (ItemState) chain.next();
+            state.getHierarchyEntry().revert();
+        }
+    }
     //----------------------< Retrieve information present in the ChangeLog >---
     /**
      *

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java Thu Mar  1 03:17:22 2007
@@ -427,20 +427,19 @@
      */
     public void reconnect(boolean keepChanges) throws NoSuchItemStateException, ItemStateException {
         checkIsSessionState();
-        // Need to use the workspace-ISF in order not to create yet another
-        // session-state.
+        // Need to use the workspace-ISF in order not to create a session-state.
         ItemStateFactory wspIsf;
         if (overlayedState != null) {
             wspIsf = overlayedState.isf;
         } else {
             wspIsf = getParent().overlayedState.isf;
         }
-
+        ItemId id = (overlayedState == null) ? getId() : overlayedState.getId();
         ItemState overlayed;
         if (isNode()) {
-            overlayed = wspIsf.createNodeState((NodeId) getId(), (NodeEntry) getHierarchyEntry());
+            overlayed = wspIsf.createNodeState((NodeId) id, (NodeEntry) getHierarchyEntry());
         } else {
-            overlayed = wspIsf.createPropertyState((PropertyId) getId(), (PropertyEntry) getHierarchyEntry());
+            overlayed = wspIsf.createPropertyState((PropertyId) id, (PropertyEntry) getHierarchyEntry());
         }
         setOverLayedState(overlayed);
         boolean modified = merge(overlayed, keepChanges);
@@ -493,10 +492,18 @@
         }
     }
 
-    EffectiveNodeType getEffectiveNodeType() throws RepositoryException {
+    EffectiveNodeType getEffectiveParentNodeType() throws RepositoryException {
         try {
-            EffectiveNodeType ent = getNodeTypeRegistry().getEffectiveNodeType(getParent().getNodeTypeNames());
-            return ent;
+            /*
+            for NEW-states the definition is always set upon creation.
+            for all other states the definion must be retrieved only taking
+            the effective nodetypes present on the parent into account
+            any kind of transiently added mixins must not have an effect
+            on the definition retrieved for an state that has been persisted
+            before. The effective NT must be evaluated as if it had been
+            evaluated upon creating the workspace state.
+            */
+            return getNodeTypeRegistry().getEffectiveNodeType(getParent().getNodeTypeNames());
         } catch (ItemStateException e) {
             throw new RepositoryException("Error while accessing Definition ", e);
         } catch (NodeTypeConflictException e) {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java Thu Mar  1 03:17:22 2007
@@ -38,6 +38,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QItemDefinition;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.NamespaceResolver;
@@ -185,7 +186,29 @@
     public EffectiveNodeType getEffectiveNodeType(NodeState nodeState)
             throws RepositoryException {
         try {
-            return getEffectiveNodeType(nodeState.getNodeTypeNames());
+            QName[] allNtNames;
+            if (nodeState.getStatus() == Status.EXISTING) {
+                allNtNames = nodeState.getNodeTypeNames();
+            } else {
+                // TODO: check if correct (and only used for creating new)
+                QName primaryType = nodeState.getNodeTypeName();
+                allNtNames = new QName[] { primaryType }; // default
+                PropertyEntry mixins = nodeState.getNodeEntry().getPropertyEntry(QName.JCR_MIXINTYPES);
+                if (mixins != null) {
+                    try {
+                        QValue[] values = mixins.getPropertyState().getValues();
+                        allNtNames = new QName[values.length + 1];
+                        for (int i = 0; i < values.length; i++) {
+                            allNtNames[i] = values[i].getQName();
+                        }
+                        allNtNames[values.length] = primaryType;
+                    } catch (ItemStateException e) {
+                        // ignore
+                    }
+                }
+            }
+
+            return getEffectiveNodeType(allNtNames);
         } catch (NodeTypeConflictException ntce) {
             String msg = "Internal error: failed to build effective node type from node types defined with " + safeGetJCRPath(nodeState);
             log.debug(msg);
@@ -195,8 +218,7 @@
 
     /**
      * Helper method that builds the effective (i.e. merged and resolved)
-     * node type representation of the specified node's primary and mixin
-     * node types.
+     * node type representation of the specified node types.
      *
      * @param nodeTypeNames
      * @return the effective node type
@@ -204,8 +226,20 @@
      * @throws NoSuchNodeTypeException
      */
     public EffectiveNodeType getEffectiveNodeType(QName[] nodeTypeNames)
-        throws NodeTypeConflictException, NoSuchNodeTypeException  {
-            return ntReg.getEffectiveNodeType(nodeTypeNames);
+            throws NodeTypeConflictException, NoSuchNodeTypeException  {
+        return ntReg.getEffectiveNodeType(nodeTypeNames);
+    }
+
+    /**
+     * Helper method that builds the effective (i.e. merged and resolved)
+     * node type representation of the specified node type.
+     *
+     * @param nodeTypeName
+     * @return the effective node type
+     * @throws NoSuchNodeTypeException
+     */
+    public EffectiveNodeType getEffectiveNodeType(QName nodeTypeName) throws NoSuchNodeTypeException  {
+        return ntReg.getEffectiveNodeType(nodeTypeName);
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Thu Mar  1 03:17:22 2007
@@ -46,7 +46,7 @@
 
     private static Logger log = LoggerFactory.getLogger(NodeState.class);
 
-    private NodeEntry hierarchyEntry;
+    private final NodeEntry hierarchyEntry;
 
     /**
      * the name of this node's primary type
@@ -141,10 +141,6 @@
         synchronized (another) {
             NodeState nState = (NodeState) another;
 
-            if (hierarchyEntry != nState.hierarchyEntry) {
-                hierarchyEntry = nState.hierarchyEntry;
-                modified = true;
-            }
             if (nState.definition != null && !nState.definition.equals(definition)) {
                 definition = nState.definition;
                 modified = true;
@@ -175,7 +171,11 @@
      * @return the id of this node state.
      */
     public NodeId getNodeId() {
-        return getNodeEntry().getId();
+        if (isWorkspaceState()) {
+            return getNodeEntry().getWorkspaceId();
+        } else {
+            return getNodeEntry().getId();
+        }
     }
 
     /**
@@ -250,7 +250,7 @@
      */
     public QNodeDefinition getDefinition() throws RepositoryException {
         if (definition == null) {
-            definition = getEffectiveNodeType().getApplicableNodeDefinition(getQName(), getNodeTypeName(), getNodeTypeRegistry());
+            definition = getEffectiveParentNodeType().getApplicableNodeDefinition(getQName(), getNodeTypeName(), getNodeTypeRegistry());
         }
         return definition;
     }
@@ -390,10 +390,8 @@
             ItemState modState = (ItemState) it.next();
             if (modState.isNode()) {
                 if (StateUtility.isMovedState((NodeState) modState)) {
-                    // move overlayed state as well by setting NodeEntry and
-                    // definition according to session-state
+                    // set definition of overlayed according to session-state
                     NodeState overlayed = (NodeState) modState.overlayedState;
-                    overlayed.hierarchyEntry = ((NodeState) modState).hierarchyEntry;
                     overlayed.definition = ((NodeState) modState).definition;
 
                     // and mark the moved state existing
@@ -467,6 +465,7 @@
 
         NodeEntry before = (beforeNode == null) ? null : beforeNode.getNodeEntry();
         insertNode.getNodeEntry().orderBefore(before);
+        
         // mark this state as modified
         markModified();
     }
@@ -482,22 +481,19 @@
      * @throws RepositoryException if the given child state is not a child
      * of this node state.
      */
-    synchronized void moveChildNodeEntry(NodeState newParent, NodeState childState, QName newName, QNodeDefinition newDefinition)
+    synchronized void moveChildNodeEntry(NodeState newParent, NodeState childState,
+                                         QName newName, QNodeDefinition newDefinition)
         throws RepositoryException {
         checkIsSessionState();
 
         // move child entry
-        NodeEntry newEntry = getNodeEntry().moveNodeEntry(childState, newName, newParent.getNodeEntry());
-
-        // set new NodeEntry on child state, that differs from the HE of the workspaceState
-        // TODO: check again
-        childState.hierarchyEntry = newEntry;
+        childState.getNodeEntry().move(newName, newParent.getNodeEntry(), true);
         childState.definition = newDefinition;
 
         // mark both this and newParent modified
         markModified();
-        childState.markModified();
         newParent.markModified();
+        childState.markModified();
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java Thu Mar  1 03:17:22 2007
@@ -186,7 +186,11 @@
      * @return the id of this property.
      */
     public PropertyId getPropertyId() {
-        return getPropertyEntry().getId();
+        if (isWorkspaceState()) {
+            return getPropertyEntry().getWorkspaceId();
+        } else {
+            return getPropertyEntry().getId();
+        }
     }
 
     /**
@@ -220,7 +224,7 @@
      */
     public QPropertyDefinition getDefinition() throws RepositoryException {
         if (definition == null) {
-            definition = getEffectiveNodeType().getApplicablePropertyDefinition(getQName(), getType(), isMultiValued());
+            definition = getEffectiveParentNodeType().getApplicablePropertyDefinition(getQName(), getType(), isMultiValued());
         }
         return definition;
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java Thu Mar  1 03:17:22 2007
@@ -18,7 +18,6 @@
 
 import org.apache.jackrabbit.jcr2spi.util.ReferenceChangeTracker;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.operation.OperationVisitor;
 import org.apache.jackrabbit.jcr2spi.operation.AddNode;
@@ -42,6 +41,7 @@
 import org.apache.jackrabbit.jcr2spi.operation.AddLabel;
 import org.apache.jackrabbit.jcr2spi.operation.RemoveLabel;
 import org.apache.jackrabbit.jcr2spi.operation.RemoveVersion;
+import org.apache.jackrabbit.jcr2spi.operation.WorkspaceImport;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.slf4j.LoggerFactory;
@@ -53,7 +53,6 @@
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.uuid.UUID;
-import org.apache.commons.collections.iterators.IteratorChain;
 
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemNotFoundException;
@@ -163,15 +162,8 @@
     public void undo(ItemState itemState) throws ItemStateException, ConstraintViolationException {
         ChangeLog changeLog = getChangeLog(itemState, false);
         if (!changeLog.isEmpty()) {
-            // now do it for real
-            // TODO: check if states are reverted in correct order
-            Iterator[] its = new Iterator[] {changeLog.addedStates(), changeLog.deletedStates(), changeLog.modifiedStates()};
-            IteratorChain chain = new IteratorChain(its);
-            while (chain.hasNext()) {
-                ItemState state = (ItemState) chain.next();
-                state.getHierarchyEntry().revert();
-            }
-
+            // let changelog revert all changes
+            changeLog.undo();
             // remove transient states and related operations from the t-statemanager
             transientStateMgr.dispose(changeLog);
             changeLog.reset();
@@ -395,7 +387,7 @@
         int options = ItemStateValidator.CHECK_LOCK
             | ItemStateValidator.CHECK_VERSIONING
             | ItemStateValidator.CHECK_CONSTRAINTS;
-        setPropertyStateValue(pState, operation.getValues(), operation.getPropertyType(), options);
+        setPropertyStateValue(pState, operation.getValues(), operation.getValueType(), options);
         transientStateMgr.addOperation(operation);
     }
 
@@ -528,6 +520,14 @@
         throw new UnsupportedOperationException("Internal error: RemoveVersion cannot be handled by session ItemStateManager.");
     }
 
+    /**
+     * @throws UnsupportedOperationException
+     * @see OperationVisitor#visit(WorkspaceImport)
+     */
+    public void visit(WorkspaceImport operation) throws RepositoryException {
+        throw new UnsupportedOperationException("Internal error: WorkspaceImport cannot be handled by session ItemStateManager.");
+    }
+
     //--------------------------------------------< Internal State Handling >---
     /**
      *
@@ -601,14 +601,11 @@
 
         // check if add node is possible. note, that the options differ if
         // the 'addNode' is called from inside a regular add-node to create
-        // autocreated child nodes that my are 'protected' by their def.
+        // autocreated child nodes that may be 'protected'.
         validator.checkAddNode(parent, nodeName, nodeTypeName, options);
+        // a new NodeState doesn't have mixins defined yet -> ent is ent of primarytype
+        EffectiveNodeType ent = validator.getEffectiveNodeType(nodeTypeName);
 
-        try {
-            validator.getEffectiveNodeType(new QName[]{nodeTypeName});
-        } catch (NodeTypeConflictException e) {
-            throw new RepositoryException("node type conflict: " + e.getMessage());
-        }
         if (nodeTypeName == null) {
             // no primary node type specified,
             // try default primary type from definition
@@ -620,18 +617,27 @@
             }
         }
 
-        NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, uuid, nodeTypeName, definition, parent);
+        // create new nodeState. NOTE, that the uniqueID is not added to the
+        // state for consistency between 'addNode' and importXML // TODO review
+        NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, null, nodeTypeName, definition, parent);
+        if (uuid != null) {
+            QValue[] value = getQValues(uuid, qValueFactory);
+            EffectiveNodeType effnt = validator.getEffectiveNodeType(QName.MIX_REFERENCEABLE);
+            QPropertyDefinition pDef = effnt.getApplicablePropertyDefinition(QName.JCR_UUID, PropertyType.STRING, false);
+            addPropertyState(nodeState, QName.JCR_UUID, PropertyType.STRING, value, pDef, 0);
+        }
 
-        EffectiveNodeType ent = validator.getEffectiveNodeType(nodeState);
         // add 'auto-create' properties defined in node type
         QPropertyDefinition[] pda = ent.getAutoCreatePropDefs();
         for (int i = 0; i < pda.length; i++) {
             QPropertyDefinition pd = pda[i];
-            QValue[] autoValue = computeSystemGeneratedPropertyValues(nodeState, pd);
-            if (autoValue != null) {
-                int propOptions = ItemStateValidator.CHECK_NONE;
-                // execute 'addProperty' without adding operation.
-                addPropertyState(nodeState, pd.getQName(), pd.getRequiredType(), autoValue, pd, propOptions);
+            if (!nodeState.hasPropertyName(pd.getQName())) {
+                QValue[] autoValue = computeSystemGeneratedPropertyValues(nodeState, pd);
+                if (autoValue != null) {
+                    int propOptions = ItemStateValidator.CHECK_NONE;
+                    // execute 'addProperty' without adding operation.
+                    addPropertyState(nodeState, pd.getQName(), pd.getRequiredType(), autoValue, pd, propOptions);
+                }
             }
         }
 
@@ -704,11 +710,7 @@
             QName name = def.getQName();
             if (QName.MIX_REFERENCEABLE.equals(declaringNT) && QName.JCR_UUID.equals(name)) {
                 // mix:referenceable node type defines jcr:uuid
-                String uniqueID = parent.getUniqueID();
-                if (uniqueID == null) {
-                    uniqueID = UUID.randomUUID().toString();
-                }
-                genValues = new QValue[]{qValueFactory.create(uniqueID, PropertyType.REFERENCE)};
+                genValues = getQValues(parent.getUniqueID(), qValueFactory);
             } else if (QName.NT_BASE.equals(declaringNT)) {
                 // nt:base node type
                 if (QName.JCR_PRIMARYTYPE.equals(name)) {
@@ -747,5 +749,12 @@
             ret[i] = factory.create(qNames[i]);
         }
         return ret;
+    }
+
+    private static QValue[] getQValues(String uniqueID, QValueFactory factory) {
+        if (uniqueID == null) {
+            uniqueID = UUID.randomUUID().toString();
+        }
+        return new QValue[] {factory.create(uniqueID, PropertyType.STRING)};
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java Thu Mar  1 03:17:22 2007
@@ -69,7 +69,7 @@
      * @param newUUID
      */
     public void mappedUUIDs(String oldUUID, String newUUID) {
-        if (oldUUID.equals(newUUID) || oldUUID == null) {
+        if (oldUUID == null || oldUUID.equals(newUUID)) {
             // only remember if uuid exists and has changed
             return;
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/StateUtility.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/StateUtility.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/StateUtility.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/StateUtility.java Thu Mar  1 03:17:22 2007
@@ -21,8 +21,8 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.Status;
-import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.spi.QValue;
 
 import javax.jcr.RepositoryException;
@@ -72,16 +72,8 @@
             // the root state cannot be moved
             return false;
         } else {
-            // a session-state is moved, if its NodeEntry is not the same as
-            // the NodeEntry of its overlayed state. If no overlayedState
-            // exists the state not moved anyway.
-            ItemState overlayed = state.getWorkspaceState();
-            if (overlayed == null) {
-                return false;
-            } else {
-                return state.getHierarchyEntry() != overlayed.getHierarchyEntry();
-                //return modState.overlayedState.getParent() != modState.getParent().overlayedState;
-            }
+            NodeEntry ne = state.getNodeEntry();
+            return ne.isTransientlyMoved();
         }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java Thu Mar  1 03:17:22 2007
@@ -41,6 +41,7 @@
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.spi.IdIterator;
 import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.QValue;
 
 /**
  * <code>VersionManagerImpl</code>...
@@ -156,11 +157,45 @@
         return op.getFailedIds();
     }
 
-    public void resolveMergeConflict(NodeState nodeState, NodeState versionState, boolean done) throws RepositoryException {
+    public void resolveMergeConflict(NodeState nodeState, NodeState versionState,
+                                     boolean done) throws RepositoryException {
         NodeState wspState = getWorkspaceState(nodeState);
-        NodeState wspVState = getWorkspaceState(versionState);
-        Operation op = ResolveMergeConflict.create(wspState, wspVState, done);
-        workspaceManager.execute(op);
+        NodeId vId = getWorkspaceState(versionState).getNodeId();
+        try {
+            PropertyState mergeFailedState = wspState.getPropertyState(QName.JCR_MERGEFAILED);
+            QValue[] vs = mergeFailedState.getValues();
+
+            NodeId[] mergeFailedIds = new NodeId[vs.length - 1];
+            for (int i = 0, j = 0; i < vs.length; i++) {
+                NodeId id = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
+                if (!id.equals(vId)) {
+                    mergeFailedIds[j] = id;
+                    j++;
+                }
+                // else: the version id is being solved by this call and not
+                // part of 'jcr:mergefailed' any more
+            }
+
+            PropertyState predecessorState = wspState.getPropertyState(QName.JCR_PREDECESSORS);
+            vs = predecessorState.getValues();
+
+            int noOfPredecessors = (done) ? vs.length + 1 : vs.length;
+            NodeId[] predecessorIds = new NodeId[noOfPredecessors];
+
+            int i = 0;
+            while (i < vs.length) {
+                predecessorIds[i] = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
+                i++;
+            }
+            if (done) {
+                predecessorIds[i] = vId;
+            }
+            Operation op = ResolveMergeConflict.create(wspState, mergeFailedIds, predecessorIds, done);
+            workspaceManager.execute(op);
+
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     public NodeEntry getVersionableNodeState(NodeState versionState) throws RepositoryException {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/Importer.java Thu Mar  1 03:17:22 2007
@@ -57,14 +57,11 @@
 
     //--------------------------------------------------------< inner classes >
     static class NodeInfo {
-        private QName name;
-        private QName nodeTypeName;
-        private QName[] mixinNames;
+        private final QName name;
+        private final QName nodeTypeName;
+        private final QName[] mixinNames;
         private String uuid;
 
-        public NodeInfo() {
-        }
-
         public NodeInfo(QName name, QName nodeTypeName, QName[] mixinNames, String uuid) {
             this.name = name;
             this.nodeTypeName = nodeTypeName;
@@ -72,26 +69,14 @@
             this.uuid = uuid;
         }
 
-        public void setName(QName name) {
-            this.name = name;
-        }
-
         public QName getName() {
             return name;
         }
 
-        public void setNodeTypeName(QName nodeTypeName) {
-            this.nodeTypeName = nodeTypeName;
-        }
-
         public QName getNodeTypeName() {
             return nodeTypeName;
         }
 
-        public void setMixinNames(QName[] mixinNames) {
-            this.mixinNames = mixinNames;
-        }
-
         public QName[] getMixinNames() {
             return mixinNames;
         }
@@ -106,12 +91,9 @@
     }
 
     static class PropInfo {
-        private QName name;
-        private int type;
-        private TextValue[] values;
-
-        public PropInfo() {
-        }
+        private final QName name;
+        private final int type;
+        private final TextValue[] values;
 
         public PropInfo(QName name, int type, TextValue[] values) {
             this.name = name;
@@ -119,24 +101,12 @@
             this.values = values;
         }
 
-        public void setName(QName name) {
-            this.name = name;
-        }
-
         public QName getName() {
             return name;
         }
 
-        public void setType(int type) {
-            this.type = type;
-        }
-
         public int getType() {
             return type;
-        }
-
-        public void setValues(TextValue[] values) {
-            this.values = values;
         }
 
         public TextValue[] getValues() {



Mime
View raw message