jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1174889 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jc...
Date Fri, 23 Sep 2011 17:09:55 GMT
Author: mduerig
Date: Fri Sep 23 17:09:55 2011
New Revision: 1174889

URL: http://svn.apache.org/viewvc?rev=1174889&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
Remove support for Item.save and Item.refresh. Forward calls to the respective Session methods
and log an error.

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/SessionImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SpiLoggerFactory.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.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=1174889&r1=1174888&r2=1174889&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
Fri Sep 23 17:09:55 2011
@@ -195,41 +195,14 @@ public abstract class ItemImpl<STATE_TYP
 
     @Override
     public void save() throws RepositoryException {
-        // check state of this instance
-        checkStatus();
-        session.getSessionItemStateManager().save(getItemState());
+        log.error("Item.save ist not supported anymore. Redirecting to session.save", new
Exception("occurred here"));
+        session.save();
     }
 
     @Override
     public void refresh(boolean keepChanges) throws RepositoryException {
-        // check session status
-        session.checkIsAlive();
-        Status status = state.getStatus();
-        // check if item has been removed by this or another session
-        if (Status.isTerminal(status) || Status.EXISTING_REMOVED == status) {
-            throw new InvalidItemStateException("Item '" + this + "' doesn't exist anymore");
-        }
-
-        // If 'keepChanges' is true, items that do not have changes pending have
-        //   their state refreshed to reflect the current saved state
-        if (keepChanges) {
-            if (status != Status.NEW) {
-                // merge current transient modifications with latest changes
-                // from the 'server'.
-                state.getHierarchyEntry().invalidate(true);
-            }
-        } else {
-            // check status of item state
-            if (status == Status.NEW) {
-                String msg = "Cannot refresh a new item (" + safeGetJCRPath() + ").";
-                log.debug(msg);
-                throw new RepositoryException(msg);
-            }
-
-            // Reset all transient modifications from this item and its descendants.
-            session.getSessionItemStateManager().undo(state);
-            state.getHierarchyEntry().invalidate(true);
-        }
+        log.error("Item.refresh ist not supported anymore. Redirecting to session.refresh",
new Exception("occurred here"));
+        session.refresh(keepChanges);
     }
 
     @Override

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Fri Sep 23 17:09:55 2011
@@ -290,15 +290,20 @@ public class SessionImpl extends Abstrac
 
     @Override
     public void save() throws RepositoryException {
+        checkIsAlive();
         checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
-        // delegate to the root node (including check for isAlive)
-        getRootNode().save();
+        getSessionItemStateManager().save();
     }
 
     @Override
     public void refresh(boolean keepChanges) throws RepositoryException {
-        // delegate to the root node (including check for isAlive)
-        getRootNode().refresh(keepChanges);
+        checkIsAlive();
+
+        if (!keepChanges) {
+            // Reset all transient modifications from this item and its descendants
+            getSessionItemStateManager().undo();
+        }
+        getHierarchyManager().getRootEntry().invalidate(true);
     }
 
     @Override

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Fri Sep 23 17:09:55 2011
@@ -704,8 +704,7 @@ public final class WorkspaceManager impl
         private void execute(ChangeLog changeLog) throws RepositoryException {
             RepositoryException ex = null;
             try {
-                ItemState<?> target = changeLog.getTarget();
-                batch = service.createBatch(sessionInfo, target.getId());
+                batch = service.createBatch(sessionInfo);  
                 for (Operation op : changeLog.getOperations()) {
                     log.debug("executing " + op.getName());
                     op.accept(this);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
Fri Sep 23 17:09:55 2011
@@ -44,15 +44,9 @@ public class ChangeLog {
     private static final Logger log = LoggerFactory.getLogger(ChangeLog.class);
 
     /**
-     * The change log target: Root item of the tree whose changes are contained
-     * in this change log.
+     * List of operations
      */
-    private final ItemState<?> target;
-
-    /**
-     * Set of operations
-     */
-    private final Set<Operation> operations;
+    private final List<Operation> operations;
 
     private final Set<ItemState<?>> affectedStates;
 
@@ -60,14 +54,12 @@ public class ChangeLog {
      * Create a new change log and populates it with operations and states
      * that are within the scope of this change set.
      *
-     * @param target
      * @param operations
      * @param affectedStates
      * @throws InvalidItemStateException
      * @throws ConstraintViolationException
      */
-    ChangeLog(ItemState<?> target, Set<Operation> operations, Set<ItemState<?>>
affectedStates) {
-        this.target = target;
+    ChangeLog(List<Operation> operations, Set<ItemState<?>> affectedStates)
{
         this.operations = operations;
         this.affectedStates = affectedStates;
     }
@@ -193,13 +185,6 @@ public class ChangeLog {
     //----------------------< Retrieve information present in the ChangeLog >---
 
     /**
-     * @return the target state
-     */
-    public ItemState<?> getTarget() {
-        return target;
-    }
-
-    /**
      * @return true if no {@code operations} are present.
      */
     public boolean isEmpty() {
@@ -209,7 +194,7 @@ public class ChangeLog {
     /**
      * @return set of operations.
      */
-    public Set<Operation> getOperations() {
+    public List<Operation> getOperations() {
         return operations;
     }
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Fri Sep 23 17:09:55 2011
@@ -80,7 +80,7 @@ public class SessionItemStateManager ext
 
     private final QValueFactory qValueFactory;
 
-    private final SessionImpl mgrProvider;
+    private final SessionImpl session;
 
     /**
      * Creates a new {@code SessionItemStateManager} instance.
@@ -89,10 +89,10 @@ public class SessionItemStateManager ext
      * @param validator
      * @param qValueFactory
      * @param isf
-     * @param mgrProvider
+     * @param session
      */
     public SessionItemStateManager(UpdateableItemStateManager workspaceItemStateMgr, ItemStateValidator
validator,
-            QValueFactory qValueFactory, ItemStateFactory isf, SessionImpl mgrProvider) {
+            QValueFactory qValueFactory, ItemStateFactory isf, SessionImpl session) {
 
         this.workspaceItemStateMgr = workspaceItemStateMgr;
         transientStateMgr = new TransientItemStateManager();
@@ -100,7 +100,7 @@ public class SessionItemStateManager ext
 
         this.validator = validator;
         this.qValueFactory = qValueFactory;
-        this.mgrProvider = mgrProvider;
+        this.session = session;
     }
 
     /**
@@ -112,51 +112,36 @@ public class SessionItemStateManager ext
     }
 
     /**
-     * This will save {@code state} and all descendants items of
-     * {@code state} that are transiently modified in a single step. If
-     * this operation fails, no item will have been saved.
-     *
-     * @param state the root state of the update operation
+     * Atomically save all transiently modified items.
      */
-    public void save(ItemState<?> state) throws RepositoryException {
+    public void save() throws RepositoryException {
         // shortcut, if no modifications are present
         if (!transientStateMgr.hasPendingChanges()) {
             return;
         }
         // collect the changes to be saved
-        ChangeLog changeLog = transientStateMgr.getChangeLog(state, true);
+        ChangeLog changeLog = transientStateMgr.getChangeLog(true);
         if (!changeLog.isEmpty()) {
-            // only pass change log if there are transient modifications available
-            // for the specified item and its descendants.
+            // only pass change log if there are transient modifications
             workspaceItemStateMgr.execute(changeLog);
-            // remove states and operations just processed from the transient ISM
-            transientStateMgr.dispose(changeLog);
-            // now its save to clear the changeLog
+            transientStateMgr.dispose();
             changeLog.reset();
         }
     }
 
     /**
-     * This will undo all changes made to {@code state} and descendant
-     * items of {@code state} inside this item state manager.
-     *
-     * @param itemState the root state of the cancel operation.
-     * @throws ConstraintViolationException
-     * @throws RepositoryException if undoing changes made to {@code state}
-     * and descendant items is not a closed set of changes. That is, at least
-     * another item needs to be canceled as well in another sub-tree.
+     * This will undo all changes made to this session.
      */
-    public void undo(ItemState<?> itemState) throws RepositoryException {
+    public void undo() throws RepositoryException {
         // short cut
         if (!transientStateMgr.hasPendingChanges()) {
             return;
         }
-        ChangeLog changeLog = transientStateMgr.getChangeLog(itemState, false);
+        ChangeLog changeLog = transientStateMgr.getChangeLog(false);
         if (!changeLog.isEmpty()) {
             // let change log revert all changes
             changeLog.undo();
-            // remove transient states and related operations from the state manager
-            transientStateMgr.dispose(changeLog);
+            transientStateMgr.dispose();
             changeLog.reset();
         }
     }
@@ -234,7 +219,7 @@ public class SessionItemStateManager ext
     @Override
     public void visit(AddNode operation) throws RepositoryException {
         NodeState parent = operation.getParentState();
-        ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+        ItemDefinitionProvider defProvider = session.getItemDefinitionProvider();
         QNodeDefinition def = defProvider.getQNodeDefinition(parent.getAllNodeTypeNames(),
operation.getNodeName(),
                 operation.getNodeTypeName());
 
@@ -275,8 +260,9 @@ public class SessionItemStateManager ext
             srcState.getNodeTypeName(), operation.getOptions());
 
         // retrieve applicable definition at the new place
-        ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
-        QNodeDefinition newDefinition = defProvider.getQNodeDefinition(destParent.getAllNodeTypeNames(),
operation.getDestinationName(), srcState.getNodeTypeName());
+        ItemDefinitionProvider defProvider = session.getItemDefinitionProvider();
+        QNodeDefinition newDefinition = defProvider.getQNodeDefinition(destParent.getAllNodeTypeNames(),
+                operation.getDestinationName(), srcState.getNodeTypeName());
 
         // perform the move (modifying states)
         srcParent.moveChildNodeEntry(destParent, srcState, operation.getDestinationName(),
newDefinition);
@@ -312,7 +298,7 @@ public class SessionItemStateManager ext
                 setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME,
operation.getOptions());
             } else {
                 // create new jcr:mixinTypes property
-                ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+                ItemDefinitionProvider defProvider = session.getItemDefinitionProvider();
                 QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState.getAllNodeTypeNames(),
                         NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true);
 
@@ -340,7 +326,7 @@ public class SessionItemStateManager ext
 
         // detect obvious node type conflicts
 
-        EffectiveNodeTypeProvider entProvider = mgrProvider.getEffectiveNodeTypeProvider();
+        EffectiveNodeTypeProvider entProvider = session.getEffectiveNodeTypeProvider();
 
         // try to build new effective node type (will throw in case of conflicts)
         Name[] mixins = nState.getMixinTypeNames();
@@ -414,7 +400,7 @@ public class SessionItemStateManager ext
         // autocreated child nodes that may be 'protected'.
         validator.checkAddNode(parent, nodeName, nodeTypeName, options);
         // a new NodeState doesn't have mixins defined yet -> ent is ent of primary type
-        EffectiveNodeType ent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeTypeName);
+        EffectiveNodeType ent = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeTypeName);
 
         if (nodeTypeName == null) {
             // no primary node type specified,
@@ -435,7 +421,7 @@ public class SessionItemStateManager ext
         addedStates.add(nodeState);
         if (uuid != null) {
             QValue[] value = getQValues(uuid, qValueFactory);
-            ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+            ItemDefinitionProvider defProvider = session.getItemDefinitionProvider();
             QPropertyDefinition pDef = defProvider.getQPropertyDefinition(NameConstants.MIX_REFERENCEABLE,
                     NameConstants.JCR_UUID, PropertyType.STRING, false);
 
@@ -540,7 +526,7 @@ public class SessionItemStateManager ext
             } else if (NameConstants.JCR_CREATEDBY.equals(name)
                     && NameConstants.MIX_CREATED.equals(declaringNT)) {
                 // jcr:createdBy property of a mix:created
-                genValues = new QValue[]{qValueFactory.create(mgrProvider.getUserID(), PropertyType.STRING)};
+                genValues = new QValue[]{qValueFactory.create(session.getUserID(), PropertyType.STRING)};
 
             } else if (NameConstants.JCR_LASTMODIFIED.equals(name)
                     && NameConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
@@ -550,7 +536,7 @@ public class SessionItemStateManager ext
             } else if (NameConstants.JCR_LASTMODIFIEDBY.equals(name)
                     && NameConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
                 // jcr:lastModifiedBy property of a mix:lastModified
-                genValues = new QValue[]{qValueFactory.create(mgrProvider.getUserID(), PropertyType.STRING)};
+                genValues = new QValue[]{qValueFactory.create(session.getUserID(), PropertyType.STRING)};
 
             } else {
                 // ask the SPI implementation for advice
@@ -576,4 +562,5 @@ public class SessionItemStateManager ext
     private static QValue[] getQValues(String uniqueID, QValueFactory factory) throws RepositoryException
{
         return new QValue[] {factory.create(uniqueID, PropertyType.STRING)};
     }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
Fri Sep 23 17:09:55 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.jcr2spi.state;
 
-import org.apache.commons.collections.iterators.IteratorChain;
-import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
@@ -32,13 +30,11 @@ import javax.jcr.InvalidItemStateExcepti
 import javax.jcr.ItemExistsException;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
-import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
-
 /**
  * {@code TransientItemStateManager} adds support for transient changes on
  * {@link ItemState}s and also provides methods to create new item states.
@@ -78,7 +74,7 @@ public class TransientItemStateManager i
     /**
      * Set of operations
      */
-    private final Set<Operation> operations = new LinkedHashSet<Operation>();
+    private final List<Operation> operations = new ArrayList<Operation>();
 
     TransientItemStateManager() {
     }
@@ -101,14 +97,8 @@ public class TransientItemStateManager i
     }
 
     /**
-     * Create the change log for the tree starting at {@code target}. This
-     * includes a  check if the ChangeLog to be created is totally 'self-contained'
-     * and independent; items within the scope of this update operation (i.e.
-     * below the target) must not have dependencies outside of this tree (e.g.
-     * moving a node requires that the target node including both old and new
-     * parents are saved).
+     * Create the change log for session.
      *
-     * @param target
      * @param throwOnStale Throws InvalidItemStateException if either the given
      * {@code ItemState} or any of its descendants is stale and the flag is true.
      * @return
@@ -118,89 +108,23 @@ public class TransientItemStateManager i
      * therefore not reuse the {@code changeLog} if such an exception is thrown.
      * @throws RepositoryException if {@code state} is a new item state.
      */
-    ChangeLog getChangeLog(ItemState<?> target, boolean throwOnStale) throws RepositoryException
{
-        // fail-fast test: check status of this item's state
-        if (target.getStatus() == Status.NEW) {
-            String msg = "Cannot save/revert an item with status NEW (" +target+ ").";
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        if (throwOnStale && Status.isStale(target.getStatus())) {
-            String msg =  "Attempt to save/revert an item, that has been externally modified
(" +target+ ").";
-            log.debug(msg);
-            throw new InvalidItemStateException(msg);
-        }
-
-        Set<Operation> ops = new LinkedHashSet<Operation>();
+    ChangeLog getChangeLog(boolean throwOnStale) throws RepositoryException {
         Set<ItemState<?>> affectedStates = new LinkedHashSet<ItemState<?>>();
 
-        HierarchyEntry<?> he = target.getHierarchyEntry();
-        if (he.getParent() == null) {
-            // the root entry -> the complete change log can be used for
-            // simplicity. collecting ops, states can be omitted.
-            if (throwOnStale && !staleStates.isEmpty()) {
-                String msg = "Cannot save changes: States has been modified externally.";
-                log.debug(msg);
-                throw new InvalidItemStateException(msg);
-            } else {
-                affectedStates.addAll(staleStates);
-            }
-            ops.addAll(operations);
-            affectedStates.addAll(addedStates);
-            affectedStates.addAll(modifiedStates);
-            affectedStates.addAll(removedStates);
+        // the root entry -> the complete change log can be used for
+        // simplicity. collecting ops, states can be omitted.
+        if (throwOnStale && !staleStates.isEmpty()) {
+            String msg = "Cannot save changes: States has been modified externally.";
+            log.debug(msg);
+            throw new InvalidItemStateException(msg);
         } else {
-            // not root entry:
-            // - check if there is a stale state in the scope (save only)
-            if (throwOnStale) {
-                for (ItemState<?> state : staleStates) {
-                    if (containedInTree(target, state)) {
-                        String msg = "Cannot save changes: States has been modified externally.";
-                        log.debug(msg);
-                        throw new InvalidItemStateException(msg);
-                    }
-                }
-            }
-            // - collect all affected states within the scope of save/undo
-            Iterator<?>[] its = new Iterator[] {
-                    addedStates.iterator(),
-                    removedStates.iterator(),
-                    modifiedStates.iterator()
-            };
-            IteratorChain chain = new IteratorChain(its);
-            if (!throwOnStale) {
-                chain.addIterator(staleStates.iterator());
-            }
-            while (chain.hasNext()) {
-                ItemState<?> state = cast(chain.next());
-                if (containedInTree(target, state)) {
-                    affectedStates.add(state);
-                }
-            }
-            // - collect the set of operations and
-            //   check if the affected states listed by the operations are all
-            //   listed in the modified,removed or added states collected by this
-            //   change log.
-            for (Operation op : operations) {
-                Collection<ItemState<?>> opStates = op.getAffectedItemStates();
-                for (ItemState<?> state : opStates) {
-                    if (affectedStates.contains(state)) {
-                        // operation needs to be included
-                        if (!affectedStates.containsAll(opStates)) {
-                            // incomplete change log: need to save a parent as well
-                            String msg = "ChangeLog is not self contained.";
-                            throw new ConstraintViolationException(msg);
-                        }
-                        // no violation: add operation an stop iteration over
-                        // all affected states present in the operation.
-                        ops.add(op);
-                        break;
-                    }
-                }
-            }
+            affectedStates.addAll(staleStates);
         }
+        affectedStates.addAll(addedStates);
+        affectedStates.addAll(modifiedStates);
+        affectedStates.addAll(removedStates);
 
-        return new ChangeLog(target, ops, affectedStates);
+        return new ChangeLog(new ArrayList<Operation>(operations), affectedStates);
     }
 
     /**
@@ -266,27 +190,10 @@ public class TransientItemStateManager i
         modifiedStates.clear();
         removedStates.clear();
         staleStates.clear();
-        // also clear all operations
         operations.clear();
     }
 
     /**
-     * Remove the states and operations listed in the changeLog from internal
-     * list of modifications.
-     *
-     * @param subChangeLog
-     */
-    void dispose(ChangeLog subChangeLog) {
-        Set<ItemState<?>> affectedStates = subChangeLog.getAffectedStates();
-        addedStates.removeAll(affectedStates);
-        modifiedStates.removeAll(affectedStates);
-        removedStates.removeAll(affectedStates);
-        staleStates.removeAll(affectedStates);
-
-        operations.removeAll(subChangeLog.getOperations());
-    }
-
-    /**
      * A state has been removed. If the state is not a new state
      * (not in the collection of added ones), then remove
      * it from the modified states collection and add it to the
@@ -301,35 +208,6 @@ public class TransientItemStateManager i
         removedStates.add(state);
     }
 
-    /**
-     *
-     * @param parent
-     * @param state
-     * @return
-     */
-    private static boolean containedInTree(ItemState<?> parent, ItemState<?>
state) {
-        HierarchyEntry<?> he = state.getHierarchyEntry();
-        HierarchyEntry<?> pHe = parent.getHierarchyEntry();
-        // short cuts first
-        if (he == pHe || he.getParent() == pHe) {
-            return true;
-        }
-        if (!parent.isNode() || he == pHe.getParent()) {
-            return false;
-        }
-        // none of the simple cases: walk up hierarchy
-        NodeEntry pe = he.getParent();
-        while (pe != null) {
-            if (pe == pHe) {
-                return true;
-            }
-            pe = pe.getParent();
-        }
-
-        // state isn't descendant of 'parent'
-        return false;
-    }
-
     //-----------------------------------------< ItemStateLifeCycleListener >---
 
     /**

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
Fri Sep 23 17:09:55 2011
@@ -328,8 +328,8 @@ public abstract class AbstractJCR2SPITes
 
     //-----------------------------------------------< general modification >---
 
-    public Batch createBatch(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException
{
-        return repositoryService.createBatch(sessionInfo, itemId);
+    public Batch createBatch(SessionInfo sessionInfo) throws RepositoryException {
+        return repositoryService.createBatch(sessionInfo);
     }
 
     public void submit(Batch batch) throws RepositoryException {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
Fri Sep 23 17:09:55 2011
@@ -22,7 +22,6 @@ import org.apache.jackrabbit.spi.Batch;
 import org.apache.jackrabbit.spi.EventBundle;
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.LockInfo;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
@@ -496,8 +495,7 @@ public abstract class AbstractRepository
      * @throws UnsupportedRepositoryOperationException always.
      */
     @Override
-    public Batch createBatch(SessionInfo sessionInfo, ItemId itemId)
-            throws RepositoryException {
+    public Batch createBatch(SessionInfo sessionInfo) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
Fri Sep 23 17:09:55 2011
@@ -261,13 +261,13 @@ public class RepositoryServiceLogger ext
     }
 
     @Override
-    public Batch createBatch(final SessionInfo sessionInfo, final ItemId itemId) throws RepositoryException
{
+    public Batch createBatch(final SessionInfo sessionInfo) throws RepositoryException {
         return execute(new Callable<Batch>() {
             @Override
             public Batch call() throws RepositoryException {
-                return service.createBatch(unwrap(sessionInfo), itemId);
+                return service.createBatch(unwrap(sessionInfo));
             }
-        }, "createBatch(SessionInfo, ItemId)", new Object[]{unwrap(sessionInfo), itemId});
+        }, "createBatch(SessionInfo, ItemId)", new Object[]{unwrap(sessionInfo)});
     }
 
     @Override

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SpiLoggerFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SpiLoggerFactory.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SpiLoggerFactory.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SpiLoggerFactory.java
Fri Sep 23 17:09:55 2011
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.spi.common
 
 import org.apache.jackrabbit.spi.Batch;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.QValueFactory;
@@ -371,10 +370,8 @@ public final class SpiLoggerFactory {
         }
 
         @Override
-        public Batch createBatch(SessionInfo sessionInfo, ItemId itemId)
-                throws RepositoryException {
-
-            Batch result = super.createBatch(sessionInfo, itemId);
+        public Batch createBatch(SessionInfo sessionInfo) throws RepositoryException {
+            Batch result = super.createBatch(sessionInfo);
             return result == null
                 ? null
                 : create(result, logWriterProvider);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Fri Sep 23 17:09:55 2011
@@ -316,6 +316,7 @@ public interface RepositoryService {
             throws ItemNotFoundException, RepositoryException;
 
     //-----------------------------------------------< general modification >---
+    
     /**
      * Indicates the start of a set of operations that cause modifications
      * on the underlying persistence layer. All modification called on the
@@ -323,9 +324,6 @@ public interface RepositoryService {
      * calling {@link #submit(Batch)}.
      *
      * @param sessionInfo
-     * @param itemId Id of the Item that is a common ancestor of all
-     * {@code Item}s affected upon batch execution. This {@code Item}
-     * might itself be modified within the scope of the {@code Batch}.
      * @return A Batch indicating the start of a set of transient modifications
      * that will be execute at once upon {@link #submit(Batch)}.
      * @throws RepositoryException
@@ -333,12 +331,11 @@ public interface RepositoryService {
      * @see javax.jcr.Session#save()
      * @see Batch
      */
-    Batch createBatch(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException;
+    Batch createBatch(SessionInfo sessionInfo) throws RepositoryException;
 
     /**
      * Completes the given {@link Batch} or discard all the previous modifications.
-     * See {@link #createBatch(SessionInfo,ItemId)} for additional information
-     * regarding batch creation.
+     * See {@link #createBatch(SessionInfo)} for additional information regarding batch creation.
      *
      * @param batch
      * @throws PathNotFoundException

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1174889&r1=1174888&r2=1174889&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri Sep 23 17:09:55 2011
@@ -463,7 +463,7 @@ public class RepositoryServiceImpl exten
     //-----------------------------< write methods >----------------------------
 
     @Override
-    public Batch createBatch(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException
{
+    public Batch createBatch(SessionInfo sessionInfo) throws RepositoryException {
         return new ChangeLog(sessionInfo);
     }
 



Mime
View raw message