avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/logger/factory AsyncLogTargetFactory.java
Date Mon, 14 Jan 2002 21:49:35 GMT
bloritsch    02/01/14 13:49:35

  Modified:    src/java/org/apache/avalon/excalibur/datasource
                        JdbcConnectionFactory.java
               src/java/org/apache/avalon/excalibur/logger/factory
                        AsyncLogTargetFactory.java
  Log:
  make thread for async logtarget a daemon thread, move dynamic class management in JdbcConnectionFactory
to constructor, fix problem with not being able to load Jdbc3Connection
  
  Revision  Changes    Path
  1.9       +61 -33    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JdbcConnectionFactory.java	11 Dec 2001 09:53:28 -0000	1.8
  +++ JdbcConnectionFactory.java	14 Jan 2002 21:49:34 -0000	1.9
  @@ -18,7 +18,7 @@
    * The Factory implementation for JdbcConnections.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.8 $ $Date: 2001/12/11 09:53:28 $
  + * @version CVS $Revision: 1.9 $ $Date: 2002/01/14 21:49:34 $
    * @since 4.0
    */
   public class JdbcConnectionFactory extends AbstractLogEnabled implements ObjectFactory
  @@ -28,9 +28,10 @@
       private final String m_password;
       private final boolean m_autoCommit;
       private final String m_keepAlive;
  -    private       String m_connectionClass;
  +    private final Class  m_class;
       private final static String DEFAULT_KEEPALIVE = "SELECT 1";
       private final static String ORACLE_KEEPALIVE = JdbcConnectionFactory.DEFAULT_KEEPALIVE
+ " FROM DUAL";
  +    private       Connection m_firstConnection;
   
       /**
        * @deprecated  Use the new constructor with the connectionClass
  @@ -66,62 +67,89 @@
                                    final String keepAlive,
                                    final String connectionClass)
      {
  -       this.m_dburl = url;
  -       this.m_username = username;
  -       this.m_password = password;
  -       this.m_autoCommit = autoCommit;
  -       this.m_keepAlive = keepAlive;
  -       this.m_connectionClass = connectionClass;
  -   }
  +        this.m_dburl = url;
  +        this.m_username = username;
  +        this.m_password = password;
  +        this.m_autoCommit = autoCommit;
  +        this.m_keepAlive = keepAlive;
   
  -    public Object newInstance() throws Exception
  -    {
  -        JdbcConnection jdbcConnection = null;
  -        Connection connection = null;
  +        Class clazz = null;
   
  -        if( null == m_username )
  +        try
           {
  -            connection = DriverManager.getConnection( m_dburl );
  +            if( null == m_username )
  +            {
  +                m_firstConnection = DriverManager.getConnection( m_dburl );
  +            }
  +            else
  +            {
  +                m_firstConnection = DriverManager.getConnection( m_dburl, m_username, m_password
);
  +            }
  +
  +            String className = connectionClass;
  +            if ( null == className )
  +            {
  +                try
  +                {
  +                    java.lang.reflect.Method meth = m_firstConnection.getClass().getMethod("getHoldability",
new Class[] {});
  +                    className = "org.apache.avalon.excalibur.datasource.Jdbc3Connection";
  +                }
  +                catch (Exception e)
  +                {
  +                    className = "org.apache.avalon.excalibur.datasource.JdbcConnection";
  +                }
  +            }
  +
  +            clazz = Thread.currentThread().getContextClassLoader().loadClass( className
);
           }
  -        else
  +        catch (Exception e)
           {
  -            connection = DriverManager.getConnection( m_dburl, m_username, m_password );
  +            // ignore for now
           }
   
  -        if ( null == this.m_connectionClass )
  +        this.m_class = clazz;
  +    }
  +
  +    public Object newInstance() throws Exception
  +    {
  +        AbstractJdbcConnection jdbcConnection = null;
  +        Connection connection = m_firstConnection;
  +
  +        if ( null == connection )
           {
  -            try
  +            if( null == m_username )
               {
  -                java.lang.reflect.Method meth = connection.getClass().getMethod("getHoldability",
new Class[] {});
  -                this.m_connectionClass = "org.apache.avalon.excalibur.datasource.Jdbc3Connection";
  +                connection = DriverManager.getConnection( m_dburl );
               }
  -            catch (Exception e)
  +            else
               {
  -                this.m_connectionClass = "org.apache.avalon.excalibur.datasource.JdbcConnection";
  +                connection = DriverManager.getConnection( m_dburl, m_username, m_password
);
               }
           }
  +        else
  +        {
  +            m_firstConnection = null;
  +        }
   
  -        if ( null != this.m_connectionClass )
  +        if ( null != this.m_class )
           {
               try
               {
  -                Class clazz = Thread.currentThread().getContextClassLoader().loadClass(
this.m_connectionClass );
                   Class[] paramTypes = new Class[] { Connection.class, String.class };
                   Object[] params = new Object[] { connection, this.m_keepAlive };
   
  -                Constructor constructor = clazz.getConstructor( paramTypes );
  -                jdbcConnection = (JdbcConnection) constructor.newInstance( params );
  +                Constructor constructor = m_class.getConstructor( paramTypes );
  +                jdbcConnection = (AbstractJdbcConnection) constructor.newInstance( params
);
               }
               catch ( Exception e )
               {
                   try
                   {
  -                    Class clazz = Thread.currentThread().getContextClassLoader().loadClass(
this.m_connectionClass );
                       Class[] paramTypes = new Class[] { Connection.class, boolean.class
};
                       Object[] params = new Object[] { connection, new Boolean( this.m_keepAlive.equalsIgnoreCase(JdbcConnectionFactory.ORACLE_KEEPALIVE)
) };
   
  -                    Constructor constructor = clazz.getConstructor( paramTypes );
  -                    jdbcConnection = (JdbcConnection) constructor.newInstance( params );
  +                    Constructor constructor = m_class.getConstructor( paramTypes );
  +                    jdbcConnection = (AbstractJdbcConnection) constructor.newInstance(
params );
                   }
                   catch ( Exception ie )
                   {
  @@ -156,13 +184,13 @@
   
       public Class getCreatedClass()
       {
  -        return JdbcConnection.class;
  +        return m_class;
       }
   
       public void decommission(Object object) throws Exception
       {
  -        if (object instanceof JdbcConnection) {
  -            ((JdbcConnection) object).dispose();
  +        if (object instanceof AbstractJdbcConnection) {
  +            ((AbstractJdbcConnection) object).dispose();
           }
       }
   }
  
  
  
  1.4       +2 -1      jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/logger/factory/AsyncLogTargetFactory.java
  
  Index: AsyncLogTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/logger/factory/AsyncLogTargetFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AsyncLogTargetFactory.java	11 Dec 2001 09:53:30 -0000	1.3
  +++ AsyncLogTargetFactory.java	14 Jan 2002 21:49:35 -0000	1.4
  @@ -47,7 +47,7 @@
    * </p>
    *
    * @author <a href="mailto:giacomo@apache,org">Giacomo Pati</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2001/12/11 09:53:30 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/01/14 21:49:35 $
    * @since 4.0
    */
   public final class AsyncLogTargetFactory
  @@ -97,6 +97,7 @@
           }
           final Thread thread = new Thread( asyncTarget );
           thread.setPriority( thread_priority );
  +        thread.setDaemon( true );
           thread.start();
           return asyncTarget;
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message