jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r267207 - in /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core: state/ version/ virtual/
Date Fri, 02 Sep 2005 14:18:47 GMT
Author: tripod
Date: Fri Sep  2 07:18:34 2005
New Revision: 267207

URL: http://svn.apache.org/viewcvs?rev=267207&view=rev
Log:
- seperating VersionManagerImpl from ItemStateProvider to avoid potential deadlocks during
checkin.
- VersionItemStateProvider returns now shared item states
- Node References handling adjusted

Added:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=267207&r1=267206&r2=267207&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Fri Sep  2 07:18:34 2005
@@ -35,7 +35,6 @@
 import javax.jcr.PropertyType;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.io.PrintStream;
 
@@ -329,10 +328,6 @@
 
         ChangeLog shared = new ChangeLog();
 
-        // set of virtual node references
-        // todo: remember by provider
-        ArrayList virtualRefs = new ArrayList();
-
         EventStateCollection events = null;
         if (obsMgr != null) {
             events = obsMgr.createEventStateCollection();
@@ -351,25 +346,14 @@
             while (iter.hasNext()) {
                 NodeReferences refs = (NodeReferences) iter.next();
                 NodeId id = new NodeId(refs.getUUID());
-                // if targetid is in virtual provider, transfer to its modified set
-                for (int i = 0; i < virtualProviders.length; i++) {
-                    VirtualItemStateProvider provider = virtualProviders[i];
-                    if (provider.hasItemState(id)) {
-                        virtualRefs.add(refs);
-                        refs = null;
-                        break;
+                if (refs.hasReferences()) {
+                    if (!local.has(id) && !hasItemState(id)) {
+                        String msg = "Target node " + id
+                                + " of REFERENCE property does not exist";
+                        throw new ItemStateException(msg);
                     }
                 }
-                if (refs != null) {
-                    if (refs.hasReferences()) {
-                        if (!local.has(id) && !hasItemState(id)) {
-                            String msg = "Target node " + id
-                                    + " of REFERENCE property does not exist";
-                            throw new ItemStateException(msg);
-                        }
-                    }
-                    shared.modified(refs);
-                }
+                shared.modified(refs);
             }
 
             boolean succeeded = false;
@@ -464,18 +448,6 @@
 
             /* Let the shared item listeners know about the change */
             shared.persisted();
-
-            /* notify virtual providers about node references */
-            iter = virtualRefs.iterator();
-            while (iter.hasNext()) {
-                NodeReferences refs = (NodeReferences) iter.next();
-                // if targetid is in virtual provider, transfer to its modified set
-                for (int i = 0; i < virtualProviders.length; i++) {
-                    if (virtualProviders[i].setNodeReferences(refs)) {
-                        break;
-                    }
-                }
-            }
 
             // downgrade to read lock
             acquireReadLock();

Added: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java?rev=267207&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
(added)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
Fri Sep  2 07:18:34 2005
@@ -0,0 +1,199 @@
+/*
+ * 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.version;
+
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.jackrabbit.Constants;
+import org.apache.jackrabbit.core.ItemId;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.state.ItemState;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.state.NodeReferencesId;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
+import org.apache.jackrabbit.core.virtual.VirtualNodeState;
+import org.apache.jackrabbit.core.virtual.VirtualPropertyState;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.uuid.UUID;
+import org.apache.log4j.Logger;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * This Class implements a virtual item state provider.
+ */
+public class VersionItemStateProvider implements VirtualItemStateProvider,
+        Constants {
+
+    /**
+     * the default logger
+     */
+    private static Logger log = Logger.getLogger(VersionItemStateProvider.class);
+
+    /**
+     * The version manager
+     */
+    private final VersionManagerImpl vMgr;
+
+    /**
+     * The root node UUID for the version storage
+     */
+    private final NodeId historyRootId;
+
+    /**
+     * The item state manager directly on the version persistence mgr
+     */
+    private final SharedItemStateManager stateMgr;
+
+    /**
+     * Map of returned items. this is kept for invalidating
+     */
+    private ReferenceMap items = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
+
+    /**
+     * Creates a bew vesuion manager
+     *
+     */
+    public VersionItemStateProvider(VersionManagerImpl vMgr, SharedItemStateManager stateMgr)
{
+        this.vMgr = vMgr;
+        this.stateMgr = stateMgr;
+        this.historyRootId = vMgr.getHistoryRootId();
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean isVirtualRoot(ItemId id) {
+        return id.equals(historyRootId);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public NodeId getVirtualRootId() {
+        return historyRootId;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public VirtualPropertyState createPropertyState(VirtualNodeState parent,
+                                                    QName name, int type,
+                                                    boolean multiValued)
+            throws RepositoryException {
+        throw new IllegalStateException("VersionManager should never create a VirtualPropertyState");
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public VirtualNodeState createNodeState(VirtualNodeState parent, QName name,
+                                            String uuid, QName nodeTypeName)
+            throws RepositoryException {
+        throw new IllegalStateException("VersionManager should never create a VirtualNodeState");
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public synchronized ItemState getItemState(ItemId id)
+            throws NoSuchItemStateException, ItemStateException {
+        ItemState item = (ItemState) items.get(id);
+        if (item == null) {
+            item = stateMgr.getItemState(id);
+            items.put(id, item);
+
+            // attach us as listener
+            item.addListener(this);
+
+            // special check for successors
+            if (item instanceof PropertyState) {
+                PropertyState prop = (PropertyState) item;
+                if (prop.getName().equals(JCR_SUCCESSORS)) {
+                    try {
+                        InternalVersion v = vMgr.getVersion(prop.getParentUUID());
+                        if (v != null) {
+                            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()));
+                            }
+                            prop.setValues(succV);
+                        }
+                    } catch (RepositoryException e) {
+                        log.warn("Unable to resolve jcr:successors property for " + id);
+                    }
+                }
+            }
+        }
+        return item;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean hasItemState(ItemId id) {
+        return stateMgr.hasItemState(id);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public NodeReferences getNodeReferences(NodeReferencesId id)
+            throws NoSuchItemStateException, ItemStateException {
+        return stateMgr.getNodeReferences(id);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean hasNodeReferences(NodeReferencesId id) {
+        return stateMgr.hasNodeReferences(id);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void stateCreated(ItemState created) {
+        // ignore
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void stateModified(ItemState modified) {
+        // ignore
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void stateDestroyed(ItemState destroyed) {
+        items.remove(destroyed.getId());
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void stateDiscarded(ItemState discarded) {
+        items.remove(discarded.getId());
+    }
+}

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

Propchange: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=267207&r1=267206&r2=267207&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Fri Sep  2 07:18:34 2005
@@ -67,8 +67,7 @@
 /**
  * This Class implements a VersionManager.
  */
-public class VersionManagerImpl implements VersionManager,
-        VirtualItemStateProvider, Constants {
+public class VersionManagerImpl implements VersionManager, Constants {
 
     /**
      * the default logger
@@ -91,6 +90,11 @@
     private LocalItemStateManager stateMgr;
 
     /**
+     * the virtual item state provider that exposes the version storage
+     */
+    private final VersionItemStateProvider versProvider;
+
+    /**
      * the persistent root node of the version histories
      */
     private final NodeStateEx historyRoot;
@@ -151,20 +155,20 @@
             stateMgr = new LocalItemStateManager(sharedStateMgr, null);
             NodeState nodeState = (NodeState) stateMgr.getItemState(new NodeId(VERSION_STORAGE_NODE_UUID));
             historyRoot = new NodeStateEx(stateMgr, ntReg, nodeState, JCR_VERSIONSTORAGE);
+
+            // create the virtual item state provider
+            versProvider = new VersionItemStateProvider(this, sharedStateMgr);
+
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
         }
     }
 
     /**
-     * returns the virtual item state provider that exposes the internal versions
-     * as items.
-     *
-     * @param base
-     * @return
+     * {@inheritDoc}
      */
-    public synchronized ItemStateManager getItemStateProvider(ItemStateManager base) {
-        return stateMgr;
+    public VirtualItemStateProvider getVirtualItemStateProvider() {
+        return versProvider;
     }
 
     /**
@@ -748,13 +752,6 @@
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public VirtualItemStateProvider getVirtualItemStateProvider() {
-        return this;
-    }
-
-    /**
      * invalidates the item
      *
      * @param id
@@ -780,94 +777,13 @@
     }
 
 
-    //--------------------------------------------------------------------------
-    //--------------------------------------------------------------------------
-
-    public boolean isVirtualRoot(ItemId id) {
-        return id.equals(historyRoot.getState().getId());
-    }
-
-    public NodeId getVirtualRootId() {
+    /**
+     * returns the id of the version history root node
+     *
+     * @return the id of the version history root node
+     */
+    NodeId getHistoryRootId() {
         return (NodeId) historyRoot.getState().getId();
     }
 
-    public VirtualPropertyState createPropertyState(VirtualNodeState parent, QName name,
int type, boolean multiValued) throws RepositoryException {
-        throw new IllegalStateException("VersionManager should never create a VirtualPropertyState");
-    }
-
-    public VirtualNodeState createNodeState(VirtualNodeState parent, QName name, String uuid,
QName nodeTypeName) throws RepositoryException {
-        throw new IllegalStateException("VersionManager should never create a VirtualNodeState");
-    }
-
-    public boolean setNodeReferences(NodeReferences refs) {
-        try {
-            InternalVersionItem item = getItem(refs.getTargetId().getUUID());
-            setItemReferences(item, refs.getReferences());
-            return true;
-        } catch (RepositoryException e) {
-            log.error("Error while setting references: " + e.toString());
-            return false;
-        }
-    }
-
-    public synchronized ItemState getItemState(ItemId id)
-            throws NoSuchItemStateException, ItemStateException {
-        ItemState item = (ItemState) items.get(id);
-        if (item == null) {
-            item = stateMgr.getItemState(id);
-            items.put(id, item);
-
-            // special check for successors
-            if (item instanceof PropertyState) {
-                PropertyState prop = (PropertyState) item;
-                if (prop.getName().equals(JCR_SUCCESSORS)) {
-                    try {
-                        InternalVersion v = getVersion(prop.getParentUUID());
-                        if (v != null) {
-                            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()));
-                            }
-                            prop.setValues(succV);
-                        }
-                    } catch (RepositoryException e) {
-                        log.warn("Unable to resolve jcr:successors property for " + id);
-                    }
-                }
-            }
-        }
-        return item;
-    }
-
-    public boolean hasItemState(ItemId id) {
-        return stateMgr.hasItemState(id);
-    }
-
-    public NodeReferences getNodeReferences(NodeReferencesId id)
-            throws NoSuchItemStateException, ItemStateException {
-        return stateMgr.getNodeReferences(id);
-    }
-
-    public boolean hasNodeReferences(NodeReferencesId id) {
-        return stateMgr.hasNodeReferences(id);
-    }
-
-    public void stateCreated(ItemState created) {
-        stateMgr.stateCreated(created);
-    }
-
-    public void stateModified(ItemState modified) {
-        stateMgr.stateModified(modified);
-    }
-
-    public void stateDestroyed(ItemState destroyed) {
-        items.remove(destroyed.getId());
-        stateMgr.stateDestroyed(destroyed);
-    }
-
-    public void stateDiscarded(ItemState discarded) {
-        items.remove(discarded.getId());
-        stateMgr.stateDiscarded(discarded);
-    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?rev=267207&r1=267206&r2=267207&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
Fri Sep  2 07:18:34 2005
@@ -393,13 +393,6 @@
     /**
      * {@inheritDoc}
      */
-    public boolean setNodeReferences(NodeReferences refs) {
-        return false;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public void stateCreated(ItemState created) {
     }
 

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java?rev=267207&r1=267206&r2=267207&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
Fri Sep  2 07:18:34 2005
@@ -74,14 +74,4 @@
                                             String uuid, QName nodeTypeName)
             throws RepositoryException;
 
-    /**
-     * Informs this provider that the node references to one of its states has
-     * changed.
-     *
-     * @param refs
-     * @return <code>true</code> if the reference target is one of its items.
-     */
-    boolean setNodeReferences(NodeReferences refs);
-
-
 }



Mime
View raw message