jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r164980 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual
Date Wed, 27 Apr 2005 13:44:52 GMT
Author: tripod
Date: Wed Apr 27 06:44:50 2005
New Revision: 164980

URL: http://svn.apache.org/viewcvs?rev=164980&view=rev
Log:
- fixing some versioning issues. all versioning tests now pass.

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualValueProvider.java
  (with props)
Modified:
    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/VersionNodeState.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualPropertyState.java

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?rev=164980&r1=164979&r2=164980&view=diff
==============================================================================
--- 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
Wed Apr 27 06:44:50 2005
@@ -185,18 +185,12 @@
                 state.setDefinitionId(NDEF_VERSION_HISTORY);
                 // add version labels node state
                 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.
-                state.addStateReference(vlns);
-                cache(vlns);
 
             } else if (vi instanceof InternalVersionLabels) {
-                // load parent, that must be a version history
-                getItemState(new NodeId(vi.getParent().getId()));
-                // this is a bit dangerous
-                state = (VirtualNodeState) getItemState(id);
+                InternalVersionLabels vl = (InternalVersionLabels) vi;
+                state = new VersionLabelsNodeState(this, (InternalVersionHistory) vl.getParent(),
vl.getParent().getId(), vi.getId());
+                state.setDefinitionId(NDEF_VERSION_LABELS);
 
             } else if (vi instanceof InternalVersion) {
                 InternalVersion v = (InternalVersion) vi;

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?rev=164980&r1=164979&r2=164980&view=diff
==============================================================================
--- 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
Wed Apr 27 06:44:50 2005
@@ -143,7 +143,7 @@
      */
     public VersionHistory createVersionHistory(NodeImpl node) throws RepositoryException
{
         InternalVersionHistory history = vMgr.createVersionHistory(node);
-        virtProvider.invalidateItem(new NodeId(VERSION_STORAGE_NODE_UUID));
+        virtProvider.invalidateItem(new NodeId(VERSION_STORAGE_NODE_UUID), false);
         VersionHistoryImpl vh = (VersionHistoryImpl) node.getSession().getNodeByUUID(history.getId());
 
         // generate observation events
@@ -248,7 +248,7 @@
     public Version checkin(NodeImpl node) throws RepositoryException {
         SessionImpl session = (SessionImpl) node.getSession();
         InternalVersion version = vMgr.checkin(node);
-        virtProvider.invalidateItem(new NodeId(version.getVersionHistory().getId()));
+        virtProvider.invalidateItem(new NodeId(version.getVersionHistory().getId()), true);
         VersionImpl v = (VersionImpl) session.getNodeByUUID(version.getId());
 
         // generate observation events
@@ -283,7 +283,7 @@
         InternalVersionHistory vh = ((VersionHistoryImpl) history).getInternalVersionHistory();
         vh.removeVersion(name);
 
-        virtProvider.invalidateItem(new NodeId(vh.getId()));
+        virtProvider.invalidateItem(new NodeId(vh.getId()), true);
         obsMgr.dispatch(events, session);
     }
 
@@ -329,7 +329,7 @@
                     labelNode.getSession()
             ));
         }
-        virtProvider.invalidateItem(new NodeId(vh.getId()));
+        virtProvider.invalidateItem(new NodeId(labelNode.internalGetUUID()), false);
         obsMgr.dispatch(events, session);
         if (v == null) {
             return null;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionNodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionNodeState.java?rev=164980&r1=164979&r2=164980&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionNodeState.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionNodeState.java
Wed Apr 27 06:44:50 2005
@@ -18,10 +18,10 @@
 
 import org.apache.jackrabbit.core.InternalValue;
 import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.util.uuid.UUID;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 import org.apache.jackrabbit.core.virtual.VirtualPropertyState;
+import org.apache.jackrabbit.core.virtual.VirtualValueProvider;
 
 import javax.jcr.RepositoryException;
 
@@ -30,7 +30,7 @@
  * since some properties like 'jcr:versionLabels', 'jcr:predecessors' etc. can
  * change over time, we treat them specially.
  */
-public class VersionNodeState extends VirtualNodeState {
+public class VersionNodeState extends VirtualNodeState implements VirtualValueProvider {
 
     /**
      * the internal version
@@ -62,29 +62,40 @@
 
     /**
      * {@inheritDoc}
+     *
+     * Additionally set this as virtual value provider for the 'predecessors'
+     * and 'successors' properties.
+     */
+    protected VirtualPropertyState getOrCreatePropertyState(QName name, int type, boolean
multiValued) throws RepositoryException {
+        VirtualPropertyState prop =
+                super.getOrCreatePropertyState(name, type, multiValued);
+        // attach us as value provider
+        if (name.equals(JCR_PREDECESSORS) || name.equals(JCR_SUCCESSORS)) {
+            prop.setValueProvider(this);
+        }
+        return prop;
+    }
+
+    /**
+     * {@inheritDoc}
      */
-    public VirtualPropertyState getProperty(QName name)
-            throws NoSuchItemStateException {
-        VirtualPropertyState state = super.getProperty(name);
-        if (state != null) {
-            if (name.equals(JCR_VERSIONLABELS)) {
-                state.setValues(InternalValue.create(v.getLabels()));
-            } else if (name.equals(JCR_PREDECESSORS)) {
-                InternalVersion[] preds = v.getPredecessors();
-                InternalValue[] predV = new InternalValue[preds.length];
-                for (int i = 0; i < preds.length; i++) {
-                    predV[i] = InternalValue.create(new UUID(preds[i].getId()));
-                }
-                state.setValues(predV);
-            } else if (name.equals(JCR_SUCCESSORS)) {
-                InternalVersion[] succs = v.getSuccessors();
-                InternalValue[] succV = new InternalValue[succs.length];
-                for (int i = 0; i < succs.length; i++) {
-                    succV[i] = InternalValue.create(new UUID(succs[i].getId()));
-                }
-                state.setValues(succV);
+    public InternalValue[] getVirtualValues(QName name) {
+        if (name.equals(JCR_PREDECESSORS)) {
+            InternalVersion[] preds = v.getPredecessors();
+            InternalValue[] predV = new InternalValue[preds.length];
+            for (int i = 0; i < preds.length; i++) {
+                predV[i] = InternalValue.create(new UUID(preds[i].getId()));
+            }
+            return predV;
+        } else if (name.equals(JCR_SUCCESSORS)) {
+            InternalVersion[] succs = v.getSuccessors();
+            InternalValue[] succV = new InternalValue[succs.length];
+            for (int i = 0; i < succs.length; i++) {
+                succV[i] = InternalValue.create(new UUID(succs[i].getId()));
             }
+            return succV;
+        } else {
+            return null;
         }
-        return state;
     }
 }

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?rev=164980&r1=164979&r2=164980&view=diff
==============================================================================
--- 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
Wed Apr 27 06:44:50 2005
@@ -319,33 +319,25 @@
     }
 
     /**
-     * Removes the item and all hard refernces from the cache and discards the
-     * states.
+     * invalidates the item
      *
      * @param id
      */
-    public void invalidateItem(ItemId id) {
-        if (id.equals(rootNodeId)) {
-            if (root != null) {
-                root.discard();
-                try {
-                    root = createRootNodeState();
-                } catch (RepositoryException e) {
-                    // ignore
-                }
-            }
-            return;
-        }
-        VirtualNodeState state = (VirtualNodeState) nodes.remove(id);
+    public void invalidateItem(ItemId id, boolean recursive) {
+        VirtualNodeState state = id.equals(rootNodeId) ? root : (VirtualNodeState) nodes.get(id);
         if (state != null) {
-            HashSet set = state.removeAllStateReferences();
-            if (set != null) {
-                Iterator iter = set.iterator();
+            if (recursive) {
+                VirtualPropertyState[] props = state.getProperties();
+                for (int i=0; i<props.length; i++) {
+                    props[i].notifyStateUpdated();
+                }
+                Iterator iter = state.getChildNodeEntries().iterator();
                 while (iter.hasNext()) {
-                    invalidateItem(((NodeState) iter.next()).getId());
+                    NodeState.ChildNodeEntry pe = (NodeState.ChildNodeEntry) iter.next();
+                    invalidateItem(new NodeId(pe.getUUID()), true);
                 }
             }
-            state.discard();
+            state.notifyStateUpdated();
         }
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java?rev=164980&r1=164979&r2=164980&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
Wed Apr 27 06:44:50 2005
@@ -170,7 +170,7 @@
      * @return
      * @throws RepositoryException
      */
-    private VirtualPropertyState getOrCreatePropertyState(QName name, int type, boolean multiValued)
+    protected VirtualPropertyState getOrCreatePropertyState(QName name, int type, boolean
multiValued)
             throws RepositoryException {
 
         VirtualPropertyState prop = (VirtualPropertyState) properties.get(name);
@@ -254,24 +254,4 @@
         }
         stateRefs.add(state);
     }
-
-    /**
-     * Removes a hard reference to another state
-     * @param state
-     */
-    public void removeStateReferences(NodeState state) {
-        if (stateRefs != null) {
-            stateRefs.remove(state);
-        }
-    }
-
-    /**
-     * Returns the hard references of this state
-     */
-    public HashSet removeAllStateReferences() {
-        HashSet set = stateRefs;
-        stateRefs = null;
-        return set;
-    }
-
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualPropertyState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualPropertyState.java?rev=164980&r1=164979&r2=164980&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualPropertyState.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualPropertyState.java
Wed Apr 27 06:44:50 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.virtual;
 
 import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.InternalValue;
 import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.PropertyState;
 
@@ -26,11 +27,45 @@
 public class VirtualPropertyState extends PropertyState {
 
     /**
+     * a virtual value provider, if needed.
+     */
+    private VirtualValueProvider valueProvider;
+
+    /**
      * Creates a new virtual property state
      * @param name
      * @param parentUUID
      */
     public VirtualPropertyState(QName name, String parentUUID) {
         super(name, parentUUID, ItemState.STATUS_EXISTING, false);
+    }
+
+    /**
+     * Returns the virtual value provider, if registered.
+     * @return
+     */
+    public VirtualValueProvider getValueProvider() {
+        return valueProvider;
+    }
+
+    /**
+     * Sets a virtual value provider for this property
+     * @param valueProvider
+     */
+    public void setValueProvider(VirtualValueProvider valueProvider) {
+        this.valueProvider = valueProvider;
+    }
+
+    /**
+     * Returns the value of this state evt. by using the registered virtual
+     * value provider.
+     * @return
+     */
+    public InternalValue[] getValues() {
+        InternalValue[] values = null;
+        if (valueProvider != null) {
+            values = valueProvider.getVirtualValues(name);
+        }
+        return valueProvider == null ? super.getValues() : values;
     }
 }

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualValueProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualValueProvider.java?rev=164980&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualValueProvider.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualValueProvider.java
Wed Apr 27 06:44:50 2005
@@ -0,0 +1,35 @@
+/*
+ * 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.virtual;
+
+import org.apache.jackrabbit.core.InternalValue;
+import org.apache.jackrabbit.core.QName;
+
+/**
+ * A <code>VirtualValueProvider</code> is used for virtual properties that
+ * want to provide values dynamically.
+ */
+public interface VirtualValueProvider {
+
+    /**
+     * Returns the values for the given name
+     * @param propName the name of the property
+     * @return the values
+     */
+    public InternalValue[] getVirtualValues(QName propName);
+
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualValueProvider.java
------------------------------------------------------------------------------
    svn = 

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



Mime
View raw message