commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp PoolableConnectionFactory.java BasicDataSourceFactory.java BasicDataSource.java
Date Mon, 25 Aug 2003 16:17:45 GMT
dirkv       2003/08/25 09:17:45

  Modified:    dbcp/src/java/org/apache/commons/dbcp
                        PoolableConnectionFactory.java
                        BasicDataSourceFactory.java BasicDataSource.java
  Log:
  Bugzilla Bug 18550: Add defaultTransactionIsolation to BasicDataSource
  
  - requested feature implemented
  
  Revision  Changes    Path
  1.11      +76 -3     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java
  
  Index: PoolableConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PoolableConnectionFactory.java	22 Aug 2003 16:59:11 -0000	1.10
  +++ PoolableConnectionFactory.java	25 Aug 2003 16:17:45 -0000	1.11
  @@ -74,6 +74,7 @@
    * @author Rodney Waldhoff
    * @author Glenn L. Nielsen
    * @author James House (<a href="mailto:james@interobjective.com">james@interobjective.com</a>)
  + * @author Dirk Verbeeck
    * @version $Id$
    */
   public class PoolableConnectionFactory implements PoolableObjectFactory {
  @@ -104,6 +105,27 @@
        * @param validationQuery a query to use to {@link #validateObject validate} {@link
Connection}s.  Should return at least one row. May be <tt>null</tt>
        * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
        * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
  +     * @param defaultTransactionIsolation the default "Transaction Isolation" setting for
returned {@link Connection}s
  +     */
  +    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory
stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit,
int defaultTransactionIsolation) {
  +        _connFactory = connFactory;
  +        _pool = pool;
  +        _pool.setFactory(this);
  +        _stmtPoolFactory = stmtPoolFactory;
  +        _validationQuery = validationQuery;
  +        _defaultReadOnly = defaultReadOnly;
  +        _defaultAutoCommit = defaultAutoCommit;
  +        _defaultTransactionIsolation = defaultTransactionIsolation;
  +    }
  +
  +    /**
  +     * Create a new <tt>PoolableConnectionFactory</tt>.
  +     * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link
Connection}s
  +     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
  +     * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link
KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt>
to disable {@link java.sql.PreparedStatement} pooling
  +     * @param validationQuery a query to use to {@link #validateObject validate} {@link
Connection}s.  Should return at least one row. May be <tt>null</tt>
  +     * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
  +     * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
        * @param config the AbandonedConfig if tracing SQL objects
        * @deprecated AbandonedConfig is now deprecated.
        */
  @@ -127,6 +149,39 @@
       }
   
       /**
  +     * Create a new <tt>PoolableConnectionFactory</tt>.
  +     * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link
Connection}s
  +     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
  +     * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link
KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt>
to disable {@link java.sql.PreparedStatement} pooling
  +     * @param validationQuery a query to use to {@link #validateObject validate} {@link
Connection}s.  Should return at least one row. May be <tt>null</tt>
  +     * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
  +     * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
  +     * @param defaultTransactionIsolation the default "Transaction Isolation" setting for
returned {@link Connection}s
  +     * @param config the AbandonedConfig if tracing SQL objects
  +     * @deprecated AbandonedConfig is now deprecated.
  +     */
  +    public PoolableConnectionFactory(
  +        ConnectionFactory connFactory,
  +        ObjectPool pool,
  +        KeyedObjectPoolFactory stmtPoolFactory,
  +        String validationQuery,
  +        boolean defaultReadOnly,
  +        boolean defaultAutoCommit,
  +        int defaultTransactionIsolation,
  +        AbandonedConfig config) {
  +            
  +        _connFactory = connFactory;
  +        _pool = pool;
  +        _config = config;
  +        _pool.setFactory(this);
  +        _stmtPoolFactory = stmtPoolFactory;
  +        _validationQuery = validationQuery;
  +        _defaultReadOnly = defaultReadOnly;
  +        _defaultAutoCommit = defaultAutoCommit;
  +        _defaultTransactionIsolation = defaultTransactionIsolation;
  +    }
  +
  +    /**
        * Sets the {@link ConnectionFactory} from which to obtain base {@link Connection}s.
        * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link
Connection}s
        */
  @@ -189,6 +244,14 @@
           _defaultAutoCommit = defaultAutoCommit;
       }
   
  +    /**
  +     * Sets the default "Transaction Isolation" setting for borrowed {@link Connection}s
  +     * @param defaultTransactionIsolation the default "Transaction Isolation" setting for
returned {@link Connection}s
  +     */
  +    public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
  +        _defaultTransactionIsolation = defaultTransactionIsolation;
  +    }
  +
       synchronized public Object makeObject() throws Exception {
           Connection conn = _connFactory.createConnection();
           if(null != _stmtPoolFactory) {
  @@ -271,6 +334,9 @@
               Connection conn = (Connection)obj;
               conn.setAutoCommit(_defaultAutoCommit);
               conn.setReadOnly(_defaultReadOnly);
  +            if (_defaultTransactionIsolation != UNKNOWN_TRANSACTIONISOLATION) {
  +                conn.setTransactionIsolation(_defaultTransactionIsolation);
  +            }
           }
       }
   
  @@ -280,9 +346,16 @@
       protected KeyedObjectPoolFactory _stmtPoolFactory = null;
       protected boolean _defaultReadOnly = false;
       protected boolean _defaultAutoCommit = true;
  +    protected int _defaultTransactionIsolation = UNKNOWN_TRANSACTIONISOLATION;
       
       /**
        * @deprecated AbandonedConfig is now deprecated.
        */
       protected AbandonedConfig _config = null;
  +
  +    /**
  +     * Internal constant to indicate the level is not set. 
  +     */
  +	static final int UNKNOWN_TRANSACTIONISOLATION = -1;
  +
   }
  
  
  
  1.8       +38 -4     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java
  
  Index: BasicDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BasicDataSourceFactory.java	22 Aug 2003 16:08:31 -0000	1.7
  +++ BasicDataSourceFactory.java	25 Aug 2003 16:17:45 -0000	1.8
  @@ -62,6 +62,7 @@
   package org.apache.commons.dbcp;
   
   import java.io.ByteArrayInputStream;
  +import java.sql.Connection;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Properties;
  @@ -81,6 +82,7 @@
    * <code>BasicDataSource</code> bean properties.</p>
    *
    * @author Craig R. McClanahan
  + * @author Dirk Verbeeck
    * @version $Revision$ $Date$
    */
   
  @@ -134,6 +136,38 @@
           if (ra != null) {
               dataSource.setDefaultReadOnly
                   (Boolean.valueOf(ra.getContent().toString()).booleanValue());
  +        }
  +
  +        ra = ref.get("defaultTransactionIsolation");
  +        if (ra != null) {
  +            String value = ra.getContent().toString();
  +            int level = PoolableConnectionFactory.UNKNOWN_TRANSACTIONISOLATION;
  +            if ("NONE".equalsIgnoreCase(value)) {
  +                level = Connection.TRANSACTION_NONE;
  +            }
  +            else if ("READ_COMMITTED".equalsIgnoreCase(value)) {
  +                level = Connection.TRANSACTION_READ_COMMITTED;
  +            }
  +            else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) {
  +                level = Connection.TRANSACTION_READ_UNCOMMITTED;
  +            }
  +            else if ("REPEATABLE_READ".equalsIgnoreCase(value)) {
  +                level = Connection.TRANSACTION_REPEATABLE_READ;
  +            }
  +            else if ("SERIALIZABLE".equalsIgnoreCase(value)) {
  +                level = Connection.TRANSACTION_SERIALIZABLE;
  +            }
  +            else {
  +                try {
  +                    level = Integer.parseInt(value);
  +                } catch (NumberFormatException e) {
  +                    System.err.println("Could not parse defaultTransactionIsolation: "
+ value);
  +                    System.err.println("WARNING: defaultTransactionIsolation not set");
  +                    System.err.println("using default value of database driver");
  +                    level = PoolableConnectionFactory.UNKNOWN_TRANSACTIONISOLATION;
  +                }
  +            }
  +            dataSource.setDefaultTransactionIsolation(level);
           }
   
           ra = ref.get("driverClassName");
  
  
  
  1.21      +18 -4     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java
  
  Index: BasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- BasicDataSource.java	22 Aug 2003 16:08:31 -0000	1.20
  +++ BasicDataSource.java	25 Aug 2003 16:17:45 -0000	1.21
  @@ -82,6 +82,7 @@
    *
    * @author Glenn L. Nielsen
    * @author Craig R. McClanahan
  + * @author Dirk Verbeeck
    * @version $Revision$ $Date$
    */
   
  @@ -118,6 +119,18 @@
           this.defaultReadOnly = defaultReadOnly;
       }
   
  +    /**
  +     * The default TransactionIsolation state of connections created by this pool.
  +     */
  +    protected int defaultTransactionIsolation = PoolableConnectionFactory.UNKNOWN_TRANSACTIONISOLATION;
  +
  +    public int getDefaultTransactionIsolation() {
  +        return this.defaultTransactionIsolation;
  +    }
  +
  +    public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
  +        this.defaultTransactionIsolation = defaultTransactionIsolation;
  +    }
   
       /**
        * The fully qualified Java class name of the JDBC driver to be used.
  @@ -710,6 +723,7 @@
                                                 validationQuery,
                                                 defaultReadOnly,
                                                 defaultAutoCommit,
  +                                              defaultTransactionIsolation,
                                                 abandonedConfig);
               if (connectionFactory == null) {
                   throw new SQLException("Cannot create PoolableConnectionFactory");
  
  
  

Mime
View raw message