leif        02/01/26 08:58:06

  Modified:    src/java/org/apache/avalon/excalibur/datasource
                        JdbcDataSource.java JdbcConnectionFactory.java
  Log:
  Added the ability to disable the keep-alive feature.
  
  Revision  Changes    Path
  1.14      +16 -7     
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/JdbcDataSource.java
  
  Index: JdbcDataSource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/JdbcDataSource.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JdbcDataSource.java       11 Dec 2001 09:53:28 -0000      1.13
  +++ JdbcDataSource.java       26 Jan 2002 16:58:06 -0000      1.14
  @@ -25,7 +25,7 @@
    * <pre>
    *   &lt;jdbc&gt;
    *     &lt;pool-controller min="<i>5</i>" max="<i>10</i>" 
connection-class="<i>my.overrided.ConnectionClass</i>"&gt;
  - *       &lt;keep-alive&gt;select 1&lt;/keep-alive&gt;
  + *       &lt;keep-alive disable="false"&gt;select 1&lt;/keep-alive&gt;
    *     &lt;/pool-controller&gt;
    *     &lt;driver&gt;<i>com.database.jdbc.JdbcDriver</i>&lt;/driver&gt;
    *     &lt;dburl&gt;<i>jdbc:driver://host/mydb</i>&lt;/dburl&gt;
  @@ -35,7 +35,7 @@
    * </pre>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.13 $ $Date: 2001/12/11 09:53:28 $
  + * @version CVS $Revision: 1.14 $ $Date: 2002/01/26 16:58:06 $
    * @since 4.0
    */
   public class JdbcDataSource
  @@ -69,13 +69,15 @@
               final String user = configuration.getChild( "user" ).getValue( 
null );
               final String passwd = configuration.getChild( "password" 
).getValue( null );
               final Configuration controller = configuration.getChild( 
"pool-controller" );
  -            String keepAlive = controller.getChild( "keep-alive" 
).getValue(null);
  +            String keepAlive = controller.getChild( "keep-alive" ).getValue( 
"SELECT 1" );
  +            final boolean disableKeepAlive = controller.getChild( 
"keep-alive" ).getAttributeAsBoolean( "disable", false );
   
               final int min = controller.getAttributeAsInteger( "min", 1 );
               final int max = controller.getAttributeAsInteger( "max", 3 );
               final long timeout = controller.getAttributeAsLong( "timeout", 
-1 );
               final boolean autoCommit = 
configuration.getChild("auto-commit").getValueAsBoolean(true);
               final boolean oradb = controller.getAttributeAsBoolean( "oradb", 
false );
  +            // Get the JdbcConnection class.  The factory will resolve one 
if null.
               final String connectionClass = controller.getAttribute( 
"connection-class", null );
   
               final int l_max;
  @@ -102,6 +104,7 @@
                   }
               }
   
  +            // Validate the min and max pool size values.
               if ( min < 1 )
               {
                   if (getLogger().isWarnEnabled())
  @@ -142,7 +145,16 @@
                       l_max = max;
                   }
               }
  +            
  +            // If the keepAlive disable attribute was set, then set the 
keepAlive query to null, disabling it.
  +            if (disableKeepAlive)
  +            {
  +                keepAlive = null;
  +            }
   
  +            // If the oradb attribute was set, then override the keepAlive 
query.
  +            // This will override any specified keepalive value even if 
disabled.
  +            //  (Deprecated, but keep this for backwards-compatability)
               if (oradb)
               {
                   keepAlive = "SELECT 1 FROM DUAL";
  @@ -153,11 +165,8 @@
                                        "keep-alive element instead.");
                   }
               }
  -            else
  -            {
  -                keepAlive = "SELECT 1";
  -            }
   
  +            
               final JdbcConnectionFactory factory =
                       new JdbcConnectionFactory( dburl, user, passwd, 
autoCommit, keepAlive, connectionClass );
               final DefaultPoolController poolController = new 
DefaultPoolController(l_max / 4);
  
  
  
  1.10      +40 -24    
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionFactory.java
  
  Index: JdbcConnectionFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JdbcConnectionFactory.java        14 Jan 2002 21:49:34 -0000      1.9
  +++ JdbcConnectionFactory.java        26 Jan 2002 16:58:06 -0000      1.10
  @@ -18,7 +18,7 @@
    * The Factory implementation for JdbcConnections.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.9 $ $Date: 2002/01/14 21:49:34 $
  + * @version CVS $Revision: 1.10 $ $Date: 2002/01/26 16:58:06 $
    * @since 4.0
    */
   public class JdbcConnectionFactory extends AbstractLogEnabled implements 
ObjectFactory
  @@ -34,7 +34,7 @@
       private       Connection m_firstConnection;
   
       /**
  -     * @deprecated  Use the new constructor with the connectionClass
  +     * @deprecated  Use the new constructor with the keepalive and 
connectionClass
        *              specified.
        */
       public JdbcConnectionFactory( final String url,
  @@ -46,27 +46,40 @@
           this(url, username, password, autoCommit, oradb, null);
       }
   
  -   /**
  -    * @ deprecated Use the new constructor with the keepalive and 
connectionClass
  -    *              specified.
  -    */
  -   public JdbcConnectionFactory( final String url,
  -                                 final String username,
  -                                 final String password,
  -                                 final boolean autoCommit,
  -                                 final boolean oradb,
  -                                 final String connectionClass)
  -   {
  -       this(url, username, password, autoCommit, (oradb) ? 
JdbcConnectionFactory.ORACLE_KEEPALIVE : 
JdbcConnectionFactory.DEFAULT_KEEPALIVE, connectionClass);
  -   }
  -
  -   public JdbcConnectionFactory( final String url,
  -                                 final String username,
  -                                 final String password,
  -                                 final boolean autoCommit,
  -                                 final String keepAlive,
  -                                 final String connectionClass)
  -   {
  +    /**
  +     * @ deprecated Use the new constructor with the keepalive and 
connectionClass
  +     *              specified.
  +     */
  +    public JdbcConnectionFactory( final String url,
  +                                  final String username,
  +                                  final String password,
  +                                  final boolean autoCommit,
  +                                  final boolean oradb,
  +                                  final String connectionClass)
  +    {
  +        this(url, username, password, autoCommit, (oradb) ? 
JdbcConnectionFactory.ORACLE_KEEPALIVE : 
JdbcConnectionFactory.DEFAULT_KEEPALIVE, connectionClass);
  +    }
  +    
  +    /**
  +     * Creates and configures a new JdbcConnectionFactory.
  +     *
  +     * @param url full JDBC database url.
  +     * @param username username to use when connecting to the database.
  +     * @param password password to use when connecting to the database.
  +     * @param autoCommit true if connections to the database should operate 
with auto commit
  +     *                   enabled.
  +     * @param keepAlive a query which will be used to check the statis of a 
connection after it
  +     *                  has been idle.  A null value will cause the keep 
alive feature to
  +     *                  be disabled.
  +     * @param connectionClass class of connections created by the factory.
  +     */
  +    public JdbcConnectionFactory( final String url,
  +                                  final String username,
  +                                  final String password,
  +                                  final boolean autoCommit,
  +                                  final String keepAlive,
  +                                  final String connectionClass)
  +    {
           this.m_dburl = url;
           this.m_username = username;
           this.m_password = password;
  @@ -145,8 +158,11 @@
               {
                   try
                   {
  +                    // Support the deprecated connection constructor as well.
  +                    boolean oracleKeepAlive = ( m_keepAlive != null ) && 
m_keepAlive.equalsIgnoreCase( JdbcConnectionFactory.ORACLE_KEEPALIVE );
  +                    
                       Class[] paramTypes = new Class[] { Connection.class, 
boolean.class };
  -                    Object[] params = new Object[] { connection, new 
Boolean( 
this.m_keepAlive.equalsIgnoreCase(JdbcConnectionFactory.ORACLE_KEEPALIVE) ) };
  +                    Object[] params = new Object[] { connection, new 
Boolean( oracleKeepAlive ) };
   
                       Constructor constructor = m_class.getConstructor( 
paramTypes );
                       jdbcConnection = (AbstractJdbcConnection) 
constructor.newInstance( params );
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to