logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1612743 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java
Date Wed, 23 Jul 2014 01:52:35 GMT
Author: mattsicker
Date: Wed Jul 23 01:52:35 2014
New Revision: 1612743

URL: http://svn.apache.org/r1612743
Log:
Add basic batch update support for JDBC appender.

  - Part of LOG4J2-734

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java?rev=1612743&r1=1612742&r2=1612743&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java
Wed Jul 23 01:52:35 2014
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.ap
 
 import java.io.StringReader;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Timestamp;
@@ -43,6 +44,7 @@ public final class JdbcDatabaseManager e
 
     private Connection connection;
     private PreparedStatement statement;
+    private boolean isBatchSupported;
 
     private JdbcDatabaseManager(final String name, final int bufferSize, final ConnectionSource
connectionSource,
                                 final String sqlStatement, final List<Column> columns)
{
@@ -53,8 +55,11 @@ public final class JdbcDatabaseManager e
     }
 
     @Override
-    protected void startupInternal() {
-        // nothing to see here
+    protected void startupInternal() throws Exception {
+        this.connection = this.connectionSource.getConnection();
+        final DatabaseMetaData metaData = this.connection.getMetaData();
+        this.isBatchSupported = metaData.supportsBatchUpdates();
+        Closer.closeSilently(this.connection);
     }
 
     @Override
@@ -109,7 +114,9 @@ public final class JdbcDatabaseManager e
                 }
             }
 
-            if (this.statement.executeUpdate() == 0) {
+            if (this.isBatchSupported) {
+                this.statement.addBatch();
+            } else if (this.statement.executeUpdate() == 0) {
                 throw new AppenderLoggingException(
                         "No records inserted in database table for log event in JDBC manager.");
             }
@@ -125,6 +132,9 @@ public final class JdbcDatabaseManager e
     protected void commitAndClose() {
         try {
             if (this.connection != null && !this.connection.isClosed()) {
+                if (this.isBatchSupported) {
+                    this.statement.executeBatch();
+                }
                 this.connection.commit();
             }
         } catch (final SQLException e) {



Mime
View raw message