User: mulder  
  Date: 00/10/20 22:20:22

  Modified:    src/main/org/jboss/minerva/factories
                        XAConnectionFactory.java
  Log:
  Make jBoss work with Oracle XADataSource driver.
  Not yet a very elegant solution - we need to be able to use a different
      Xid implementation class per pool for this to really work right.
  
  The requirements of the Oracle driver were:
   - Xid must be instanceof OracleXid
   - Global and Branch IDs must be exactly 64 bytes
   - RM that end is called on must be *exactly* the same as start
        was called on (XAConnection.getXAResource returns a different
        instance each time *despite* the documented 1-to-1 relation)
   - Can't execute DDL (create/drop table, etc) within a transaction
  
  Haven't tested this well with multiple data sources - that's next.
  
  Revision  Changes    Path
  1.10      +12 -6     
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XAConnectionFactory.java  2000/10/19 20:01:19     1.9
  +++ XAConnectionFactory.java  2000/10/21 05:20:22     1.10
  @@ -25,6 +25,7 @@
   import org.jboss.minerva.xa.XAConnectionImpl;
   import org.jboss.logging.Logger;
   
  +
   /**
    * Object factory for JDBC 2.0 standard extension XAConnections.  You pool the
    * XAConnections instead of the java.sql.Connections since with vendor
  @@ -38,7 +39,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.9 $
  + * @version $Revision: 1.10 $
    * @author Aaron Mulder ([EMAIL PROTECTED])
    */
   public class XAConnectionFactory extends PoolObjectFactory {
  @@ -51,7 +52,7 @@
       private TransactionListener transListener;
       private ObjectPool pool;
       private PrintWriter log;
  -    private HashMap wrapperTx;
  +    private HashMap wrapperTx, rms;
       private TransactionManager tm;
   
       /**
  @@ -61,6 +62,7 @@
       public XAConnectionFactory() throws NamingException {
           ctx = new InitialContext();
           wrapperTx = new HashMap();
  +        rms = new HashMap();
           errorListener = new ConnectionEventListener() {
               public void connectionErrorOccurred(ConnectionEvent evt) {
                   if(pool.isInvalidateOnError()) {
  @@ -89,7 +91,9 @@
                   try {
                       if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
                           trans = tm.getTransaction();
  -                        trans.delistResource(con.getXAResource(), status);
  +                        XAResource res = 
(XAResource)rms.get(con);//con.getXAResource();
  +                        trans.delistResource(res, status);
  +                        rms.remove(con);
                       }
                   } catch(Exception e) {
                       Logger.exception(e);
  @@ -225,13 +229,15 @@
        */
       public Object prepareObject(Object pooledObject) {
           XAConnection con = (XAConnection)pooledObject;
  +        con.addConnectionEventListener(listener);
           Transaction trans = null;
           try {
               if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
                   trans = tm.getTransaction();
  -                trans.enlistResource(con.getXAResource());
  -                con.addConnectionEventListener(listener);
  -                if(log != null) log.println("Enlisted with transaction.");
  +                XAResource res = con.getXAResource();
  +                trans.enlistResource(res);
  +                rms.put(con, res);
  +                if(log != null) log.println("Resource '"+res+"' enlisted for 
'"+con+"'.");
               } else {
                   if(log != null) log.println("No transaction right now.");
               }
  
  
  

Reply via email to