[jboss-cvs] JBossAS SVN: r111023 - in projects/jboss-jca/trunk: core/src/main/java/org/jboss/jca/core/connectionmanager/listener and 14 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 24 16:19:53 EDT 2011
Author: jesper.pedersen
Date: 2011-03-24 16:19:52 -0400 (Thu, 24 Mar 2011)
New Revision: 111023
Added:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocal.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocalDelegate.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalDelegateImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/package.html
Modified:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerFactory.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManagerImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/TransactionIntegration.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionIntegrationImpl.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/common/MockConnectionManager.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/OnePoolTestCase.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerTestCase.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/XATxConnectionManagerTestCase.java
projects/jboss-jca/trunk/core/src/test/resources/transaction.xml
projects/jboss-jca/trunk/embedded/src/main/resources/transaction.xml
projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/transaction.xml
Log:
[JBJCA-533] Transaction infrastructure (Part 2)
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerFactory.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerFactory.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -160,7 +160,7 @@
allocationRetry, allocationRetryWaitMillis,
txIntegration.getTransactionManager(), txIntegration.getUserTransactionRegistry());
setTxProperties(cm, interleaving, xaResourceTimeout, isSameRMOverride, wrapXAResource, padXid);
- handleTxIntegration(txIntegration.getTransactionManager());
+ handleTxIntegration(txIntegration);
return cm;
}
@@ -245,12 +245,12 @@
/**
* Associate the transaction synchronizer with the transaction
- * manager.
+ * integration.
*
- * @param tm TransactionManager
+ * @param ti TransactionManager
*/
- public void handleTxIntegration(final TransactionManager tm)
+ public void handleTxIntegration(final TransactionIntegration ti)
{
- TransactionSynchronizer.setTransactionManager(tm);
+ TransactionSynchronizer.setTransactionIntegration(ti);
}
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -21,6 +21,8 @@
*/
package org.jboss.jca.core.connectionmanager.listener;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
+
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnection;
import javax.transaction.TransactionManager;
@@ -42,7 +44,7 @@
* @return a new connection event listener
* @throws ResourceException for any error
*/
- ConnectionListener createConnectionListener(ManagedConnection managedConnection, Object context)
+ public ConnectionListener createConnectionListener(ManagedConnection managedConnection, Object context)
throws ResourceException;
/**
@@ -50,12 +52,19 @@
*
* @return whether it is a transactional or not
*/
- boolean isTransactional();
+ public boolean isTransactional();
/**
* Get the transaction manager.
*
* @return the transaction manager
*/
- TransactionManager getTransactionManager();
+ public TransactionManager getTransactionManager();
+
+ /**
+ * Get the transaction integration.
+ *
+ * @return the transaction integration
+ */
+ public TransactionIntegration getTransactionIntegration();
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManagerImpl.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManagerImpl.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -27,6 +27,7 @@
import org.jboss.jca.core.connectionmanager.NoTxConnectionManager;
import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
import org.jboss.jca.core.connectionmanager.listener.NoTxConnectionListener;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import java.util.Collection;
@@ -79,6 +80,12 @@
}
@Override
+ public TransactionIntegration getTransactionIntegration()
+ {
+ return null;
+ }
+
+ @Override
public boolean isTransactional()
{
return false;
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -28,6 +28,8 @@
import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
import org.jboss.jca.core.connectionmanager.pool.api.Pool;
import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
@@ -42,9 +44,7 @@
import javax.transaction.TransactionManager;
import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionLocal;
-
/**
* Abstract pool implementation.
* <p>
@@ -149,7 +149,7 @@
SubPoolContext subPoolContext = subPools.get(key);
if (subPoolContext == null)
{
- SubPoolContext newSubPoolContext = new SubPoolContext(getTransactionManager(), mcf, clf, subject,
+ SubPoolContext newSubPoolContext = new SubPoolContext(getTransactionIntegration(), mcf, clf, subject,
cri, poolConfiguration, this, log);
subPoolContext = subPools.putIfAbsent(key, newSubPoolContext);
if (subPoolContext == null)
@@ -162,6 +162,23 @@
}
/**
+ * Get any transaction integration associated with the pool.
+ *
+ * @return the transaction integration
+ */
+ protected TransactionIntegration getTransactionIntegration()
+ {
+ if (clf != null)
+ {
+ return clf.getTransactionIntegration();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
* Get any transaction manager associated with the pool.
*
* @return the transaction manager
@@ -178,7 +195,6 @@
}
}
-
/**
* {@inheritDoc}
*/
@@ -242,7 +258,7 @@
ManagedConnectionPool imcp = subPoolContext.getSubPool();
// Are we doing track by transaction?
- TransactionLocal trackByTx = subPoolContext.getTrackByTx();
+ TransactionLocal trackByTx = subPoolContext.getTrackByTx(); // TODO - Use TSR
if (trackByTransaction == null || trackByTx == null)
{
@@ -338,7 +354,7 @@
{
ConnectionListener cl = null;
- // Track by transaction
+ // Track by transaction // TODO - Use Coordinator
try
{
trackByTx.lock(trackByTransaction);
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -27,15 +27,15 @@
import org.jboss.jca.core.connectionmanager.pool.api.Pool;
import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool;
import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPoolFactory;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnectionFactory;
import javax.security.auth.Subject;
-import javax.transaction.TransactionManager;
import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionLocal;
/**
* Sub-pool context.
@@ -54,7 +54,7 @@
/**
* Create a new SubPoolContext.
*
- * @param tm the transaction manager
+ * @param ti the transaction integration
* @param mcf the managed connection factory
* @param clf the connection listener factory
* @param subject the subject
@@ -64,7 +64,7 @@
* @param log The logger for the managed connection pool
* @throws ResourceException for any error
*/
- public SubPoolContext(TransactionManager tm, ManagedConnectionFactory mcf, ConnectionListenerFactory clf,
+ public SubPoolContext(TransactionIntegration ti, ManagedConnectionFactory mcf, ConnectionListenerFactory clf,
Subject subject, ConnectionRequestInfo cri, PoolConfiguration pc, Pool p, Logger log)
throws ResourceException
{
@@ -74,9 +74,9 @@
subPool = mcpf.create(mcf, clf, subject, cri, pc, p, this, log);
- if (tm != null)
+ if (ti != null)
{
- trackByTx = new TransactionLocal(tm);
+ trackByTx = ti.createTransactionLocal();
}
}
catch (Throwable t)
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/TransactionSynchronizer.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -21,6 +21,9 @@
*/
package org.jboss.jca.core.connectionmanager.transaction;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
+
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.Condition;
@@ -30,10 +33,8 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionLocal;
import org.jboss.util.NestedRuntimeException;
/**
@@ -79,11 +80,11 @@
/**
* Initialization.
- * @param tm transaction manager
+ * @param ti transaction integration
*/
- public static void setTransactionManager(TransactionManager tm)
+ public static void setTransactionIntegration(TransactionIntegration ti)
{
- txSynchs = new TransactionLocal(tm);
+ txSynchs = ti.createTransactionLocal();
}
/**
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerImpl.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerImpl.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -32,6 +32,7 @@
import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import org.jboss.jca.core.spi.transaction.TransactionTimeoutConfiguration;
import org.jboss.jca.core.spi.transaction.TxUtils;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -52,7 +53,6 @@
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
-import org.jboss.tm.TransactionLocal;
import org.jboss.util.NestedRuntimeException;
import org.jboss.util.NotImplementedException;
@@ -184,6 +184,15 @@
}
/**
+ * Get the transaction integration instance
+ * @return The transaction integration
+ */
+ public TransactionIntegration getTransactionIntegration()
+ {
+ return txIntegration;
+ }
+
+ /**
* Gets interleaving flag.
* @return interleaving flag
*/
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/TransactionIntegration.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/TransactionIntegration.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/TransactionIntegration.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -24,6 +24,8 @@
import org.jboss.jca.core.api.connectionmanager.ConnectionManager;
import org.jboss.jca.core.spi.recovery.RecoveryPlugin;
import org.jboss.jca.core.spi.transaction.local.LocalXAResource;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocalDelegate;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecoveryRegistry;
import org.jboss.jca.core.spi.transaction.usertx.UserTransactionRegistry;
@@ -84,6 +86,12 @@
public XATerminator getXATerminator();
/**
+ * Get the transaction local delegate
+ * @return The value
+ */
+ public TransactionLocalDelegate getTransactionLocalDelegate();
+
+ /**
* Create an XAResourceRecovery instance
*
* @param mcf The managed connection factory
@@ -126,4 +134,10 @@
boolean pad, Boolean override,
String productName, String productVersion,
String jndiName);
+
+ /**
+ * Create a transaction local instance
+ * @return The value
+ */
+ public TransactionLocal createTransactionLocal();
}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocal.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocal.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocal.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.spi.transaction.local;
+
+import javax.transaction.Transaction;
+
+/**
+ * A TransactionLocal is similar to ThreadLocal except it is keyed on the
+ * Transactions. A transaction local variable is cleared after the transaction
+ * completes.
+ *
+ * @author <a href="mailto:dain at daingroup.com">Dain Sundstrom</a>
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ */
+public interface TransactionLocal
+{
+ /**
+ * Lock the TransactionLocal using the current transaction<p>
+ *
+ * WARN: The current implemention just "locks the transactions"
+ *
+ * @throws IllegalStateException if the transaction is not active
+ * @throws InterruptedException if the thread is interrupted
+ */
+ public void lock() throws InterruptedException;
+
+ /**
+ * Lock the TransactionLocal using the provided transaction<p>
+ *
+ * WARN: The current implemention just "locks the transactions"
+ *
+ * @param transaction the transaction
+ * @throws IllegalStateException if the transaction is not active
+ * @throws InterruptedException if the thread is interrupted
+ */
+ public void lock(Transaction transaction) throws InterruptedException;
+
+ /**
+ * Unlock the TransactionLocal using the current transaction
+ */
+ public void unlock();
+
+ /**
+ * Unlock the ThreadLocal using the provided transaction
+ *
+ * @param transaction the transaction
+ */
+ public void unlock(Transaction transaction);
+
+ /**
+ * Returns the value of this TransactionLocal variable associated with the
+ * thread context transaction. Creates and initializes the copy if this is
+ * the first time the method is called in a transaction.
+ *
+ * @return the value of this TransactionLocal
+ */
+ public Object get();
+
+ /**
+ * Returns the value of this TransactionLocal variable associated with the
+ * specified transaction. Creates and initializes the copy if this is the
+ * first time the method is called in a transaction.
+ *
+ * @param transaction the transaction for which the variable it to
+ * be retrieved
+ * @return the value of this TransactionLocal
+ * @throws IllegalStateException if an error occures while registering
+ * a synchronization callback with the transaction
+ */
+ public Object get(Transaction transaction);
+
+ /**
+ * Sets the value of this TransactionLocal variable associtated with the
+ * thread context transaction. This is only used to change the value from
+ * the one assigned by the initialValue method, and many applications will
+ * have no need for this functionality.
+ *
+ * @param value the value to be associated with the thread context
+ * transactions's TransactionLocal
+ */
+ public void set(Object value);
+
+ /**
+ * Sets the value of this TransactionLocal variable associtated with the
+ * specified transaction. This is only used to change the value from
+ * the one assigned by the initialValue method, and many applications will
+ * have no need for this functionality.
+ *
+ * @param transaction the transaction for which the value will be set
+ * @param value the value to be associated with the thread context
+ * transactions's TransactionLocal
+ */
+ public void set(Transaction transaction, Object value);
+
+ /**
+ * Get the current transaction
+ * @return The value
+ */
+ public Transaction getTransaction();
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocalDelegate.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocalDelegate.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/transaction/local/TransactionLocalDelegate.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.spi.transaction.local;
+
+import javax.transaction.Transaction;
+
+/**
+ * The interface to implementated for a transaction local implementation
+ *
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ */
+public interface TransactionLocalDelegate
+{
+ /**
+ * get the transaction local value.
+ *
+ * @param local the transaction local
+ * @param tx the transcation
+ * @return the value
+ */
+ public Object getValue(TransactionLocal local, Transaction tx);
+
+ /**
+ * put the value in the transaction local
+ *
+ * @param local the transaction local
+ * @param tx the transcation
+ * @param value the value
+ */
+ public void storeValue(TransactionLocal local, Transaction tx, Object value);
+
+ /**
+ * does Transaction contain object?
+ *
+ * @param local the transaction local
+ * @param tx the transcation
+ * @return true if it has the value
+ */
+ public boolean containsValue(TransactionLocal local, Transaction tx);
+
+ /**
+ * Lock the transaction local in the context of this transaction
+ *
+ * @param local the transaction local
+ * @param tx the transcation
+ * @throws IllegalStateException if the transaction is not active
+ * @throws InterruptedException if the thread is interrupted
+ */
+ public void lock(TransactionLocal local, Transaction tx) throws InterruptedException;
+
+ /**
+ * Unlock the transaction local in the context of this transaction
+ *
+ * @param local the transaction local
+ * @param tx the transcation
+ */
+ public void unlock(TransactionLocal local, Transaction tx);
+}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionIntegrationImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionIntegrationImpl.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionIntegrationImpl.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -25,6 +25,8 @@
import org.jboss.jca.core.spi.recovery.RecoveryPlugin;
import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import org.jboss.jca.core.spi.transaction.local.LocalXAResource;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocalDelegate;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecoveryRegistry;
import org.jboss.jca.core.spi.transaction.usertx.UserTransactionRegistry;
@@ -38,7 +40,6 @@
import org.jboss.logging.Logger;
import org.jboss.security.SubjectFactory;
-import org.jboss.tm.JBossXATerminator;
/**
* This class provide an implementation of the transaction integration for
@@ -61,11 +62,14 @@
private org.jboss.tm.usertx.UserTransactionRegistry utr;
/** XATerminator */
- private JBossXATerminator terminator;
+ private org.jboss.tm.JBossXATerminator terminator;
/** Recovery registry */
private org.jboss.tm.XAResourceRecoveryRegistry rr;
+ /** Transaction local delegate */
+ private org.jboss.tm.TransactionLocalDelegate tld;
+
/**
* Constructor
* @param tm The transaction manager
@@ -73,18 +77,22 @@
* @param utr The user transaction registry
* @param terminator The XA terminator
* @param rr The recovery registry
+ * @param tld The transaction local delegate
*/
public TransactionIntegrationImpl(TransactionManager tm,
TransactionSynchronizationRegistry tsr,
org.jboss.tm.usertx.UserTransactionRegistry utr,
- JBossXATerminator terminator,
- org.jboss.tm.XAResourceRecoveryRegistry rr)
+ org.jboss.tm.JBossXATerminator terminator,
+ org.jboss.tm.XAResourceRecoveryRegistry rr,
+ org.jboss.tm.TransactionLocalDelegate tld)
{
this.tm = tm;
this.tsr = tsr;
this.utr = utr;
this.terminator = terminator;
this.rr = rr;
+ this.tld = tld;
+ log.error("TransactionIntegrationImpl: 6");
}
/**
@@ -133,6 +141,15 @@
}
/**
+ * Get the XATerminator
+ * @return The value
+ */
+ public TransactionLocalDelegate getTransactionLocalDelegate()
+ {
+ return new TransactionLocalDelegateImpl(tld);
+ }
+
+ /**
* Create an XAResourceRecovery instance
*
* @param mcf The managed connection factory
@@ -189,4 +206,13 @@
{
return new XAResourceWrapperImpl(xares, pad, override, productName, productVersion, jndiName);
}
+
+ /**
+ * Create a transaction local instance
+ * @return The value
+ */
+ public TransactionLocal createTransactionLocal()
+ {
+ return new TransactionLocalImpl(this);
+ }
}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalDelegateImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalDelegateImpl.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalDelegateImpl.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.tx.jbossts;
+
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
+
+import javax.transaction.Transaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A transaction local delegate implementation
+ */
+public class TransactionLocalDelegateImpl
+ implements org.jboss.jca.core.spi.transaction.local.TransactionLocalDelegate
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger(TransactionLocalDelegateImpl.class);
+
+ /** Delegator */
+ private org.jboss.tm.TransactionLocalDelegate delegator;
+
+ /**
+ * Constructor
+ * @param delegator The delegator
+ */
+ public TransactionLocalDelegateImpl(org.jboss.tm.TransactionLocalDelegate delegator)
+ {
+ this.delegator = delegator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getValue(TransactionLocal local, Transaction tx)
+ {
+ if (!(local instanceof TransactionLocalImpl))
+ throw new IllegalArgumentException("Local is not a TransactionLocalImpl instance");
+
+ return delegator.getValue((TransactionLocalImpl)local, tx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void storeValue(TransactionLocal local, Transaction tx, Object value)
+ {
+ if (!(local instanceof TransactionLocalImpl))
+ throw new IllegalArgumentException("Local is not a TransactionLocalImpl instance");
+
+ delegator.storeValue((TransactionLocalImpl)local, tx, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean containsValue(TransactionLocal local, Transaction tx)
+ {
+ if (!(local instanceof TransactionLocalImpl))
+ throw new IllegalArgumentException("Local is not a TransactionLocalImpl instance");
+
+ return delegator.containsValue((TransactionLocalImpl)local, tx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void lock(TransactionLocal local, Transaction tx) throws InterruptedException
+ {
+ if (!(local instanceof TransactionLocalImpl))
+ throw new IllegalArgumentException("Local is not a TransactionLocalImpl instance");
+
+ delegator.lock((TransactionLocalImpl)local, tx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unlock(TransactionLocal local, Transaction tx)
+ {
+ if (!(local instanceof TransactionLocalImpl))
+ throw new IllegalArgumentException("Local is not a TransactionLocalImpl instance");
+
+ delegator.unlock((TransactionLocalImpl)local, tx);
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalImpl.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/jbossts/TransactionLocalImpl.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -0,0 +1,263 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.tx.jbossts;
+
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocalDelegate;
+
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+
+/**
+ * A TransactionLocal is similar to ThreadLocal except it is keyed on the
+ * Transactions. A transaction local variable is cleared after the transaction
+ * completes.
+ *
+ * @author <a href="mailto:dain at daingroup.com">Dain Sundstrom</a>
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ */
+public class TransactionLocalImpl extends org.jboss.tm.TransactionLocal
+ implements org.jboss.jca.core.spi.transaction.local.TransactionLocal
+{
+ /**
+ * To simplify null values handling in the preloaded data pool we use
+ * this value instead of 'null'
+ */
+ private static final Object NULL_VALUE = new Object();
+
+ /** The transaction integration */
+ private final TransactionIntegration transactionIntegration;
+
+ /** The delegator */
+ private final TransactionLocalDelegate delegate;
+
+ /**
+ * Creates a transaction local variable.
+ * Using the given transaction integration
+ *
+ * @param ti The transaction intgration
+ */
+ public TransactionLocalImpl(TransactionIntegration ti)
+ {
+ super(ti.getTransactionManager());
+
+ if (ti.getTransactionLocalDelegate() == null)
+ throw new IllegalArgumentException("Null transaction local delegate");
+
+ this.transactionIntegration = ti;
+ this.delegate = ti.getTransactionLocalDelegate();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void lock() throws InterruptedException
+ {
+ lock(getTransaction());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void lock(Transaction transaction) throws InterruptedException
+ {
+ // ignore when there is no transaction
+ if (transaction == null)
+ return;
+
+ delegate.lock(this, transaction);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void unlock()
+ {
+ unlock(getTransaction());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void unlock(Transaction transaction)
+ {
+ // ignore when there is no transaction
+ if (transaction == null)
+ return;
+
+ delegate.unlock(this, transaction);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object initialValue()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getValue(Transaction tx)
+ {
+ return delegate.getValue(this, tx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void storeValue(Transaction tx, Object value)
+ {
+ delegate.storeValue(this, tx, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean containsValue(Transaction tx)
+ {
+ return delegate.containsValue(this, tx);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get()
+ {
+ return get(getTransaction());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get(Transaction transaction)
+ {
+ if (transaction == null)
+ return initialValue();
+
+ Object value = getValue(transaction);
+
+ // is we didn't get a value initalize this object with initialValue()
+ if (value == null)
+ {
+ // get the initial value
+ value = initialValue();
+
+ // if value is null replace it with the null value standin
+ if (value == null)
+ {
+ value = NULL_VALUE;
+ }
+
+ // store the value
+ try
+ {
+ storeValue(transaction, value);
+ }
+ catch (IllegalStateException e)
+ {
+ // depending on the delegate implementation it may be considered an error to
+ // call storeValue after the tx has ended. Further, the tx ending may have
+ // caused the disposal of a previously stored initial value.
+ // for user convenience we ignore such errors and return the initialvalue here.
+ return initialValue();
+ }
+ }
+
+ // if the value is the null standin return null
+ if (value == NULL_VALUE)
+ {
+ return null;
+ }
+
+ // finall return the value
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void set(Object value)
+ {
+ set(getTransaction(), value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void set(Transaction transaction, Object value)
+ {
+ if (transaction == null)
+ throw new IllegalStateException("there is no transaction");
+
+ // If this transaction is unknown, register for synchroniztion callback,
+ // and call initialValue to give subclasses a chance to do some
+ // initialization.
+ if (!containsValue(transaction))
+ {
+ initialValue();
+ }
+
+ // if value is null replace it with the null value standin
+ if (value == null)
+ {
+ value = NULL_VALUE;
+ }
+
+ // finally store the value
+ storeValue(transaction, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Transaction getTransaction()
+ {
+ if (transactionIntegration.getTransactionManager() == null)
+ throw new IllegalStateException("Null transaction manager");
+
+ try
+ {
+ return transactionIntegration.getTransactionManager().getTransaction();
+ }
+ catch (SystemException e)
+ {
+ throw new IllegalStateException("An error occured while getting the " +
+ "transaction associated with the current thread: " + e);
+ }
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/tx/package.html 2011-03-24 20:19:52 UTC (rev 111023)
@@ -0,0 +1,3 @@
+<body>
+This package contains internal transaction related interfaces and classes that are shared across all transaction manager integrations.
+</body>
Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/common/MockConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/common/MockConnectionManager.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/common/MockConnectionManager.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -24,6 +24,7 @@
import org.jboss.jca.core.connectionmanager.AbstractConnectionManager;
import org.jboss.jca.core.connectionmanager.ConnectionRecord;
import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import java.util.Collection;
@@ -72,6 +73,12 @@
}
@Override
+ public TransactionIntegration getTransactionIntegration()
+ {
+ return null;
+ }
+
+ @Override
public boolean isTransactional()
{
return false;
Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/OnePoolTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/OnePoolTestCase.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/pool/OnePoolTestCase.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -25,6 +25,7 @@
import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool;
import org.jboss.jca.core.connectionmanager.pool.strategy.OnePool;
+import org.jboss.jca.core.spi.transaction.local.TransactionLocal;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;
@@ -32,8 +33,6 @@
import javax.security.auth.Subject;
import javax.transaction.Transaction;
-import org.jboss.tm.TransactionLocal;
-
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerTestCase.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManagerTestCase.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -82,7 +82,7 @@
assertNotNull(txConnectionManager.getCachedConnectionManager());
TransactionManager transactionManager = txConnectionManager.getTransactionManager();
- TransactionSynchronizer.setTransactionManager(transactionManager);
+ TransactionSynchronizer.setTransactionIntegration(txConnectionManager.getTransactionIntegration());
assertNotNull(transactionManager);
try
@@ -231,7 +231,7 @@
{
//given
TransactionManager transactionManager = txConnectionManager.getTransactionManager();
- TransactionSynchronizer.setTransactionManager(transactionManager);
+ TransactionSynchronizer.setTransactionIntegration(txConnectionManager.getTransactionIntegration());
try
{
//when
@@ -257,7 +257,7 @@
{
//given
TransactionManager transactionManager = txConnectionManager.getTransactionManager();
- TransactionSynchronizer.setTransactionManager(transactionManager);
+ TransactionSynchronizer.setTransactionIntegration(txConnectionManager.getTransactionIntegration());
//when no transactionManager.begin() called
Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/XATxConnectionManagerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/XATxConnectionManagerTestCase.java 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/connectionmanager/tx/XATxConnectionManagerTestCase.java 2011-03-24 20:19:52 UTC (rev 111023)
@@ -82,7 +82,7 @@
TransactionManager transactionManager = txConnectionManager.getTransactionManager();
assertNotNull(transactionManager);
- TransactionSynchronizer.setTransactionManager(transactionManager);
+ TransactionSynchronizer.setTransactionIntegration(txConnectionManager.getTransactionIntegration());
try
{
@@ -199,7 +199,7 @@
{
//given
TransactionManager transactionManager = txConnectionManager.getTransactionManager();
- TransactionSynchronizer.setTransactionManager(transactionManager);
+ TransactionSynchronizer.setTransactionIntegration(txConnectionManager.getTransactionIntegration());
try
{
//when
@@ -225,7 +225,7 @@
{
//given
TransactionManager transactionManager = txConnectionManager.getTransactionManager();
- TransactionSynchronizer.setTransactionManager(transactionManager);
+ TransactionSynchronizer.setTransactionIntegration(txConnectionManager.getTransactionIntegration());
//when no transactionManager.begin() called
Modified: projects/jboss-jca/trunk/core/src/test/resources/transaction.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/transaction.xml 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/core/src/test/resources/transaction.xml 2011-03-24 20:19:52 UTC (rev 111023)
@@ -237,6 +237,7 @@
<parameter><inject bean="UserTransactionRegistry"/></parameter>
<parameter><inject bean="TransactionManager" property="XATerminator"/></parameter>
<parameter><inject bean="RecoveryManager"/></parameter>
+ <parameter><inject bean="RealTransactionManager"/></parameter>
</constructor>
</bean>
Modified: projects/jboss-jca/trunk/embedded/src/main/resources/transaction.xml
===================================================================
--- projects/jboss-jca/trunk/embedded/src/main/resources/transaction.xml 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/embedded/src/main/resources/transaction.xml 2011-03-24 20:19:52 UTC (rev 111023)
@@ -237,6 +237,7 @@
<parameter><inject bean="UserTransactionRegistry"/></parameter>
<parameter><inject bean="TransactionManager" property="XATerminator"/></parameter>
<parameter><inject bean="RecoveryManager"/></parameter>
+ <parameter><inject bean="RealTransactionManager"/></parameter>
</constructor>
</bean>
Modified: projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/transaction.xml
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/transaction.xml 2011-03-24 16:28:36 UTC (rev 111022)
+++ projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/transaction.xml 2011-03-24 20:19:52 UTC (rev 111023)
@@ -237,6 +237,7 @@
<parameter><inject bean="UserTransactionRegistry"/></parameter>
<parameter><inject bean="TransactionManager" property="XATerminator"/></parameter>
<parameter><inject bean="RecoveryManager"/></parameter>
+ <parameter><inject bean="RealTransactionManager"/></parameter>
</constructor>
</bean>
More information about the jboss-cvs-commits
mailing list