jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r800478 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ test/java/org/apache/jackrabbit/core/
Date Mon, 03 Aug 2009 17:53:35 GMT
Author: jukka
Date: Mon Aug  3 17:53:35 2009
New Revision: 800478

URL: http://svn.apache.org/viewvc?rev=800478&view=rev
Log:
JCR-1972: Preserving UUID and document version history on repository migration

Prepare to add the new checkin() signatures by cleaning up the deprecated versioning methods
in NodeImpl.

Added a NodeImpl.getNodeState() method to avoid extra type casting.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ProtectedItemModifier.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Mon Aug  3 17:53:35 2009
@@ -155,7 +155,7 @@
 
             // fallback: try finding applicable definition
             NodeImpl parent = (NodeImpl) getItem(state.getParentId());
-            NodeState parentState = (NodeState) parent.getItemState();
+            NodeState parentState = parent.getNodeState();
             ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
             def = parent.getApplicableChildNodeDefinition(cne.getName(), state.getNodeTypeName());
             state.setDefinitionId(def.unwrap().getId());

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
Mon Aug  3 17:53:35 2009
@@ -297,7 +297,7 @@
         }
         if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
             NodeImpl node = (item.isNode()) ? (NodeImpl) item : (NodeImpl) item.getParent();
-            if (!node.internalIsCheckedOut()) {
+            if (!node.isCheckedOut()) {
                 String msg = "Unable to perform operation. Node is checked-in.";
                 log.debug(msg);
                 throw new VersionException(msg);
@@ -345,7 +345,7 @@
         }
         if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
             NodeImpl node = (item.isNode()) ? (NodeImpl) item : (NodeImpl) item.getParent();
-            if (!node.internalIsCheckedOut()) {
+            if (!node.isCheckedOut()) {
                 return false;
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Mon Aug  3 17:53:35 2009
@@ -62,6 +62,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
@@ -102,6 +103,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_ISCHECKEDOUT;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_LIFECYCLE_POLICY;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_CURRENT_LIFECYCLE_STATE;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_LIFECYCLE;
@@ -145,6 +147,15 @@
     }
 
     /**
+     * Returns the node-state associated with this node.
+     *
+     * @return state associated with this node
+     */
+    NodeState getNodeState() {
+        return data.getNodeState();
+    }
+
+    /**
      * Returns the id of the property at <code>relPath</code> or <code>null</code>
      * if no property exists at <code>relPath</code>.
      * <p/>
@@ -3213,8 +3224,8 @@
         Path parentPath = parentNode.getPrimaryPath();
         PathBuilder builder = new PathBuilder(parentPath);
 
-        ChildNodeEntry entry = ((NodeState) parentNode.getItemState()).
-                getChildNodeEntry(getNodeId());
+        ChildNodeEntry entry =
+            parentNode.getNodeState().getChildNodeEntry(getNodeId());
         if (entry == null) {
             String msg = "failed to build path of " + id + ": "
                     + parentId + " has no child entry for "
@@ -3236,195 +3247,150 @@
     /**
      * {@inheritDoc}
      */
-    public void update(String srcWorkspaceName)
-            throws NoSuchWorkspaceException, AccessDeniedException,
-            LockException, InvalidItemStateException, RepositoryException {
-        ((VersionManagerImpl) session.getWorkspace().getVersionManager()).update(this, srcWorkspaceName);
+    public boolean isCheckedOut() throws RepositoryException {
+        // check state of this instance
+        sanityCheck();
+
+        // try shortcut first:
+        // if current node is 'new' we can safely consider it checked-out since
+        // otherwise it would had been impossible to add it in the first place
+        if (isNew()) {
+            return true;
+        }
+
+        // search nearest ancestor that is versionable
+        // FIXME should not only rely on existence of jcr:isCheckedOut property
+        // but also verify that node.isNodeType("mix:versionable")==true;
+        // this would have a negative impact on performance though...
+        try {
+            NodeState state = getNodeState();
+            while (!state.hasPropertyName(JCR_ISCHECKEDOUT)) {
+                ItemId parentId = state.getParentId();
+                if (parentId == null) {
+                    // root reached or out of hierarchy
+                    return true;
+                }
+                state = (NodeState)
+                    session.getItemStateManager().getItemState(parentId);
+            }
+            PropertyId id = new PropertyId(state.getNodeId(), JCR_ISCHECKEDOUT);
+            PropertyState ps =
+                (PropertyState) session.getItemStateManager().getItemState(id);
+            return ps.getValues()[0].getBoolean();
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    /**
+     * Returns the version manager of this workspace.
+     */
+    private VersionManagerImpl getVersionManagerImpl() {
+        return session.getWorkspaceImpl().getVersionManagerImpl();
     }
 
     /**
      * {@inheritDoc}
      */
-    @Deprecated
-    public Version checkin()
-            throws VersionException, UnsupportedRepositoryOperationException,
-            InvalidItemStateException, LockException, RepositoryException {
-        return session.getWorkspace().getVersionManager().checkin(getPath());
+    public void update(String srcWorkspaceName) throws RepositoryException {
+        getVersionManagerImpl().update(this, srcWorkspaceName);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#checkin(String)} instead
      */
     @Deprecated
-    public void checkout()
-            throws UnsupportedRepositoryOperationException, LockException,
-            RepositoryException {
-        session.getWorkspace().getVersionManager().checkout(getPath());
+    public Version checkin() throws RepositoryException {
+        return getVersionManagerImpl().checkin(getPath());
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#checkout(String)} instead
      */
     @Deprecated
-    public NodeIterator merge(String srcWorkspace, boolean bestEffort)
-            throws NoSuchWorkspaceException, AccessDeniedException,
-            VersionException, LockException, InvalidItemStateException,
-            RepositoryException {
-        return session.getWorkspace().getVersionManager().merge(getPath(), srcWorkspace,
bestEffort);
+    public void checkout() throws RepositoryException {
+        getVersionManagerImpl().checkout(getPath());
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#merge(String, String, boolean)} instead
      */
     @Deprecated
-    public void cancelMerge(Version version)
-            throws VersionException, InvalidItemStateException,
-            UnsupportedRepositoryOperationException, RepositoryException {
-        session.getWorkspace().getVersionManager().cancelMerge(getPath(), version);
+    public NodeIterator merge(String srcWorkspace, boolean bestEffort)
+            throws RepositoryException {
+        return getVersionManagerImpl().merge(
+                getPath(), srcWorkspace, bestEffort);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#cancelMerge(String, Version)} instead
      */
     @Deprecated
-    public void doneMerge(Version version) throws VersionException,
-            InvalidItemStateException, UnsupportedRepositoryOperationException,
-            RepositoryException {
-        session.getWorkspace().getVersionManager().doneMerge(getPath(), version);
+    public void cancelMerge(Version version) throws RepositoryException {
+        getVersionManagerImpl().cancelMerge(getPath(), version);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#doneMerge(String, Version)} instead
      */
-    public boolean isCheckedOut() throws RepositoryException {
-        // check state of this instance
-        sanityCheck();
-        return internalIsCheckedOut();
+    @Deprecated
+    public void doneMerge(Version version) throws RepositoryException {
+        getVersionManagerImpl().doneMerge(getPath(), version);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#restore(String, String, boolean)} instead
      */
     @Deprecated
     public void restore(String versionName, boolean removeExisting)
-            throws VersionException, ItemExistsException,
-            UnsupportedRepositoryOperationException, LockException,
-            InvalidItemStateException, RepositoryException {
-
-        // checks
-        sanityCheck();
-        session.getWorkspace().getVersionManager().restore(getPath(), versionName, removeExisting);
+            throws RepositoryException {
+        getVersionManagerImpl().restore(getPath(), versionName, removeExisting);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#restore(String, Version, boolean)} instead
      */
     @Deprecated
     public void restore(Version version, boolean removeExisting)
-            throws VersionException, ItemExistsException,
-            UnsupportedRepositoryOperationException, LockException,
-            RepositoryException {
-
-        // do checks
-        sanityCheck();
-        session.getWorkspace().getVersionManager().restore(getPath(), version, removeExisting);
+            throws RepositoryException {
+        getVersionManagerImpl().restore(getPath(), version, removeExisting);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#restore(String, Version, boolean)} instead
      */
     @Deprecated
     public void restore(Version version, String relPath, boolean removeExisting)
-            throws PathNotFoundException, ItemExistsException, VersionException,
-            ConstraintViolationException, UnsupportedRepositoryOperationException,
-            LockException, InvalidItemStateException, RepositoryException {
-
-        // do checks
-        sanityCheck();
-        String path = getPath() + "/" + relPath;
-        session.getWorkspace().getVersionManager().restore(path, version, removeExisting);
+            throws RepositoryException {
+        getVersionManagerImpl().restore(
+                getPath() + "/" + relPath, version, removeExisting);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#restoreByLabel(String, String, boolean)}
+     * instead
      */
     @Deprecated
     public void restoreByLabel(String versionLabel, boolean removeExisting)
-            throws VersionException, ItemExistsException,
-            UnsupportedRepositoryOperationException, LockException,
-            InvalidItemStateException, RepositoryException {
-
-        // do checks
-        sanityCheck();
-        session.getWorkspace().getVersionManager().restoreByLabel(getPath(), versionLabel,
removeExisting);
+            throws RepositoryException {
+        getVersionManagerImpl().restoreByLabel(
+                getPath(), versionLabel, removeExisting);
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#getVersionHistory(String)} instead
      */
     @Deprecated
-    public VersionHistory getVersionHistory()
-            throws UnsupportedRepositoryOperationException, RepositoryException {
-        sanityCheck();
-        return session.getWorkspace().getVersionManager().getVersionHistory(getPath());
+    public VersionHistory getVersionHistory() throws RepositoryException {
+        return getVersionManagerImpl().getVersionHistory(getPath());
     }
 
     /**
-     * {@inheritDoc}
+     * Use {@link VersionManager#getBaseVersion(String)} instead
      */
     @Deprecated
-    public Version getBaseVersion()
-            throws UnsupportedRepositoryOperationException, RepositoryException {
-        // check state of this instance
-        sanityCheck();
-        return session.getWorkspace().getVersionManager().getBaseVersion(getPath());
-    }
-
-    //-----------------------------------< versioning support: implementation >
-    /**
-     * Determines the checked-out status of this node.
-     * <p/>
-     * A node is considered <i>checked-out</i> if it is versionable and
-     * checked-out, or is non-versionable but its nearest versionable ancestor
-     * is checked-out, or is non-versionable and there are no versionable
-     * ancestors.
-     *
-     * @return a boolean
-     * @see Node#isCheckedOut()
-     * @throws RepositoryException if an error occurs
-     */
-    protected boolean internalIsCheckedOut() throws RepositoryException {
-        /**
-         * try shortcut first:
-         * if current node is 'new' we can safely consider it checked-out
-         * since otherwise it would had been impossible to add it in the first
-         * place
-         */
-        if (isNew()) {
-            return true;
-        }
-
-        // search nearest ancestor that is versionable
-        /**
-         * FIXME should not only rely on existence of jcr:isCheckedOut property
-         * but also verify that node.isNodeType("mix:versionable")==true;
-         * this would have a negative impact on performance though...
-         */
-        try {
-            NodeState state = (NodeState) getItemState();
-            while (!state.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
-                ItemId parentId = state.getParentId();
-                if (parentId == null) {
-                    // root reached or out of hierarchy
-                    return true;
-                }
-                state = (NodeState) session.getItemStateManager().getItemState(parentId);
-            }
-            PropertyState ps = (PropertyState) session.getItemStateManager().getItemState(new
PropertyId(state.getNodeId(), NameConstants.JCR_ISCHECKEDOUT));
-            return ps.getValues()[0].getBoolean();
-        } catch (ItemStateException e) {
-            throw new RepositoryException(e.getMessage());
-        }
+    public Version getBaseVersion() throws RepositoryException {
+        return getVersionManagerImpl().getBaseVersion(getPath());
     }
 
     //------------------------------------------------------< locking support >

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ProtectedItemModifier.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ProtectedItemModifier.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ProtectedItemModifier.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ProtectedItemModifier.java
Mon Aug  3 17:53:35 2009
@@ -74,7 +74,7 @@
 
         // check for name collisions
         // TODO: improve. copied from NodeImpl
-        NodeState thisState = (NodeState) parentImpl.getItemState();
+        NodeState thisState = parentImpl.getNodeState();
         ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
         if (cne != null) {
             // there's already a child node entry with that name;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Mon Aug  3 17:53:35 2009
@@ -794,6 +794,10 @@
      * {@inheritDoc}
      */
     public Workspace getWorkspace() {
+        return getWorkspaceImpl();
+    }
+
+    WorkspaceImpl getWorkspaceImpl() {
         return wsp;
     }
 
@@ -1111,7 +1115,7 @@
             destParentNode.renameChildNode(srcName.getName(), index, targetId, destName.getName());
         } else {
             // check shareable case
-            if (((NodeState) targetNode.getItemState()).isShareable()) {
+            if (targetNode.getNodeState().isShareable()) {
                 String msg = "Moving a shareable node is not supported.";
                 log.debug(msg);
                 throw new UnsupportedRepositoryOperationException(msg);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
Mon Aug  3 17:53:35 2009
@@ -257,8 +257,11 @@
     /**
      * @see javax.jcr.Workspace#getVersionManager()
      */
-    public VersionManager getVersionManager()
-            throws UnsupportedRepositoryOperationException, RepositoryException {
+    public VersionManager getVersionManager() {
+        return getVersionManagerImpl();
+    }
+
+    VersionManagerImpl getVersionManagerImpl() {
         if (versionMgr == null) {
             versionMgr = new VersionManagerImpl(session, stateMgr, hierMgr);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java?rev=800478&r1=800477&r2=800478&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
Mon Aug  3 17:53:35 2009
@@ -101,7 +101,7 @@
      * @throws RepositoryException
      * @throws NotExecutableException
      */
-    public void testInternalIsCheckedOut() throws RepositoryException, NotExecutableException
{
+    public void testIsCheckedOut() throws RepositoryException, NotExecutableException {
         Node n = testRootNode.addNode(nodeName1);
         NodeImpl testNode = (NodeImpl) n.addNode(nodeName2);
         testRootNode.save();
@@ -113,13 +113,13 @@
         Session readOnly = getHelper().getReadOnlySession();
         try {
             NodeImpl tn = (NodeImpl) readOnly.getItem(testNode.getPath());
-            assertTrue(tn.internalIsCheckedOut());
+            assertTrue(tn.isCheckedOut());
 
             n.addMixin(mixVersionable);
             testRootNode.save();
             n.checkin();
 
-            assertFalse(tn.internalIsCheckedOut());
+            assertFalse(tn.isCheckedOut());
         } finally {
             readOnly.logout();
             // reset the denied read-access



Mime
View raw message