You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2004/05/24 18:14:35 UTC

cvs commit: logging-log4j/tests/src/java/org/apache/log4j/db DBPerfTest.java FullCycleDBTest.java

ceki        2004/05/24 09:14:35

  Modified:    src/java/org/apache/log4j/db/dialect MsSQLDialect.java
                        Util.java
               src/java/org/apache/log4j/db DBReceiver.java
                        ConnectionSource.java DBReceiverJob.java
                        DBHelper.java DataSourceConnectionSource.java
                        DBAppender.java JNDIConnectionSource.java
                        DriverManagerConnectionSource.java
                        ConnectionSourceSkeleton.java
               tests/input/db append-with-pooled-datasource1.xml
                        read-with-drivermanager1.xml
               tests/src/java/org/apache/log4j/db DBPerfTest.java
                        FullCycleDBTest.java
  Added:       tests/input/db append-with-c3p0.xml
  Log:
  - Added support for the JDBC 3.0 getGeneratedKeys function which
  if supported by the JDC driver obsoletes the need for a RDBMS specific
  SQLDialect.
  
  Revision  Changes    Path
  1.2       +3 -0      logging-log4j/src/java/org/apache/log4j/db/dialect/MsSQLDialect.java
  
  Index: MsSQLDialect.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/MsSQLDialect.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MsSQLDialect.java	18 May 2004 17:00:08 -0000	1.1
  +++ MsSQLDialect.java	24 May 2004 16:14:34 -0000	1.2
  @@ -19,6 +19,9 @@
   /** 
   * The MS SQL Server dialect is untested. 
   * 
  +* Note that the dialect is not needed if your JDBC driver supports 
  +* the getGeneratedKeys method introduced in JDBC 3.0 specification.
  +* 
   * @author James Stauffer 
   */ 
   public class MsSQLDialect implements SQLDialect { 
  
  
  
  1.3       +2 -3      logging-log4j/src/java/org/apache/log4j/db/dialect/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/Util.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Util.java	20 May 2004 15:38:00 -0000	1.2
  +++ Util.java	24 May 2004 16:14:34 -0000	1.3
  @@ -19,7 +19,6 @@
   import org.apache.log4j.db.ConnectionSource;
   import org.apache.log4j.helpers.LogLog;
   
  -import java.sql.Connection;
   import java.sql.DatabaseMetaData;
   import java.sql.SQLException;
   
  @@ -35,11 +34,11 @@
     private static final String ORACLE_PART = "oracle";
     private static final String MSSQL_PART = "mssqlserver4";
   
  -  public static int discoverSQLDialect(Connection connection) {
  +  public static int discoverSQLDialect(DatabaseMetaData meta) {
       int dialectCode = 0;
   
       try {
  -      DatabaseMetaData meta = connection.getMetaData();
  +
         String dbName = meta.getDatabaseProductName().toLowerCase();
         LogLog.debug("**db name is " + dbName);
   
  
  
  
  1.10      +0 -2      logging-log4j/src/java/org/apache/log4j/db/DBReceiver.java
  
  Index: DBReceiver.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBReceiver.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DBReceiver.java	21 May 2004 18:45:07 -0000	1.9
  +++ DBReceiver.java	24 May 2004 16:14:34 -0000	1.10
  @@ -41,8 +41,6 @@
   
     public void activateOptions() {
       if (connectionSource != null) {
  -      LogLog.info("activating connectionSource");
  -      connectionSource.activateOptions();
         receiverJob = new DBReceiverJob(this);
   
         Scheduler scheduler = LogManager.getSchedulerInstance();
  
  
  
  1.6       +10 -1     logging-log4j/src/java/org/apache/log4j/db/ConnectionSource.java
  
  Index: ConnectionSource.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/ConnectionSource.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConnectionSource.java	21 May 2004 18:45:07 -0000	1.5
  +++ ConnectionSource.java	24 May 2004 16:14:34 -0000	1.6
  @@ -57,9 +57,18 @@
     
     /**
      * 
  -   * Get the SQL dialect that should be used for this connection.
  +   * Get the SQL dialect that should be used for this connection. Note that the
  +   * dialect is not needed if the DBC 3.0 getGeneratedKeys is supported.
  +   * 
      *
      */
     int getSQLDialectCode();
  +  
  +  /**
  +   * If the connection supports the JDBC 3.0 getGeneratedKeys method, then
  +   * we do not need any specific dialect support.
  +   * 
  +   */
  +  boolean supportsGetGeneratedKeys();
     
   }
  
  
  
  1.2       +5 -5      logging-log4j/src/java/org/apache/log4j/db/DBReceiverJob.java
  
  Index: DBReceiverJob.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBReceiverJob.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DBReceiverJob.java	21 May 2004 18:45:07 -0000	1.1
  +++ DBReceiverJob.java	24 May 2004 16:14:34 -0000	1.2
  @@ -82,15 +82,14 @@
         Statement statement = connection.createStatement();
         ResultSet rs = statement.executeQuery(sql.toString());
         rs.beforeFirst();
  -
  +      
         while (rs.next()) {
           LoggingEvent event = new LoggingEvent();
  -        long id;
  +        
           event.setSequenceNumber(rs.getLong(1));
           event.setTimeStamp(rs.getLong(2));
           event.setRenderedMessage(rs.getString(3));
           event.setLoggerName(rs.getString(4));
  -
           String levelStr = rs.getString(5);
   
           // TODO CG The conversion of levelStr should be more general
  @@ -114,7 +113,8 @@
               new LocationInfo(fileName, className, methodName, lineNumber));
           }
   
  -        id = rs.getLong(13);
  +        long id = rs.getLong(13);
  +        LogLog.info("Received event with id=" +id);
           lastId = id;
           
           // Scott asked for this info to be
  @@ -136,7 +136,7 @@
         statement.close();
         statement = null;
       } catch (SQLException sqle) {
  -      LogLog.error("Problem receiving events", sqle);
  +      LogLog.error("*************Problem receiving events", sqle);
       } finally {
         closeConnection(connection);
       }
  
  
  
  1.4       +23 -2     logging-log4j/src/java/org/apache/log4j/db/DBHelper.java
  
  Index: DBHelper.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DBHelper.java	10 May 2004 19:38:58 -0000	1.3
  +++ DBHelper.java	24 May 2004 16:14:34 -0000	1.4
  @@ -16,8 +16,12 @@
   
   package org.apache.log4j.db;
   
  +import java.sql.Connection;
  +import java.sql.SQLException;
  +import java.sql.Statement;
   import java.util.Set;
   
  +import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.spi.LoggingEvent;
   
   /**
  @@ -29,7 +33,7 @@
     public static short PROPERTIES_EXIST = 0x01;
     public static short EXCEPTION_EXISTS = 0x02;
     
  -  static short computeReferenceMask(LoggingEvent event) {
  +  public  static short computeReferenceMask(LoggingEvent event) {
       short mask = 0;
       Set propertiesKeys = event.getPropertyKeySet();
       if(propertiesKeys.size() > 0) {
  @@ -42,5 +46,22 @@
       return mask;
     }
     
  -
  +  static public void closeConnection(Connection connection) {
  +    if(connection != null) {
  +      try { 
  +        connection.close();
  +      } catch(SQLException sqle) {
  +        LogLog.warn("Failed to close connection.");
  +      }
  +    }
  +  }
  +  
  +  public static void closeStatement(Statement statement) {
  +    if(statement != null) {
  +      try {
  +        statement.close();
  +      } catch(SQLException sqle) {
  +      }
  +    }
  +  }
   }
  
  
  
  1.6       +14 -7     logging-log4j/src/java/org/apache/log4j/db/DataSourceConnectionSource.java
  
  Index: DataSourceConnectionSource.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DataSourceConnectionSource.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DataSourceConnectionSource.java	21 May 2004 18:45:07 -0000	1.5
  +++ DataSourceConnectionSource.java	24 May 2004 16:14:34 -0000	1.6
  @@ -20,6 +20,7 @@
   import org.apache.log4j.helpers.LogLog;
   
   import java.sql.Connection;
  +import java.sql.DatabaseMetaData;
   import java.sql.SQLException;
   
   import javax.sql.DataSource;
  @@ -37,7 +38,7 @@
   public class DataSourceConnectionSource extends ConnectionSourceSkeleton {
   
     private DataSource dataSource;
  -  int dialectCode;
  +
     
     public void activateOptions() {
       //LogLog.debug("**********DataSourceConnectionSource.activateOptions called");
  @@ -55,10 +56,18 @@
           LogLog.warn("Could not get a connection to discover the dialect to use.", se);
         }
         if(connection != null) {
  -        dialectCode = Util.discoverSQLDialect(connection);
  +        try {
  +          DatabaseMetaData meta = connection.getMetaData();
  +          supportsGetGeneratedKeys =   meta.supportsGetGeneratedKeys();
  +          if(!supportsGetGeneratedKeys) {
  +            dialectCode = Util.discoverSQLDialect(meta);
  +          }
  +        } catch(SQLException sqle) {
  +          LogLog.warn("Could not get a discover connection properties.");
  +        }
         } 
  -      if(dialectCode == ConnectionSource.UNKNOWN_DIALECT) {
  -        LogLog.warn("Could not get a discover the dialect.");
  +      if(!supportsGetGeneratedKeys && dialectCode == ConnectionSource.UNKNOWN_DIALECT) {
  +        LogLog.warn("Connection does not support GetGeneratedKey method and could not discover the dialect.");
         }
           
       }
  @@ -91,7 +100,5 @@
       this.dataSource = dataSource;
     }
   
  -  public int getSQLDialectCode() {
  -    return dialectCode;
  -  }
  +
   }
  
  
  
  1.12      +72 -67    logging-log4j/src/java/org/apache/log4j/db/DBAppender.java
  
  Index: DBAppender.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBAppender.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DBAppender.java	21 May 2004 18:45:07 -0000	1.11
  +++ DBAppender.java	24 May 2004 16:14:34 -0000	1.12
  @@ -34,15 +34,63 @@
   
   
   /**
  - *
  + * The DBAppender writes events to a database table. You first need to
  + * create the database tables with the help of SQL scripts found in the
  + * org/apache/log4j/db/dialect/ directory. There exist scripts for the most
  + * popular database systems. If it is missing, you should be able to write
  + * the appropriate script quite quickly.
  + * 
  + * <p>If the JDBC driver you are using supports the getGeneratedKeys method 
  + * introduced in JDBC 3.0 specification, then you are all set. Otherwise,
  + * there must be an {@link SQLDialect} appropriate for your database system.
  + * Currently, we have dialects for PostgreSQL, MySQL, Oracle and MsSQL. As 
  + * mentioed previously, an SQLDialect is required only the JDBC driver for your 
  + * database system does not support the getGeneratedKeys method.
  + * </p>
  + * 
  + * <p><b>Performance</b> Experiments show that writing a single event into the
  + * database takes approximately 50 milliseconds, on a "standard" PC. If pooled
  + * connections are used, this figure drops to under 10 milliseconds. Note that
  + * most JDBC drivers already ship with connection pooling support. 
  + * 
    * @author Ceki G&uuml;lc&uuml;
  - *
  + * @author Ray DeCampo
  + * @since 1.3
    */
   public class DBAppender extends AppenderSkeleton {
     ConnectionSource connectionSource;
  +  boolean cnxSupportsGetGeneratedKeys = false;
     SQLDialect sqlDialect;
     boolean locationInfo = false;
  -
  +  
  +  static final String insertPropertiesSQL =
  +    "INSERT INTO  logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)";
  +  
  +  static final String insertExceptionSQL =
  +    "INSERT INTO  logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
  +  
  +  static final String insertSQL;
  +
  +  static {StringBuffer sql = new StringBuffer();
  +    sql.append("INSERT INTO logging_event (");
  +    sql.append("sequence_number, ");
  +    sql.append("timestamp, ");
  +    sql.append("rendered_message, ");
  +    sql.append("logger_name, ");
  +    sql.append("level_string, ");
  +    sql.append("ndc, ");
  +    sql.append("thread_name, ");
  +    sql.append("reference_flag, ");
  +    sql.append("caller_filename, ");
  +    sql.append("caller_class, ");
  +    sql.append("caller_method, ");
  +    sql.append("caller_line) ");
  +    sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?)");
  +    insertSQL = sql.toString();
  +  }
  +  
  +  public DBAppender() {
  +  }  
     public void activateOptions() {
       LogLog.debug("DBAppender.activateOptions called");
   
  @@ -52,10 +100,11 @@
       }
   
       sqlDialect = Util.getDialectFromCode(connectionSource.getSQLDialectCode());
  -
  -    if (sqlDialect == null) {
  +    cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
  +    
  +    if (!cnxSupportsGetGeneratedKeys && sqlDialect == null) {
         throw new IllegalStateException(
  -        "DBAppender cannot function without a determined SQL dialect");
  +        "DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect");
       }
     }
   
  @@ -80,35 +129,7 @@
         connection = connectionSource.getConnection();
         connection.setAutoCommit(false);
   
  -
  -      //      sequence_number BIGINT NOT NULL,
  -      //      timestamp         BIGINT NOT NULL,
  -      //      rendered_message  TEXT NOT NULL,
  -      //      logger_name       VARCHAR(254) NOT NULL,
  -      //      level_string      VARCHAR(254) NOT NULL,
  -      //      ndc               TEXT,
  -      //      thread_name       VARCHAR(254),
  -      //      id                INT NOT NULL AUTO_INCREMENT PRIMARY KEY
  -      StringBuffer sql = new StringBuffer();
  -      sql.append("INSERT INTO logging_event (");
  -      sql.append("sequence_number, ");
  -      sql.append("timestamp, ");
  -      sql.append("rendered_message, ");
  -      sql.append("logger_name, ");
  -      sql.append("level_string, ");
  -      sql.append("ndc, ");
  -      sql.append("thread_name, ");
  -      sql.append("reference_flag, ");
  -      sql.append("caller_filename, ");
  -      sql.append("caller_class, ");
  -      sql.append("caller_method, ");
  -      sql.append("caller_line) ");
  -
  -      sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?)");
  -
  -
  -      PreparedStatement insertStatement =
  -        connection.prepareStatement(sql.toString());
  +      PreparedStatement insertStatement = connection.prepareStatement(insertSQL);
         insertStatement.setLong(1, event.getSequenceNumber());
         insertStatement.setLong(2, event.getTimeStamp());
         insertStatement.setString(3, event.getRenderedMessage());
  @@ -136,35 +157,34 @@
           LogLog.warn("Failed to insert loggingEvent");
         }
   
  -      // close the statement
  -      insertStatement.close();
  -      insertStatement = null;
  -      
         Statement idStatement = connection.createStatement();
         idStatement.setMaxRows(1);
   
  -      ResultSet rs = idStatement.executeQuery(sqlDialect.getSelectInsertId());
  +      
  +      ResultSet rs = null;
  +        if(cnxSupportsGetGeneratedKeys) {
  +          rs = insertStatement.getGeneratedKeys();
  +        } else {
  +         rs = idStatement.executeQuery(sqlDialect.getSelectInsertId());
  +        }
         rs.first();
  -
         int eventId = rs.getInt(1);
   
  -
  -      //      LogLog.info("inserted id is " + eventId);
  -      //      event_id        INT NOT NULL,
  -      //      mapped_key        VARCHAR(254) NOT NULL,
  -      //      mapped_value      VARCHAR(254),
  +      // we no longer need the insertStatement
  +      insertStatement.close();
  +      insertStatement = null;
  +      
         Set propertiesKeys = event.getPropertyKeySet();
   
         if (propertiesKeys.size() > 0) {
  -        String insertPropertiesSQL =
  -          "INSERT INTO  logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)";
  +
           PreparedStatement insertPropertiesStatement =
             connection.prepareStatement(insertPropertiesSQL);
   
           for (Iterator i = propertiesKeys.iterator(); i.hasNext();) {
             String key = (String) i.next();
             String value = (String) event.getProperty(key);
  -          LogLog.info("id " + eventId + ", key " + key + ", value " + value);
  +          //LogLog.info("id " + eventId + ", key " + key + ", value " + value);
             insertPropertiesStatement.setInt(1, eventId);
             insertPropertiesStatement.setString(2, key);
             insertPropertiesStatement.setString(3, value);
  @@ -181,13 +201,6 @@
         if (strRep != null) {
           LogLog.info("Logging an exception");
   
  -
  -        //        CREATE TABLE logging_event_exception (
  -        //          event_id         INT NOT NULL,
  -        //          i                SMALLINT NOT NULL,
  -        //          trace_line       VARCHAR(254) NOT NULL)
  -        String insertExceptionSQL =
  -          "INSERT INTO  logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
           PreparedStatement insertExceptionStatement =
             connection.prepareStatement(insertExceptionSQL);
   
  @@ -207,21 +220,13 @@
       } catch (SQLException sqle) {
         LogLog.error("problem appending event", sqle);
       } finally {
  -      closeConnection(connection);
  +      DBHelper.closeConnection(connection);
       }
     }
   
  -  void closeConnection(Connection connection) {
  -    if(connection != null) {
  -      try { 
  -        connection.close();
  -      } catch(SQLException sqle) {
  -        LogLog.warn("Failed to close connection.");
  -      }
  -    }
  -  }
  +
     public void close() {
  -    // TODO Auto-generated method st  
  +    closed = true;
     }
   
     /*
  
  
  
  1.7       +3 -8      logging-log4j/src/java/org/apache/log4j/db/JNDIConnectionSource.java
  
  Index: JNDIConnectionSource.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/JNDIConnectionSource.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JNDIConnectionSource.java	21 May 2004 10:50:39 -0000	1.6
  +++ JNDIConnectionSource.java	24 May 2004 16:14:34 -0000	1.7
  @@ -26,9 +26,9 @@
   // import javax.rmi.PortableRemoteObject;
   import javax.sql.DataSource;
   
  -import org.apache.log4j.db.dialect.Util;
   import org.apache.log4j.helpers.LogLog;
   
  +
   /**
    *  The <id>JNDIConnectionSource</id> is an implementation of
    *  {@link ConnectionSource} that obtains a {@link javax.sql.DataSource} from a
  @@ -77,13 +77,8 @@
         errorHandler.error("No JNDI location specified for JNDIConnectionSource.");
       }
       
  -    try {
  -      Connection connection = getConnection();
  -      dialectCode = Util.discoverSQLDialect(connection);
  -    } catch(SQLException se) {
  -      LogLog.warn("Could not discover the dialect to use.", se);
  -    }
  -    
  +    discoverConnnectionProperties();
  +
     }
     
     /**
  
  
  
  1.5       +12 -37    logging-log4j/src/java/org/apache/log4j/db/DriverManagerConnectionSource.java
  
  Index: DriverManagerConnectionSource.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DriverManagerConnectionSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DriverManagerConnectionSource.java	20 May 2004 15:37:59 -0000	1.4
  +++ DriverManagerConnectionSource.java	24 May 2004 16:14:34 -0000	1.5
  @@ -13,14 +13,15 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  +
   package org.apache.log4j.db;
   
  +import org.apache.log4j.spi.ErrorCode;
  +
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.SQLException;
   
  -import org.apache.log4j.spi.ErrorCode;
  -
   
   /**
    *  The DriverManagerConnectionSource is an implementation of {@link ConnectionSource}
  @@ -65,14 +66,7 @@
    *
    *  @author <a href="mailto:rdecampo@twcny.rr.com">Ray DeCampo</a>
    */
  -public class DriverManagerConnectionSource
  -       extends ConnectionSourceSkeleton {
  -  static private final String POSTGRES_PART = "postgresql";
  -  static private final String MYSQL_PART = "mysql";
  -  static private final String ORACLE_PART = "oracle";
  -  static private final String MSSQL_PART = "mssql"; 
  -  static private final String HSQLDB_PART = "hsqldb"; 
  -  
  +public class DriverManagerConnectionSource extends ConnectionSourceSkeleton {
     private String driverClass = null;
     protected String url = null;
   
  @@ -80,12 +74,17 @@
       try {
         if (driverClass != null) {
           Class.forName(driverClass);
  +        discoverConnnectionProperties();
         } else if (errorHandler != null) {
  -        errorHandler.error("WARNING: No JDBC driver specified for log4j " + "DriverManagerConnectionSource.");
  +        errorHandler.error(
  +          "WARNING: No JDBC driver specified for log4j "
  +          + "DriverManagerConnectionSource.");
         }
       } catch (final ClassNotFoundException cnfe) {
         if (errorHandler != null) {
  -        errorHandler.error("Could not load JDBC driver class: " + driverClass, cnfe, ErrorCode.GENERIC_FAILURE);
  +        errorHandler.error(
  +          "Could not load JDBC driver class: " + driverClass, cnfe,
  +          ErrorCode.GENERIC_FAILURE);
         } else {
           cnfe.printStackTrace();
         }
  @@ -96,8 +95,7 @@
     /**
      * @see org.apache.log4j.db.ConnectionSource#getConnection()
      */
  -  public Connection getConnection()
  -         throws SQLException {
  +  public Connection getConnection() throws SQLException {
       if (user == null) {
         return DriverManager.getConnection(url);
       } else {
  @@ -139,28 +137,5 @@
      */
     public void setDriverClass(String driverClass) {
       this.driverClass = driverClass;
  -  }
  -
  -
  -  public int getSQLDialectCode() {
  -    int dialectCode = 0;
  -
  -    if (url == null) {
  -      return ConnectionSource.UNKNOWN_DIALECT;
  -    }
  -
  -    if (url.indexOf(POSTGRES_PART) != -1) {
  -      return ConnectionSource.POSTGRES_DIALECT;
  -    } else if (url.indexOf(MYSQL_PART) != -1) {
  -      return ConnectionSource.MYSQL_DIALECT;
  -    } else if (url.indexOf(ORACLE_PART) != -1) {
  -      return ConnectionSource.ORACLE_DIALECT;
  -    } else if (url.indexOf(MSSQL_PART) != -1) {
  -      return ConnectionSource.MSSQL_DIALECT;
  -    } else if (url.indexOf(HSQLDB_PART) != -1) {
  -      return ConnectionSource.HSQLDB_DIALECT;
  -    } else {
  -      return ConnectionSource.UNKNOWN_DIALECT;
  -    }
     }
   }
  
  
  
  1.3       +57 -4     logging-log4j/src/java/org/apache/log4j/db/ConnectionSourceSkeleton.java
  
  Index: ConnectionSourceSkeleton.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/ConnectionSourceSkeleton.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionSourceSkeleton.java	18 May 2004 16:50:42 -0000	1.2
  +++ ConnectionSourceSkeleton.java	24 May 2004 16:14:34 -0000	1.3
  @@ -1,16 +1,68 @@
  +/*
  + * Copyright 1999,2004 The Apache Software Foundation.
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *      http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
   package org.apache.log4j.db;
   
  +import org.apache.log4j.db.dialect.Util;
  +import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.spi.ErrorHandler;
   
  +import java.sql.Connection;
  +import java.sql.DatabaseMetaData;
  +import java.sql.SQLException;
  +
  +
   /**
    * @author Ceki G&uuml;lc&uuml;
    */
  -abstract public class ConnectionSourceSkeleton
  -       implements ConnectionSource {
  +public abstract class ConnectionSourceSkeleton implements ConnectionSource {
     protected String user = null;
     protected String password = null;
     protected ErrorHandler errorHandler = null;
   
  +  // initially we have an unkonw dialect
  +  protected int dialectCode = UNKNOWN_DIALECT;
  +  protected boolean supportsGetGeneratedKeys = false;
  +
  +  /**
  +   * Learn relevant information about this connection source.
  +   *
  +   */
  +  public void discoverConnnectionProperties() {
  +    try {
  +      Connection connection = getConnection();
  +      if(connection == null) {
  +        LogLog.warn("Could not get a conneciton");
  +        return;
  +      }
  +      DatabaseMetaData meta = connection.getMetaData();
  +      supportsGetGeneratedKeys = meta.supportsGetGeneratedKeys();
  +      dialectCode = Util.discoverSQLDialect(meta);
  +    } catch (SQLException se) {
  +      LogLog.warn("Could not discover the dialect to use.", se);
  +    }
  +  }
  +
  +  /**
  +   * Does this connection support the JDBC Connection.getGeneratedKeys method?
  +   */
  +  public boolean supportsGetGeneratedKeys() {
  +    return supportsGetGeneratedKeys;
  +  }
  +
     /**
      * Get teh errorHandler for this connection source
      */
  @@ -26,7 +78,9 @@
       this.errorHandler = errorHandler;
     }
   
  -
  +  public int getSQLDialectCode() {
  +    return dialectCode;
  +  }
   
     /**
      * Get the password for this connection source.
  @@ -58,5 +112,4 @@
     public void setUser(String username) {
       this.user = username;
     }
  -
   }
  
  
  
  1.2       +6 -1      logging-log4j/tests/input/db/append-with-pooled-datasource1.xml
  
  Index: append-with-pooled-datasource1.xml
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/input/db/append-with-pooled-datasource1.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- append-with-pooled-datasource1.xml	19 May 2004 17:58:09 -0000	1.1
  +++ append-with-pooled-datasource1.xml	24 May 2004 16:14:34 -0000	1.2
  @@ -11,7 +11,12 @@
          <dataSource class="${pooledDataSourceClass}">
            <param name="url" value="${url}"/>
            <param name="serverName" value="${serverName}"/>
  -         <param name="databaseName" value="${databaseName}"/>         
  +         <param name="databaseName" value="${databaseName}"/>
  +         <param name="user" value="${user}"/>
  +         <param name="password" value="${password}"/>
  +                
  +         <param name="initialConnections" value="10"/>
  +         <param name="maxConnections" value="10"/>
          </dataSource>
          
          <param name="user" value="${user}"/>
  
  
  
  1.2       +1 -1      logging-log4j/tests/input/db/read-with-drivermanager1.xml
  
  Index: read-with-drivermanager1.xml
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/input/db/read-with-drivermanager1.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- read-with-drivermanager1.xml	19 May 2004 17:58:09 -0000	1.1
  +++ read-with-drivermanager1.xml	24 May 2004 16:14:34 -0000	1.2
  @@ -5,7 +5,7 @@
   	  
     <substitutionProperty file="input/db/db.properties"/>
   	  
  -  <plugin name="DB1" class="org.apache.log4j.db.DBReceiver">
  +  <plugin name="DB" class="org.apache.log4j.db.DBReceiver">
        <connectionSource class="org.apache.log4j.db.DriverManagerConnectionSource">
          <param name="driverClass" value="${driverClass}"/>
          <param name="url" value="${url}"/>
  
  
  
  1.1                  logging-log4j/tests/input/db/append-with-c3p0.xml
  
  Index: append-with-c3p0.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE log4j:configuration>
  	  
  <log4j:configuration debug="true">
  	  
    <substitutionProperty file="input/db/db.properties"/>
  	    
    <appender name="DB" class="org.apache.log4j.db.DBAppender">
       <connectionSource class="org.apache.log4j.db.DataSourceConnectionSource">
         
         <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
           <param name="driverClass" value="${driverClass}"/>
           <param name="jdbcUrl" value="${url}"/>
           <param name="serverName" value="${serverName}"/>
           <param name="databaseName" value="${databaseName}"/>
           <param name="user" value="${user}"/>
           <param name="password" value="${password}"/>
                  <!--
           <param name="initialConnections" value="10"/>
           <param name="maxConnections" value="10"/>
         
           <param name="max-connections" value="100"/>                                                    
           <param name="min-connections" value="5" />                                                     
           <param name="inactivity-timeout" value="200"/>        
           -->                                         
         </dataSource>
         
         <param name="user" value="${user}"/>
         <param name="password" value="${password}"/>
       </connectionSource>
    </appender>
  
    <appender name="VECTOR" class="org.apache.log4j.VectorAppender">
    </appender>
    
    <root>
      <level value ="debug"/>
      <appender-ref ref="DB" />
      <appender-ref ref="VECTOR" />
    </root>  
  </log4j:configuration>
  
  
  
  
  
  1.2       +6 -2      logging-log4j/tests/src/java/org/apache/log4j/db/DBPerfTest.java
  
  Index: DBPerfTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/db/DBPerfTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DBPerfTest.java	21 May 2004 18:45:07 -0000	1.1
  +++ DBPerfTest.java	24 May 2004 16:14:34 -0000	1.2
  @@ -8,6 +8,7 @@
   
   import org.apache.log4j.LogManager;
   import org.apache.log4j.Logger;
  +import org.apache.log4j.MDC;
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.joran.JoranConfigurator;
   
  @@ -42,16 +43,19 @@
       //appendConfigFile = "./input/db/append-with-drivermanager1.xml";
       appendConfigFile = "./input/db/append-with-pooled-datasource1.xml";
       //appendConfigFile = "./input/db/append-with-c3p0.xml";
  +    
  +
       JoranConfigurator jc1 = new JoranConfigurator();
       jc1.doConfigure(appendConfigFile, LogManager.getLoggerRepository());
       
       long startTime = System.currentTimeMillis();
  +    MDC.put("key1", "vaelu1");
       int i;
  -    for(i = 0; i < 500; i++) {
  +    for(i = 0; i < 100; i++) {
         logger.debug("message "+i);
       }
       long endTime = System.currentTimeMillis();
       LogLog.info("writing "+i+" events took "+(endTime-startTime)+" millis.");
  -    LogLog.info("or "+(endTime-startTime)/i+" millis per event.");
  +    LogLog.info("or "+(double)(endTime-startTime)/i+" millis per event.");
     }
   }
  
  
  
  1.7       +16 -6     logging-log4j/tests/src/java/org/apache/log4j/db/FullCycleDBTest.java
  
  Index: FullCycleDBTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/db/FullCycleDBTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FullCycleDBTest.java	20 May 2004 15:38:00 -0000	1.6
  +++ FullCycleDBTest.java	24 May 2004 16:14:34 -0000	1.7
  @@ -28,6 +28,7 @@
   import org.apache.log4j.Logger;
   import org.apache.log4j.MDC;
   import org.apache.log4j.VectorAppender;
  +import org.apache.log4j.helpers.Constants;
   import org.apache.log4j.helpers.IntializationUtil;
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.joran.JoranConfigurator;
  @@ -84,7 +85,6 @@
     protected void tearDown()
            throws Exception {
       super.tearDown();
  -    lrWrite.shutdown();
       lrRead.shutdown();
       witnessEvents = null;
     }
  @@ -116,11 +116,14 @@
       // Write out just one log message
       Logger out = lrWrite.getLogger("testSingleOutput.out");
       out.debug("some message"+startTime);
  -    
  +
       VectorAppender witnessAppender = (VectorAppender) lrWrite.getRootLogger().getAppender("VECTOR");
       witnessEvents = witnessAppender.getVector();
       assertEquals(1, witnessEvents.size());    
  -    
  +
  +    // We have to close all appenders before starting to read
  +    lrWrite.shutdown();
  +
       // now read it back
       readBack(readConfigFile, startTime);
   
  @@ -156,7 +159,6 @@
       MDC.put("key3", "value2-"+startTime);
       out.error("some error message"+startTime, new Exception("testing"));
       
  -
       // we clear the MDC to avoid interference with the events read back from
       // the db
       MDC.clear();
  @@ -165,6 +167,9 @@
       witnessEvents = witnessAppender.getVector();
       assertEquals(2, witnessEvents.size());    
   
  +    // We have to close all appenders just before starting to read
  +    lrWrite.shutdown();
  +    
       readBack(readConfigFile, startTime);
     }
   
  @@ -197,12 +202,17 @@
         if(re.getTimeStamp() < le.getTimeStamp()) {
           fail("Returned event cannot preceed witness timestamp");
         }
  +      
  +      if((re.getProperties() != null) && re.getProperties().containsKey(Constants.LOG4J_ID_KEY)) {
  +        re.getProperties().remove(Constants.LOG4J_ID_KEY);
  +      }
  +      
         if(le.getProperties() == null || le.getProperties().size() == 0) {
           if(!(re.getProperties() == null || re.getProperties().size() == 0)) {
  +          LogLog.warn("properties are "+re.getProperties());
             fail("Returned event should have been empty");
           }
  -      }
  -      else {
  +      } else {
           assertEquals(le.getProperties(), re.getProperties());
         }
         comprareStringArrays( le.getThrowableStrRep(),  re.getThrowableStrRep());
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org