jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r125924 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . state state/xml version version/persistence
Date Fri, 21 Jan 2005 11:55:03 GMT
Author: tripod
Date: Fri Jan 21 03:55:02 2005
New Revision: 125924

URL: http://svn.apache.org/viewcvs?view=rev&rev=125924
Log:
- use seperate persistence manager for versioning
Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java	Fri Jan 21
03:55:02 2005
@@ -2339,17 +2339,30 @@
             throws VersionException, UnsupportedRepositoryOperationException,
             RepositoryException {
 
+        // check if versionable
+        checkVersionable();
+
+        // check if checked out
         if (!isCheckedOut()) {
-            String msg = "Unable to checkin node. Is not checked-out. " + safeGetJCRPath();
+            String msg = safeGetJCRPath() + ": Node is already checked-in. ignoring.";
             log.debug(msg);
-            throw new VersionException(msg);
+            return getBaseVersion();
         }
+
         // check transient state
         if (isModified()) {
             String msg = "Unable to checkin node. Not allowed on transient node. " + safeGetJCRPath();
             log.debug(msg);
-            throw new IllegalStateException(msg);
+            throw new InvalidItemStateException(msg);
         }
+
+        // check if not merge failed
+        if (hasProperty(ItemImpl.PROPNAME_MERGE_FAILED) && getProperty(ItemImpl.PROPNAME_MERGE_FAILED).getValues().length>0)
{
+            String msg = "Unable to checkin node. Clear 'jcr:mergeFailed' first. " + safeGetJCRPath();
+            log.debug(msg);
+            throw new VersionException(msg);
+        }
+
         Version v = session.versionMgr.checkin(this);
         Property prop = internalSetProperty(VersionManager.PROPNAME_IS_CHECKED_OUT, InternalValue.create(false));
         prop.save();
@@ -2365,11 +2378,23 @@
      */
     public void checkout()
             throws UnsupportedRepositoryOperationException, RepositoryException {
+        // check if versionable
+        checkVersionable();
+
+        // check if already checked out
         if (isCheckedOut()) {
-            String msg = "Unable to checkout node. Is not checked-in. " + safeGetJCRPath();
+            String msg = safeGetJCRPath() + ": Node is already checked-out. ignoring.";
             log.debug(msg);
-            throw new VersionException(msg);
+            return;
+        }
+
+        // check transient state
+        if (isModified()) {
+            String msg = "Unable to checkout node. Not allowed on transient node. " + safeGetJCRPath();
+            log.debug(msg);
+            throw new InvalidItemStateException(msg);
         }
+
         Property prop = internalSetProperty(VersionManager.PROPNAME_IS_CHECKED_OUT, InternalValue.create(true));
         prop.save();
         prop = internalSetProperty(VersionManager.PROPNAME_PREDECESSORS,
@@ -2679,7 +2704,7 @@
         // search nearest ancestor that is versionable
         NodeImpl node = this;
         while (!node.hasProperty(VersionManager.PROPNAME_IS_CHECKED_OUT)) {
-            if (node.isRepositoryRoot() || !inherit) {
+            if (!inherit || node.isRepositoryRoot()) {
                 return true;
             }
             node = (NodeImpl) node.getParent();
@@ -2700,16 +2725,18 @@
     public void restore(String versionName)
             throws VersionException, UnsupportedRepositoryOperationException,
             RepositoryException {
+        boolean removeExisting = true;
 
-        if (!isCheckedOut()) {
-            String msg = "Unable to restore version. Node is not checked-out " + safeGetJCRPath();
-            log.debug(msg);
-            throw new VersionException(msg);
+        // check if transient
+        if (session.hasPendingChanges()) {
+            String msg = "Unable to restore version. Session has pending changes.";
+            log.error(msg);
+            throw new InvalidItemStateException(msg);
         }
 
         GenericVersionSelector gvs = new GenericVersionSelector();
         gvs.setName(versionName);
-        internalRestore(getVersionHistory().getVersion(versionName), gvs);
+        internalRestore(getVersionHistory().getVersion(versionName), gvs, removeExisting);
         save();
     }
 
@@ -2718,18 +2745,20 @@
      */
     public void restore(Version version)
             throws UnsupportedRepositoryOperationException, RepositoryException {
+        boolean removeExisting = true;
 
-        if (!isCheckedOut()) {
-            String msg = "Unable to restore version. Node is not checked-out " + safeGetJCRPath();
-            log.debug(msg);
-            throw new VersionException(msg);
+        // check if transient
+        if (session.hasPendingChanges()) {
+            String msg = "Unable to restore version. Session has pending changes.";
+            log.error(msg);
+            throw new InvalidItemStateException(msg);
         }
 
         // check if 'own' version
         if (!version.getParent().getUUID().equals(getVersionHistory().getUUID())) {
             throw new VersionException("Unable to restore version. Not same version history.");
         }
-        internalRestore(version, new GenericVersionSelector(version.getCreated()));
+        internalRestore(version, new GenericVersionSelector(version.getCreated()), removeExisting);
         save();
     }
 
@@ -2741,22 +2770,24 @@
             throws PathNotFoundException, ItemExistsException,
             ConstraintViolationException, UnsupportedRepositoryOperationException,
             RepositoryException {
+        boolean removeExisting = true;
+
+        // check if transient
+        if (session.hasPendingChanges()) {
+            String msg = "Unable to restore version. Session has pending changes.";
+            log.error(msg);
+            throw new InvalidItemStateException(msg);
+        }
 
         // if node exists, do a 'normal' restore
         if (hasNode(relPath)) {
             getNode(relPath).restore(version);
+        } else {
+            // recreate node from frozen state
+            NodeImpl node = addNode(relPath, ((VersionImpl) version).getFrozenNode());
+            node.internalRestore(version, new GenericVersionSelector(version.getCreated()),
removeExisting);
+            node.getParent().save();
         }
-
-        // recreate node from frozen state
-        NodeImpl node = addNode(relPath, ((VersionImpl) version).getFrozenNode());
-        if (!node.isCheckedOut()) {
-            String msg = "Unable to restore version. Node is not checked-out " + node.safeGetJCRPath();
-            log.debug(msg);
-            throw new VersionException(msg);
-        }
-
-        node.internalRestore(version, new GenericVersionSelector(version.getCreated()));
-        node.getParent().save();
     }
 
     /**
@@ -2764,18 +2795,20 @@
      */
     public void restoreByLabel(String versionLabel)
             throws UnsupportedRepositoryOperationException, RepositoryException {
+        boolean removeExisting = false;
 
-        if (!isCheckedOut()) {
-            String msg = "Unable to restore version. Node is not checked-out " + safeGetJCRPath();
-            log.debug(msg);
-            throw new VersionException(msg);
+        // check if transient
+        if (session.hasPendingChanges()) {
+            String msg = "Unable to restore version. Session has pending changes.";
+            log.error(msg);
+            throw new InvalidItemStateException(msg);
         }
 
         Version v = getVersionHistory().getVersionByLabel(versionLabel);
         if (v == null) {
             throw new VersionException("No version for label " + versionLabel + " found.");
         }
-        internalRestore(v, new GenericVersionSelector(versionLabel));
+        internalRestore(v, new GenericVersionSelector(versionLabel), removeExisting);
         save();
     }
 
@@ -2886,9 +2919,54 @@
      *
      * @throws RepositoryException
      */
-    private void internalRestore(Version version, VersionSelector vsel)
+    private void internalRestore(Version version, VersionSelector vsel, boolean removeExisting)
             throws UnsupportedRepositoryOperationException, RepositoryException {
-        internalRestore(((VersionImpl) version).getInternalVersion(), vsel);
+        internalRestore(((VersionImpl) version).getInternalVersion(), vsel, removeExisting);
+    }
+
+    /**
+     * Checks if any frozen uuid in the given frozen node or its descendants
+     * collides with the one in the workspace. if 'removeExisting' is true,
+     * collisions will be removed, otherwise an ItemExistsException is thrown.
+     * If a frozen version history is already restored outside this nodes
+     * subtree, a exception is thrown, too, if the removeExisting is true.
+     * @param f
+     * @param removeExisting
+     * @throws RepositoryException
+     */
+    private void checkUUIDCollisions(InternalFrozenNode f, boolean removeExisting)
+            throws RepositoryException {
+
+        if (itemMgr.itemExists(new NodeId(f.getFrozenUUID()))) {
+            NodeImpl node = (NodeImpl) session.getNodeByUUID(f.getFrozenUUID());
+            if (removeExisting) {
+                node.remove();
+            } else {
+                throw new ItemExistsException("Unable to restore. UUID collides with " +
node.safeGetJCRPath());
+            }
+        }
+        InternalFreeze[] fs = f.getFrozenChildNodes();
+        for (int i=0; i<fs.length; i++) {
+            if (fs[i] instanceof InternalFrozenNode) {
+                checkUUIDCollisions((InternalFrozenNode) fs[i], removeExisting);
+            } else if (!removeExisting) {
+                InternalFrozenVersionHistory fh = (InternalFrozenVersionHistory) fs[i];
+                VersionHistory history = (VersionHistory) session.getNodeByUUID(fh.getVersionHistoryId());
+                String nodeId = history.getName(); // this is implementation detail!
+
+                // check if representing vh already exists somewhere
+                if (itemMgr.itemExists(new NodeId(nodeId))) {
+                    NodeImpl n = (NodeImpl) session.getNodeByUUID(nodeId);
+                    try {
+                        if (!n.getPrimaryPath().isDescendantOf(getPrimaryPath())) {
+                            throw new ItemExistsException("Unable to restore. Same node already
restored at " + n.safeGetJCRPath());
+                        }
+                    } catch (MalformedPathException e) {
+                        throw new RepositoryException(e);
+                    }
+                }
+            }
+        }
     }
 
     /**
@@ -2897,17 +2975,23 @@
      * @param version
      * @param vsel    the version selector that will select the correct version for
      *                OPV=Version childnodes.
-     * @throws UnsupportedRepositoryOperationException
+     * @param removeExisting
      *
      * @throws RepositoryException
      */
-    private void internalRestore(InternalVersion version, VersionSelector vsel)
-            throws UnsupportedRepositoryOperationException, RepositoryException {
+    private void internalRestore(InternalVersion version, VersionSelector vsel, boolean removeExisting)
+            throws RepositoryException {
+
+        // first check, if any uuid conflicts would occurr
+        checkUUIDCollisions(version.getFrozenNode(), removeExisting);
+
+        // set jcr:isCheckedOut property to true, in order to avoid any conflicts
+        internalSetProperty(VersionManager.PROPNAME_IS_CHECKED_OUT, InternalValue.create(true));
 
         // 1. The child node and properties of N will be changed, removed or
         //    added to, depending on their corresponding copies in V and their
         //    own OnParentVersion attributes (see 7.2.8, below, for details).
-        restoreFrozenState(version.getFrozenNode(), vsel);
+        restoreFrozenState(version.getFrozenNode(), vsel, removeExisting);
 
         // 2. Nís jcr:baseVersion property will be changed to point to V.
         internalSetProperty(VersionManager.PROPNAME_BASE_VERSION, InternalValue.create(new
UUID(version.getId())));
@@ -2927,7 +3011,7 @@
      * @param freeze
      * @throws RepositoryException
      */
-    void restoreFrozenState(InternalFrozenNode freeze, VersionSelector vsel)
+    void restoreFrozenState(InternalFrozenNode freeze, VersionSelector vsel, boolean removeExisting)
             throws RepositoryException {
         // check uuid
         if (isNodeType(NodeTypeRegistry.MIX_REFERENCEABLE)) {
@@ -2977,15 +3061,11 @@
         for (int i = 0; i < props.length; i++) {
             PropertyState prop = props[i];
             propNames.add(prop.getName());
-            if (prop.getValues().length == 1) {
-                try {
-                    internalSetProperty(props[i].getName(), prop.getValues()[0]);
-                    continue;
-                } catch (RepositoryException e) {
-                    // ignore and try multiple below
-                }
+            if (prop.isMultiValued()) {
+                internalSetProperty(props[i].getName(), prop.getValues());
+            } else {
+                internalSetProperty(props[i].getName(), prop.getValues()[0]);
             }
-            internalSetProperty(props[i].getName(), prop.getValues());
         }
         // remove properties that do not exist the the frozen representation
         PropertyIterator piter = getProperties();
@@ -3007,27 +3087,51 @@
 
         // restore the frozen nodes
         InternalFreeze[] frozenNodes = freeze.getFrozenChildNodes();
+
+        // first delete all non frozen version histories
+        NodeIterator iter = getNodes();
+        while (iter.hasNext()) {
+            NodeImpl n = (NodeImpl) iter.nextNode();
+            // this is a bit lousy
+            boolean found = false;
+            for (int i=0; i<frozenNodes.length; i++) {
+                InternalFreeze child = frozenNodes[i];
+                if (child instanceof InternalFrozenVersionHistory) {
+                    if (n.internalGetUUID().equals(child.getId())) {
+                        found = true;
+                        break;
+                    }
+                }
+            }
+            if (!found) {
+                n.remove();
+            }
+        }
         for (int i = 0; i < frozenNodes.length; i++) {
             InternalFreeze child = frozenNodes[i];
             if (child instanceof InternalFrozenNode) {
                 InternalFrozenNode f = (InternalFrozenNode) child;
-                // if frozen node exist, replace
-                // todo: make work for same name siblings
-                if (hasNode(f.getName())) {
-                    getNode(f.getName()).remove();
-                }
                 NodeImpl n = addNode(f.getName(), f);
-                n.restoreFrozenState(f, vsel);
+                n.restoreFrozenState(f, vsel, removeExisting);
             } else if (child instanceof InternalFrozenVersionHistory) {
-                // check if child already exists
-                if (hasNode(child.getName())) {
-                    // do nothing
+                InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
+                VersionHistory history = (VersionHistory) session.getNodeByUUID(f.getVersionHistoryId());
+                String nodeId = history.getName(); // this is implementation detail!
+
+                // check if representing vh already exists somewhere
+                if (itemMgr.itemExists(new NodeId(nodeId))) {
+                    NodeImpl n = (NodeImpl) session.getNodeByUUID(nodeId);
+                    if (hasNode(n.getQName())) {
+                        // so order at end
+                        orderBefore(n.getName(), "");
+                    } else {
+                        session.move(n.getPath(), getPath()+ "/" + n.getName());
+                    }
                 } else {
                     // get desired version from version selector
-                    VersionHistory history = (VersionHistory) session.getNodeByUUID(((InternalFrozenVersionHistory)
child).getVersionHistoryId());
                     InternalVersion v = ((VersionImpl) vsel.select(history)).getInternalVersion();
                     NodeImpl node = addNode(child.getName(), v.getFrozenNode());
-                    node.internalRestore(v, vsel);
+                    node.internalRestore(v, vsel, removeExisting);
                 }
             }
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Fri
Jan 21 03:55:02 2005
@@ -28,6 +28,7 @@
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.observation.ObservationManagerFactory;
 import org.apache.jackrabbit.core.state.*;
+import org.apache.jackrabbit.core.state.xml.XMLPersistenceManager;
 import org.apache.jackrabbit.core.state.tx.TransactionManager;
 import org.apache.jackrabbit.core.state.tx.XASessionImpl;
 import org.apache.jackrabbit.core.util.uuid.UUID;
@@ -152,6 +153,7 @@
         }
         versionStore = new BasedFileSystem(repStore, fsRootPath);
 
+
         FileSystemResource uuidFile = new FileSystemResource(metaDataStore, "rootUUID");
         try {
             if (uuidFile.exists()) {
@@ -278,9 +280,14 @@
         }
 
         // init version manager
-        // todo: as soon as dynamic workspaces are available, base on system ws
-        SessionImpl verSession = getSystemSession(repConfig.getDefaultWorkspaceName());
-        pvMgr = new NativePVM(verSession);
+        // todo: improve configurability
+        XMLPersistenceManager pm = new XMLPersistenceManager();
+        try {
+            pm.init(versionStore, repConfig.getHomeDir()+"/versions");
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+        pvMgr = new NativePVM(pm, getNodeTypeRegistry());
         vMgr = new VersionManagerImpl(pvMgr);
 
         // finally register shutdown hook

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java
Fri Jan 21 03:55:02 2005
@@ -113,7 +113,7 @@
      *
      * @return persistence manager
      */
-    protected PersistenceManager getPersistenceManager() {
+    public PersistenceManager getPersistenceManager() {
         return persistMgr;
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Fri Jan 21 03:55:02 2005
@@ -342,11 +342,18 @@
      * @see PersistenceManager#init
      */
     public void init(PMContext context) throws Exception {
+        init(context.getWorkspaceConfig().getFileSystem(),
+                context.getWorkspaceConfig().getHomeDir());
+    }
+
+    /**
+     * @see PersistenceManager#init
+     */
+    public void init(FileSystem wspFS, String homeDir) throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
         }
 
-        FileSystem wspFS = context.getWorkspaceConfig().getFileSystem();
         itemStateStore = new BasedFileSystem(wspFS, "/data");
 
         //blobStore = new BasedFileSystem(wspFS, "/blobs");
@@ -356,7 +363,7 @@
          * todo make blob store configurable
          */
         LocalFileSystem blobFS = new LocalFileSystem();
-        blobFS.setPath(context.getWorkspaceConfig().getHomeDir() + "/blobs");
+        blobFS.setPath(homeDir + "/blobs");
         blobFS.init();
         blobStore = blobFS;
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
Fri Jan 21 03:55:02 2005
@@ -186,6 +186,7 @@
                     state = new VersionNodeState(this, v, vi.getParent().getId());
                     state.setDefinitionId(NDEF_VERSION);
                     state.setPropertyValue(VersionManager.PROPNAME_CREATED, InternalValue.create(v.getCreated()));
+                    // todo: do not read frozen stuff from frozen node instance here, rather
put to version
                     state.setPropertyValue(VersionManager.PROPNAME_FROZEN_UUID, InternalValue.create(v.getFrozenNode().getFrozenUUID()));
                     state.setPropertyValue(VersionManager.PROPNAME_FROZEN_PRIMARY_TYPE, InternalValue.create(v.getFrozenNode().getFrozenPrimaryType()));
                     state.setPropertyValues(VersionManager.PROPNAME_FROZEN_MIXIN_TYPES, PropertyType.NAME,
InternalValue.create(v.getFrozenNode().getFrozenMixinTypes()));

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java
Fri Jan 21 03:55:02 2005
@@ -267,7 +267,7 @@
                 switch (opv) {
                     case OnParentVersionAction.ABORT:
                         parent.reload();
-                        throw new RepositoryException("Checkin aborted due to OPV in " +
prop.safeGetJCRPath());
+                        throw new VersionException("Checkin aborted due to OPV in " + prop.safeGetJCRPath());
                     case OnParentVersionAction.COMPUTE:
                     case OnParentVersionAction.IGNORE:
                     case OnParentVersionAction.INITIALIZE:
@@ -287,7 +287,7 @@
                 int opv = forceCopy ? OnParentVersionAction.COPY : child.getDefinition().getOnParentVersion();
                 switch (opv) {
                     case OnParentVersionAction.ABORT:
-                        throw new RepositoryException("Checkin aborted due to OPV in " +
child.safeGetJCRPath());
+                        throw new VersionException("Checkin aborted due to OPV in " + child.safeGetJCRPath());
                     case OnParentVersionAction.COMPUTE:
                     case OnParentVersionAction.IGNORE:
                     case OnParentVersionAction.INITIALIZE:

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
Fri Jan 21 03:55:02 2005
@@ -20,13 +20,8 @@
 import org.apache.jackrabbit.core.version.*;
 import org.apache.jackrabbit.core.*;
 import org.apache.jackrabbit.core.util.uuid.UUID;
-import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.state.PersistentItemStateProvider;
-import org.apache.jackrabbit.core.state.PersistentNodeState;
-import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.*;
 import org.apache.commons.collections.ReferenceMap;
 
 import javax.jcr.RepositoryException;
@@ -126,11 +121,6 @@
     private PersistentItemStateProvider stateMgr;
 
     /**
-     * the nodetype manager for the version storage
-     */
-    private NodeTypeManagerImpl ntMgr;
-
-    /**
      * mapping from virtual uuids to persistent ids of the persistent nodes
      * key=externalId, value=PersistentId
      */
@@ -155,36 +145,15 @@
     /**
      * Creates a new PersistentVersionManager.
      *
-     * @param session
+     * @param pMgr
+     * @param ntReg
      * @throws javax.jcr.RepositoryException
      */
-    public NativePVM(SessionImpl session) throws RepositoryException {
-        this.stateMgr = ((WorkspaceImpl) session.getWorkspace()).getPersistentStateManager();
-        this.ntMgr = session.getNodeTypeManager();
-
+    public NativePVM(PersistenceManager pMgr, NodeTypeRegistry ntReg) throws RepositoryException
{
         try {
-            NodeImpl systemRoot = ((RepositoryImpl) session.getRepository()).getSystemRootNode(session);
-            // enable this to make the persistence storage visible
-            if (true) {
-                // check for versionhistory root
-                if (!systemRoot.hasNode(VERSION_HISTORY_ROOT_NAME)) {
-                    // if not exist, create
-                    systemRoot.addNode(VERSION_HISTORY_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
-                    systemRoot.save();
-                }
-                PersistentNodeState nodeState = (PersistentNodeState) stateMgr.getItemState(new
NodeId(systemRoot.getNode(VERSION_HISTORY_ROOT_NAME).internalGetUUID()));
-                historyRoot = new PersistentNode(stateMgr, ntMgr, nodeState);
-            } else {
-                if (!stateMgr.hasItemState(PERSISTENT_ROOT_ID)) {
-                    PersistentNodeState nodeState = stateMgr.createNodeState(PERSISTENT_ROOT_ID.getUUID(),
NodeTypeRegistry.NT_UNSTRUCTURED, null);
-                    nodeState.setDefinitionId(new NodeDefId(ntMgr.getRootNodeDefinition().unwrap()));
-                    nodeState.store();
-                    historyRoot = new PersistentNode(stateMgr, ntMgr, nodeState);
-                } else {
-                    PersistentNodeState nodeState = (PersistentNodeState) stateMgr.getItemState(PERSISTENT_ROOT_ID);
-                    historyRoot = new PersistentNode(stateMgr, ntMgr, nodeState);
-                }
-            }
+            this.stateMgr = new PersistentItemStateManager(pMgr, PERSISTENT_ROOT_ID.getUUID(),
ntReg);
+            PersistentNodeState nodeState = (PersistentNodeState) stateMgr.getItemState(PERSISTENT_ROOT_ID);
+            historyRoot = new PersistentNode(stateMgr, nodeState);
             initVirtualIds(historyRoot.getState());
             log.info("loaded " + idsByExternal.size() + " virtual ids.");
         } catch (ItemStateException e) {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java&r2=125924
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java
Fri Jan 21 03:55:02 2005
@@ -25,8 +25,6 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.NodeDef;
-import javax.jcr.nodetype.PropertyDef;
 import java.util.HashSet;
 import java.util.List;
 
@@ -47,11 +45,6 @@
     private final PersistentItemStateProvider stateMgr;
 
     /**
-     * the node type manager
-     */
-    private final NodeTypeManagerImpl ntMgr;
-
-    /**
      * the cached name
      */
     private QName name = null;
@@ -60,15 +53,12 @@
      * Creates a new persistent node
      *
      * @param statemgr
-     * @param ntMgr
      * @param nodeState
      */
     protected PersistentNode(PersistentItemStateProvider statemgr,
-                             NodeTypeManagerImpl ntMgr,
                              PersistentNodeState nodeState) {
         this.nodeState = nodeState;
         this.stateMgr = statemgr;
-        this.ntMgr = ntMgr;
     }
 
 
@@ -236,12 +226,10 @@
             }
         } else {
             try {
-                PropertyDefImpl def = getApplicablePropertyDef(name, type, multiValued);
                 PersistentPropertyState propState = stateMgr.createPropertyState(nodeState.getUUID(),
name);
                 propState.setType(type);
                 propState.setMultiValued(multiValued);
-                propState.setDefinitionId(new PropDefId(def.unwrap()));
-
+                propState.setDefinitionId(PropDefId.valueOf("0"));
                 // need to store nodestate
                 nodeState.addPropertyEntry(name);
                 if (nodeState.getStatus()==ItemState.STATUS_EXISTING) {
@@ -255,58 +243,6 @@
     }
 
     /**
-     * retrieves the property definition for the given contraints
-     *
-     * @param propertyName
-     * @param type
-     * @param multiValued
-     * @return
-     * @throws RepositoryException
-     */
-    protected PropertyDefImpl getApplicablePropertyDef(QName propertyName,
-                                                       int type, boolean multiValued)
-            throws RepositoryException {
-        PropDef pd = getEffectiveNodeType().getApplicablePropertyDef(propertyName, type,
multiValued);
-        return ntMgr.getPropDef(new PropDefId(pd));
-    }
-
-    /**
-     * Retrieves the node definition for the given contraints.
-     *
-     * @param nodeName
-     * @param nodeTypeName
-     * @return
-     * @throws RepositoryException
-     */
-    protected NodeDefImpl getApplicableChildNodeDef(QName nodeName, QName nodeTypeName)
-            throws RepositoryException {
-        ChildNodeDef cnd = getEffectiveNodeType().getApplicableChildNodeDef(nodeName, nodeTypeName);
-        return ntMgr.getNodeDef(new NodeDefId(cnd));
-    }
-
-    /**
-     * Returns the effective (i.e. merged and resolved) node type representation
-     * of this node's primary and mixin node types.
-     *
-     * @return the effective node type
-     * @throws RepositoryException
-     */
-    protected EffectiveNodeType getEffectiveNodeType() throws RepositoryException {
-        // build effective node type of mixins & primary type
-        NodeTypeRegistry ntReg = ntMgr.getNodeTypeRegistry();
-        // existing mixin's
-        HashSet set = new HashSet(nodeState.getMixinTypeNames());
-        // primary type
-        set.add(nodeState.getNodeTypeName());
-        try {
-            return ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
-        } catch (NodeTypeConflictException ntce) {
-            String msg = "internal error: failed to build effective node type for node "
+ nodeState.getUUID();
-            throw new RepositoryException(msg, ntce);
-        }
-    }
-
-    /**
      * checks if the given child node exists.
      *
      * @param name
@@ -362,7 +298,7 @@
         }
         try {
             PersistentNodeState state = (PersistentNodeState) stateMgr.getItemState(new NodeId(entry.getUUID()));
-            return new PersistentNode(stateMgr, ntMgr, state);
+            return new PersistentNode(stateMgr, state);
         } catch (ItemStateException e) {
             throw new RepositoryException("Unable to getNode: " + e.toString());
         }
@@ -378,7 +314,7 @@
     protected PersistentNode getNodeByUUID(String uuid) throws RepositoryException {
         try {
             PersistentNodeState state = (PersistentNodeState) stateMgr.getItemState(new NodeId(uuid));
-            return new PersistentNode(stateMgr, ntMgr, state);
+            return new PersistentNode(stateMgr, state);
         } catch (ItemStateException e) {
             throw new RepositoryException("Unable to getNode: " + e.toString());
         }
@@ -396,37 +332,18 @@
      */
     protected PersistentNode addNode(QName nodeName, QName nodeTypeName)
             throws NoSuchNodeTypeException, ConstraintViolationException, RepositoryException
{
-        NodeTypeImpl nodeType = ntMgr.getNodeType(nodeTypeName);
-        NodeDefImpl def;
-        try {
-            def = getApplicableChildNodeDef(name, nodeType == null ? null : nodeType.getQName());
-        } catch (RepositoryException re) {
-            // hack, use nt:unstructured as parent
-            NodeTypeRegistry ntReg = ntMgr.getNodeTypeRegistry();
-            EffectiveNodeType ent = ntReg.getEffectiveNodeType(NodeTypeRegistry.NT_UNSTRUCTURED);
-            ChildNodeDef cnd = ent.getApplicableChildNodeDef(name, nodeTypeName);
-            def = ntMgr.getNodeDef(new NodeDefId(cnd));
-        }
-
-        if (nodeType == null) {
-            // use default node type
-            nodeType = (NodeTypeImpl) def.getDefaultPrimaryType();
-        }
-        return createChildNode(nodeName, def, nodeType, null);
+        return createChildNode(nodeName, nodeTypeName, null);
     }
 
     /**
      * creates a new child node
      *
      * @param name
-     * @param def
-     * @param nodeType
      * @param uuid
      * @return
      * @throws RepositoryException
      */
-    private PersistentNode createChildNode(QName name, NodeDefImpl def,
-                                           NodeTypeImpl nodeType, String uuid)
+    private PersistentNode createChildNode(QName name, QName nodeTypeName, String uuid)
             throws RepositoryException {
 
         String parentUUID = nodeState.getUUID();
@@ -436,37 +353,20 @@
             if (uuid == null) {
                 uuid = UUID.randomUUID().toString();	// version 4 uuid
             }
-            state = stateMgr.createNodeState(uuid, nodeType.getQName(), parentUUID);
-            state.setDefinitionId(new NodeDefId(def.unwrap()));
+            state = stateMgr.createNodeState(uuid, nodeTypeName, parentUUID);
+            state.setDefinitionId(NodeDefId.valueOf("0"));
         } catch (ItemStateException ise) {
             String msg = "failed to add child node " + name + " to " + parentUUID;
             throw new RepositoryException(msg, ise);
         }
 
         // create Node instance wrapping new node state
-        PersistentNode node = new PersistentNode(stateMgr, ntMgr, state);
+        PersistentNode node = new PersistentNode(stateMgr, state);
         // add new child node entry
         nodeState.addChildNodeEntry(name, state.getUUID());
         if (nodeState.getStatus()==ItemState.STATUS_EXISTING) {
             nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
         }
-
-        // add 'auto-create' properties defined in node type
-        PropertyDef[] pda = nodeType.getAutoCreatePropertyDefs();
-        for (int i = 0; i < pda.length; i++) {
-            PropertyDefImpl pd = (PropertyDefImpl) pda[i];
-            node.getOrCreatePropertyState(pd.getQName(), pd.getRequiredType(), pd.isMultiple());
-        }
-
-        // recursively add 'auto-create' child nodes defined in node type
-        NodeDef[] nda = nodeType.getAutoCreateNodeDefs();
-        for (int i = 0; i < nda.length; i++) {
-            NodeDefImpl nd = (NodeDefImpl) nda[i];
-            node.createChildNode(nd.getQName(), nd, (NodeTypeImpl) nd.getDefaultPrimaryType(),
null);
-        }
-
-        // store primary type
-        node.setPropertyValue(ItemImpl.PROPNAME_PRIMARYTYPE, InternalValue.create(nodeType.getQName()));
         return node;
     }
 
@@ -483,7 +383,7 @@
             for (int i = 0; i < entries.size(); i++) {
                 NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(i);
                 PersistentNodeState state = (PersistentNodeState) stateMgr.getItemState(new
NodeId(entry.getUUID()));
-                children[i] = new PersistentNode(stateMgr, ntMgr, state);
+                children[i] = new PersistentNode(stateMgr, state);
             }
             return children;
         } catch (ItemStateException e) {
@@ -586,8 +486,7 @@
     protected void copyFrom(PropertyImpl prop) throws RepositoryException {
         if (prop.getDefinition().isMultiple()) {
             InternalValue[] values = prop.internalGetValues();
-            int type = values.length>0 ? values[0].getType() : prop.getDefinition().getRequiredType();
-            setPropertyValues(prop.getQName(), type, values);
+            setPropertyValues(prop.getQName(), values[0].getType(), values);
         } else {
             setPropertyValue(prop.getQName(), prop.internalGetValue());
         }

Mime
View raw message