jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: rev 56480 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . state state/obj state/tx state/xml
Date Wed, 03 Nov 2004 09:19:48 GMT
Author: stefan
Date: Wed Nov  3 01:19:47 2004
New Revision: 56480

Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentItemStateManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/DefaultTransactionalStore.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalItemStateManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalStore.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Log:
misc. small changes for better performance

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java	Wed Nov 
3 01:19:47 2004
@@ -768,15 +768,17 @@
      * Initializes the version history of all new nodes of node type
      * <code>mix:versionable</code>.
      * <p/>
-     * Called by {@link #validateTransientItems(Iterator)}.
+     * Called by {@link #save()}.
      *
      * @param iter
+     * @return true if this call generated new transient state; otherwise false
      * @throws RepositoryException
      */
-    private void initVersionHistories(Iterator iter) throws RepositoryException {
+    private boolean initVersionHistories(Iterator iter) throws RepositoryException {
         // todo consolidate version history creation code (currently in NodeImpl.addMixin
& ItemImpl.initVersionHistories
         // walk through list of transient items and
         // search for new versionable nodes
+        boolean createdTransientState = false;
         while (iter.hasNext()) {
             ItemState itemState = (ItemState) iter.next();
             if (itemState.isNode() && itemState.getStatus() == ItemState.STATUS_NEW)
{
@@ -787,9 +789,11 @@
                     node.internalSetProperty(VersionManager.PROPNAME_BASE_VERSION, InternalValue.create(new
UUID(hist.getRootVersion().getUUID())));
                     node.internalSetProperty(VersionManager.PROPNAME_IS_CHECKED_OUT, InternalValue.create(true));
                     node.internalSetProperty(VersionManager.PROPNAME_PREDECESSORS, new InternalValue[]{InternalValue.create(new
UUID(hist.getRootVersion().getUUID()))});
+                    createdTransientState = true;
                 }
             }
         }
+        return createdTransientState;
     }
 
     /**
@@ -1026,7 +1030,7 @@
         try {
             /**
              * turn on temporary path caching for better performance
-             * (assuming that the paths won't change during the save() call)
+             * (assuming that the paths won't change during this save() call)
              */
             itemStateMgr.enablePathCaching(true);
 
@@ -1135,11 +1139,14 @@
                     itemStateMgr.disposeTransientItemStateInAttic(transientState);
                 }
 
-                // initialize version histories for new nodes (might create new transient
state)
-                initVersionHistories(dirty.iterator());
-
-                // re-build the list of transient states (might have changed by now)
-                dirty = getTransientStates();
+                // initialize version histories for new nodes (might generate new transient
state)
+                if (initVersionHistories(dirty.iterator())) {
+                    /**
+                     * re-build the list of transient states because the previous call
+                     * generated new transient state
+                     */
+                    dirty = getTransientStates();
+                }
 
                 // persist 'new' or 'modified' transient states
                 persistTransientItems(dirty.iterator());

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
Wed Nov  3 01:19:47 2004
@@ -15,6 +15,8 @@
  */
 package org.apache.jackrabbit.core.state;
 
+import org.apache.jackrabbit.core.ItemId;
+import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
 
 /**
@@ -92,4 +94,27 @@
      * @throws ItemStateException
      */
     public void destroy(NodeReferences refs) throws ItemStateException;
+
+    /**
+     * Determines if there's <code>PersistentItemState</code> data for
+     * the given item.
+     *
+     * @param id
+     * @return
+     * @throws ItemStateException
+     * @see #load(PersistentNodeState)
+     * @see #load(PersistentPropertyState)
+     */
+    public boolean exists(ItemId id) throws ItemStateException;
+
+    /**
+     * Determines if there's <code>NodeReferences</code> data for
+     * the given target id.
+     *
+     * @param targetId
+     * @return
+     * @throws ItemStateException
+     * @see #load(NodeReferences)
+     */
+    public boolean referencesExist(NodeId targetId) throws ItemStateException;
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentItemStateManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentItemStateManager.java
Wed Nov  3 01:19:47 2004
@@ -232,9 +232,12 @@
      * @see ItemStateProvider#hasItemState(ItemId)
      */
     public boolean hasItemState(ItemId id) {
-        try {
-            getItemState(id);
+        if (isCached(id)) {
             return true;
+        }
+        
+        try {
+            return persistMgr.exists(id);
         } catch (ItemStateException ise) {
             return false;
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
Wed Nov  3 01:19:47 2004
@@ -15,10 +15,7 @@
  */
 package org.apache.jackrabbit.core.state.obj;
 
-import org.apache.jackrabbit.core.BLOBFileValue;
-import org.apache.jackrabbit.core.InternalValue;
-import org.apache.jackrabbit.core.PropertyId;
-import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.*;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.*;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -720,6 +717,53 @@
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete references: " + uuid;
+            log.error(msg, fse);
+            throw new ItemStateException(msg, fse);
+        }
+    }
+
+    /**
+     * @see PersistenceManager#exists(org.apache.jackrabbit.core.ItemId id)
+     */
+    public boolean exists(ItemId id) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        try {
+            if (id.denotesNode()) {
+                NodeId nodeId = (NodeId) id;
+                String nodeFilePath = buildNodeFilePath(nodeId.getUUID());
+                FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
+                return nodeFile.exists();
+            } else {
+                PropertyId propId = (PropertyId) id;
+                String propFilePath = buildPropFilePath(propId.getParentUUID(), propId.getName());
+                FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
+                return propFile.exists();
+            }
+        } catch (FileSystemException fse) {
+            String msg = "failed to check existence of item state: " + id;
+            log.error(msg, fse);
+            throw new ItemStateException(msg, fse);
+        }
+    }
+
+    /**
+     * @see PersistenceManager#referencesExist(NodeId targetId)
+     */
+    public boolean referencesExist(NodeId targetId) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        try {
+            String uuid = targetId.getUUID();
+            String refsFilePath = buildNodeReferencesFilePath(uuid);
+            FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
+            return refsFile.exists();
+        } catch (FileSystemException fse) {
+            String msg = "failed to check existence of references: " + targetId;
             log.error(msg, fse);
             throw new ItemStateException(msg, fse);
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/DefaultTransactionalStore.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/DefaultTransactionalStore.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/DefaultTransactionalStore.java
Wed Nov  3 01:19:47 2004
@@ -51,6 +51,14 @@
     }
 
     /**
+     * @see TransactionalStore#exists
+     */
+    public boolean exists(ItemId id) {
+
+        return provider.hasItemState(id);
+    }
+
+    /**
      * @see TransactionalStore#beginUpdate
      */
     public TransactionalStore.Update beginUpdate() {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalItemStateManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalItemStateManager.java
Wed Nov  3 01:19:47 2004
@@ -130,15 +130,10 @@
      * @see PersistentItemStateProvider#hasItemState
      */
     public boolean hasItemState(ItemId id) {
-        // try shortcut first
         if (isCached(id)) {
             return true;
-        }
-        try {
-            getItemState(id);
-            return true;
-        } catch (ItemStateException e) {
-            return false;
+        } else {
+            return store.exists(id);
         }
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalStore.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalStore.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/tx/TransactionalStore.java
Wed Nov  3 01:19:47 2004
@@ -33,6 +33,13 @@
             throws NoSuchItemStateException, ItemStateException;
 
     /**
+     * Determines if an item with the specified id exists in this store.
+     * @param id item id
+     * @return true if an item exists; false otherwise
+     */
+    public boolean exists(ItemId id);
+
+    /**
      * Begin an update operation. Subsequent save operations are passed to
      * the update object returned.
      *

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Wed Nov  3 01:19:47 2004
@@ -15,10 +15,7 @@
  */
 package org.apache.jackrabbit.core.state.xml;
 
-import org.apache.jackrabbit.core.BLOBFileValue;
-import org.apache.jackrabbit.core.InternalValue;
-import org.apache.jackrabbit.core.PropertyId;
-import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.*;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.*;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -867,6 +864,53 @@
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete references: " + uuid;
+            log.error(msg, fse);
+            throw new ItemStateException(msg, fse);
+        }
+    }
+
+    /**
+     * @see PersistenceManager#exists(org.apache.jackrabbit.core.ItemId id)
+     */
+    public boolean exists(ItemId id) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        try {
+            if (id.denotesNode()) {
+                NodeId nodeId = (NodeId) id;
+                String nodeFilePath = buildNodeFilePath(nodeId.getUUID());
+                FileSystemResource nodeFile = new FileSystemResource(itemStateStore, nodeFilePath);
+                return nodeFile.exists();
+            } else {
+                PropertyId propId = (PropertyId) id;
+                String propFilePath = buildPropFilePath(propId.getParentUUID(), propId.getName());
+                FileSystemResource propFile = new FileSystemResource(itemStateStore, propFilePath);
+                return propFile.exists();
+            }
+        } catch (FileSystemException fse) {
+            String msg = "failed to check existence of item state: " + id;
+            log.error(msg, fse);
+            throw new ItemStateException(msg, fse);
+        }
+    }
+
+    /**
+     * @see PersistenceManager#referencesExist(NodeId targetId)
+     */
+    public boolean referencesExist(NodeId targetId) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        try {
+            String uuid = targetId.getUUID();
+            String refsFilePath = buildNodeReferencesFilePath(uuid);
+            FileSystemResource refsFile = new FileSystemResource(itemStateStore, refsFilePath);
+            return refsFile.exists();
+        } catch (FileSystemException fse) {
+            String msg = "failed to check existence of references: " + targetId;
             log.error(msg, fse);
             throw new ItemStateException(msg, fse);
         }

Mime
View raw message