[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-113-g2181956

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Mar 23 20:01:09 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  2181956a1dae32a14218f9da2d844e8913bb218e (commit)
      from  16e8cfbd6a3a9cb96a883270907792400790dc49 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=2181956a1dae32a14218f9da2d844e8913bb218e
http://github.com/ceki/logback/commit/2181956a1dae32a14218f9da2d844e8913bb218e

commit 2181956a1dae32a14218f9da2d844e8913bb218e
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Mar 23 19:58:33 2010 +0100

    - event_id is now expected to be of type LONG. This is a first step in
    fixing http://jira.qos.ch/browse/LBCLASSIC-198 (more tests to follow)

diff --git a/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java b/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
index 0f1879d..b8e3a25 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
@@ -82,7 +82,7 @@ public class DBAppender extends DBAppenderBase<AccessEvent> {
     }
     
     if (insertHeaders) {
-      int eventId = selectEventId(insertStatement, connection);
+      long eventId = selectEventId(insertStatement, connection);
       addRequestHeaders(event, connection, eventId);
     }
   }
@@ -102,7 +102,7 @@ public class DBAppender extends DBAppenderBase<AccessEvent> {
   }
   
   void addRequestHeaders(AccessEvent event,
-      Connection connection, int eventId) throws SQLException {
+      Connection connection, long eventId) throws SQLException {
     Enumeration names = event.getRequestHeaderNames();
     if (names.hasMoreElements()) {
       PreparedStatement insertHeaderStatement = connection
@@ -113,7 +113,7 @@ public class DBAppender extends DBAppenderBase<AccessEvent> {
         String key = (String) names.nextElement();
         String value = (String) event.getRequestHeader(key);
 
-        insertHeaderStatement.setInt(1, eventId);
+        insertHeaderStatement.setLong(1, eventId);
         insertHeaderStatement.setString(2, key);
         insertHeaderStatement.setString(3, value);
 
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java b/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
index 7c92e50..68c398f 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
@@ -94,8 +94,10 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
       addWarn("Failed to insert loggingEvent");
     }
 
-    int eventId = selectEventId(insertStatement, connection);
+    long eventId = selectEventId(insertStatement, connection);
 
+    System.out.println("eventId"+eventId);
+    
     Map<String, String> mergedMap = mergePropertyMaps(event);
     insertProperties(mergedMap, connection, eventId);
 
@@ -155,7 +157,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
   }
 
   protected void insertProperties(Map<String, String> mergedMap,
-      Connection connection, int eventId) throws SQLException {
+      Connection connection, long eventId) throws SQLException {
     Set propertiesKeys = mergedMap.keySet();
     if (propertiesKeys.size() > 0) {
       PreparedStatement insertPropertiesStatement = connection
@@ -165,7 +167,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
         String key = (String) i.next();
         String value = (String) mergedMap.get(key);
 
-        insertPropertiesStatement.setInt(1, eventId);
+        insertPropertiesStatement.setLong(1, eventId);
         insertPropertiesStatement.setString(2, key);
         insertPropertiesStatement.setString(3, value);
 
@@ -190,8 +192,8 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
    * batch updates are not supported.
    */
   void updateExceptionStatement(PreparedStatement exceptionStatement,
-      String txt, short i, int eventId) throws SQLException {
-    exceptionStatement.setInt(1, eventId);
+      String txt, short i, long eventId) throws SQLException {
+    exceptionStatement.setLong(1, eventId);
     exceptionStatement.setShort(2, i);
     exceptionStatement.setString(3, txt);
     if (cnxSupportsBatchUpdates) {
@@ -202,7 +204,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
   }
 
   short buildExceptionStatement(IThrowableProxy tp, short baseIndex,
-      PreparedStatement insertExceptionStatement, int eventId)
+      PreparedStatement insertExceptionStatement, long eventId)
       throws SQLException {
 
     StringBuilder buf = new StringBuilder();
@@ -232,7 +234,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
   }
 
   protected void insertThrowable(IThrowableProxy tp, Connection connection,
-      int eventId) throws SQLException {
+      long eventId) throws SQLException {
 
     PreparedStatement exceptionStatement = connection
         .prepareStatement(insertExceptionSQL);
@@ -246,6 +248,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
 
     if (cnxSupportsBatchUpdates) {
       exceptionStatement.executeBatch();
+      System.out.println("executin batch");
     }
     exceptionStatement.close();
     exceptionStatement = null;
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql
index 0ba314d..f8660c0 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql
@@ -1,35 +1,36 @@
 # This SQL script creates the required tables by ch.qos.logback.classic.db.DBAppender.
 #
-# It is intended for HSQL databases. It has been tested on HSQL 1.8.07.
+# It is intended for H2 databases. 
 
-DROP TABLE logging_event_exception IF EXISTS;
-DROP TABLE logging_event_property IF EXISTS;
-DROP TABLE logging_event IF EXISTS;
 
-CREATE TABLE logging_event (
-  timestmp BIGINT NOT NULL,
-  formatted_message LONGVARCHAR NOT NULL,
-  logger_name VARCHAR(256) NOT NULL,
-  level_string VARCHAR(256) NOT NULL,
-  thread_name VARCHAR(256),
-  reference_flag SMALLINT,
-  caller_filename VARCHAR(256), 
-  caller_class VARCHAR(256), 
-  caller_method VARCHAR(256), 
-  caller_line CHAR(4),
-  event_id INT NOT NULL IDENTITY);
+DROP TABLE LOGGING_EVENT_EXCEPTION IF EXISTSu;
+DROP TABLE LOGGING_EVENT_PROPERTY IF EXISTS;
+DROP TABLE LOGGING_EVENT IF EXISTS;
 
+CREATE TABLE LOGGING_EVENT (
+  TIMESTMP BIGINT NOT NULL,
+  FORMATTED_MESSAGE LONGVARCHAR NOT NULL,
+  LOGGER_NAME VARCHAR(256) NOT NULL,
+  LEVEL_STRING VARCHAR(256) NOT NULL,
+  THREAD_NAME VARCHAR(256),
+  REFERENCE_FLAG SMALLINT,
+  CALLER_FILENAME VARCHAR(256), 
+  CALLER_CLASS VARCHAR(256), 
+  CALLER_METHOD VARCHAR(256), 
+  CALLER_LINE CHAR(4),
+  EVENT_ID IDENTITY NOT NULL);
 
-CREATE TABLE logging_event_property (
-  event_id INT NOT NULL,
-  mapped_key  VARCHAR(254) NOT NULL,
-  mapped_value LONGVARCHAR,
-  PRIMARY KEY(event_id, mapped_key),
-  FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
 
-CREATE TABLE logging_event_exception (
-  event_id INT NOT NULL,
-  i SMALLINT NOT NULL,
-  trace_line VARCHAR(256) NOT NULL,
-  PRIMARY KEY(event_id, i),
-  FOREIGN KEY (event_id) REFERENCES logging_event(event_id)); 
\ No newline at end of file
+CREATE TABLE LOGGING_EVENT_PROPERTY (
+  EVENT_ID BIGINT NOT NULL,
+  MAPPED_KEY  VARCHAR(254) NOT NULL,
+  MAPPED_VALUE LONGVARCHAR,
+  PRIMARY KEY(EVENT_ID, MAPPED_KEY),
+  FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));
+
+CREATE TABLE LOGGING_EVENT_EXCEPTION (
+  EVENT_ID BIGINT NOT NULL,
+  I SMALLINT NOT NULL,
+  TRACE_LINE VARCHAR(256) NOT NULL,
+  PRIMARY KEY(EVENT_ID, I),
+  FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql
index 3cdeccc..e308f34 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql
@@ -2,34 +2,34 @@
 #
 # It is intended for HSQL databases. It has been tested on HSQL 1.8.07.
 
-DROP TABLE logging_event_exception IF EXISTS;
-DROP TABLE logging_event_property IF EXISTS;
-DROP TABLE logging_event IF EXISTS;
+DROP TABLE LOGGING_EVENT_EXCEPTION IF EXISTSu;
+DROP TABLE LOGGING_EVENT_PROPERTY IF EXISTS;
+DROP TABLE LOGGING_EVENT IF EXISTS;
 
-CREATE TABLE logging_event (
-  timestmp BIGINT NOT NULL,
-  formatted_message LONGVARCHAR NOT NULL,
-  logger_name VARCHAR(256) NOT NULL,
-  level_string VARCHAR(256) NOT NULL,
-  thread_name VARCHAR(256),
-  reference_flag SMALLINT,
-  caller_filename VARCHAR(256), 
-  caller_class VARCHAR(256), 
-  caller_method VARCHAR(256), 
-  caller_line CHAR(4),
-  event_id INT NOT NULL IDENTITY);
+CREATE TABLE LOGGING_EVENT (
+  TIMESTMP BIGINT NOT NULL,
+  FORMATTED_MESSAGE LONGVARCHAR NOT NULL,
+  LOGGER_NAME VARCHAR(256) NOT NULL,
+  LEVEL_STRING VARCHAR(256) NOT NULL,
+  THREAD_NAME VARCHAR(256),
+  REFERENCE_FLAG SMALLINT,
+  CALLER_FILENAME VARCHAR(256), 
+  CALLER_CLASS VARCHAR(256), 
+  CALLER_METHOD VARCHAR(256), 
+  CALLER_LINE CHAR(4),
+  EVENT_ID BIGINT NOT NULL IDENTITY);
 
 
-CREATE TABLE logging_event_property (
-  event_id INT NOT NULL,
-  mapped_key  VARCHAR(254) NOT NULL,
-  mapped_value LONGVARCHAR,
-  PRIMARY KEY(event_id, mapped_key),
-  FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
+CREATE TABLE LOGGING_EVENT_PROPERTY (
+  EVENT_ID BIGINT NOT NULL,
+  MAPPED_KEY  VARCHAR(254) NOT NULL,
+  MAPPED_VALUE LONGVARCHAR,
+  PRIMARY KEY(EVENT_ID, MAPPED_KEY),
+  FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));
 
-CREATE TABLE logging_event_exception (
-  event_id INT NOT NULL,
-  i SMALLINT NOT NULL,
-  trace_line VARCHAR(256) NOT NULL,
-  PRIMARY KEY(event_id, i),
-  FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
\ No newline at end of file
+CREATE TABLE LOGGING_EVENT_EXCEPTION (
+  EVENT_ID BIGINT NOT NULL,
+  I SMALLINT NOT NULL,
+  TRACE_LINE VARCHAR(256) NOT NULL,
+  PRIMARY KEY(EVENT_ID, I),
+  FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));
\ No newline at end of file
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
index 3ba8e00..286d570 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
@@ -14,6 +14,7 @@
 package ch.qos.logback.classic.db;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.sql.ResultSet;
@@ -21,6 +22,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
 
+import org.apache.log4j.MDC;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -31,6 +33,7 @@ import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.db.DriverManagerConnectionSource;
+import ch.qos.logback.core.testUtil.RandomUtil;
 import ch.qos.logback.core.util.StatusPrinter;
 
 public class DBAppenderH2Test  {
@@ -39,8 +42,8 @@ public class DBAppenderH2Test  {
   Logger logger;
   DBAppender appender;
   DriverManagerConnectionSource connectionSource;
-
   DBAppenderH2TestFixture dbAppenderH2TestFixture;
+  int diff = RandomUtil.getPositiveInt();
   
   @Before
   public void setUp() throws SQLException {
@@ -58,6 +61,7 @@ public class DBAppenderH2Test  {
     connectionSource.setContext(lc);
     connectionSource.setDriverClass(DBAppenderH2TestFixture.H2_DRIVER_CLASS);
     connectionSource.setUrl(dbAppenderH2TestFixture.url);
+    System.out.println("cs.url="+dbAppenderH2TestFixture.url);
     connectionSource.setUser(dbAppenderH2TestFixture.user);
     connectionSource.setPassword(dbAppenderH2TestFixture.password);
     
@@ -109,17 +113,23 @@ public class DBAppenderH2Test  {
   @Test
   public void testAppendThrowable() throws SQLException {
     ILoggingEvent event = createLoggingEvent();
-
     appender.append(event);
-    
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
-    rs = stmt.executeQuery("SELECT * FROM logging_event_exception where event_id = 0");
+    rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_EXCEPTION WHERE EVENT_ID=1");
+    rs.next();
+    String expected = "java.lang.Exception: test Ex";
+    String firstLine = rs.getString(3);
+    assertTrue("["+firstLine+"] does not match ["+expected+"]", firstLine.contains(expected));
+    
     int i = 0;
     while (rs.next()) {
-      assertEquals(event.getThrowableProxy().getStackTraceElementProxyArray()[i].toString(), rs.getString(3));
+      expected = event.getThrowableProxy().getStackTraceElementProxyArray()[i].toString();
+      String st = rs.getString(3);
+      assertTrue("["+st+"] does not match ["+expected+"]", st.contains(expected));
       i++;
     }
+    assertTrue(i != 0);
     
     rs.close();
     stmt.close();
@@ -127,21 +137,24 @@ public class DBAppenderH2Test  {
   
   @Test
   public void testContextInfo() throws SQLException {
-    ILoggingEvent event = createLoggingEvent();
     lc.putProperty("testKey1", "testValue1");
+    MDC.put("k"+diff, "v"+diff);
+    ILoggingEvent event = createLoggingEvent();
     
     appender.append(event);
     
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
-    rs = stmt.executeQuery("SELECT * FROM logging_event_property where event_id = 0");
+    rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_PROPERTY WHERE EVENT_ID=1");
     Map<String, String> map = appender.mergePropertyMaps(event);
+    int i = 0;
     while (rs.next()) {
       String key = rs.getString(2);
       assertEquals(map.get(key), rs.getString(3));
-      //System.out.println("value: " + map.get(key));
+      i++;
     }
-    
+    assertTrue(map.size() != 0);
+    assertEquals(map.size(), i);
     rs.close();
     stmt.close();
   }
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java
index 8727b25..810e73a 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java
@@ -31,7 +31,6 @@ public class DBAppenderH2TestFixture  {
   }
   
   public static final String H2_DRIVER_CLASS = "org.h2.Driver";
-  // String serverProps;
   String url = null;
   String user = "sa";
   String password = "";
@@ -70,6 +69,7 @@ public class DBAppenderH2TestFixture  {
   }
 
   Connection newConnection() throws SQLException {
+    System.out.println("url="+url);
     org.h2.Driver driver = Driver.load();
     Properties props = new Properties();
     props.setProperty("user", user);
@@ -80,50 +80,50 @@ public class DBAppenderH2TestFixture  {
   private void createTables() throws SQLException {
     assertNotNull(connection);
     StringBuffer buf = new StringBuffer();
-    buf.append("CREATE TABLE logging_event (");
-    buf.append("timestmp BIGINT NOT NULL,");
-    buf.append("formatted_message LONGVARCHAR NOT NULL,");
-    buf.append("logger_name VARCHAR(256) NOT NULL,");
-    buf.append("level_string VARCHAR(256) NOT NULL,");
-    buf.append("thread_name VARCHAR(256),");
-    buf.append("reference_flag SMALLINT,");
-    buf.append("caller_filename VARCHAR(256), ");
-    buf.append("caller_class VARCHAR(256), ");
-    buf.append("caller_method VARCHAR(256), ");
-    buf.append("caller_line CHAR(4), ");
-    buf.append("event_id INT NOT NULL IDENTITY);");
+    buf.append("CREATE TABLE LOGGING_EVENT (");
+    buf.append("TIMESTMP BIGINT NOT NULL,");
+    buf.append("FORMATTED_MESSAGE LONGVARCHAR NOT NULL,");
+    buf.append("LOGGER_NAME VARCHAR(256) NOT NULL,");
+    buf.append("LEVEL_STRING VARCHAR(256) NOT NULL,");
+    buf.append("THREAD_NAME VARCHAR(256),");
+    buf.append("REFERENCE_FLAG SMALLINT,");
+    buf.append("CALLER_FILENAME VARCHAR(256), ");
+    buf.append("CALLER_CLASS VARCHAR(256), ");
+    buf.append("CALLER_METHOD VARCHAR(256), ");
+    buf.append("CALLER_LINE CHAR(4), ");
+    buf.append("EVENT_ID IDENTITY NOT NULL);");
     executeQuery(connection, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("CREATE TABLE logging_event_property (");
-    buf.append("event_id INT NOT NULL,");
-    buf.append("mapped_key  VARCHAR(254) NOT NULL,");
-    buf.append("mapped_value LONGVARCHAR,");
-    buf.append("PRIMARY KEY(event_id, mapped_key),");
-    buf.append("FOREIGN KEY (event_id) REFERENCES logging_event(event_id));");
+    buf.append("CREATE TABLE LOGGING_EVENT_PROPERTY (");
+    buf.append("EVENT_ID BIGINT NOT NULL,");
+    buf.append("MAPPED_KEY  VARCHAR(254) NOT NULL,");
+    buf.append("MAPPED_VALUE LONGVARCHAR,");
+    buf.append("PRIMARY KEY(EVENT_ID, MAPPED_KEY),");
+    buf.append("FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));");
     executeQuery(connection, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("CREATE TABLE logging_event_exception (");
-    buf.append("event_id INT NOT NULL,");
-    buf.append("i SMALLINT NOT NULL,");
-    buf.append("trace_line VARCHAR(256) NOT NULL,");
-    buf.append("PRIMARY KEY(event_id, i),");
-    buf.append("FOREIGN KEY (event_id) REFERENCES logging_event(event_id));");
+    buf.append("CREATE TABLE LOGGING_EVENT_EXCEPTION (");
+    buf.append("EVENT_ID BIGINT NOT NULL,");
+    buf.append("I SMALLINT NOT NULL,");
+    buf.append("TRACE_LINE VARCHAR(256) NOT NULL,");
+    buf.append("PRIMARY KEY(EVENT_ID, I),");
+    buf.append("FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));");
     executeQuery(connection, buf.toString());
   }
 
   private  void dropTables() throws SQLException {
     StringBuffer buf = new StringBuffer();
-    buf.append("DROP TABLE logging_event_exception IF EXISTS;");
+    buf.append("DROP TABLE LOGGING_EVENT_EXCEPTION IF EXISTS;");
     executeQuery(connection, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("DROP TABLE logging_event_property IF EXISTS;");
+    buf.append("DROP TABLE LOGGING_EVENT_PROPERTY IF EXISTS;");
     executeQuery(connection, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("DROP TABLE logging_event IF EXISTS;");
+    buf.append("DROP TABLE LOGGING_EVENT IF EXISTS;");
     executeQuery(connection, buf.toString());
   }
 
@@ -132,7 +132,7 @@ public class DBAppenderH2TestFixture  {
     st = conn.createStatement();
     int i = st.executeUpdate(expression);
     if (i == -1) {
-      System.out.println("db error : " + expression);
+      throw new IllegalStateException("db error : " + expression);
     }
     st.close();
   }
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java
index 51117cd..20cead3 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java
@@ -14,6 +14,7 @@
 package ch.qos.logback.classic.db;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.sql.ResultSet;
@@ -21,6 +22,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
 
+import org.apache.log4j.MDC;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -31,6 +33,7 @@ import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.db.DriverManagerConnectionSource;
+import ch.qos.logback.core.testUtil.RandomUtil;
 
 public class DBAppenderHSQLTest  {
 
@@ -40,6 +43,7 @@ public class DBAppenderHSQLTest  {
   DriverManagerConnectionSource connectionSource;
 
   DBAppenderHSQLTestFixture dbAppenderHSQLTestFixture;
+  int diff = RandomUtil.getPositiveInt();
   
   @Before
   public void setUp() throws SQLException {
@@ -109,34 +113,46 @@ public class DBAppenderHSQLTest  {
     
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
-    rs = stmt.executeQuery("SELECT * FROM logging_event_exception where event_id = 0");
+    rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_EXCEPTION where EVENT_ID = 0");
+    
+    rs.next();
+    String expected = "java.lang.Exception: test Ex";
+    String firstLine = rs.getString(3);
+    assertTrue("["+firstLine+"] does not match ["+expected+"]", firstLine.contains(expected));
+    
     int i = 0;
     while (rs.next()) {
-      assertEquals(event.getThrowableProxy().getStackTraceElementProxyArray()[i].toString(), rs.getString(3));
+      expected = event.getThrowableProxy().getStackTraceElementProxyArray()[i].toString();
+      String st = rs.getString(3);
+      assertTrue("["+st+"] does not match ["+expected+"]", st.contains(expected));
       i++;
     }
-    
+    assertTrue(i != 0);
     rs.close();
     stmt.close();
   }
   
   @Test
   public void testContextInfo() throws SQLException {
-    ILoggingEvent event = createLoggingEvent();
     lc.putProperty("testKey1", "testValue1");
+    MDC.put("k"+diff, "v"+diff);
+    ILoggingEvent event = createLoggingEvent();
     
     appender.append(event);
     
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
-    rs = stmt.executeQuery("SELECT * FROM logging_event_property where event_id = 0");
+    rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_PROPERTY  WHERE EVENT_ID = 0");
     Map<String, String> map = appender.mergePropertyMaps(event);
+    System.out.println("ma.size="+map.size());
+    int i = 0;
     while (rs.next()) {
       String key = rs.getString(2);
       assertEquals(map.get(key), rs.getString(3));
-      //System.out.println("value: " + map.get(key));
+      i++;
     }
-    
+    assertTrue(map.size() != 0);
+    assertEquals(map.size(), i);
     rs.close();
     stmt.close();
   }
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java
index 1f6e00f..30f8a58 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java
@@ -108,51 +108,51 @@ public class DBAppenderHSQLTestFixture  {
     Connection conn = newConnection();
     assertNotNull(conn);
     StringBuffer buf = new StringBuffer();
-    buf.append("CREATE TABLE logging_event (");
-    buf.append("timestmp BIGINT NOT NULL,");
-    buf.append("formatted_message LONGVARCHAR NOT NULL,");
-    buf.append("logger_name VARCHAR(256) NOT NULL,");
-    buf.append("level_string VARCHAR(256) NOT NULL,");
-    buf.append("thread_name VARCHAR(256),");
-    buf.append("reference_flag SMALLINT,");
-    buf.append("caller_filename VARCHAR(256), ");
-    buf.append("caller_class VARCHAR(256), ");
-    buf.append("caller_method VARCHAR(256), ");
-    buf.append("caller_line CHAR(4), ");
-    buf.append("event_id INT NOT NULL IDENTITY);");
+    buf.append("CREATE TABLE LOGGING_EVENT (");
+    buf.append("TIMESTMP BIGINT NOT NULL,");
+    buf.append("FORMATTED_MESSAGE LONGVARCHAR NOT NULL,");
+    buf.append("LOGGER_NAME VARCHAR(256) NOT NULL,");
+    buf.append("LEVEL_STRING VARCHAR(256) NOT NULL,");
+    buf.append("THREAD_NAME VARCHAR(256),");
+    buf.append("REFERENCE_FLAG SMALLINT,");
+    buf.append("CALLER_FILENAME VARCHAR(256), ");
+    buf.append("CALLER_CLASS VARCHAR(256), ");
+    buf.append("CALLER_METHOD VARCHAR(256), ");
+    buf.append("CALLER_LINE CHAR(4), ");
+    buf.append("EVENT_ID BIGINT NOT NULL IDENTITY);");
     query(conn, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("CREATE TABLE logging_event_property (");
-    buf.append("event_id INT NOT NULL,");
-    buf.append("mapped_key  VARCHAR(254) NOT NULL,");
-    buf.append("mapped_value LONGVARCHAR,");
-    buf.append("PRIMARY KEY(event_id, mapped_key),");
-    buf.append("FOREIGN KEY (event_id) REFERENCES logging_event(event_id));");
+    buf.append("CREATE TABLE LOGGING_EVENT_PROPERTY (");
+    buf.append("EVENT_ID BIGINT NOT NULL,");
+    buf.append("MAPPED_KEY  VARCHAR(254) NOT NULL,");
+    buf.append("MAPPED_VALUE LONGVARCHAR,");
+    buf.append("PRIMARY KEY(EVENT_ID, MAPPED_KEY),");
+    buf.append("FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));");
     query(conn, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("CREATE TABLE logging_event_exception (");
-    buf.append("event_id INT NOT NULL,");
-    buf.append("i SMALLINT NOT NULL,");
-    buf.append("trace_line VARCHAR(256) NOT NULL,");
-    buf.append("PRIMARY KEY(event_id, i),");
-    buf.append("FOREIGN KEY (event_id) REFERENCES logging_event(event_id));");
+    buf.append("CREATE TABLE LOGGING_EVENT_EXCEPTION (");
+    buf.append("EVENT_ID BIGINT NOT NULL,");
+    buf.append("I SMALLINT NOT NULL,");
+    buf.append("TRACE_LINE VARCHAR(256) NOT NULL,");
+    buf.append("PRIMARY KEY(EVENT_ID, I),");
+    buf.append("FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));");
     query(conn, buf.toString());
   }
 
   private  void dropTables() throws SQLException {
     Connection conn = newConnection();
     StringBuffer buf = new StringBuffer();
-    buf.append("DROP TABLE logging_event_exception IF EXISTS;");
+    buf.append("DROP TABLE LOGGING_EVENT_EXCEPTION IF EXISTS;");
     query(conn, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("DROP TABLE logging_event_property IF EXISTS;");
+    buf.append("DROP TABLE LOGGING_EVENT_PROPERTY IF EXISTS;");
     query(conn, buf.toString());
 
     buf = new StringBuffer();
-    buf.append("DROP TABLE logging_event IF EXISTS;");
+    buf.append("DROP TABLE LOGGING_EVENT IF EXISTS;");
     query(conn, buf.toString());
   }
 
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
index 869fe27..5c90451 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
@@ -18,6 +18,7 @@ import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(Suite.class)
- at SuiteClasses( {DBAppenderHSQLTest.class})
+ at SuiteClasses( { DBAppenderHSQLTest.class, DBAppenderH2Test.class,
+    DBAppenderIntegrationTest.class })
 public class PackageTest {
 }
\ No newline at end of file
diff --git a/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
index ed08712..373ce6c 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
@@ -118,7 +118,7 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
   protected abstract void subAppend(Object eventObject, Connection connection,
       PreparedStatement statement) throws Throwable;
 
-  protected int selectEventId(PreparedStatement insertStatement,
+  protected long selectEventId(PreparedStatement insertStatement,
       Connection connection) throws SQLException, InvocationTargetException {
     ResultSet rs = null;
     Statement idStatement = null;
@@ -150,7 +150,7 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
     // A ResultSet cursor is initially positioned before the first row;
     // the first call to the method next makes the first row the current row
     rs.next();
-    int eventId = rs.getInt(1);
+    long eventId = rs.getLong(1);
 
     rs.close();
 

-----------------------------------------------------------------------

Summary of changes:
 .../java/ch/qos/logback/access/db/DBAppender.java  |    6 +-
 .../java/ch/qos/logback/classic/db/DBAppender.java |   17 ++++---
 .../java/ch/qos/logback/classic/db/dialect/h2.sql  |   57 ++++++++++----------
 .../ch/qos/logback/classic/db/dialect/hsqldb.sql   |   54 +++++++++---------
 .../qos/logback/classic/db/DBAppenderH2Test.java   |   31 ++++++++---
 .../classic/db/DBAppenderH2TestFixture.java        |   58 ++++++++++----------
 .../qos/logback/classic/db/DBAppenderHSQLTest.java |   30 ++++++++---
 .../classic/db/DBAppenderHSQLTestFixture.java      |   54 +++++++++---------
 .../ch/qos/logback/classic/db/PackageTest.java     |    3 +-
 .../ch/qos/logback/core/db/DBAppenderBase.java     |    4 +-
 10 files changed, 174 insertions(+), 140 deletions(-)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list