jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r434001 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ state/
Date Wed, 23 Aug 2006 10:11:55 GMT
Author: mreutegg
Date: Wed Aug 23 03:11:54 2006
New Revision: 434001

URL: http://svn.apache.org/viewvc?rev=434001&view=rev
Log:
- Remove ItemState.isTransient
- Implement ItemState.isTransient() based on ItemState status.

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
Wed Aug 23 03:11:54 2006
@@ -242,18 +242,17 @@
         }
 
         // check status of this item's state
-        if (isTransient()) {
-            switch (state.getStatus()) {
-                case ItemState.STATUS_NEW:
-                    String msg = "Cannot refresh a new item (" + safeGetJCRPath() + ").";
-                    log.debug(msg);
-                    throw new RepositoryException(msg);
-                case ItemState.STATUS_STALE_DESTROYED:
-                    msg = "Cannot refresh on a deleted item (" + safeGetJCRPath() + ").";
-                    log.debug(msg);
-                    throw new InvalidItemStateException(msg);
-            }
+        switch (state.getStatus()) {
+            case ItemState.STATUS_NEW:
+                String msg = "Cannot refresh a new item (" + safeGetJCRPath() + ").";
+                log.debug(msg);
+                throw new RepositoryException(msg);
+            case ItemState.STATUS_STALE_DESTROYED:
+                msg = "Cannot refresh on a deleted item (" + safeGetJCRPath() + ").";
+                log.debug(msg);
+                throw new InvalidItemStateException(msg);
         }
+
         // reset all transient modifications from this item and its decendants.
         try {
             session.getSessionItemStateManager().undo(state);
@@ -507,15 +506,6 @@
     ItemState getItemState() {
         return state;
     }
-
-    /**
-     *
-     * @return
-     */
-    boolean isTransient() {
-        return state.isTransient();
-    }
-
 
     /**
      * Failsafe conversion of internal <code>Path</code> to JCR path for use
in

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
Wed Aug 23 03:11:54 2006
@@ -72,11 +72,6 @@
     protected int status;
 
     /**
-     * Flag indicating whether this state is transient
-     */
-    private final boolean isTransient;
-
-    /**
      * Listeners (weak references)
      */
     private final transient Collection listeners = new WeakIdentityCollection(5);
@@ -103,10 +98,8 @@
      *
      * @param parent
      * @param initialStatus the initial status of the item state object
-     * @param isTransient   flag indicating whether this state is transient or not
      */
-    protected ItemState(NodeState parent, int initialStatus, boolean isTransient,
-                        IdFactory idFactory) {
+    protected ItemState(NodeState parent, int initialStatus, IdFactory idFactory) {
         switch (initialStatus) {
             case STATUS_EXISTING:
             case STATUS_NEW:
@@ -119,7 +112,6 @@
         }
         this.parent = parent;
         overlayedState = null;
-        this.isTransient = isTransient;
         this.idFactory = idFactory;
     }
 
@@ -129,10 +121,9 @@
      *
      * @param overlayedState the backing item state being overlayed
      * @param initialStatus the initial status of the new <code>ItemState</code>
instance
-     * @param isTransient   flag indicating whether this state is transient or not
      */
-    protected ItemState(ItemState overlayedState, NodeState parent, int initialStatus,
-                        boolean isTransient, IdFactory idFactory) {
+    protected ItemState(ItemState overlayedState, NodeState parent,
+                        int initialStatus, IdFactory idFactory) {
         switch (initialStatus) {
             case STATUS_EXISTING:
             case STATUS_EXISTING_MODIFIED:
@@ -144,7 +135,6 @@
                 log.debug(msg);
                 throw new IllegalArgumentException(msg);
         }
-        this.isTransient = isTransient;
         this.parent = parent;
         this.idFactory = idFactory;
         connect(overlayedState);
@@ -329,14 +319,13 @@
 
     /**
      * Returns <code>true</code> if this item state represents new or modified
-     * state (i.e. the result of copy-on-write) or <code>false</code> if it
-     * represents existing, unmodified state.
+     * state or <code>false</code> if it represents existing, unmodified state.
      *
      * @return <code>true</code> if this item state is modified or new,
      *         otherwise <code>false</code>
      */
     public boolean isTransient() {
-        return isTransient;
+        return status == STATUS_EXISTING_MODIFIED || status == STATUS_NEW;
     }
 
     /**
@@ -493,10 +482,10 @@
      */
     public void stateDestroyed(ItemState destroyed) {
         // underlying state has been permanently destroyed
-        if (isTransient) {
+        if (isTransient()) {
             setStatus(STATUS_STALE_DESTROYED);
         } else {
-            setStatus(STATUS_EXISTING_REMOVED);
+            setStatus(STATUS_REMOVED);
             notifyStateDestroyed();
         }
     }
@@ -506,7 +495,7 @@
      */
     public void stateModified(ItemState modified) {
         // underlying state has been modified
-        if (isTransient) {
+        if (isTransient()) {
             setStatus(STATUS_STALE_MODIFIED);
         } else {
             synchronized (this) {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Wed Aug 23 03:11:54 2006
@@ -131,17 +131,15 @@
      * @param nodeTypeName  node type of this node
      * @param definition
      * @param initialStatus the initial status of the node state object
-     * @param isTransient   flag indicating whether this state is transient or
-     *                      not.
      * @param isf           the item state factory responsible for creating node
      *                      states.
      * @param idFactory     the <code>IdFactory</code> to create new id
      */
     protected NodeState(QName name, String uuid, NodeState parent,
                         QName nodeTypeName, QNodeDefinition definition,
-                        int initialStatus, boolean isTransient,
-                        ItemStateFactory isf, IdFactory idFactory) {
-        super(parent, initialStatus, isTransient, idFactory);
+                        int initialStatus, ItemStateFactory isf,
+                        IdFactory idFactory) {
+        super(parent, initialStatus, idFactory);
         this.name = name;
         this.uuid = uuid;
         this.nodeTypeName = nodeTypeName;
@@ -156,15 +154,13 @@
      * @param overlayedState the backing node state being overlayed
      * @param parent         the parent of this NodeState
      * @param initialStatus  the initial status of the node state object
-     * @param isTransient    flag indicating whether this state is transient or
-     *                       not
      * @param idFactory      the <code>IdFactory</code> to create new id
      *                       instance.
      */
     protected NodeState(NodeState overlayedState, NodeState parent,
-                        int initialStatus, boolean isTransient,
-                        ItemStateFactory isf, IdFactory idFactory) {
-        super(overlayedState, parent, initialStatus, isTransient, idFactory);
+                        int initialStatus, ItemStateFactory isf,
+                        IdFactory idFactory) {
+        super(overlayedState, parent, initialStatus, idFactory);
         this.isf = isf;
         pull();
     }
@@ -1004,8 +1000,7 @@
      * @param references
      */
     void setNodeReferences(NodeReferences references) {
-        if (isTransient()) {
-            // TODO: check again
+        if (getOverlayedState() != null) {
             throw new UnsupportedOperationException("Cannot set references to a transient
node state.");
         }
         this.references = references;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
Wed Aug 23 03:11:54 2006
@@ -64,12 +64,11 @@
      * @param overlayedState
      * @param parent
      * @param initialStatus
-     * @param isTransient
      * @param idFactory
      */
     protected PropertyState(PropertyState overlayedState, NodeState parent,
-                            int initialStatus, boolean isTransient, IdFactory idFactory)
{
-        super(overlayedState, parent, initialStatus, isTransient, idFactory);
+                            int initialStatus, IdFactory idFactory) {
+        super(overlayedState, parent, initialStatus, idFactory);
         pull();
     }
 
@@ -80,12 +79,11 @@
      * @param parent
      * @param definition
      * @param initialStatus
-     * @param isTransient
      * @param idFactory
      */
-    protected PropertyState(QName name, NodeState parent, QPropertyDefinition definition,
int initialStatus,
-                            boolean isTransient, IdFactory idFactory) {
-        super(parent, initialStatus, isTransient, idFactory);
+    protected PropertyState(QName name, NodeState parent, QPropertyDefinition definition,
+                            int initialStatus, IdFactory idFactory) {
+        super(parent, initialStatus, idFactory);
         this.name = name;
         this.def = definition;
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Wed Aug 23 03:11:54 2006
@@ -364,30 +364,28 @@
     private void collectTransientStates(ItemState state, ChangeLog changeLog, boolean throwOnStale)
             throws StaleItemStateException, ItemStateException {
         // fail-fast test: check status of this item's state
-        if (state.isTransient()) {
+        switch (state.getStatus()) {
+            case ItemState.STATUS_NEW:
+                {
+                    String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) + ":
cannot save a new item.";
+                    log.debug(msg);
+                    throw new ItemStateException(msg);
+                }
+        }
+        if (throwOnStale) {
             switch (state.getStatus()) {
-                case ItemState.STATUS_NEW:
+                case ItemState.STATUS_STALE_MODIFIED:
                     {
-                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) +
": cannot save a new item.";
+                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) +
": the item cannot be saved because it has been modified externally.";
                         log.debug(msg);
-                        throw new ItemStateException(msg);
+                        throw new StaleItemStateException(msg);
+                    }
+                case ItemState.STATUS_STALE_DESTROYED:
+                    {
+                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) +
": the item cannot be saved because it has been deleted externally.";
+                        log.debug(msg);
+                        throw new StaleItemStateException(msg);
                     }
-            }
-            if (throwOnStale) {
-                switch (state.getStatus()) {
-                    case ItemState.STATUS_STALE_MODIFIED:
-                        {
-                            String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr)
+ ": the item cannot be saved because it has been modified externally.";
-                            log.debug(msg);
-                            throw new StaleItemStateException(msg);
-                        }
-                    case ItemState.STATUS_STALE_DESTROYED:
-                        {
-                            String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr)
+ ": the item cannot be saved because it has been deleted externally.";
-                            log.debug(msg);
-                            throw new StaleItemStateException(msg);
-                        }
-                }
             }
         }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
Wed Aug 23 03:11:54 2006
@@ -413,7 +413,7 @@
                                             NodeState parent, QName nodetypeName,
                                             QNodeDefinition definition) {
             NodeState nodeState = new NodeState(name, uuid, parent, nodetypeName,
-                definition, ItemState.STATUS_NEW, true, this, idFactory);
+                definition, ItemState.STATUS_NEW, this, idFactory);
             // get a notification when this item state is saved or invalidated
             nodeState.addListener(listener);
             // notify listener that a node state has been created
@@ -427,7 +427,7 @@
          */
         public PropertyState createNewPropertyState(QName name, NodeState parent, QPropertyDefinition
definition) {
             PropertyState propState = new PropertyState(name, parent,
-                definition, ItemState.STATUS_NEW, true, idFactory);
+                definition, ItemState.STATUS_NEW, idFactory);
             // get a notification when this item state is saved or invalidated
             propState.addListener(listener);
             // notify listener that a property state has been created
@@ -449,7 +449,7 @@
                 parentState = (NodeState) ism.getItemState(overlayedParent.getId());
             }
             NodeState nodeState = new NodeState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, true, this, idFactory);
+                    ItemState.STATUS_EXISTING, this, idFactory);
             nodeState.addListener(listener);
             return nodeState;
         }
@@ -463,7 +463,7 @@
             // retrieve state to overlay
             NodeState overlayedState = (NodeState) parent.getItemState(nodeId);
             NodeState nodeState = new NodeState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, true, this, idFactory);
+                    ItemState.STATUS_EXISTING, this, idFactory);
             nodeState.addListener(listener);
             return nodeState;
         }
@@ -478,7 +478,7 @@
             // retrieve state to overlay
             PropertyState overlayedState = (PropertyState) parent.getItemState(propertyId);
             PropertyState propState = new PropertyState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, true, idFactory);
+                    ItemState.STATUS_EXISTING, idFactory);
             propState.addListener(listener);
             return propState;
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=434001&r1=434000&r2=434001&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Wed Aug 23 03:11:54 2006
@@ -132,7 +132,7 @@
                 uuid = info.getId().getUUID();
             }
             NodeState state = new NodeState(info.getQName(), uuid, parent, info.getNodetype(),
-                definition, ItemState.STATUS_EXISTING, false, this, service.getIdFactory());
+                definition, ItemState.STATUS_EXISTING, this, service.getIdFactory());
 
             // set mixin nodetypes
             state.setMixinTypeNames(info.getMixins());
@@ -225,7 +225,7 @@
 
             // build the PropertyState
             PropertyState state = new PropertyState(info.getQName(), parent,
-                def, ItemState.STATUS_EXISTING, false, service.getIdFactory());
+                def, ItemState.STATUS_EXISTING, service.getIdFactory());
             state.setType(info.getType());
             QValue[] qValues;
             if (info.getType() == PropertyType.BINARY) {



Mime
View raw message