[logback-dev] svn commit: r877 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/db logback-core/src/main/java/ch/qos/logback/core/db logback-core/src/main/java/ch/qos/logback/core/db/dialect
noreply.seb at qos.ch
noreply.seb at qos.ch
Tue Nov 7 09:30:52 CET 2006
Author: seb
Date: Tue Nov 7 09:30:52 2006
New Revision: 877
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java
Log:
refactoring onrefactored DBAppender and DBAppenderBase to remove all mentions of classic concepts from core module
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java Tue Nov 7 09:30:52 2006
@@ -10,6 +10,7 @@
package ch.qos.logback.classic.db;
+import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -101,7 +102,39 @@
* @author Sébastien Pennec
*/
public class DBAppender extends DBAppenderBase {
-
+ protected static final String insertPropertiesSQL = "INSERT INTO logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)";
+ protected static final String insertExceptionSQL = "INSERT INTO logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
+ protected static final String insertSQL;
+ protected static final Method GET_GENERATED_KEYS_METHOD;
+
+ static {
+ StringBuffer sql = new StringBuffer();
+ sql.append("INSERT INTO logging_event (");
+ sql.append("timestmp, ");
+ sql.append("formatted_message, ");
+ sql.append("logger_name, ");
+ sql.append("level_string, ");
+ 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();
+ //
+ // PreparedStatement.getGeneratedKeys added in JDK 1.4
+ //
+ Method getGeneratedKeysMethod;
+ try {
+ getGeneratedKeysMethod = PreparedStatement.class.getMethod(
+ "getGeneratedKeys", (Class[]) null);
+ } catch (Exception ex) {
+ getGeneratedKeysMethod = null;
+ }
+ GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
+ }
+
public DBAppender() {
}
@@ -168,4 +201,24 @@
return mergedMap;
}
+
+ @Override
+ protected Method getGeneratedKeysMethod() {
+ return GET_GENERATED_KEYS_METHOD;
+ }
+
+ @Override
+ protected String getInsertExceptionSQL() {
+ return insertExceptionSQL;
+ }
+
+ @Override
+ protected String getInsertPropertiesSQL() {
+ return insertPropertiesSQL;
+ }
+
+ @Override
+ protected String getInsertSQL() {
+ return insertSQL;
+ }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java Tue Nov 7 09:30:52 2006
@@ -32,44 +32,17 @@
* @author Sébastien Pennec
*/
public abstract class DBAppenderBase extends AppenderBase {
- protected static final String insertPropertiesSQL = "INSERT INTO logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)";
- protected static final String insertExceptionSQL = "INSERT INTO logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
- protected static final String insertSQL;
- protected static final Method GET_GENERATED_KEYS_METHOD;
-
- static {
- StringBuffer sql = new StringBuffer();
- sql.append("INSERT INTO logging_event (");
- sql.append("timestmp, ");
- sql.append("formatted_message, ");
- sql.append("logger_name, ");
- sql.append("level_string, ");
- 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();
- //
- // PreparedStatement.getGeneratedKeys added in JDK 1.4
- //
- Method getGeneratedKeysMethod;
- try {
- getGeneratedKeysMethod = PreparedStatement.class.getMethod(
- "getGeneratedKeys", (Class[]) null);
- } catch (Exception ex) {
- getGeneratedKeysMethod = null;
- }
- GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
- }
protected ConnectionSource connectionSource;
protected boolean cnxSupportsGetGeneratedKeys = false;
protected boolean cnxSupportsBatchUpdates = false;
protected SQLDialect sqlDialect;
+ protected abstract Method getGeneratedKeysMethod();
+ protected abstract String getInsertSQL();
+ protected abstract String getInsertPropertiesSQL();
+ protected abstract String getInsertExceptionSQL();
+
@Override
public void start() {
@@ -80,7 +53,7 @@
sqlDialect = DBUtil
.getDialectFromCode(connectionSource.getSQLDialectCode());
- if (GET_GENERATED_KEYS_METHOD != null) {
+ if (getGeneratedKeysMethod() != null) {
cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
} else {
cnxSupportsGetGeneratedKeys = false;
@@ -112,14 +85,13 @@
@Override
public void append(Object eventObject) {
- // LoggingEvent event = (LoggingEvent) eventObject;
Connection connection = null;
try {
connection = connectionSource.getConnection();
connection.setAutoCommit(false);
PreparedStatement insertStatement = connection
- .prepareStatement(insertSQL);
+ .prepareStatement(getInsertSQL());
subAppend(eventObject, connection, insertStatement);
@@ -147,7 +119,7 @@
boolean gotGeneratedKeys = false;
if (cnxSupportsGetGeneratedKeys) {
try {
- rs = (ResultSet) GET_GENERATED_KEYS_METHOD.invoke(insertStatement,
+ rs = (ResultSet) getGeneratedKeysMethod().invoke(insertStatement,
(Object[]) null);
gotGeneratedKeys = true;
} catch (InvocationTargetException ex) {
@@ -193,7 +165,7 @@
Set propertiesKeys = mergedMap.keySet();
if (propertiesKeys.size() > 0) {
PreparedStatement insertPropertiesStatement = connection
- .prepareStatement(insertPropertiesSQL);
+ .prepareStatement(getInsertPropertiesSQL());
for (Iterator i = propertiesKeys.iterator(); i.hasNext();) {
String key = (String) i.next();
@@ -223,7 +195,7 @@
int eventId) throws SQLException {
PreparedStatement insertExceptionStatement = connection
- .prepareStatement(insertExceptionSQL);
+ .prepareStatement(getInsertExceptionSQL());
for (short i = 0; i < strRep.length; i++) {
insertExceptionStatement.setInt(1, eventId);
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java Tue Nov 7 09:30:52 2006
@@ -15,8 +15,6 @@
*
* @author ceki
*
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PostgreSQLDialect
implements SQLDialect {
More information about the logback-dev
mailing list