logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject RE: svn commit: r1615861 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java
Date Tue, 05 Aug 2014 11:40:28 GMT
Curious: is there a perf hit in getting the connection metadata?

Gary

<div>-------- Original message --------</div><div>From: mattsicker@apache.org
</div><div>Date:08/05/2014  00:35  (GMT-05:00) </div><div>To: commits@logging.apache.org
</div><div>Subject: svn commit: r1615861 -
  /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java
</div><div>
</div>Author: mattsicker
Date: Tue Aug  5 04:35:41 2014
New Revision: 1615861

URL: http://svn.apache.org/r1615861
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=1615861&r1=1615860&r2=1615861&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
Tue Aug  5 04:35:41 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