Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-438

JDBCDatabaseManager does not send commit command

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta9
    • Fix Version/s: 2.0-rc1
    • Component/s: Appenders
    • Labels:
      None
    • Environment:

      Java 7u45, Windows, H2

      Description

      I'm fiddling with the log4j jdbc appender and found an issue with datasources that have the flag defaultAutoCommit set to false. With such datasources the application has to call the method connection.commit() after an update statement, if omitted nothing will be updated or inserted in the database.

      That is the problem with the class JDBCDatabaseManager. It executes the statement (with this.statement.executeUpdate()) but does not call commit. Nothing is inserted if the defaultAutoCommit flag of the datasource is set to false.

      One possible solution is to check the autoCommit flag of the datasource and call commit when it's set to false.

      if (this.statement.executeUpdate() == 0) {
      throw new AppenderLoggingException(
      "No records inserted in database table for log event in JDBC manager.");
      }

      if (!this.connection.getAutoCommit()) {
      this.connection.commit();
      }

      Maybe this has to be done differently when a buffer is used. The method AbstractDatabaseManager.flush should only call commit after the loop.

      if (this.isConnected() && this.buffer.size() > 0) {
      for (final LogEvent event : this.buffer)

      { this.writeInternal(event); }

      if (!connection.getAutoCommit())

      { connection.commit(); }

      this.buffer.clear();
      }

      Or maybe using the batch methods of jdbc would improve the performance even more

      if (this.isConnected() && this.buffer.size() > 0) {
      for (final LogEvent event : this.buffer)

      { //create statement ....... statement.addBatch() }

      statement.executeBatch();
      if (!connection.getAutoCommit())

      { connection.commit(); }

      this.buffer.clear();
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                beamerblvd Nick Williams
                Reporter:
                rasc Ralph Schaer
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: