avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource JdbcConnectionFactory.java
Date Fri, 27 Sep 2002 13:44:12 GMT
cziegeler    2002/09/27 06:44:12

  Modified:    datasource/src/java/org/apache/avalon/excalibur/datasource
                        JdbcConnectionFactory.java
  Log:
  Fixing bug 11400 by applying patch from vgritsenko@apache.org (Vadim Gritsenko)
  
  Revision  Changes    Path
  1.15      +57 -45    jakarta-avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionFactory.java
  
  Index: JdbcConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionFactory.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JdbcConnectionFactory.java	4 Apr 2002 07:09:53 -0000	1.14
  +++ JdbcConnectionFactory.java	27 Sep 2002 13:44:11 -0000	1.15
  @@ -27,7 +27,8 @@
       private final String m_password;
       private final boolean m_autoCommit;
       private final String m_keepAlive;
  -    private final Class m_class;
  +    private final String m_connectionClass;
  +    private Class m_class;
       private static final String DEFAULT_KEEPALIVE = "SELECT 1";
       private static final String ORACLE_KEEPALIVE = JdbcConnectionFactory.DEFAULT_KEEPALIVE
+ " FROM DUAL";
       private Connection m_firstConnection;
  @@ -84,8 +85,7 @@
           this.m_password = password;
           this.m_autoCommit = autoCommit;
           this.m_keepAlive = keepAlive;
  -
  -        Class clazz = null;
  +        this.m_connectionClass = connectionClass;
   
           try
           {
  @@ -98,21 +98,7 @@
                   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
);
  +            init( m_firstConnection );
           }
           catch( Exception e )
           {
  @@ -121,8 +107,25 @@
               //  as it can be a real pain to track down the cause when this happens.
               //System.out.println( "Unable to get specified connection class: " + e );
           }
  +    }
  +
  +    private void init( Connection connection ) throws Exception
  +    {
  +        String className = m_connectionClass;
  +        if( null == className )
  +        {
  +            try
  +            {
  +                java.lang.reflect.Method meth = connection.getClass().getMethod( "getHoldability",
new Class[]{} );
  +                className = "org.apache.avalon.excalibur.datasource.Jdbc3Connection";
  +            }
  +            catch( Exception e )
  +            {
  +                className = "org.apache.avalon.excalibur.datasource.JdbcConnection";
  +            }
  +        }
   
  -        this.m_class = clazz;
  +        this.m_class = Thread.currentThread().getContextClassLoader().loadClass( className
);
       }
   
       public Object newInstance() throws Exception
  @@ -146,43 +149,52 @@
               m_firstConnection = null;
           }
   
  -        if( null != this.m_class )
  +        if( null == this.m_class )
           {
               try
               {
  -                Class[] paramTypes = new Class[]{Connection.class, String.class};
  -                Object[] params = new Object[]{connection, this.m_keepAlive};
  -
  -                Constructor constructor = m_class.getConstructor( paramTypes );
  -                jdbcConnection = (AbstractJdbcConnection)constructor.newInstance( params
);
  +                init( connection );
               }
               catch( Exception e )
               {
  -                try
  +                if( getLogger().isDebugEnabled() )
                   {
  -                    // Support the deprecated connection constructor as well.
  -                    boolean oracleKeepAlive = ( m_keepAlive != null ) && m_keepAlive.equalsIgnoreCase(
JdbcConnectionFactory.ORACLE_KEEPALIVE );
  +                    getLogger().debug( "Exception in JdbcConnectionFactory.newInstance:",
e );
  +                }
  +                throw new NoValidConnectionException( "No valid JdbcConnection class available"
);
  +            }
  +        }
   
  -                    Class[] paramTypes = new Class[]{Connection.class, boolean.class};
  -                    Object[] params = new Object[]{connection, new Boolean( oracleKeepAlive
)};
  +        try
  +        {
  +            Class[] paramTypes = new Class[]{Connection.class, String.class};
  +            Object[] params = new Object[]{connection, this.m_keepAlive};
   
  -                    Constructor constructor = m_class.getConstructor( paramTypes );
  -                    jdbcConnection = (AbstractJdbcConnection)constructor.newInstance( params
);
  -                }
  -                catch( Exception ie )
  -                {
  -                    if( getLogger().isDebugEnabled() )
  -                    {
  -                        getLogger().debug( "Exception in JdbcConnectionFactory.newInstance:",
ie );
  -                    }
  +            Constructor constructor = m_class.getConstructor( paramTypes );
  +            jdbcConnection = (AbstractJdbcConnection)constructor.newInstance( params );
  +        }
  +        catch( Exception e )
  +        {
  +            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( oracleKeepAlive
)};
   
  -                    throw new NoValidConnectionException( ie.getMessage() );
  +                Constructor constructor = m_class.getConstructor( paramTypes );
  +                jdbcConnection = (AbstractJdbcConnection)constructor.newInstance( params
);
  +            }
  +            catch( Exception ie )
  +            {
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    getLogger().debug( "Exception in JdbcConnectionFactory.newInstance:",
ie );
                   }
  +
  +                throw new NoValidConnectionException( ie.getMessage() );
               }
  -        }
  -        else
  -        {
  -            throw new NoValidConnectionException( "No valid JdbcConnection class available"
);
           }
   
           jdbcConnection.enableLogging( getLogger() );
  
  
  

--
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