jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r159366 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: ./ observation/ version/ version/persistence/ virtual/
Date Tue, 29 Mar 2005 12:41:18 GMT
Author: tripod
Date: Tue Mar 29 04:41:15 2005
New Revision: 159366

URL: http://svn.apache.org/viewcvs?view=rev&rev=159366
Log:
- rearranging structure of versioning (will corrupt versioned data)
- adding observation of version storage (work in progress)

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java   (with props)
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventState.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.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/InternalFrozenVHImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.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
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java

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&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Tue Mar 29 04:41:15 2005
@@ -32,6 +32,7 @@
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.virtual.VirtualNodeTypeStateProvider;
 import org.apache.jackrabbit.core.observation.ObservationManagerFactory;
+import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
 import org.apache.jackrabbit.core.security.CredentialsCallbackHandler;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.PMContext;
@@ -63,8 +64,6 @@
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.security.AccessControlContext;
-import java.security.AccessController;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -116,6 +115,9 @@
     // sub file system where the repository stores meta data such as uuid of root node, etc.
     private final FileSystem metaDataStore;
 
+    /** the deletagin observation dispatcher for all workspaces */
+    private final DelegatingObservationDispatcher delegatingDispatcher = new DelegatingObservationDispatcher();
+
     /**
      * map of workspace names and <code>WorkspaceInfo<code>s.
      */
@@ -272,7 +274,7 @@
                 nsReg,
                 ntReg);
         pvMgr = new NativePVM(pm, getNodeTypeRegistry());
-        vMgr = new VersionManagerImpl(pvMgr, ntReg, VERSION_STORAGE_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
+        vMgr = new VersionManagerImpl(pvMgr, ntReg, delegatingDispatcher, VERSION_STORAGE_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
 
         // initialize workspaces
         iter = wspInfos.keySet().iterator();
@@ -348,6 +350,9 @@
                     Event.PROPERTY_CHANGED,
                     "/", true, null, null, false);
         }
+
+        // register the observation factory of that workspace
+        delegatingDispatcher.addDispatcher(getObservationManagerFactory(wspName));
     }
 
     RepositoryConfig getConfig() {

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java?view=auto&rev=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java Tue Mar 29 04:41:15 2005
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.observation;
+
+import org.apache.jackrabbit.core.SessionImpl;
+
+import javax.jcr.RepositoryException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This Class implements an observation dispatcher, that delegates events to
+ * a set of underlaying dispatchers.
+ */
+public class DelegatingObservationDispatcher {
+
+    /**
+     * the set of dispatchers
+     */
+    private final HashSet dispatchers = new HashSet();
+
+    /**
+     * Adds a new observation factory to the set of dispatchers
+     *
+     * @param disp
+     */
+    public void addDispatcher(ObservationManagerFactory disp) {
+        dispatchers.add(disp);
+    }
+
+    /**
+     * Removes a observation factory from the set of dispatchers
+     *
+     * @param disp
+     */
+    public void removeDispatcher(ObservationManagerFactory disp) {
+        dispatchers.remove(disp);
+    }
+
+    /**
+     * Dispatchers a list of events to all registered dispatchers. A new
+     * {@link EventStateCollection} is created for every dispatcher, fille with
+     * the given event list and then dispatched.
+     * 
+     * @param eventList
+     * @param session
+     * @throws RepositoryException
+     */
+    public void dispatch(List eventList, SessionImpl session) throws RepositoryException {
+        Iterator iter = dispatchers.iterator();
+        while (iter.hasNext()) {
+            ObservationManagerFactory fac = (ObservationManagerFactory) iter.next();
+            EventStateCollection events = new EventStateCollection(fac, session);
+            events.addAll(eventList);
+            events.prepare();
+            events.dispatch();
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventState.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventState.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventState.java Tue Mar 29 04:41:15 2005
@@ -26,7 +26,7 @@
  * The <code>EventState</code> class encapsulates the session
  * independent state of an {@link javax.jcr.observation.Event}.
  */
-class EventState {
+public class EventState {
 
     /**
      * The {@link javax.jcr.observation.Event} of this event.

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java Tue Mar 29 04:41:15 2005
@@ -41,6 +41,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Arrays;
+import java.util.Collection;
 
 /**
  * The <code>EventStateCollection</code> class implements how {@link EventState}
@@ -180,7 +181,6 @@
                             Path parentPath = getParent(newPath);
                             Path oldPath = null;
                             try {
-                                oldPath = null;
                                 if (moved.getIndex() == 0) {
                                     oldPath = Path.create(parentPath, moved.getName(), false);
                                 } else {
@@ -325,6 +325,14 @@
                 }
             }
         }
+    }
+
+    /**
+     * Adds all event states in the given collection to this collection
+     * @param c
+     */
+    public void addAll(Collection c) {
+        events.addAll(c);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java Tue Mar 29 04:41:15 2005
@@ -144,4 +144,11 @@
      * @return
      */
     public QName[] getVersionLabels();
+
+    /**
+     * Returns the UUID of the version labels node
+     * 
+     * @return
+     */
+    public String getVersionLabelsUUID();
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java Tue Mar 29 04:41:15 2005
@@ -17,12 +17,10 @@
 package org.apache.jackrabbit.core.version;
 
 import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.QName;
 import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-import javax.jcr.version.VersionException;
 import java.util.Iterator;
 import java.util.List;
 
@@ -108,29 +106,19 @@
     /**
      * checks, if the item with the given external id exists
      *
-     * @param externalId
+     * @param id
      * @return
      */
-    public boolean hasItem(String externalId);
+    public boolean hasItem(String id);
 
     /**
-     * returns the item referred by the external id
+     * returns the item referred by the id
      *
-     * @param externalId
+     * @param id
      * @return
      * @throws RepositoryException
      */
-    public InternalVersionItem getItemByExternal(String externalId)
-            throws RepositoryException;
-
-    /**
-     * returns the item referred by the internal id
-     *
-     * @param internalId
-     * @return
-     * @throws RepositoryException
-     */
-    public InternalVersionItem getItemByInternal(String internalId)
+    public InternalVersionItem getItem(String id)
             throws RepositoryException;
 
     /**

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&r1=159365&r2=159366
==============================================================================
--- 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 Tue Mar 29 04:41:15 2005
@@ -170,11 +170,12 @@
         try {
             InternalVersionItem vi = vMgr.getItem(id.getUUID());
             if (vi instanceof InternalVersionHistory) {
-                state = new VersionHistoryNodeState(this, (InternalVersionHistory) vi, rootNodeId.getUUID());
+                InternalVersionHistory vh = (InternalVersionHistory) vi;
+                state = new VersionHistoryNodeState(this, vh, rootNodeId.getUUID());
                 state.setDefinitionId(NDEF_VERSION_HISTORY);
                 // add version labels node state
-                String uuid = UUID.randomUUID().toString();
-                VersionLabelsNodeState vlns = new VersionLabelsNodeState(this, (InternalVersionHistory) vi, state.getUUID(), uuid);
+                String uuid = vh.getVersionLabelsUUID();
+                VersionLabelsNodeState vlns = new VersionLabelsNodeState(this, vh, state.getUUID(), uuid);
                 vlns.setDefinitionId(NDEF_VERSION_LABELS);
                 state.addChildNodeEntry(JCR_VERSIONLABELS, uuid);
                 // need to add as hard reference to version history, so that it does not get fluhed.
@@ -186,11 +187,6 @@
                 state = new VersionNodeState(this, v, vi.getParent().getId());
                 state.setDefinitionId(NDEF_VERSION);
                 state.setPropertyValue(JCR_CREATED, InternalValue.create(v.getCreated()));
-                // todo: do not read frozen stuff from frozen node instance here, rather put to version
-                //state.setPropertyValue(JCR_FROZENUUID, InternalValue.create(v.getFrozenNode().getFrozenUUID()));
-                //state.setPropertyValue(JCR_FROZENPRIMARYTYPE, InternalValue.create(v.getFrozenNode().getFrozenPrimaryType()));
-                //state.setPropertyValues(JCR_FROZENMIXINTYPES, PropertyType.NAME, InternalValue.create(v.getFrozenNode().getFrozenMixinTypes()));
-                //state.setPropertyValues(JCR_VERSIONLABELS, PropertyType.STRING, InternalValue.create(v.getLabels()));
                 state.setPropertyValues(JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[0]);
                 state.setPropertyValues(JCR_SUCCESSORS, PropertyType.REFERENCE, new InternalValue[0]);
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java Tue Mar 29 04:41:15 2005
@@ -20,13 +20,20 @@
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.Constants;
 import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.PropertyImpl;
+import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
+import org.apache.jackrabbit.core.observation.EventState;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.log4j.Logger;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.PropertyIterator;
+import javax.jcr.NodeIterator;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import java.util.Iterator;
@@ -60,15 +67,21 @@
      * The version manager of the internal versions
      */
     private final PersistentVersionManager vMgr;
+
     /**
      * The virtual item manager that exposes the versions to the content
      */
     private VersionItemStateProvider virtProvider;
+
     /**
      * the node type manager
      */
     private NodeTypeRegistry ntReg;
 
+    /**
+     * the observation manager
+     */
+    private DelegatingObservationDispatcher obsMgr;
 
     /**
      * Creates a bew vesuion manager
@@ -76,9 +89,11 @@
      * @param vMgr
      */
     public VersionManagerImpl(PersistentVersionManager vMgr, NodeTypeRegistry ntReg,
-                              String rootUUID, String rootParentUUID) {
+                              DelegatingObservationDispatcher obsMgr, String rootUUID,
+                              String rootParentUUID) {
         this.vMgr = vMgr;
         this.ntReg = ntReg;
+        this.obsMgr = obsMgr;
         this.VERSION_STORAGE_NODE_UUID = rootUUID;
         this.VERSION_STORAGE_PARENT_NODE_UUID = rootParentUUID;
     }
@@ -127,7 +142,14 @@
         InternalVersionHistory history = vMgr.createVersionHistory(node);
         history.addListener(this);
         onVersionStorageChanged();
-        return (VersionHistory) node.getSession().getNodeByUUID(history.getId());
+        VersionHistoryImpl vh = (VersionHistoryImpl) node.getSession().getNodeByUUID(history.getId());
+
+        // now generate observation events
+        List events = new ArrayList();
+        recursiveAdd(events, (NodeImpl) vh.getParent(), vh);
+        obsMgr.dispatch(events, (SessionImpl) node.getSession());
+
+        return vh;
     }
 
     /**
@@ -218,7 +240,7 @@
      * @throws RepositoryException
      */
     public InternalVersionItem getItem(String id) throws RepositoryException {
-        InternalVersionItem item = vMgr.getItemByExternal(id);
+        InternalVersionItem item = vMgr.getItem(id);
         if (item != null) {
             item.addListener(this);
         }
@@ -234,9 +256,55 @@
      * @throws RepositoryException
      */
     public Version checkin(NodeImpl node) throws RepositoryException {
+        SessionImpl session = (SessionImpl) node.getSession();
         InternalVersion version = vMgr.checkin(node);
         version.addListener(this);
-        return (Version) node.getSession().getNodeByUUID(version.getId());
+        VersionImpl v = (VersionImpl) session.getNodeByUUID(version.getId());
+
+        // now generate observation events
+        List events = new ArrayList();
+        recursiveAdd(events, (NodeImpl) v.getParent(), v);
+        obsMgr.dispatch(events, session);
+
+        return v;
+    }
+
+    /**
+     * Adds a subtree of itemstates as 'added' to a list of events
+     *
+     * @param events
+     * @param parent
+     * @param node
+     * @throws RepositoryException
+     */
+    private void recursiveAdd(List events, NodeImpl parent, NodeImpl node)
+            throws RepositoryException {
+
+        events.add(EventState.childNodeAdded(
+                parent.internalGetUUID(),
+                parent.getPrimaryPath(),
+                node.internalGetUUID(),
+                node.getPrimaryPath().getNameElement(),
+                (NodeTypeImpl) parent.getPrimaryNodeType(),
+                node.getSession()
+        ));
+
+        PropertyIterator iter = node.getProperties();
+        while (iter.hasNext()) {
+            PropertyImpl prop = (PropertyImpl) iter.nextProperty();
+            events.add(EventState.propertyAdded(
+                    node.internalGetUUID(),
+                    node.getPrimaryPath(),
+                    prop.getPrimaryPath().getNameElement(),
+                    (NodeTypeImpl) node.getPrimaryNodeType(),
+                    node.getSession()
+            ));
+        }
+        NodeIterator niter = node.getNodes();
+        while (niter.hasNext()) {
+            NodeImpl n = (NodeImpl) niter.nextNode();
+            recursiveAdd(events, node, n);
+        }
     }
 
     /**
@@ -267,7 +335,10 @@
      */
     public void itemModifed(InternalVersionItem item) {
         try {
-            virtProvider.getItemState(new NodeId(item.getId())).discard();
+            NodeId id = new NodeId(item.getId());
+            if (virtProvider.hasItemState(id)) {
+                virtProvider.getItemState(id).discard();
+            }
         } catch (ItemStateException e) {
             log.error("Error while refreshing virtual item.", e);
         }
@@ -278,7 +349,10 @@
      */
     public void onVersionStorageChanged() {
         try {
-            virtProvider.getItemState(new NodeId(VERSION_STORAGE_NODE_UUID)).discard();
+            NodeId id = new NodeId(VERSION_STORAGE_NODE_UUID);
+            if (virtProvider.hasItemState(id)) {
+                virtProvider.getItemState(id).discard();
+            }
         } catch (ItemStateException e) {
             log.error("Error while refreshing virtual version storage.", e);
         }

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&r1=159365&r2=159366
==============================================================================
--- 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 Tue Mar 29 04:41:15 2005
@@ -74,11 +74,6 @@
     private QName[] frozenMixinTypes = null;
 
     /**
-     * the external id of this node
-     */
-    private final String id;
-
-    /**
      * Creates a new frozen node based on the given persistance node.
      *
      * @param node
@@ -86,14 +81,12 @@
      */
     protected InternalFrozenNodeImpl(PersistentVersionManager vMgr,
                                      PersistentNode node,
-                                     String id,
                                      InternalVersionItem parent) throws RepositoryException {
         super(vMgr, parent);
         this.node = node;
-        this.id = id;
 
         // init the frozen properties
-        PropertyState[] props = new org.apache.jackrabbit.core.state.PropertyState[0];
+        PropertyState[] props;
         try {
             props = node.getProperties();
         } catch (ItemStateException e) {
@@ -163,13 +156,8 @@
         return node.getName();
     }
 
-
-    protected String getPersistentId() {
-        return node.getUUID();
-    }
-
     public String getId() {
-        return id;
+        return node.getUUID();
     }
 
     /**
@@ -184,7 +172,7 @@
             int i = 0;
             while (iter.hasNext()) {
                 NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
-                freezes[i++] = (InternalFreeze) getVersionManager().getItemByInternal(entry.getUUID());
+                freezes[i++] = (InternalFreeze) getVersionManager().getItem(entry.getUUID());
             }
             return freezes;
         } catch (RepositoryException e) {
@@ -199,7 +187,7 @@
         try {
             List entries = node.getState().getChildNodeEntries(uuid);
             if (entries.size()>0) {
-                return getVersionManager().getItemByInternal(uuid) instanceof InternalFrozenVersionHistory;
+                return getVersionManager().getItem(uuid) instanceof InternalFrozenVersionHistory;
             }
         } catch (RepositoryException e) {
             // ignore
@@ -264,7 +252,7 @@
         PersistentNode node;
 
         // create new node
-        node = parent.addNode(name, NativePVM.NT_REP_FROZEN);
+        node = parent.addNode(name, NativePVM.NT_REP_FROZEN, null);
 
         // initialize the internal properties
         if (src.isNodeType(MIX_REFERENCEABLE)) {
@@ -320,7 +308,7 @@
                     case OnParentVersionAction.VERSION:
                         if (child.isNodeType(MIX_VERSIONABLE)) {
                             // create frozen versionable child
-                            PersistentNode newChild = node.addNode(child.getQName(), NativePVM.NT_REP_FROZEN_HISTORY);
+                            PersistentNode newChild = node.addNode(child.getQName(), NativePVM.NT_REP_FROZEN_HISTORY, null);
                             newChild.setPropertyValue(JCR_VERSIONHISTORY,
                                     InternalValue.create(child.getVersionHistory().getUUID()));
                             newChild.setPropertyValue(JCR_BASEVERSION,

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenVHImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenVHImpl.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenVHImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenVHImpl.java Tue Mar 29 04:41:15 2005
@@ -37,17 +37,15 @@
      */
     private PersistentNode node;
 
-    private final String id;
-
     /**
      * Creates a new frozen version history.
      *
      * @param node
      */
-    protected InternalFrozenVHImpl(PersistentVersionManager vMgr, PersistentNode node, String id, InternalVersionItem parent) {
+    protected InternalFrozenVHImpl(PersistentVersionManager vMgr, PersistentNode node,
+                                   InternalVersionItem parent) {
         super(vMgr, parent);
         this.node = node;
-        this.id = id;
     }
 
     /**
@@ -59,12 +57,8 @@
         return node.getName();
     }
 
-    protected String getPersistentId() {
-        return node.getUUID();
-    }
-
     public String getId() {
-        return id;
+        return node.getUUID();
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java Tue Mar 29 04:41:15 2005
@@ -20,7 +20,6 @@
 import org.apache.jackrabbit.core.InternalValue;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.PropertyImpl;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
 import org.apache.jackrabbit.core.util.uuid.UUID;
@@ -33,7 +32,6 @@
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.PropertyIterator;
 import javax.jcr.version.VersionException;
 import java.util.Calendar;
 import java.util.HashMap;
@@ -108,7 +106,7 @@
         labelCache.clear();
 
         // get id
-        historyId = (String) node.getPropertyValue(NativePVM.PROPNAME_HISTORY_ID).internalValue();
+        historyId = node.getUUID();
 
         // get versionable id
         versionableId = (String) node.getPropertyValue(NativePVM.PROPNAME_VERSIONABLE_ID).internalValue();
@@ -121,7 +119,7 @@
                 labelNode = child;
                 continue;
             }
-            InternalVersionImpl v = new InternalVersionImpl(this, child);
+            InternalVersionImpl v = new InternalVersionImpl(this, child, child.getName());
             versionCache.put(v.getId(), v);
             if (v.isRootVersion()) {
                 rootVersion = v;
@@ -156,10 +154,6 @@
         return historyId;
     }
 
-    protected String getPersistentId() {
-        return node.getUUID();
-    }
-
     public InternalVersionItem getParent() {
         return null;
     }
@@ -323,7 +317,7 @@
         boolean succeeded = false;
         try {
             stateMgr.edit();
-            PersistentNode lNode = labelNode.addNode(label, NT_UNSTRUCTURED);
+            PersistentNode lNode = labelNode.addNode(label, NT_UNSTRUCTURED, null);
             lNode.setPropertyValue(NativePVM.PROPNAME_NAME, InternalValue.create(label));
             lNode.setPropertyValue(NativePVM.PROPNAME_VERSION, InternalValue.create(version.getId()));
             labelNode.store();
@@ -402,10 +396,7 @@
         }
 
         String versionId = UUID.randomUUID().toString();
-        QName nodeName = new QName(NS_DEFAULT_URI, versionId);
-        PersistentNode vNode = node.addNode(nodeName, NativePVM.NT_REP_VERSION);
-        vNode.setPropertyValue(NativePVM.PROPNAME_VERSION_ID, InternalValue.create(versionId));
-        vNode.setPropertyValue(NativePVM.PROPNAME_VERSION_NAME, InternalValue.create(name));
+        PersistentNode vNode = node.addNode(name, NativePVM.NT_REP_VERSION, versionId);
 
         // initialize 'created' and 'predecessors'
         vNode.setPropertyValue(JCR_CREATED, InternalValue.create(Calendar.getInstance()));
@@ -418,7 +409,7 @@
         node.store();
 
         // update version graph
-        InternalVersionImpl version = new InternalVersionImpl(this, vNode);
+        InternalVersionImpl version = new InternalVersionImpl(this, vNode, name);
         version.resolvePredecessors();
 
         // update cache
@@ -459,10 +450,17 @@
         return (QName[]) labelCache.keySet().toArray(new QName[labelCache.size()]);
     }
 
-    protected String getUUID() {
-        return node.getUUID();
+    /**
+     * {@inheritDoc}
+     */
+    public String getVersionLabelsUUID() {
+        return labelNode.getUUID();
     }
 
+    /**
+     * Returns the persistent node of this version history
+     * @return
+     */
     protected PersistentNode getNode() {
         return node;
     }
@@ -480,22 +478,18 @@
             throws RepositoryException {
 
         // create history node
-        PersistentNode pNode = parent.addNode(name, NativePVM.NT_REP_VERSION_HISTORY);
-        pNode.setPropertyValue(NativePVM.PROPNAME_HISTORY_ID, InternalValue.create(historyId));
+        PersistentNode pNode = parent.addNode(name, NativePVM.NT_REP_VERSION_HISTORY, historyId);
 
         // set the versionable uuid
         pNode.setPropertyValue(NativePVM.PROPNAME_VERSIONABLE_ID, InternalValue.create(src.internalGetUUID()));
 
         // create label node
-        pNode.addNode(NativePVM.NODENAME_VERSION_LABELS, NT_UNSTRUCTURED);
+        pNode.addNode(NativePVM.NODENAME_VERSION_LABELS, NT_UNSTRUCTURED, null);
 
         // create root version
         String versionId = UUID.randomUUID().toString();
-        QName nodeName = new QName(NS_DEFAULT_URI, versionId);
 
-        PersistentNode vNode = pNode.addNode(nodeName, NativePVM.NT_REP_VERSION);
-        vNode.setPropertyValue(NativePVM.PROPNAME_VERSION_ID, InternalValue.create(versionId));
-        vNode.setPropertyValue(NativePVM.PROPNAME_VERSION_NAME, InternalValue.create(JCR_ROOTVERSION));
+        PersistentNode vNode = pNode.addNode(JCR_ROOTVERSION, NativePVM.NT_REP_VERSION, versionId);
 
         // initialize 'created' and 'predecessors'
         vNode.setPropertyValue(JCR_CREATED, InternalValue.create(Calendar.getInstance()));

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionImpl.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionImpl.java Tue Mar 29 04:41:15 2005
@@ -65,11 +65,6 @@
     private HashSet labelCache = null;
 
     /**
-     * the id of this version
-     */
-    private String versionId;
-
-    /**
      * specifies if this is the root version
      */
     private final boolean isRoot;
@@ -91,33 +86,21 @@
      *
      * @param node
      */
-    InternalVersionImpl(InternalVersionHistoryImpl vh, PersistentNode node) {
+    InternalVersionImpl(InternalVersionHistoryImpl vh, PersistentNode node, QName name) {
         super(vh.getVersionManager());
         this.versionHistory = vh;
         this.node = node;
-
-        // get id
-        versionId = (String) node.getPropertyValue(NativePVM.PROPNAME_VERSION_ID).internalValue();
+        this.name = name;
 
         // init internal values
         InternalValue[] values = node.getPropertyValues(JCR_CREATED);
         if (values != null) {
             created = (Calendar) values[0].internalValue();
         }
-        values = node.getPropertyValues(NativePVM.PROPNAME_VERSION_NAME);
-        if (values != null) {
-            name = (QName) values[0].internalValue();
-        } else {
-            name = null; // ????
-        }
         isRoot = name.equals(JCR_ROOTVERSION);
     }
 
     public String getId() {
-        return versionId;
-    }
-
-    protected String getPersistentId() {
         return node.getUUID();
     }
 
@@ -150,7 +133,7 @@
             if (entry == null) {
                 throw new InternalError("version has no frozen node: " + getId());
             }
-            return (InternalFrozenNode) getVersionManager().getItemByInternal(entry.getUUID());
+            return (InternalFrozenNode) getVersionManager().getItem(entry.getUUID());
         } catch (RepositoryException e) {
             throw new IllegalStateException("unable to retrieve frozen node: " + e);
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java Tue Mar 29 04:41:15 2005
@@ -75,13 +75,6 @@
     }
 
     /**
-     * Returns the internal persistent id of this item
-     *
-     * @return
-     */
-    protected abstract String getPersistentId();
-
-    /**
      * Returns the external id of this item
      *
      * @return

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&r1=159365&r2=159366
==============================================================================
--- 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 Tue Mar 29 04:41:15 2005
@@ -20,8 +20,8 @@
 import org.apache.jackrabbit.core.Constants;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ItemStateException;
@@ -30,9 +30,9 @@
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PersistenceManager;
-import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
 import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
+import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.util.uuid.UUID;
 import org.apache.jackrabbit.core.version.InternalVersion;
 import org.apache.jackrabbit.core.version.InternalVersionHistory;
@@ -76,22 +76,12 @@
      * root path for version storage
      */
     public static final QName VERSION_HISTORY_ROOT_NAME = new QName(NS_JCR_URI, "persistentVersionStorage");
-    /**
-     * name of the 'jcr:historyId' property
-     */
-    public static final QName PROPNAME_HISTORY_ID = new QName(NS_JCR_URI, "historyId");
+
     /**
      * name of the 'jcr:versionableId' property
      */
     public static final QName PROPNAME_VERSIONABLE_ID = new QName(NS_JCR_URI, "versionableId");
-    /**
-     * name of the 'jcr:versionId' property
-     */
-    public static final QName PROPNAME_VERSION_ID = new QName(NS_JCR_URI, "versionId");
-    /**
-     * name of the 'jcr:versionName' property
-     */
-    public static final QName PROPNAME_VERSION_NAME = new QName(NS_JCR_URI, "versionName");
+
     /**
      * name of the 'jcr:versionLabels' node
      */
@@ -146,18 +136,6 @@
     private PersistenceManager pMgr;
 
     /**
-     * mapping from virtual uuids to persistent ids of the persistent nodes
-     * key=externalId, value=PersistentId
-     */
-    private HashMap idsByExternal = new HashMap();
-
-    /**
-     * mapping from virtual uuids to persistent ids of the persistent nodes
-     * key=internalId, value=PersistentId
-     */
-    private HashMap idsByInternal = new HashMap();
-
-    /**
      * map of versioned uuids. key=versionedUUID, value=externalId
      */
     private HashMap versionedUUIDs = new HashMap();
@@ -176,113 +154,48 @@
      */
     public NativePVM(PersistenceManager pMgr, NodeTypeRegistry ntReg) throws RepositoryException {
         try {
-            long t1 = System.currentTimeMillis();
-            //this.stateMgr = new NativeItemStateManager(pMgr, PERSISTENT_ROOT_ID.getUUID(), ntReg);
             this.pMgr = pMgr;
             SharedItemStateManager sharedStateMgr = new SharedItemStateManager(pMgr, PERSISTENT_ROOT_ID.getUUID(), ntReg);
-            // todo versioning is not attached to any workspace!! how do we trigger observation?
             stateMgr = new LocalItemStateManager(sharedStateMgr, null);
             NodeState nodeState = (NodeState) stateMgr.getItemState(PERSISTENT_ROOT_ID);
             historyRoot = new PersistentNode(stateMgr, nodeState);
-            initVirtualIds(historyRoot.getState());
-            long t2 = System.currentTimeMillis();
-            log.info("loaded " + idsByExternal.size() + " virtual ids in " + (t2 - t1) + "ms.");
+            initVersionedUUIDs(nodeState);
         } catch (ItemStateException e) {
             throw new RepositoryException("Unable to initialize PersistentVersionManager: " + e.toString(), e);
         }
     }
 
     /**
-     * Close this persistence version manager. After having closed a persistence
-     * manager, further operations on this object are treated as illegal
-     * and throw
-     *
-     * @throws Exception if an error occurs
-     */
-    public void close() throws Exception {
-        // @todo check proper shutdown sequence
-        this.pMgr.close();
-        this.stateMgr = null;
-    }
-
-    /**
-     * initializes the internal item ids
-     *
-     * @param parent
-     * @throws RepositoryException
+     * initiealies the map of versioned uuids
+     * @param state
      * @throws ItemStateException
      */
-    private void initVirtualIds(NodeState parent)
-            throws RepositoryException, ItemStateException {
+    private void initVersionedUUIDs(NodeState state) throws ItemStateException {
 
-        Iterator iter = parent.getChildNodeEntries().iterator();
+        if (state.getNodeTypeName().equals(NT_REP_VERSION_HISTORY)) {
+            PropertyState ps = (PropertyState) stateMgr.getItemState(new PropertyId(state.getUUID(), PROPNAME_VERSIONABLE_ID));
+            String vid = (String) ps.getValues()[0].internalValue();
+            versionedUUIDs.put(vid, state.getUUID());
+            return;
+        }
+        Iterator iter = state.getChildNodeEntries().iterator();
         while (iter.hasNext()) {
             NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
-            String realUUID = entry.getName().getLocalName();
-            initVirtualIds(realUUID, (NodeState) stateMgr.getItemState(new NodeId(entry.getUUID())));
-        }
-    }
-
-    /**
-     * initializes the internal item ids
-     *
-     * @param realUUID
-     * @param state
-     * @throws ItemStateException
-     * @throws RepositoryException
-     */
-    private void initVirtualIds(String realUUID, NodeState state)
-            throws ItemStateException, RepositoryException {
-        PersistentId id = new PersistentId(realUUID, state);
-        if (id.type != PersistentId.TYPE_UNDEFINED) {
-            synchronized (idsByExternal) {
-                idsByExternal.put(id.externalId, id);
-                idsByInternal.put(id.internalId, id);
-            }
-            if (id.type == PersistentId.TYPE_HISTORY) {
-                // need to retrieve the versioned uuid in order to avoid collisions
-                PropertyState ps = (PropertyState) stateMgr.getItemState(new PropertyId(state.getUUID(), PROPNAME_VERSIONABLE_ID));
-                String vid = (String) ps.getValues()[0].internalValue();
-                versionedUUIDs.put(vid, id.externalId);
-            }
-        }
-        initVirtualIds(state);
-    }
-
-    /**
-     * returns the persistentid for a given external uuid
-     *
-     * @param uuid
-     * @return
-     */
-    private PersistentId getIdByExternal(String uuid) {
-        synchronized (idsByExternal) {
-            return (PersistentId) idsByExternal.get(uuid);
+            initVersionedUUIDs((NodeState) stateMgr.getItemState(new NodeId(entry.getUUID())));
         }
     }
 
     /**
-     * returns the persustentid for a given internal uuid
-     *
-     * @param uuid
-     * @return
-     */
-    private PersistentId getIdByInternal(String uuid) {
-        return (PersistentId) idsByInternal.get(uuid);
-    }
-
-    /**
-     * returns the persustentid for a give internal uuid and item type
+     * Close this persistence version manager. After having closed a persistence
+     * manager, further operations on this object are treated as illegal
+     * and throw
      *
-     * @param uuid
-     * @param type
-     * @return
+     * @throws Exception if an error occurs
      */
-    private PersistentId getIdByExternal(String uuid, int type) {
-        synchronized (idsByExternal) {
-            PersistentId id = (PersistentId) idsByExternal.get(uuid);
-            return id != null && id.type == type ? id : null;
-        }
+    public void close() throws Exception {
+        // @todo check proper shutdown sequence
+        this.pMgr.close();
+        this.stateMgr = null;
     }
 
     /**
@@ -294,8 +207,8 @@
      */
     private InternalVersionHistoryImpl getHistoryByVersionableUUID(String uuid)
             throws RepositoryException {
-        String externalId = (String) versionedUUIDs.get(uuid);
-        return externalId == null ? null : (InternalVersionHistoryImpl) getVersionHistory(externalId);
+        String id = (String) versionedUUIDs.get(uuid);
+        return id == null ? null : (InternalVersionHistoryImpl) getVersionHistory(id);
     }
 
     /**
@@ -324,7 +237,7 @@
             for (int i = 0; i < 3; i++) {
                 QName name = new QName(NS_DEFAULT_URI, uuid.substring(i * 2, i * 2 + 2));
                 if (!root.hasNode(name)) {
-                    root.addNode(name, NT_UNSTRUCTURED);
+                    root.addNode(name, NT_UNSTRUCTURED, null);
                     root.store();
                 }
                 root = root.getNode(name, 1);
@@ -338,7 +251,6 @@
             stateMgr.update();
             succeeded = true;
 
-            initVirtualIds(hist.getId(), hist.getNode().getState());
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
         } finally {
@@ -348,6 +260,8 @@
             }
         }
 
+        versionedUUIDs.put(hist.getVersionableUUID(), hist.getId());
+        
         log.info("Created new version history " + hist.getId() + " for " + node.safeGetJCRPath() + ". NumHistories=" + versionedUUIDs.size());
         return hist;
     }
@@ -362,8 +276,7 @@
     public InternalVersionHistory getVersionHistory(String histId)
             throws RepositoryException {
 
-        PersistentId pid = getIdByExternal(histId, PersistentId.TYPE_HISTORY);
-        return pid == null ? null : (InternalVersionHistory) getItem(pid);
+        return (InternalVersionHistory) getItem(histId);
     }
 
     /**
@@ -373,7 +286,7 @@
      * @return
      */
     public boolean hasVersionHistory(String histId) {
-        return getIdByExternal(histId, PersistentId.TYPE_HISTORY) != null;
+        return hasItem(histId);
     }
 
     /**
@@ -419,8 +332,7 @@
     public InternalVersion getVersion(String versionId)
             throws RepositoryException {
 
-        PersistentId pid = getIdByExternal(versionId, PersistentId.TYPE_VERSION);
-        return pid == null ? null : (InternalVersion) getItem(pid);
+        return (InternalVersion) getItem(versionId);
     }
 
     /**
@@ -430,74 +342,55 @@
      * @return
      */
     public boolean hasVersion(String versionId) {
-        return getIdByExternal(versionId, PersistentId.TYPE_VERSION) != null;
+        return hasItem(versionId);
     }
 
     /**
      * checks, if the item with the given external id exists
      *
-     * @param externalId
-     * @return
-     */
-    public boolean hasItem(String externalId) {
-        return getIdByExternal(externalId) != null;
-    }
-
-    /**
-     * returns the item referred by the external id
-     *
-     * @param externalId
-     * @return
-     * @throws RepositoryException
-     */
-    public InternalVersionItem getItemByExternal(String externalId)
-            throws RepositoryException {
-        PersistentId pid = getIdByExternal(externalId);
-        return pid == null ? null : getItem(pid);
-    }
-
-    /**
-     * returns the item referred by the internal id
-     *
-     * @param internalId
+     * @param uuid
      * @return
-     * @throws RepositoryException
      */
-    public InternalVersionItem getItemByInternal(String internalId)
-            throws RepositoryException {
-        PersistentId pid = getIdByInternal(internalId);
-        return pid == null ? null : getItem(pid);
+    public boolean hasItem(String uuid) {
+        NodeId id = new NodeId(uuid);
+        if (items.containsKey(id)) {
+            return true;
+        }
+        return stateMgr.hasItemState(id);
     }
 
     /**
      * returns the item with the given persistent id
      *
-     * @param pid
+     * @param uuid
      * @return
      * @throws RepositoryException
      */
-    private InternalVersionItem getItem(PersistentId pid)
-            throws RepositoryException {
-
-        InternalVersionItem item = (InternalVersionItem) items.get(pid);
+    public InternalVersionItem getItem(String uuid) throws RepositoryException {
+        NodeId id = new NodeId(uuid);
+        InternalVersionItem item = (InternalVersionItem) items.get(id);
         if (item == null) {
-            PersistentNode pNode = historyRoot.getNodeByUUID(pid.internalId);
-            if (pNode != null) {
-                InternalVersionItem parent = getItemByInternal(pNode.getParentUUID());
-                if (pid.type == PersistentId.TYPE_FROZEN) {
-                    item = new InternalFrozenNodeImpl(this, pNode, pid.externalId, parent);
-                } else if (pid.type == PersistentId.TYPE_FROZEN_HISTORY) {
-                    item = new InternalFrozenVHImpl(this, pNode, pid.externalId, parent);
-                } else if (pid.type == PersistentId.TYPE_VERSION) {
-                    item = ((InternalVersionHistory) parent).getVersion(pid.externalId);
-                } else if (pid.type == PersistentId.TYPE_HISTORY) {
+            try {
+                NodeState state = (NodeState) stateMgr.getItemState(id);
+                PersistentNode pNode = new PersistentNode(stateMgr, state);
+                InternalVersionItem parent = pNode.getParentUUID() == null ? null : getItem(pNode.getParentUUID());
+                QName ntName = state.getNodeTypeName();
+                if (ntName.equals(NT_REP_FROZEN)) {
+                    item = new InternalFrozenNodeImpl(this, pNode, parent);
+                } else if (ntName.equals(NT_REP_FROZEN_HISTORY)) {
+                    item = new InternalFrozenVHImpl(this, pNode, parent);
+                } else if (ntName.equals(NT_REP_VERSION)) {
+                    item = ((InternalVersionHistory) parent).getVersion(uuid);
+                } else if (ntName.equals(NT_REP_VERSION_HISTORY)) {
                     item = new InternalVersionHistoryImpl(this, pNode);
                 } else {
                     //return null;
                 }
-            }
-            if (item != null) {
-                items.put(pid, item);
+                if (item != null) {
+                    items.put(id, item);
+                }
+            } catch (ItemStateException e) {
+                // ignore
             }
         }
         return item;
@@ -561,8 +454,6 @@
             stateMgr.update();
             succeeded = true;
 
-            initVirtualIds(v.getId(), v.getNode().getState());
-
             // notify listeners
             history.notifyModifed();
 
@@ -589,8 +480,7 @@
      */
     public List getItemReferences(InternalVersionItem item) {
         try {
-            PersistentId id = getIdByExternal(item.getId());
-            NodeReferences refs = pMgr.load(new NodeReferencesId(id.internalId));
+            NodeReferences refs = pMgr.load(new NodeReferencesId(item.getId()));
             return refs.getReferences();
         } catch (ItemStateException e) {
             // ignore
@@ -604,8 +494,7 @@
     public void setItemReferences(InternalVersionItem item, List references) {
         try {
             ChangeLog log = new ChangeLog();
-            PersistentId id = getIdByExternal(item.getId());
-            NodeReferences refs = new NodeReferences(new NodeReferencesId(id.internalId));
+            NodeReferences refs = new NodeReferences(new NodeReferencesId(item.getId()));
             refs.addAllReferences(references);
             log.modified(refs);
             pMgr.store(log);
@@ -614,71 +503,4 @@
         }
     }
 
-    /**
-     * Helper class for persistent items
-     */
-    public static final class PersistentId {
-
-        private static final int TYPE_UNDEFINED = 0;
-        private static final int TYPE_HISTORY = 1;
-        private static final int TYPE_VERSION = 2;
-        private static final int TYPE_FROZEN = 3;
-        private static final int TYPE_FROZEN_HISTORY = 4;
-
-        /**
-         * the type of the persistent node
-         */
-        private final int type;
-
-        /**
-         * the persistent uuid of the node
-         */
-        private final String externalId;
-
-        /**
-         * the persistent uuid of the node
-         */
-        private final String internalId;
-
-        public PersistentId(int type, String external, String internal) {
-            this.type = type;
-            this.internalId = internal;
-            this.externalId = external;
-        }
-
-        public PersistentId(String external, NodeState state) {
-            this.internalId = state.getUUID();
-            if (state.getNodeTypeName().equals(NT_REP_VERSION)) {
-                this.externalId = external;
-                type = TYPE_VERSION;
-            } else if (state.getNodeTypeName().equals(NT_REP_VERSION_HISTORY)) {
-                this.externalId = external;
-                type = TYPE_HISTORY;
-            } else if (state.getNodeTypeName().equals(NT_REP_FROZEN)) {
-                // ignore given externalid, and generate new one
-                this.externalId = UUID.randomUUID().toString();
-                type = TYPE_FROZEN;
-            } else if (state.getNodeTypeName().equals(NT_REP_FROZEN_HISTORY)) {
-                // ignore given externalid, and generate new one
-                this.externalId = UUID.randomUUID().toString();
-                type = TYPE_FROZEN_HISTORY;
-            } else {
-                // ignore given externalid, and generate new one
-                this.externalId = UUID.randomUUID().toString();
-                type = TYPE_UNDEFINED;
-            }
-        }
-
-        public boolean isVersion() {
-            return type == TYPE_VERSION;
-        }
-
-        public boolean isHistory() {
-            return type == TYPE_HISTORY;
-        }
-
-        public boolean isFrozen() {
-            return type == TYPE_FROZEN;
-        }
-    }
 }

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&r1=159365&r2=159366
==============================================================================
--- 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 Tue Mar 29 04:41:15 2005
@@ -340,10 +340,10 @@
      * @throws ConstraintViolationException
      * @throws RepositoryException
      */
-    protected PersistentNode addNode(QName nodeName, QName nodeTypeName)
+    protected PersistentNode addNode(QName nodeName, QName nodeTypeName, String uuid)
             throws NoSuchNodeTypeException, ConstraintViolationException, RepositoryException {
 
-        return createChildNode(nodeName, nodeTypeName, null);
+        return createChildNode(nodeName, nodeTypeName, uuid);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?view=diff&r1=159365&r2=159366
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java Tue Mar 29 04:41:15 2005
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.version.VersionHistoryNodeState;
 import org.apache.jackrabbit.core.nodetype.ChildNodeDef;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.core.nodetype.NodeDefId;
@@ -115,13 +116,18 @@
             throws NoSuchItemStateException, ItemStateException {
 
         if (id instanceof NodeId) {
+            ItemState s;
             if (nodes.containsKey(id)) {
-                return (ItemState) nodes.get(id);
+                s = (ItemState) nodes.get(id);
             } else if (id.equals(rootNodeId)) {
-                return getRootState();
+                s = getRootState();
             } else {
-                return cache(internalGetNodeState((NodeId) id));
+                s = cache(internalGetNodeState((NodeId) id));
             }
+            if (s instanceof VersionHistoryNodeState) {
+                s.getId();
+            }
+            return s;
         } else {
             return internalGetPropertyState((PropertyId) id);
         }
@@ -286,6 +292,7 @@
     protected NodeState cache(NodeState state) {
         if (state != null) {
             nodes.put(state.getId(), state);
+            state.addListener(this);
             log.debug("item added to cache. size=" + nodes.size());
         }
         return state;
@@ -373,7 +380,7 @@
      */
     public void stateDestroyed(ItemState destroyed) {
         destroyed.removeListener(this);
-        if (destroyed.isNode() && ((NodeState) destroyed).getId().equals(rootNodeId)) {
+        if (destroyed.isNode() && destroyed.getId().equals(rootNodeId)) {
             try {
                 root = createRootNodeState();
             } catch (RepositoryException e) {
@@ -388,7 +395,7 @@
      */
     public void stateDiscarded(ItemState discarded) {
         discarded.removeListener(this);
-        if (discarded.isNode() && ((NodeState) discarded).getId().equals(rootNodeId)) {
+        if (discarded.isNode() && discarded.getId().equals(rootNodeId)) {
             try {
                 root = createRootNodeState();
             } catch (RepositoryException e) {



Mime
View raw message