You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/06/12 01:51:00 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionFactoryPooledImpl.java

arminw      2003/06/11 16:51:00

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        ConnectionFactoryPooledImpl.java
  Log:
  break validation query loop after
  more that 100 invalid attempts
  
  Revision  Changes    Path
  1.7       +11 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
  
  Index: ConnectionFactoryPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConnectionFactoryPooledImpl.java	6 Mar 2003 00:13:10 -0000	1.6
  +++ ConnectionFactoryPooledImpl.java	11 Jun 2003 23:51:00 -0000	1.7
  @@ -7,6 +7,7 @@
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.OJBRuntimeException;
   
   import java.sql.Connection;
   import java.sql.ResultSet;
  @@ -120,6 +121,7 @@
        */
       class ConPoolFactory extends BasePoolableObjectFactory
       {
  +        int failedValidationQuery;
           JdbcConnectionDescriptor jcd;
           ConnectionFactoryPooledImpl cf;
   
  @@ -156,16 +158,23 @@
           {
               Statement stmt = null;
               ResultSet rset = null;
  +            if(failedValidationQuery > 100)
  +            {
  +                throw new OJBRuntimeException("Validation of connection "+conn+" using validation query "+
  +                        query + " failed more than 100 times.");
  +            }
               try
               {
                   stmt = conn.createStatement();
                   rset = stmt.executeQuery(query);
                   if (rset.next())
                   {
  +                    failedValidationQuery = 0;
                       return true;
                   }
                   else
                   {
  +                    ++failedValidationQuery;
                       log.warn("Validation query '" + query +
                               "' result set does not match, discard connection");
                       return false;
  @@ -173,6 +182,7 @@
               }
               catch (SQLException e)
               {
  +                ++failedValidationQuery;
                   log.warn("Validation query for connection failed, discard connection. Query was " +
                           query + ", Message was " + e.getMessage());
                   if (log.isDebugEnabled()) log.debug(e);