User: mulder
Date: 00/10/28 09:05:32
Modified: src/main/org/jboss/minerva/factories
XAConnectionFactory.java
Log:
Fix logic for connections that are left open after the transaction ends.
They shouldn't be released to the pool when the transaction ends.
When the connection is closed, it should be released to the pool if its
RM is not involved with a transaction, not if there's no global transaction
(since if it was associated and then the transaction ends but the RM is
not enlisted again later even though a new transaction starts, it should
be returned to the pool when closed).
Revision Changes Path
1.12 +17 -5
jboss/src/main/org/jboss/minerva/factories/XAConnectionFactory.java
Index: XAConnectionFactory.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/minerva/factories/XAConnectionFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XAConnectionFactory.java 2000/10/25 23:54:37 1.11
+++ XAConnectionFactory.java 2000/10/28 16:05:31 1.12
@@ -23,6 +23,7 @@
import org.jboss.minerva.pools.PoolObjectFactory;
import org.jboss.minerva.xa.TransactionListener;
import org.jboss.minerva.xa.XAConnectionImpl;
+import org.jboss.minerva.xa.XAResourceImpl;
import org.jboss.logging.Logger;
@@ -39,7 +40,7 @@
* connection, the same previous connection will be returned. Otherwise,
* you won't be able to share changes across connections like you can with
* the native JDBC 2 Standard Extension implementations.</P>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
public class XAConnectionFactory extends PoolObjectFactory {
@@ -109,10 +110,13 @@
// Real XAConnection -> not associated w/ transaction
pool.releaseObject(con);
} else {
- if(trans == null) {
+ XAConnectionImpl xaCon = (XAConnectionImpl)con;
+ if(!((XAResourceImpl)xaCon.getXAResource()).isTransaction()) {
// Wrapper - we can only release it if there's no current
transaction
+ // Can't just check TM because con may have been committed
but left open
+ // so if there's a current transaction it may not apply
to the con.
try {
- ((XAConnectionImpl)con).rollback();
+ xaCon.rollback();
} catch(SQLException e) {
pool.markObjectAsInvalid(con);
}
@@ -126,21 +130,29 @@
};
transListener = new TransactionListener() {
public void transactionFinished(XAConnectionImpl con) {
- con.removeConnectionEventListener(errorListener);
con.clearTransactionListener();
Object tx = wrapperTx.remove(con);
if(tx != null)
wrapperTx.remove(tx);
+ try {
+ con.removeConnectionEventListener(errorListener);
+ } catch(IllegalArgumentException e) {
+ return; // connection was not closed, but transaction ended
+ }
pool.releaseObject(con);
}
public void transactionFailed(XAConnectionImpl con) {
- con.removeConnectionEventListener(errorListener);
con.clearTransactionListener();
Object tx = wrapperTx.remove(con);
if(tx != null)
wrapperTx.remove(tx);
pool.markObjectAsInvalid(con);
+ try {
+ con.removeConnectionEventListener(errorListener);
+ } catch(IllegalArgumentException e) {
+ return; // connection was not closed, but transaction ended
+ }
pool.releaseObject(con);
}
};