jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r957205 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ItemImpl.java ItemRefreshOperation.java ItemSaveOperation.java
Date Wed, 23 Jun 2010 13:53:26 GMT
Author: jukka
Date: Wed Jun 23 13:53:25 2010
New Revision: 957205

URL: http://svn.apache.org/viewvc?rev=957205&view=rev
Log:
JCR-890: concurrent read-only access to a session

Turn Item.refresh() into a SessionOperation

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=957205&r1=957204&r2=957205&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
Wed Jun 23 13:53:25 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core;
 
-import java.util.ArrayList;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
@@ -40,19 +39,12 @@ import org.apache.jackrabbit.core.state.
 import org.apache.jackrabbit.core.state.SessionItemStateManager;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * <code>ItemImpl</code> implements the <code>Item</code> interface.
  */
 public abstract class ItemImpl implements Item {
 
-    /**
-     * Logger instance
-     */
-    private static Logger log = LoggerFactory.getLogger(ItemImpl.class);
-
     protected static final int STATUS_NORMAL = 0;
     protected static final int STATUS_MODIFIED = 1;
     protected static final int STATUS_DESTROYED = 2;
@@ -320,106 +312,22 @@ public abstract class ItemImpl implement
     public void save() throws RepositoryException {
         // check state of this instance
         sanityCheck();
-
-        perform(new ItemSaveOperation(isNode(), getItemState()));
+        perform(new ItemSaveOperation(getItemState()));
     }
 
     /**
      * {@inheritDoc}
      */
-    public synchronized void refresh(boolean keepChanges)
-            throws InvalidItemStateException, RepositoryException {
+    public void refresh(boolean keepChanges) throws RepositoryException {
         // check state of this instance
         sanityCheck();
 
         if (keepChanges) {
-            /** todo FIXME should reset Item#status field to STATUS_NORMAL
-             * of all descendant non-transient instances; maybe also
-             * have to reset stale ItemState instances */
-            return;
-        }
-
-        if (isNode()) {
-            // check if this is the root node
-            if (getDepth() == 0) {
-                // optimization
-                stateMgr.disposeAllTransientItemStates();
-                return;
-            }
-        }
-
-        // list of transient items that should be discarded
-        ArrayList<ItemState> list = new ArrayList<ItemState>();
-
-        // check status of this item's state
-        if (isTransient()) {
-            ItemState transientState = getItemState();
-            switch (transientState.getStatus()) {
-                case ItemState.STATUS_STALE_MODIFIED:
-                case ItemState.STATUS_STALE_DESTROYED:
-                    // add this item's state to the list
-                    list.add(transientState);
-                    break;
-
-                case ItemState.STATUS_EXISTING_MODIFIED:
-                    if (!transientState.getParentId().equals(
-                            transientState.getOverlayedState().getParentId())) {
-                        throw new RepositoryException(
-                                "Cannot refresh a moved item: " + this +
-                                " - possible solution: refresh the parent");
-                    }
-                    list.add(transientState);
-                    break;
-
-                case ItemState.STATUS_NEW:
-                    throw new RepositoryException(
-                            "Cannot refresh a new item: " + this);
-
-                default:
-                    log.warn("Unexpected item state status:"
-                            + transientState.getStatus() + " of " + this);
-                    // ignore
-                    break;
-            }
-        }
-
-        if (isNode()) {
-            // build list of 'new', 'modified' or 'stale' descendants
-            for (ItemState transientState
-                    : stateMgr.getDescendantTransientItemStates((NodeId) id)) {
-                switch (transientState.getStatus()) {
-                    case ItemState.STATUS_STALE_MODIFIED:
-                    case ItemState.STATUS_STALE_DESTROYED:
-                    case ItemState.STATUS_NEW:
-                    case ItemState.STATUS_EXISTING_MODIFIED:
-                        // add new or modified state to the list
-                        list.add(transientState);
-                        break;
-
-                    default:
-                        log.debug("unexpected state status (" + transientState.getStatus()
+ ")");
-                        // ignore
-                        break;
-                }
-            }
-        }
-
-        // process list of 'new', 'modified' or 'stale' transient states
-        for (ItemState state : list) {
-            // dispose the transient state, it is no longer used;
-            // this will indirectly (through stateDiscarded listener method)
-            // either restore or permanently invalidate the wrapping Item instances
-            stateMgr.disposeTransientItemState(state);
-        }
-
-        if (isNode()) {
-            // discard all transient descendants in the attic (i.e. those marked
-            // as 'removed'); this will resurrect the removed items
-            for (ItemState state : stateMgr.getDescendantTransientItemStatesInAttic((NodeId)
id)) {
-                // dispose the transient state; this will indirectly (through
-                // stateDiscarded listener method) resurrect the wrapping Item instances
-                stateMgr.disposeTransientItemStateInAttic(state);
-            }
+            // FIXME should reset Item#status field to STATUS_NORMAL
+            // of all descendant non-transient instances; maybe also
+            // have to reset stale ItemState instances
+        } else {
+            perform(new ItemRefreshOperation(getItemState()));
         }
     }
 

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java?rev=957205&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
Wed Jun 23 13:53:25 2010
@@ -0,0 +1,114 @@
+package org.apache.jackrabbit.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.core.session.SessionOperation;
+import org.apache.jackrabbit.core.state.ItemState;
+import org.apache.jackrabbit.core.state.SessionItemStateManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ItemRefreshOperation extends SessionOperation {
+
+    /**
+     * Logger instance.
+     */
+    private static final Logger log =
+        LoggerFactory.getLogger(ItemRefreshOperation.class);
+
+    private final ItemState state;
+
+    public ItemRefreshOperation(ItemState state) {
+        super("item refresh");
+        this.state = state;
+    }
+
+    @Override
+    public void perform(SessionContext context) throws RepositoryException {
+        SessionItemStateManager stateMgr = context.getItemStateManager();
+
+        // Optimisation for the root node
+        if (state.getParentId() == null) {
+            stateMgr.disposeAllTransientItemStates();
+            return;
+        }
+
+        // list of transient items that should be discarded
+        List<ItemState> transientStates = new ArrayList<ItemState>();
+
+        // check status of this item's state
+        if (state.isTransient()) {
+            switch (state.getStatus()) {
+            case ItemState.STATUS_STALE_MODIFIED:
+            case ItemState.STATUS_STALE_DESTROYED:
+                // add this item's state to the list
+                transientStates.add(state);
+                break;
+            case ItemState.STATUS_EXISTING_MODIFIED:
+                if (!state.getParentId().equals(
+                        state.getOverlayedState().getParentId())) {
+                    throw new RepositoryException(
+                            "Cannot refresh a moved item,"
+                            + " try refreshing the parent: " + this);
+                }
+                transientStates.add(state);
+                break;
+            case ItemState.STATUS_NEW:
+                throw new RepositoryException(
+                        "Cannot refresh a new item: " + this);
+            default:
+                // log and ignore
+                log.warn("Unexpected item state status {} of {}",
+                        state.getStatus(), this);
+                break;
+            }
+        }
+
+        if (state.isNode()) {
+            // build list of 'new', 'modified' or 'stale' descendants
+            for (ItemState transientState
+                    : stateMgr.getDescendantTransientItemStates(state.getId())) {
+                switch (transientState.getStatus()) {
+                case ItemState.STATUS_STALE_MODIFIED:
+                case ItemState.STATUS_STALE_DESTROYED:
+                case ItemState.STATUS_NEW:
+                case ItemState.STATUS_EXISTING_MODIFIED:
+                    // add new or modified state to the list
+                    transientStates.add(transientState);
+                    break;
+
+                default:
+                    // log and ignore
+                    log.debug("unexpected state status ({})",
+                            transientState.getStatus());
+                    break;
+                }
+            }
+        }
+
+        // process list of 'new', 'modified' or 'stale' transient states
+        for (ItemState transientState : transientStates) {
+            // dispose the transient state, it is no longer used;
+            // this will indirectly (through stateDiscarded listener method)
+            // either restore or permanently invalidate the wrapping Item instances
+            stateMgr.disposeTransientItemState(transientState);
+        }
+
+        if (state.isNode()) {
+            // discard all transient descendants in the attic (i.e. those marked
+            // as 'removed'); this will resurrect the removed items
+            for (ItemState descendant
+                    : stateMgr.getDescendantTransientItemStatesInAttic(state.getId())) {
+                // dispose the transient state; this will indirectly
+                // (through stateDiscarded listener method) resurrect
+                // the wrapping Item instances
+                stateMgr.disposeTransientItemStateInAttic(descendant);
+            }
+        }
+    }
+
+}
\ No newline at end of file

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java?rev=957205&r1=957204&r2=957205&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
Wed Jun 23 13:53:25 2010
@@ -80,13 +80,10 @@ class ItemSaveOperation extends SessionO
     private static final Logger log =
         LoggerFactory.getLogger(ItemSaveOperation.class);
 
-    private final boolean isNode;
-
     private final ItemState state;
 
-    public ItemSaveOperation(boolean isNode, ItemState state) {
+    public ItemSaveOperation(ItemState state) {
         super("item save");
-        this.isNode = isNode;
         this.state = state;
     }
 
@@ -306,7 +303,7 @@ class ItemSaveOperation extends SessionO
         // list of transient states that should be persisted
         ArrayList<ItemState> dirty = new ArrayList<ItemState>();
 
-        if (isNode) {
+        if (state.isNode()) {
             // build list of 'new' or 'modified' descendants
             for (ItemState transientState
                     : stateMgr.getDescendantTransientItemStates(state.getId())) {
@@ -391,7 +388,7 @@ class ItemSaveOperation extends SessionO
     private Collection<ItemState> getRemovedStates(
             SessionItemStateManager stateMgr)
             throws InvalidItemStateException, RepositoryException {
-        if (isNode) {
+        if (state.isNode()) {
             ArrayList<ItemState> removed = new ArrayList<ItemState>();
             for (ItemState transientState
                     : stateMgr.getDescendantTransientItemStatesInAttic(state.getId())) {



Mime
View raw message