User: mulder
Date: 00/06/02 19:20:47
Modified: src/main/org/jboss/minerva/factories
JDBCConnectionFactory.java XAConnectionFactory.java
Log:
Change the factories to log using a log writer rather than Sysouts.
Fix a bug in XAConnectionFactory with JDBC 1 wrappers where a SQLException
didn't release the connection back to the pool if there was no current
Transaction.
Revision Changes Path
1.2 +5 -3
jboss/src/main/org/jboss/minerva/factories/JDBCConnectionFactory.java
Index: JDBCConnectionFactory.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/minerva/factories/JDBCConnectionFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JDBCConnectionFactory.java 2000/06/02 13:48:42 1.1
+++ JDBCConnectionFactory.java 2000/06/03 02:20:46 1.2
@@ -6,6 +6,7 @@
*/
package org.jboss.minerva.factories;
+import java.io.PrintWriter;
import java.sql.*;
import java.util.Properties;
import org.jboss.minerva.pools.*;
@@ -17,7 +18,7 @@
* you're interested in creating transactional-aware connections, see
* XAConnectionFactory, which complies with the JDBC 2.0 standard extension.
* @see org.jboss.minerva.factories.XAConnectionFactory
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
public class JDBCConnectionFactory extends PoolObjectFactory {
@@ -25,6 +26,7 @@
private Properties props;
private String userName;
private String password;
+ private PrintWriter log;
/**
* Creates a new factory. You must configure it with JDBC properties
@@ -79,8 +81,8 @@
/**
* Validates that connection properties were set (at least a URL).
*/
- public void poolStarted(ObjectPool pool) {
- super.poolStarted(pool);
+ public void poolStarted(ObjectPool pool, PrintWriter log) {
+ super.poolStarted(pool, log);
if(url == null)
throw new IllegalStateException("Must specify JDBC connection URL to
"+getClass().getName());
}
1.2 +14 -8
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XAConnectionFactory.java 2000/06/02 13:48:42 1.1
+++ XAConnectionFactory.java 2000/06/03 02:20:46 1.2
@@ -6,6 +6,7 @@
*/
package org.jboss.minerva.factories;
+import java.io.PrintWriter;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
@@ -21,7 +22,7 @@
* and any work done isn't associated with the java.sql.Connection anyway.
* <P><B>Note:</B> This implementation requires that the TransactionManager
* be bound to a JNDI name.</P>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
public class XAConnectionFactory extends PoolObjectFactory {
@@ -33,6 +34,7 @@
private ConnectionEventListener listener;
private TransactionListener transListener;
private ObjectPool pool;
+ private PrintWriter log;
/**
* Creates a new factory. You must set the XADataSource and
@@ -51,16 +53,19 @@
private void closeConnection(ConnectionEvent evt, int status) {
XAConnection con = (XAConnection)evt.getSource();
+ boolean transaction = false;
try {
TransactionManager tm =
(TransactionManager)ctx.lookup(tmJndiName);
- if(tm.getStatus() != Status.STATUS_NO_TRANSACTION)
+ if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
+ transaction = true;
tm.getTransaction().delistResource(con.getXAResource(),
status);
+ }
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("Unable to deregister with
TransactionManager: "+e);
}
con.removeConnectionEventListener(listener);
- if(!(con instanceof XAConnectionImpl))
+ if(!transaction || !(con instanceof XAConnectionImpl))
pool.releaseObject(con);
}
};
@@ -120,8 +125,9 @@
/**
* Verifies that the data source and transaction manager are accessible.
*/
- public void poolStarted(ObjectPool pool) {
- super.poolStarted(pool);
+ public void poolStarted(ObjectPool pool, PrintWriter log) {
+ super.poolStarted(pool, log);
+ this.log = log;
this.pool = pool;
if(source == null)
throw new IllegalStateException("Must specify XADataSource to
"+getClass().getName());
@@ -162,14 +168,14 @@
TransactionManager tm = (TransactionManager)ctx.lookup(tmJndiName);
if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
tm.getTransaction().enlistResource(con.getXAResource());
-System.out.println("Enlisted with transaction.");
+ con.addConnectionEventListener(listener);
+ if(log != null) log.println("Enlisted with transaction.");
}
-System.out.println("No transaction right now.");
+ if(log != null) log.println("No transaction right now.");
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("Unable to register with TransactionManager:
"+e);
}
- con.addConnectionEventListener(listener);
if(con instanceof XAConnectionImpl)
((XAConnectionImpl)con).setTransactionListener(transListener);
return con;