You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/10/18 23:19:32 UTC

svn commit: r1185872 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ hierarchy/ xml/

Author: mduerig
Date: Tue Oct 18 21:19:32 2011
New Revision: 1185872

URL: http://svn.apache.org/viewvc?rev=1185872&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
- remove unnecessary synchronization
- simplify

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java?rev=1185872&r1=1185871&r2=1185872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java Tue Oct 18 21:19:32 2011
@@ -428,6 +428,6 @@ public abstract class ItemImpl<STATE_TYP
             }
         }
         // he is INVALIDATED -> force reloading in order to be aware of id changes
-        he.getItemState();
+        he.resolveItemState();
     }
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java?rev=1185872&r1=1185871&r2=1185872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java Tue Oct 18 21:19:32 2011
@@ -159,7 +159,7 @@ public class ItemManager implements Item
     public boolean itemExists(HierarchyEntry<?> hierarchyEntry) {
         try {
             // session-sanity & permissions are checked upon itemExists(ItemState)
-            ItemState<?> state = hierarchyEntry.getItemState();
+            ItemState<?> state = hierarchyEntry.resolveItemState();
             return itemExists(state);
         } catch (ItemNotFoundException e) {
             return false;
@@ -224,7 +224,7 @@ public class ItemManager implements Item
      */
     public NodeImpl getItem(NodeEntry nodeEntry) throws RepositoryException {
         session.checkIsAlive();
-        NodeState state = nodeEntry.getItemState();
+        NodeState state = nodeEntry.resolveItemState();
         if (!state.isValid()) {
             throw new ItemNotFoundException(LogUtil.safeGetJCRPath(state, session.getNamePathResolver()));
         }
@@ -246,7 +246,7 @@ public class ItemManager implements Item
      */
     public PropertyImpl getItem(PropertyEntry propertyEntry) throws RepositoryException {
         session.checkIsAlive();
-        PropertyState state = propertyEntry.getItemState();
+        PropertyState state = propertyEntry.resolveItemState();
         if (!state.isValid()) {
             throw new ItemNotFoundException(LogUtil.safeGetJCRPath(state, session.getNamePathResolver()));
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java?rev=1185872&r1=1185871&r2=1185872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java Tue Oct 18 21:19:32 2011
@@ -121,51 +121,13 @@ public abstract class HierarchyEntry<STA
 
     /**
      * Resolves this {@code HierarchyEntryImpl} and returns the target
-     * {@code ItemState} of this reference. This method may return a
-     * cached {@code ItemState} if this method was called before already
-     * otherwise this method will forward the call to {@link #doResolve()}
-     * and cache its return value. If an existing state has been invalidated
-     * before, an attempt is made to reload it in order to make sure, that
-     * a call to {@link ItemState#isValid()} does not equivocally return false.
-     *
-     * @return the {@code ItemState} where this reference points to.
-     * @throws ItemNotFoundException if the referenced {@code ItemState}
-     * does not exist.
-     * @throws RepositoryException if an error occurs.
-     */
-    STATE_TYPE resolve() throws RepositoryException {
-        // check if already resolved
-        STATE_TYPE state = internalGetItemState();
-        // not yet resolved. retrieve and keep soft reference to state
-        if (state == null) {
-            try {
-                state = doResolve();
-                // set the item state unless 'setItemState' has already been
-                // called by the ItemStateFactory (recall internalGetItemState)
-                if (internalGetItemState() == null) {
-                    setItemState(state);
-                }
-            } catch (ItemNotFoundException e) {
-                remove();
-                throw e;
-            }
-        } else if (state.getStatus() == Status.INVALIDATED) {
-            // completely reload this entry, but don't reload recursively
-            reload(false);
-        }
-        return state;
-    }
-
-    /**
-     * Resolves this {@code HierarchyEntryImpl} and returns the target
      * {@code ItemState} of this reference.
      *
      * @return the {@code ItemState} where this reference points to.
-     * @throws ItemNotFoundException if the referenced {@code ItemState}
-     * does not exist.
+     * @throws ItemNotFoundException if the referenced {@code ItemState} does not exist.
      * @throws RepositoryException if another error occurs.
      */
-    abstract STATE_TYPE doResolve() throws RepositoryException;
+    protected abstract STATE_TYPE resolve() throws RepositoryException;
 
     /**
      * Build the Path of this entry
@@ -174,7 +136,7 @@ public abstract class HierarchyEntry<STA
      * @return
      * @throws RepositoryException
      */
-    abstract Path buildPath(boolean workspacePath) throws RepositoryException;
+    protected abstract Path buildPath(boolean workspacePath) throws RepositoryException;
 
     /**
      * True if this {@code HierarchyEntry} would resolve to a {@code NodeState}.
@@ -208,7 +170,7 @@ public abstract class HierarchyEntry<STA
     /**
      * @return the item state or {@code null} if the entry isn't resolved.
      */
-    STATE_TYPE internalGetItemState() {
+    protected final STATE_TYPE getItemState() {
         return itemState != null
             ? itemState.get()
             : null;
@@ -220,7 +182,7 @@ public abstract class HierarchyEntry<STA
      * @param recursive
      */
     protected void invalidateInternal(boolean recursive) {
-        STATE_TYPE state = internalGetItemState();
+        STATE_TYPE state = getItemState();
         if (state != null) {
             state.invalidate();
         }
@@ -271,7 +233,7 @@ public abstract class HierarchyEntry<STA
      * @see ItemState#getStatus()
      */
     public Status getStatus() {
-        STATE_TYPE state = internalGetItemState();
+        STATE_TYPE state = getItemState();
         return state == null
             ? Status._UNDEFINED_
             : state.getStatus();
@@ -285,28 +247,52 @@ public abstract class HierarchyEntry<STA
      *
      * @return {@code true} if the {@code ItemState} is available;
      * otherwise {@code false}.
-     * @see #getItemState()
+     * @see #resolveItemState()
      */
     public boolean isAvailable() {
-        return internalGetItemState() != null;
+        return getItemState() != null;
     }
 
     /**
      * If this {@code HierarchyEntry} has already been resolved before
      * (see {@link #isAvailable()}), that {@code ItemState} is returned.
      * Note however, that the validity of the State is not asserted.<br>
+     *
      * If the entry has not been resolved yet an attempt is made to resolve this
      * entry, which may fail if there exists no accessible {@code ItemState}
-     * or if the corresponding state has been removed in the mean time.
+     * or if the corresponding state has been removed in the mean time.<br>
+     *
+     * If this entry has not been resolved before this method will forward the call
+     * to {@link #resolve()} and cache its return value. If an existing state has
+     * been invalidated before, an attempt is made to reload it in order to make
+     * sure, that a call to {@link ItemState#isValid()} does not equivocally return
+     * false.
      *
      * @return the referenced {@code ItemState}.
-     * @throws ItemNotFoundException if the {@code ItemState} does not
-     * exist anymore.
-     * @throws RepositoryException If an error occurs while retrieving the
-     * {@code ItemState}.
+     * @throws ItemNotFoundException if the {@code ItemState} does not exist anymore.
+     * @throws RepositoryException If an error occurs while retrieving the {@code ItemState}.
      */
-    public STATE_TYPE getItemState() throws RepositoryException {
-        return resolve();
+    public STATE_TYPE resolveItemState() throws RepositoryException {
+        // check whether already resolved
+        STATE_TYPE state = getItemState();
+        
+        if (state == null) {
+            // not yet resolved. retrieve and keep soft reference to state
+            try {
+                state = resolve();
+                // set the item state unless resolved by ItemStateFactory
+                if (!isAvailable()) {
+                    setItemState(state);
+                }
+            } catch (ItemNotFoundException e) {
+                remove();
+                throw e;
+            }
+        } else if (state.getStatus() == Status.INVALIDATED) {
+            // completely reload this entry, but don't reload recursively
+            reload(false);
+        }
+        return state;
     }
 
     /**
@@ -314,8 +300,8 @@ public abstract class HierarchyEntry<STA
      *
      * @param state
      */
-    public synchronized void setItemState(STATE_TYPE state) {
-        STATE_TYPE currentState = internalGetItemState();
+    public void setItemState(STATE_TYPE state) {
+        STATE_TYPE currentState = getItemState();
         if (state == null || state == currentState || denotesNode() != state.isNode()) {
             IllegalArgumentException e = new IllegalArgumentException("Invalid item state");
             log.error(e.getMessage(), e);
@@ -367,7 +353,7 @@ public abstract class HierarchyEntry<STA
      * @throws RepositoryException if an error occurs.
      */
     public void revert() throws RepositoryException {
-        STATE_TYPE state = internalGetItemState();
+        STATE_TYPE state = getItemState();
         if (state == null) {
             // nothing to do
             return;
@@ -458,7 +444,7 @@ public abstract class HierarchyEntry<STA
      * states e.g. an item state is not valid anymore.
      */
     public void transientRemove() throws RepositoryException {
-        STATE_TYPE state = internalGetItemState();
+        STATE_TYPE state = getItemState();
         if (state == null) {
             // nothing to do -> correct status must be set upon resolution.
             return;
@@ -510,7 +496,7 @@ public abstract class HierarchyEntry<STA
      * @param staleParent
      */
     void internalRemove(boolean staleParent) {
-        STATE_TYPE state = internalGetItemState();
+        STATE_TYPE state = getItemState();
         Status status = getStatus();
         if (state != null) {
             if (status == Status.EXISTING_MODIFIED) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java?rev=1185872&r1=1185871&r2=1185872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java Tue Oct 18 21:19:32 2011
@@ -373,7 +373,7 @@ public class NodeEntry extends Hierarchy
      * {@code NodeState}.
      */
     public NodeState getNodeState() throws RepositoryException {
-        return getItemState();
+        return resolveItemState();
     }
 
     /**
@@ -704,7 +704,7 @@ public class NodeEntry extends Hierarchy
         } else {
             List<NodeEntry> entries = new ArrayList<NodeEntry>();
             // get array of the list, since during validation the childNodeEntries
-            // may be modified if upon NodeEntry.getItemState the entry gets removed.
+            // may be modified if upon NodeEntry.resolveItemState the entry gets removed.
             NodeEntry[] arr = namedEntries.toArray(new NodeEntry[namedEntries.size()]);
             for (NodeEntry cne : arr) {
                 if (EntryValidation.isValidNodeEntry(cne)) {
@@ -871,7 +871,7 @@ public class NodeEntry extends Hierarchy
         // if this entry has not yet been resolved or if it is 'invalidated'
         // all property entries, that are not contained within the specified
         // collection of property names are removed from this NodeEntry.
-        ItemState<?> state = internalGetItemState();
+        ItemState<?> state = getItemState();
         if (containsExtra && (state == null || state.getStatus() == Status.INVALIDATED)) {
             for (Name propName : diff) {
                 PropertyEntry pEntry = properties.get(propName);
@@ -1013,12 +1013,12 @@ public class NodeEntry extends Hierarchy
     //-------------------------------------------------< HierarchyEntry >---
 
     @Override
-    NodeState doResolve() throws RepositoryException {
+    protected NodeState resolve() throws RepositoryException {
         return getItemStateFactory().createNodeState(getWorkspaceId(), this);
     }
 
     @Override
-    Path buildPath(boolean wspPath) throws RepositoryException {
+    protected Path buildPath(boolean wspPath) throws RepositoryException {
         PathFactory pf = getPathFactory();
         // shortcut for root state
         if (parent == null) {
@@ -1173,7 +1173,7 @@ public class NodeEntry extends Hierarchy
         if (wspIndex && revertInfo != null) {
             return revertInfo.oldIndex;
         } else {
-            NodeState state = internalGetItemState();
+            NodeState state = getItemState();
             if (state == null || !state.hasDefinition() || state.getDefinition().allowsSameNameSiblings()) {
                 return parent.getChildIndex(this, wspIndex);
             } else {
@@ -1253,7 +1253,7 @@ public class NodeEntry extends Hierarchy
                 PropertyState ps = child.getPropertyState();
                 setUniqueID(ps.getValue().getString());
             } else if (NameConstants.JCR_MIXINTYPES.equals(child.getName())) {
-                NodeState state = internalGetItemState();
+                NodeState state = getItemState();
                 if (state != null) {
                     PropertyState ps = child.getPropertyState();
                     state.setMixinTypeNames(getMixinNames(ps));
@@ -1276,7 +1276,7 @@ public class NodeEntry extends Hierarchy
         if (NameConstants.JCR_UUID.equals(propName)) {
             setUniqueID(null);
         } else if (NameConstants.JCR_MIXINTYPES.equals(propName)) {
-            NodeState state = internalGetItemState();
+            NodeState state = getItemState();
             if (state != null) {
                 state.setMixinTypeNames(Name.EMPTY_ARRAY);
             }
@@ -1445,7 +1445,7 @@ public class NodeEntry extends Hierarchy
             if (he.getStatus() == Status.NEW) {
                 switch (operation.getStatus()) {
                     case PERSISTED:
-                        he.internalGetItemState().setStatus(Status.EXISTING);
+                        he.getItemState().setStatus(Status.EXISTING);
                         he.invalidate(false);
                         break;
                     case UNDO:
@@ -1471,7 +1471,7 @@ public class NodeEntry extends Hierarchy
                 case PERSISTED:
                     // for autocreated/protected props, mark to be reloaded
                     // upon next access.
-                    PropertyState addedState = pe.internalGetItemState();
+                    PropertyState addedState = pe.getItemState();
                     addedState.setStatus(Status.EXISTING);
                     QPropertyDefinition pd = addedState.getDefinition();
                     if (pd.isAutoCreated() || pd.isProtected()) {
@@ -1616,7 +1616,7 @@ public class NodeEntry extends Hierarchy
                     revertInfo.dispose(true);
                 }
                 // and mark the moved state existing
-                // internalGetItemState().setStatus(Status.EXISTING);
+                // getItemState().setStatus(Status.EXISTING);
                 break;
             case UNDO:
                 if (getStatus() == Status.NEW) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java?rev=1185872&r1=1185871&r2=1185872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java Tue Oct 18 21:19:32 2011
@@ -49,13 +49,14 @@ public class PropertyEntry extends Hiera
     }
 
     //------------------------------------------------------< HierarchyEntry >---
+    
     @Override
-    PropertyState doResolve() throws RepositoryException {
+    protected PropertyState resolve() throws RepositoryException {
         return getItemStateFactory().createPropertyState(getWorkspaceId(), this);
     }
 
     @Override
-    Path buildPath(boolean workspacePath) throws RepositoryException {
+    protected Path buildPath(boolean workspacePath) throws RepositoryException {
         Path parentPath = parent.buildPath(workspacePath);
         return getPathFactory().create(parentPath, getName(), true);
     }
@@ -92,7 +93,7 @@ public class PropertyEntry extends Hiera
      * {@code PropertyState}.
      */
     public PropertyState getPropertyState() throws RepositoryException {
-        return getItemState();
+        return resolveItemState();
     }
 
     //-----------------------------------------------------< HierarchyEntry >---

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java?rev=1185872&r1=1185871&r2=1185872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java Tue Oct 18 21:19:32 2011
@@ -200,7 +200,7 @@ public class SessionImporter implements 
                    NodeId conflictingId = session.getIdFactory().createNodeId(nodeInfo.getUUID());
                    NodeEntry conflicting = session.getHierarchyManager().getNodeEntry(conflictingId);
                    // assert that the entry is available
-                   conflicting.getItemState();
+                   conflicting.resolveItemState();
 
                    nodeState = resolveUUIDConflict(parent, conflicting, nodeInfo);
                } catch (ItemNotFoundException e) {