Author: manik.surtani(a)jboss.com
Date: 2008-09-22 11:53:34 -0400 (Mon, 22 Sep 2008)
New Revision: 6773
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
Log:
JBCACHE-1408: Optimistic locking + JDBC cache loader + DataSources
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-09-22
15:53:19 UTC (rev 6772)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-09-22
15:53:34 UTC (rev 6773)
@@ -5,8 +5,6 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Modification;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.jmx.annotations.ManagedOperation;
-import org.jboss.cache.jmx.annotations.ManagedAttribute;
import org.jboss.cache.commands.AbstractVisitor;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.WriteCommand;
@@ -26,12 +24,15 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.interceptors.base.SkipCheckChainedInterceptor;
+import org.jboss.cache.jmx.annotations.ManagedAttribute;
+import org.jboss.cache.jmx.annotations.ManagedOperation;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionContext;
import javax.transaction.SystemException;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
import java.util.HashMap;
@@ -294,16 +295,27 @@
{
if (configuration.getNodeLockingScheme().isVersionedScheme())
{
- for (Fqn f : affectedFqns)
+ // we need to suspend any txs here since they would be in the tx-committed state
and if the loader attempts to
+ // use JTA (E.g., a JDBC CL using connections from a tx aware datasource) it
will fail since the tx is in an
+ // illegal state to perform writes. See JBCACHE-1408.
+ Transaction tx = txMgr.suspend();
+ try
{
- // NOT going to store tombstones!!
- NodeSPI n = ctx.lookUpNode(f);
- if (n != null && !n.isDeleted())
+ for (Fqn f : affectedFqns)
{
- Map internalState = n.getInternalState(true);
- loader.put(f, internalState);
+ // NOT going to store tombstones!!
+ NodeSPI n = ctx.lookUpNode(f);
+ if (n != null && !n.isDeleted())
+ {
+ Map internalState = n.getInternalState(true);
+ loader.put(f, internalState);
+ }
}
}
+ finally
+ {
+ txMgr.resume(tx);
+ }
}
}