jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r412995 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ./ version/
Date Fri, 09 Jun 2006 10:11:02 GMT
Author: tripod
Date: Fri Jun  9 03:11:00 2006
New Revision: 412995

URL: http://svn.apache.org/viewvc?rev=412995&view=rev
Log:
JCR-455: InternalXAResource.rollback() can be called twice and without prepare
JCR-414: jcr:successors property not persisted correctly within a transaction

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/XAWorkspace.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersion.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionHistory.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersion.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionHistory.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Fri Jun  9 03:11:00 2006
@@ -117,21 +117,14 @@
 
         TransactionException txe = null;
         for (int i = 0; i < resources.length; i++) {
-            InternalXAResource resource = resources[i];
-            if (txe != null) {
-                try {
-                    resource.rollback(this);
-                } catch (TransactionException e) {
-                    log.warn("Unable to rollback changes on " + resource, e);
-                }
-            } else {
-                try {
-                    resource.prepare(this);
-                } catch (TransactionException e) {
-                    txe = e;
-                }
+            try {
+                resources[i].prepare(this);
+            } catch (TransactionException e) {
+                txe = e;
+                break;
             }
         }
+
         afterOperation();
         status = Status.STATUS_PREPARED;
 

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/XAWorkspace.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/XAWorkspace.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/XAWorkspace.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/XAWorkspace.java
Fri Jun  9 03:11:00 2006
@@ -29,6 +29,12 @@
 public class XAWorkspace extends WorkspaceImpl {
 
     /**
+     * the name of the workspace info attribute in the transaction context
+     */
+    private static final String ATTR_NAME_WORKSPACE_INFO =
+            RepositoryImpl.WorkspaceInfo.class.getName();
+
+    /**
      * Protected constructor.
      *
      * @param wspConfig The workspace configuration
@@ -50,7 +56,6 @@
         return new XAItemStateManager(shared, this);
     }
 
-
     /**
      * Returns an internal XAResource that is used at the beginning of the
      * resources chain in {@link XASessionImpl#init()}. This resource will lock
@@ -66,9 +71,13 @@
             public void beforeOperation(TransactionContext tx) {
             }
 
-            public void prepare(TransactionContext tx) throws TransactionException {
+            public void prepare(TransactionContext tx)
+                    throws TransactionException {
                 try {
-                    rep.getWorkspaceInfo(wspConfig.getName()).lockAcquire();
+                    RepositoryImpl.WorkspaceInfo wspInfo =
+                            rep.getWorkspaceInfo(wspConfig.getName());
+                    wspInfo.lockAcquire();
+                    tx.setAttribute(ATTR_NAME_WORKSPACE_INFO, wspInfo);
                 } catch (NoSuchWorkspaceException e) {
                     throw new TransactionException("Error while preparing for transaction",
e);
                 }
@@ -103,19 +112,23 @@
             public void prepare(TransactionContext tx) {
             }
 
-            public void commit(TransactionContext tx) throws TransactionException {
-                try {
-                    rep.getWorkspaceInfo(wspConfig.getName()).lockRelease();
-                } catch (NoSuchWorkspaceException e) {
-                    throw new TransactionException("Error while commit transaction", e);
+            public void commit(TransactionContext tx) {
+                RepositoryImpl.WorkspaceInfo wspInfo =
+                        (RepositoryImpl.WorkspaceInfo)
+                                tx.getAttribute(ATTR_NAME_WORKSPACE_INFO);
+                if (wspInfo != null) {
+                    wspInfo.lockRelease();
+                    tx.removeAttribute(ATTR_NAME_WORKSPACE_INFO);
                 }
             }
 
-            public void rollback(TransactionContext tx) throws TransactionException {
-                try {
-                    rep.getWorkspaceInfo(wspConfig.getName()).lockRelease();
-                } catch (NoSuchWorkspaceException e) {
-                    throw new TransactionException("Error while rollback transaction", e);
+            public void rollback(TransactionContext tx) {
+                RepositoryImpl.WorkspaceInfo wspInfo =
+                        (RepositoryImpl.WorkspaceInfo)
+                                tx.getAttribute(ATTR_NAME_WORKSPACE_INFO);
+                if (wspInfo != null) {
+                    wspInfo.lockRelease();
+                    tx.removeAttribute(ATTR_NAME_WORKSPACE_INFO);
                 }
             }
 
@@ -124,5 +137,4 @@
         };
     }
 
-}
-
+}
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersion.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersion.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersion.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersion.java
Fri Jun  9 03:11:00 2006
@@ -19,18 +19,18 @@
 import org.apache.jackrabbit.core.ItemLifeCycleListener;
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.NodeId;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.NodeIterator;
-import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import java.util.Calendar;
@@ -65,8 +65,14 @@
      * @return internal version
      * @throws RepositoryException if the internal version is not available
      */
-    protected abstract InternalVersion getInternalVersion()
-            throws RepositoryException;
+    protected InternalVersion getInternalVersion() throws RepositoryException {
+        InternalVersion version =
+                session.getVersionManager().getVersion((NodeId) id);
+        if (version == null) {
+            throw new InvalidItemStateException(id + ": the item does not exist anymore");
+        }
+        return version;
+    }
 
     /**
      * {@inheritDoc}
@@ -99,13 +105,6 @@
             ret[i] = (Version) session.getNodeById(pred[i].getId());
         }
         return ret;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getUUID() throws UnsupportedRepositoryOperationException, RepositoryException
{
-        return getInternalVersion().getId().getUUID().toString();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionHistory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionHistory.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionHistory.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionHistory.java
Fri Jun  9 03:11:00 2006
@@ -33,6 +33,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.NodeIterator;
+import javax.jcr.InvalidItemStateException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.Version;
@@ -67,11 +68,19 @@
 
     /**
      * Returns the internal version history. Subclass responsibility.
+     *
      * @return internal version history
      * @throws RepositoryException if the internal version history is not available
      */
-    protected abstract InternalVersionHistory getInternalVersionHistory()
-            throws RepositoryException;
+    protected InternalVersionHistory getInternalVersionHistory()
+            throws RepositoryException {
+        InternalVersionHistory history =
+                session.getVersionManager().getVersionHistory((NodeId) id);
+        if (history == null) {
+            throw new InvalidItemStateException(id + ": the item does not exist anymore");
+        }
+        return history;
+    }
 
     /**
      * @see javax.jcr.version.VersionHistory#getRootVersion()
@@ -241,14 +250,6 @@
         } catch (UnknownPrefixException e) {
             throw new RepositoryException(e);
         }
-    }
-
-    /**
-     * @see javax.jcr.Node#getUUID()
-     */
-    public String getUUID()
-            throws UnsupportedRepositoryOperationException, RepositoryException {
-        return getInternalVersionHistory().getId().getUUID().toString();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
Fri Jun  9 03:11:00 2006
@@ -38,6 +38,9 @@
 
 /**
  * Base implementation of the {@link VersionManager} interface.
+ * <p/>
+ * All read operations must aquire the read lock before reading, all write
+ * operations must aquire the write lock.
  */
 abstract class AbstractVersionManager implements VersionManager {
 
@@ -77,6 +80,7 @@
      * {@inheritDoc}
      */
     public InternalVersion getVersion(NodeId id) throws RepositoryException {
+        // lock handling via getItem()
         InternalVersion v = (InternalVersion) getItem(id);
         if (v == null) {
             log.warn("Versioning item not found: " + id);
@@ -89,7 +93,7 @@
      */
     public InternalVersionHistory getVersionHistory(NodeId id)
             throws RepositoryException {
-
+        // lock handling via getItem()
         return (InternalVersionHistory) getItem(id);
     }
 
@@ -97,6 +101,7 @@
      * {@inheritDoc}
      */
     public boolean hasVersionHistory(NodeId id) {
+        // lock handling via hasItem()
         return hasItem(id);
     }
 
@@ -104,6 +109,7 @@
      * {@inheritDoc}
      */
     public boolean hasVersion(NodeId id) {
+        // lock handling via hasItem()
         return hasItem(id);
     }
 
@@ -156,16 +162,24 @@
      */
     public VersionHistory getVersionHistory(Session session, NodeState node)
             throws RepositoryException {
-
-        NodeId vhId = getVersionHistoryId(node);
-        if (vhId == null) {
-            return null;
+        aquireReadLock();
+        try {
+            NodeId vhId = getVersionHistoryId(node);
+            if (vhId == null) {
+                return null;
+            }
+            return (VersionHistory) ((SessionImpl) session).getNodeById(vhId);
+        } finally {
+            releaseReadLock();
         }
-        return (VersionHistory) ((SessionImpl) session).getNodeById(vhId);
     }
 
     /**
      * Returns the item with the given persistent id. Subclass responsibility.
+     * <p/>
+     * Please note, that the overridden method must aquire the readlock before
+     * reading the state manager.
+     *
      * @param id the id of the item
      * @return version item
      * @throws RepositoryException if an error occurs
@@ -185,6 +199,10 @@
     /**
      * Returns the item references that reference the given version item.
      * Subclass responsiblity.
+     * <p/>
+     * Please note, that the overridden method must aquire the readlock before
+     * reading the state manager.
+     *
      * @param item version item
      * @return list of item references, may be empty.
      */
@@ -259,8 +277,8 @@
      *         or <code>null</code> if that node doesn't have a version history.
      * @throws javax.jcr.RepositoryException if an error occurs
      */
-    NodeId getVersionHistoryId(NodeState node) throws RepositoryException {
-
+    private NodeId getVersionHistoryId(NodeState node)
+            throws RepositoryException {
         // build and traverse path
         String uuid = node.getNodeId().getUUID().toString();
         NodeStateEx n = historyRoot;

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
Fri Jun  9 03:11:00 2006
@@ -30,11 +30,6 @@
 public class VersionHistoryImpl extends AbstractVersionHistory {
 
     /**
-     * the internal version history
-     */
-    private final InternalVersionHistory history;
-
-    /**
      * creates a new version history node.
      *
      * @param itemMgr
@@ -50,13 +45,6 @@
                               ItemLifeCycleListener[] listeners,
                               InternalVersionHistory history) {
         super(itemMgr, session, id, state, definition, listeners);
-        this.history = history;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    protected InternalVersionHistory getInternalVersionHistory() {
-        return history;
-    }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
Fri Jun  9 03:11:00 2006
@@ -30,11 +30,6 @@
 public class VersionImpl extends AbstractVersion {
 
     /**
-     * the internal version
-     */
-    private final InternalVersion version;
-
-    /**
      * creates a new version node
      *
      * @param itemMgr
@@ -50,15 +45,6 @@
                        ItemLifeCycleListener[] listeners,
                        InternalVersion version) {
         super(itemMgr, session, id, state, definition, listeners);
-        this.version = version;
     }
 
-    /**
-     * Returns the internal version
-     *
-     * @return the internal version
-     */
-    protected InternalVersion getInternalVersion() {
-        return version;
-    }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Fri Jun  9 03:11:00 2006
@@ -58,8 +58,7 @@
 /**
  * This Class implements a VersionManager.
  */
-public class VersionManagerImpl extends AbstractVersionManager
-        /*implements EventStateCollectionFactory*/ {
+public class VersionManagerImpl extends AbstractVersionManager {
 
     /**
      * the default logger
@@ -197,7 +196,6 @@
      */
     public VersionHistory createVersionHistory(Session session, final NodeState node)
             throws RepositoryException {
-
         InternalVersionHistory history = (InternalVersionHistory)
                 escFactory.doSourced((SessionImpl) session, new SourcedTarget(){
             public Object run() throws RepositoryException {
@@ -215,7 +213,12 @@
      * {@inheritDoc}
      */
     public boolean hasItem(NodeId id) {
-        return stateMgr.hasItemState(id);
+        aquireReadLock();
+        try {
+            return stateMgr.hasItemState(id);
+        } finally {
+            releaseReadLock();
+        }
     }
 
     /**
@@ -229,29 +232,31 @@
         }
         try {
             aquireReadLock();
-            InternalVersionItem item = (InternalVersionItem) versionItems.get(id);
-            if (item == null) {
-                if (stateMgr.hasItemState(id)) {
-                    NodeState state = (NodeState) stateMgr.getItemState(id);
-                    NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
-                    NodeId parentId = pNode.getParentId();
-                    InternalVersionItem parent = getItem(parentId);
-                    QName ntName = state.getNodeTypeName();
-                    if (ntName.equals(QName.NT_FROZENNODE)) {
-                        item = new InternalFrozenNodeImpl(this, pNode, parent);
-                    } else if (ntName.equals(QName.NT_VERSIONEDCHILD)) {
-                        item = new InternalFrozenVHImpl(this, pNode, parent);
-                    } else if (ntName.equals(QName.NT_VERSION)) {
-                        item = ((InternalVersionHistory) parent).getVersion(id);
-                    } else if (ntName.equals(QName.NT_VERSIONHISTORY)) {
-                        item = new InternalVersionHistoryImpl(this, pNode);
-                    } else {
-                        return null;
+            synchronized (versionItems) {
+                InternalVersionItem item = (InternalVersionItem) versionItems.get(id);
+                if (item == null) {
+                    if (stateMgr.hasItemState(id)) {
+                        NodeState state = (NodeState) stateMgr.getItemState(id);
+                        NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
+                        NodeId parentId = pNode.getParentId();
+                        InternalVersionItem parent = getItem(parentId);
+                        QName ntName = state.getNodeTypeName();
+                        if (ntName.equals(QName.NT_FROZENNODE)) {
+                            item = new InternalFrozenNodeImpl(this, pNode, parent);
+                        } else if (ntName.equals(QName.NT_VERSIONEDCHILD)) {
+                            item = new InternalFrozenVHImpl(this, pNode, parent);
+                        } else if (ntName.equals(QName.NT_VERSION)) {
+                            item = ((InternalVersionHistory) parent).getVersion(id);
+                        } else if (ntName.equals(QName.NT_VERSIONHISTORY)) {
+                            item = new InternalVersionHistoryImpl(this, pNode);
+                        } else {
+                            return null;
+                        }
                     }
+                    versionItems.put(id, item);
                 }
-                versionItems.put(id, item);
+                return item;
             }
-            return item;
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
         } finally {
@@ -334,34 +339,29 @@
 
     /**
      * Invoked by some external source to indicate that some items in the
-     * versions tree were updated. Version manager should flush its own
-     * caches.
+     * versions tree were updated. Version histories are reloaded if possible.
+     * Matching items are removed from the cache.
+     *
      * @param items items updated
      */
     public void itemsUpdated(Collection items) {
-        Iterator iter = items.iterator();
-        while (iter.hasNext()) {
-            itemUpdated((InternalVersionItem) iter.next());
-        }
-    }
-
-    /**
-     * Update internal version item. Version histories are reloaded if possible.
-     * Matching items are removed from the cache.
-     * @param item item updated
-     */
-    private void itemUpdated(InternalVersionItem item) {
+        aquireReadLock();
         try {
-            aquireReadLock();
-            InternalVersionItem cached = (InternalVersionItem) versionItems.remove(item.getId());
-            if (cached != null) {
-                if (cached instanceof InternalVersionHistoryImpl) {
-                    InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl) cached;
-                    try {
-                        vh.reload();
-                        versionItems.put(vh.getId(), vh);
-                    } catch (RepositoryException e) {
-                        log.warn("Unable to update version history: " + e.toString());
+            synchronized (versionItems) {
+                Iterator iter = items.iterator();
+                while (iter.hasNext()) {
+                    InternalVersionItem item = (InternalVersionItem) iter.next();
+                    InternalVersionItem cached = (InternalVersionItem) versionItems.remove(item.getId());
+                    if (cached != null) {
+                        if (cached instanceof InternalVersionHistoryImpl) {
+                            InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
cached;
+                            try {
+                                vh.reload();
+                                versionItems.put(vh.getId(), vh);
+                            } catch (RepositoryException e) {
+                                log.warn("Unable to update version history: " + e.toString());
+                            }
+                        }
                     }
                 }
             }
@@ -376,6 +376,7 @@
      * @return <code>true</code> if the references could be set.
      */
     public boolean setNodeReferences(NodeReferences references) {
+        aquireWriteLock();
         try {
             // filter out version storage intern ones
             NodeReferences refs = new NodeReferences(references.getId());
@@ -394,6 +395,8 @@
         } catch (ItemStateException e) {
             log.error("Error while setting references: " + e.toString());
             return false;
+        } finally {
+            releaseWriteLock();
         }
     }
 
@@ -401,11 +404,14 @@
      * {@inheritDoc}
      */
     protected List getItemReferences(InternalVersionItem item) {
+        aquireReadLock();
         try {
             NodeReferences refs = pMgr.load(new NodeReferencesId(item.getId()));
             return refs.getReferences();
         } catch (ItemStateException e) {
             // ignore
+        } finally {
+            releaseReadLock();
         }
         return Collections.EMPTY_LIST;
     }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersion.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersion.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersion.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersion.java
Fri Jun  9 03:11:00 2006
@@ -23,8 +23,6 @@
 import org.apache.jackrabbit.core.state.NodeState;
 
 import javax.jcr.nodetype.NodeDefinition;
-import javax.jcr.RepositoryException;
-import javax.jcr.InvalidItemStateException;
 
 /**
  * Implementation of a {@link javax.jcr.version.Version} that works in an
@@ -33,12 +31,6 @@
 public class XAVersion extends AbstractVersion {
 
     /**
-     * Internal version. Gets fetched again from the version manager if
-     * needed.
-     */
-    private InternalVersion version;
-
-    /**
      * XA Version manager.
      */
     private final XAVersionManager vMgr;
@@ -57,39 +49,7 @@
                      ItemLifeCycleListener[] listeners,
                      InternalVersion version) {
         super(itemMgr, session, id, state, definition, listeners);
-
-        this.version = version;
         this.vMgr = (XAVersionManager) session.getVersionManager();
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    protected InternalVersion getInternalVersion() throws RepositoryException {
-        ensureUpToDate();
-        sanityCheck();
-        return version;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected void sanityCheck() throws RepositoryException {
-        super.sanityCheck();
-
-        if (version == null) {
-            throw new InvalidItemStateException(id + ": the item does not exist anymore");
-        }
-    }
-
-    /**
-     * Ensure the internal version is up-to-date.
-     */
-    private synchronized void ensureUpToDate() throws RepositoryException {
-        if (version != null) {
-            if (vMgr.differentXAEnv((InternalVersionImpl) version)) {
-                version = vMgr.getVersion(version.getId());
-            }
-        }
-    }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionHistory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionHistory.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionHistory.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionHistory.java
Fri Jun  9 03:11:00 2006
@@ -22,8 +22,6 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.state.NodeState;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.nodetype.NodeDefinition;
 
 /**
@@ -33,17 +31,6 @@
 public class XAVersionHistory extends AbstractVersionHistory {
 
     /**
-     * Internal version history. Gets fetched again from the version manager if
-     * needed.
-     */
-    private InternalVersionHistory history;
-
-    /**
-     * XA Version manager.
-     */
-    private final XAVersionManager vMgr;
-
-    /**
      * Create a new instance of this class.
      * @param itemMgr item manager
      * @param session session
@@ -58,41 +45,6 @@
                             ItemLifeCycleListener[] listeners,
                             InternalVersionHistory history) {
         super(itemMgr, session, id, state, definition, listeners);
-
-        this.history = history;
-        this.vMgr = (XAVersionManager) session.getVersionManager();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected InternalVersionHistory getInternalVersionHistory()
-            throws RepositoryException {
-
-        ensureUpToDate();
-        sanityCheck();
-        return history;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected void sanityCheck() throws RepositoryException {
-        super.sanityCheck();
-
-        if (history == null) {
-            throw new InvalidItemStateException(id + ": the item does not exist anymore");
-        }
     }
 
-    /**
-     * Ensure the internal version is up-to-date.
-     */
-    private synchronized void ensureUpToDate() throws RepositoryException {
-        if (history != null) {
-            if (vMgr.differentXAEnv(((InternalVersionHistoryImpl) history))) {
-                history = vMgr.getVersionHistory(history.getId());
-            }
-        }
-    }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=412995&r1=412994&r2=412995&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Fri Jun  9 03:11:00 2006
@@ -87,6 +87,11 @@
     private Map xaItems;
 
     /**
+     * flag that indicates if the version manager was locked during prepare
+     */
+    private boolean vmgrLocked = false;
+
+    /**
      * Creates a new instance of this class.
      */
     public XAVersionManager(VersionManagerImpl vMgr, NodeTypeRegistry ntReg,
@@ -438,7 +443,9 @@
      * Delegate the call to our XA item state manager.
      */
     public void prepare(TransactionContext tx) throws TransactionException {
+        vMgr.aquireWriteLock();
         vMgr.getSharedStateMgr().setNoLockHack(true);
+        vmgrLocked = true;
         ((XAItemStateManager) stateMgr).prepare(tx);
     }
 
@@ -449,13 +456,13 @@
      * global repository manager to update its caches.
      */
     public void commit(TransactionContext tx) throws TransactionException {
-        vMgr.aquireWriteLock();
         ((XAItemStateManager) stateMgr).commit(tx);
         vMgr.getSharedStateMgr().setNoLockHack(false);
 
         Map xaItems = (Map) tx.getAttribute(ITEMS_ATTRIBUTE_NAME);
         vMgr.itemsUpdated(xaItems.values());
         vMgr.releaseWriteLock();
+        vmgrLocked = false;
     }
 
     /**
@@ -465,7 +472,11 @@
      */
     public void rollback(TransactionContext tx) {
         ((XAItemStateManager) stateMgr).rollback(tx);
-        vMgr.getSharedStateMgr().setNoLockHack(false);
+        if (vmgrLocked) {
+            vMgr.getSharedStateMgr().setNoLockHack(false);
+            vMgr.releaseWriteLock();
+            vmgrLocked = false;
+        }
     }
 
     /**
@@ -496,10 +507,13 @@
             throws RepositoryException {
 
         NodeState state;
+        aquireReadLock();
         try {
             state = (NodeState) stateMgr.getItemState(history.getId());
         } catch (ItemStateException e) {
             throw new RepositoryException("Unable to make local copy", e);
+        } finally {
+            releaseReadLock();
         }
         NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null);
         return new InternalVersionHistoryImpl(this, stateEx);



Mime
View raw message