User: lqd     
  Date: 02/03/04 15:35:09

  Modified:    src/main/org/jboss/pool/jdbc/xa/wrapper Tag: Branch_2_4
                        XADataSourceImpl.java
  Log:
  - more changes from proprietary PrintWriter logging to log4j
  - no more NPE at startup
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.1 +70 -40    
jbosspool/src/main/org/jboss/pool/jdbc/xa/wrapper/Attic/XADataSourceImpl.java
  
  Index: XADataSourceImpl.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosspool/src/main/org/jboss/pool/jdbc/xa/wrapper/Attic/XADataSourceImpl.java,v
  retrieving revision 1.1.1.1
  retrieving revision 1.1.1.1.2.1
  diff -u -r1.1.1.1 -r1.1.1.1.2.1
  --- XADataSourceImpl.java     15 May 2001 07:58:24 -0000      1.1.1.1
  +++ XADataSourceImpl.java     4 Mar 2002 23:35:09 -0000       1.1.1.1.2.1
  @@ -4,9 +4,15 @@
   package org.jboss.pool.jdbc.xa.wrapper;
   
   import java.io.PrintWriter;
  -import java.sql.*;
  +import java.sql.Connection;
  +import java.sql.DriverManager;
  +import java.sql.SQLException;
   import java.util.Properties;
  -import javax.sql.*;
  +import javax.sql.XAConnection;
  +import javax.sql.XADataSource;
  +
  +import org.jboss.logging.Logger;
  +import org.jboss.logging.log4j.CategoryWriter;
   
   /**
    * Transactional DataSource wrapper for JDBC 1.0 drivers.  This is very
  @@ -26,6 +32,8 @@
       private int loginTimeout;
       private PrintWriter logWriter;
   
  +    private static Logger log = Logger.getLogger( XADataSourceImpl.class );
  +
       /**
        * Empty constructure for beans, reflection, etc.
        */
  @@ -84,15 +92,31 @@
        */
       public void setProperties(Properties properties) {this.properties = properties;}
   
  -    /**
  -     * Gets the log writer used to record when XAConnections are opened.
  -     */
  -    public PrintWriter getLogWriter() throws SQLException {return logWriter;}
  -
  -    /**
  -     * Sets a log writer used to record when XAConnections are opened.
  -     */
  -    public void setLogWriter(PrintWriter writer) throws SQLException {logWriter = 
writer;}
  +   /**
  +    * Gets the log writer used to record when XAConnections are opened.
  +    */
  +   public PrintWriter getLogWriter()
  +      throws SQLException
  +   {
  +      return logWriter;
  +   }
  +
  +   /**
  +    * Sets a log writer used to record when XAConnections are opened.
  +    */
  +   public void setLogWriter(PrintWriter writer)
  +      throws SQLException
  +   {
  +      if( writer == null )
  +      {
  +         logWriter = null;
  +      }
  +      else
  +      {
  +         if( logWriter == null )
  +            logWriter = new CategoryWriter( log.getCategory() );
  +      }
  +   }
   
       /**
        * This is not used by the current implementation, since the effect would
  @@ -106,37 +130,40 @@
        */
       public void setLoginTimeout(int timeout) throws SQLException {loginTimeout = 
timeout;}
   
  -    /**
  -     * Gets an XAConnection.  This first gets a java.sql.Connection from the
  -     * underlying driver, and then wraps it in an XAConnection and XAResource.
  -     * This uses the URL, user, password, and properties (or as many as you
  -     * have specified) to make the connection.
  -     */
  -    public XAConnection getXAConnection() throws SQLException {
  -        Connection con;
  -        if(user != null && user.length() > 0)
  -            con = DriverManager.getConnection(url, user, password);
  -        else if(properties != null)
  -            con = DriverManager.getConnection(url, properties);
  -        else
  -            con = DriverManager.getConnection(url);
  -
  -        try {
  -            con.setAutoCommit(false);
  -        } catch(SQLException e) {
  -            if(logWriter != null)
  -                logWriter.println("XADataSource unable to disable auto-commit on 
"+con.getClass().getName());
  -        }
  -
  -        XAResourceImpl res = new XAResourceImpl(con);
  -        XAConnectionImpl xacon = new XAConnectionImpl(con, res);
  -        res.setXAConnection(xacon);
  +   /**
  +    * Gets an XAConnection.  This first gets a java.sql.Connection from the
  +    * underlying driver, and then wraps it in an XAConnection and XAResource.
  +    * This uses the URL, user, password, and properties (or as many as you
  +    * have specified) to make the connection.
  +    */
  +   public XAConnection getXAConnection()
  +      throws SQLException
  +   {
  +      Connection con;
  +      if(user != null && user.length() > 0)
  +         con = DriverManager.getConnection(url, user, password);
  +      else if(properties != null)
  +         con = DriverManager.getConnection(url, properties);
  +      else
  +         con = DriverManager.getConnection(url);
  +
  +      try
  +      {
  +         con.setAutoCommit(false);
  +      } catch(SQLException e)
  +      {
  +         log.warn( "Unable to disable auto-commit on " + con.getClass().getName() );
  +      }
  +
  +      XAResourceImpl res = new XAResourceImpl(con);
  +      XAConnectionImpl xacon = new XAConnectionImpl(con, res);
  +      res.setXAConnection(xacon);
   
  -        if(logWriter != null)
  -            logWriter.println(getClass().getName()+" created new Connection 
("+con.getClass().getName()+") with XAResource "+res.getClass().getName()+" and 
XAConnection "+xacon.getClass().getName()+".");
  +      if( log.isDebugEnabled() )
  +         log.debug( "created new Connection(" + con.getClass().getName() + ") with 
XAResource " + res.getClass().getName() + " and XAConnection " + 
xacon.getClass().getName() + "." );
   
  -        return xacon;
  -    }
  +      return xacon;
  +   }
   
       /**
        * Gets an XAConnection.  This first gets a java.sql.Connection from the
  @@ -151,3 +178,6 @@
           return getXAConnection();
       }
   }
  +/*
  +vim:tabstop=3:et:shiftwidth=3
  +*/
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to