jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r550466 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version: VersionItemStateManager.java VersionItemStateProvider.java VersionManagerImpl.java
Date Mon, 25 Jun 2007 12:16:45 GMT
Author: mreutegg
Date: Mon Jun 25 05:16:44 2007
New Revision: 550466

URL: http://svn.apache.org/viewvc?view=rev&rev=550466
Log:
JCR-978: Remove circular dependency between VersionManagerImpl and VersionItemStateProvider

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java?view=auto&rev=550466
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
Mon Jun 25 05:16:44 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import javax.jcr.ReferentialIntegrityException;
+import java.util.Iterator;
+
+/**
+ * Spezialized SharedItemStateManager that filters out NodeReferences to
+ * non-versioning states.
+ */
+public class VersionItemStateManager extends SharedItemStateManager {
+
+    /**
+     * Logger instance for this class.
+     */
+    private static final Logger log = LoggerFactory.getLogger(VersionItemStateManager.class);
+
+    /**
+     * The persistence manager.
+     */
+    private final PersistenceManager pMgr;
+
+    public VersionItemStateManager(PersistenceManager persistMgr,
+                                   NodeId rootNodeId,
+                                   NodeTypeRegistry ntReg,
+                                   ItemStateCacheFactory cacheFactory)
+            throws ItemStateException {
+        super(persistMgr, rootNodeId, ntReg, false, cacheFactory);
+        this.pMgr = persistMgr;
+    }
+
+    /**
+     * Sets the
+     * @param references
+     * @return
+     */
+    public boolean setNodeReferences(NodeReferences references) {
+        try {
+            // filter out version storage intern ones
+            NodeReferences refs = new NodeReferences(references.getId());
+            Iterator iter = references.getReferences().iterator();
+            while (iter.hasNext()) {
+                PropertyId id = (PropertyId) iter.next();
+                if (!hasItemState(id.getParentId())) {
+                    refs.addReference(id);
+                }
+            }
+
+            ChangeLog log = new ChangeLog();
+            log.modified(refs);
+            pMgr.store(log);
+            return true;
+        } catch (ItemStateException e) {
+            log.error("Error while setting references: " + e.toString());
+            return false;
+        }
+    }
+
+    protected void checkReferentialIntegrity(ChangeLog changes)
+            throws ReferentialIntegrityException, ItemStateException {
+        // only store VV-type references and NV-type references
+
+        // check whether targets of modified node references exist
+        for (Iterator iter = changes.modifiedRefs(); iter.hasNext();) {
+            NodeReferences refs = (NodeReferences) iter.next();
+            NodeId id = refs.getTargetId();
+            // no need to check existence of target if there are no references
+            if (refs.hasReferences()) {
+                if (!changes.has(id) && !hasItemState(id)) {
+                    // remove references
+                    iter.remove();
+                }
+            }
+        }
+    }
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java?view=diff&rev=550466&r1=550465&r2=550466
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
Mon Jun 25 05:16:44 2007
@@ -25,7 +25,6 @@
 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.SharedItemStateManager;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 import org.apache.jackrabbit.core.virtual.VirtualPropertyState;
@@ -39,11 +38,6 @@
 class VersionItemStateProvider implements VirtualItemStateProvider, ItemStateListener {
 
     /**
-     * The version manager
-     */
-    private final VersionManagerImpl vMgr;
-
-    /**
      * The root node UUID for the version storage
      */
     private final NodeId historyRootId;
@@ -51,7 +45,7 @@
     /**
      * The item state manager directly on the version persistence mgr
      */
-    private final SharedItemStateManager stateMgr;
+    private final VersionItemStateManager stateMgr;
 
     /**
      * Map of returned items. this is kept for invalidating
@@ -59,13 +53,13 @@
     private ReferenceMap items = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
 
     /**
-     * Creates a bew vesuion manager
+     * Creates a new version manager
      *
      */
-    public VersionItemStateProvider(VersionManagerImpl vMgr, SharedItemStateManager stateMgr)
{
-        this.vMgr = vMgr;
+    public VersionItemStateProvider(NodeId historyRootId,
+                                    VersionItemStateManager stateMgr) {
+        this.historyRootId = historyRootId;
         this.stateMgr = stateMgr;
-        this.historyRootId = vMgr.getHistoryRootId();
 
         stateMgr.addListener(this);
     }
@@ -122,7 +116,7 @@
      * @inheritDoc
      */
     public boolean setNodeReferences(NodeReferences refs) {
-        return vMgr.setNodeReferences(refs);
+        return stateMgr.setNodeReferences(refs);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?view=diff&rev=550466&r1=550465&r2=550466
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Mon Jun 25 05:16:44 2007
@@ -54,7 +54,6 @@
 import java.util.List;
 
 import javax.jcr.PropertyType;
-import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.version.Version;
@@ -100,9 +99,9 @@
     private final FileSystem fs;
 
     /**
-     * the shared state manager for the version storage
+     * the version state manager for the version storage
      */
-    private SharedItemStateManager sharedStateMgr;
+    private VersionItemStateManager sharedStateMgr;
 
     /**
      * the virtual item state provider that exposes the version storage
@@ -158,7 +157,7 @@
                 cl.added(pt);
                 pMgr.store(cl);
             }
-            sharedStateMgr = createSharedStateManager(pMgr, rootId, ntReg, cacheFactory);
+            sharedStateMgr = createItemStateManager(pMgr, rootId, ntReg, cacheFactory);
 
             stateMgr = new LocalItemStateManager(sharedStateMgr, escFactory, cacheFactory);
             stateMgr.addListener(this);
@@ -167,7 +166,8 @@
             historyRoot = new NodeStateEx(stateMgr, ntReg, nodeState, QName.JCR_VERSIONSTORAGE);
 
             // create the virtual item state provider
-            versProvider = new VersionItemStateProvider(this, sharedStateMgr);
+            versProvider = new VersionItemStateProvider(
+                    getHistoryRootId(), sharedStateMgr);
 
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
@@ -405,47 +405,15 @@
     }
 
     /**
-     * Sets and stored the node references from external nodes.
-     * @param references
-     * @return <code>true</code> if the references could be set.
-     */
-    public boolean setNodeReferences(NodeReferences references) {
-        acquireWriteLock();
-        try {
-            // filter out version storage intern ones
-            NodeReferences refs = new NodeReferences(references.getId());
-            Iterator iter = references.getReferences().iterator();
-            while (iter.hasNext()) {
-                PropertyId id = (PropertyId) iter.next();
-                if (!hasItem(id.getParentId())) {
-                    refs.addReference(id);
-                }
-            }
-
-            ChangeLog log = new ChangeLog();
-            log.modified(refs);
-            pMgr.store(log);
-            return true;
-        } catch (ItemStateException e) {
-            log.error("Error while setting references: " + e.toString());
-            return false;
-        } finally {
-            releaseWriteLock();
-        }
-    }
-
-    /**
      * {@inheritDoc}
      */
     protected List getItemReferences(InternalVersionItem item) {
-        acquireReadLock();
         try {
-            NodeReferences refs = pMgr.load(new NodeReferencesId(item.getId()));
+            NodeReferences refs = stateMgr.getNodeReferences(
+                    new NodeReferencesId(item.getId()));
             return refs.getReferences();
         } catch (ItemStateException e) {
             return Collections.EMPTY_LIST;
-        } finally {
-            releaseReadLock();
         }
     }
 
@@ -466,7 +434,7 @@
     }
 
     /**
-     * Creates a <code>SharedItemStateManager</code> or derivative.
+     * Creates a <code>VersionItemStateManager</code> or derivative.
      *
      * @param pMgr          persistence manager
      * @param rootId        root node id
@@ -475,12 +443,11 @@
      * @return item state manager
      * @throws ItemStateException if an error occurs
      */
-    protected SharedItemStateManager createSharedStateManager(PersistenceManager pMgr,
-                                                              NodeId rootId,
-                                                              NodeTypeRegistry ntReg,
-                                                              ItemStateCacheFactory cacheFactory)
+    protected VersionItemStateManager createItemStateManager(PersistenceManager pMgr,
+                                                             NodeId rootId,
+                                                             NodeTypeRegistry ntReg,
+                                                             ItemStateCacheFactory cacheFactory)
             throws ItemStateException {
-
         return new VersionItemStateManager(pMgr, rootId, ntReg, cacheFactory);
     }
 
@@ -533,39 +500,6 @@
     }
 
     //--------------------------------------------------------< inner classes >
-    /**
-     * Spezialized SharedItemStateManager that filters out NodeReferences to
-     * non-versioning states.
-     */
-    protected class VersionItemStateManager extends SharedItemStateManager {
-
-        public VersionItemStateManager(PersistenceManager persistMgr,
-                                       NodeId rootNodeId,
-                                       NodeTypeRegistry ntReg,
-                                       ItemStateCacheFactory cacheFactory)
-                throws ItemStateException {
-            super(persistMgr, rootNodeId, ntReg, false, cacheFactory);
-        }
-
-        protected void checkReferentialIntegrity(ChangeLog changes)
-                throws ReferentialIntegrityException, ItemStateException {
-            // only store VV-type references and NV-type references
-
-            // check whether targets of modified node references exist
-            for (Iterator iter = changes.modifiedRefs(); iter.hasNext();) {
-                NodeReferences refs = (NodeReferences) iter.next();
-                NodeId id = refs.getTargetId();
-                // no need to check existence of target if there are no references
-                if (refs.hasReferences()) {
-                    if (!changes.has(id) && !hasItemState(id)) {
-                        // remove references
-                        iter.remove();
-                    }
-                }
-            }
-        }
-
-    }
 
     public static final class DynamicESCFactory implements EventStateCollectionFactory {
 



Mime
View raw message