[logback-dev] svn commit: r1860 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/db logback-classic logback-classic/src/main/java/ch/qos/logback/classic/db logback-classic/src/test/input/integration logback-classic/src/test/input/integration/db logback-classic/src/test/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 logback-examples logback-examples/src/main/java/chapter4/mail logback-site/src/site/pages/manual

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Oct 22 22:50:48 CEST 2008


Author: ceki
Date: Wed Oct 22 22:50:47 2008
New Revision: 1860

Added:
   logback/trunk/logback-classic/src/test/input/integration/
   logback/trunk/logback-classic/src/test/input/integration/db/
   logback/trunk/logback-classic/src/test/input/integration/db/mysql-with-driver.xml
   logback/trunk/logback-classic/src/test/input/integration/db/oracle10g-with-driver.xml
   logback/trunk/logback-classic/src/test/input/integration/db/oracle11g-with-driver.xml
   logback/trunk/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml
   logback/trunk/logback-classic/src/test/input/integration/db/sqlserver-with-driver.xml
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialectCode.java
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
   logback/trunk/logback-classic/pom.xml
   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/ConnectionSource.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSourceBase.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/DataSourceConnectionSource.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/DBUtil.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/HSQLDBDialect.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialect.java
   logback/trunk/logback-examples/pom.xml
   logback/trunk/logback-examples/src/main/java/chapter4/mail/   (props changed)
   logback/trunk/logback-site/src/site/pages/manual/appenders.html

Log:
Related to LBCORE-15

- minor refactoring in DBAppender and related classes
- As suggested by John Gibson in LBCORE-15, we now use the prepareStatement method of 
  Connection which takes the sql statement followed by the autogenerateed key columnNames 
  (of type String[])

  This change is compatible with JDBC drivers of SQLServer and MySQL, as well as Oracle.

  JDBC drivers not supporting getGeneratedKeys are not affected by this change.

- added integration tests which are active only on my machine, namely, Orion. This avoids other
  developers from having to install Oracle, MySQL, Postgres and SQL Server just for the 
  logback tests to pass.
  
- similar tests on logback-access to follow.  

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java	Wed Oct 22 22:50:47 2008
@@ -79,7 +79,7 @@
     }
     
     if (insertHeaders) {
-      int eventId = getEventId(insertStatement, connection);
+      int eventId = selectEventId(insertStatement, connection);
       addRequestHeaders(event, connection, eventId);
     }
   }

Modified: logback/trunk/logback-classic/pom.xml
==============================================================================
--- logback/trunk/logback-classic/pom.xml	(original)
+++ logback/trunk/logback-classic/pom.xml	Wed Oct 22 22:50:47 2008
@@ -171,8 +171,46 @@
         </configuration>
       </plugin>
     </plugins>
+  </build>
 
+	<profiles>
+    
+		<profile>
+      <!-- Integration tests require the host-orion profile -->
+			<id>host-orion</id>
+	
+			<dependencies>
+        <dependency>
+          <groupId>mysql</groupId>
+          <artifactId>mysql-connector-java</artifactId>
+          <version>5.0.8</version>
+          <scope>test</scope>
+				</dependency>
 
-  </build>
+        <dependency>
+          <groupId>postgresql</groupId>
+          <artifactId>postgresql</artifactId>
+          <version>8.2-507.jdbc3</version>
+        </dependency>
+
+        <!-- locally installed artifact -->        
+				<dependency>
+					<groupId>com.microsoft.sqlserver</groupId>
+					<artifactId>sqljdbc</artifactId>
+					<version>2.0</version>
+          <scope>test</scope>
+				</dependency>
+        <!-- locally installed artifact -->
+        <dependency>
+          <groupId>com.oracle</groupId>
+          <artifactId>ojdbc14</artifactId>
+          <version>10.2.0.1</version>
+          <scope>test</scope>
+				</dependency>
+			</dependencies>
+
+		</profile>
+
+	</profiles>
 
 </project>
\ No newline at end of file

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	Wed Oct 22 22:50:47 2008
@@ -56,11 +56,11 @@
     sql.append("caller_line) ");
     sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?,?)");
     insertSQL = sql.toString();
-    //
-    // PreparedStatement.getGeneratedKeys added in JDK 1.4
-    //
+    
+    // PreparedStatement.getGeneratedKeys() method was added in JDK 1.4
     Method getGeneratedKeysMethod;
     try {
+      // the 
       getGeneratedKeysMethod = PreparedStatement.class.getMethod(
           "getGeneratedKeys", (Class[]) null);
     } catch (Exception ex) {
@@ -77,16 +77,16 @@
       PreparedStatement insertStatement) throws Throwable {
     LoggingEvent event = (LoggingEvent) eventObject;
 
-    addLoggingEvent(insertStatement, event);
-    // This is very expensive... should we do it every time?
-    addCallerData(insertStatement, event.getCallerData());
+    bindLoggingEventWithInsertStatement(insertStatement, event);
+    // This is expensive... should we do it every time?
+    bindCallerDataWithPreparedStatement(insertStatement, event.getCallerData());
 
     int updateCount = insertStatement.executeUpdate();
     if (updateCount != 1) {
       addWarn("Failed to insert loggingEvent");
     }
 
-    int eventId = getEventId(insertStatement, connection);
+    int eventId = selectEventId(insertStatement, connection);
 
     Map<String, String> mergedMap = mergePropertyMaps(event);
     insertProperties(mergedMap, connection, eventId);
@@ -96,7 +96,7 @@
     }
   }
 
-  void addLoggingEvent(PreparedStatement stmt, LoggingEvent event)
+  void bindLoggingEventWithInsertStatement(PreparedStatement stmt, LoggingEvent event)
       throws SQLException {
     stmt.setLong(1, event.getTimeStamp());
     stmt.setString(2, event.getFormattedMessage());
@@ -106,7 +106,7 @@
     stmt.setShort(6, DBHelper.computeReferenceMask(event));
   }
 
-  void addCallerData(PreparedStatement stmt, CallerData[] callerDataArray)
+  void bindCallerDataWithPreparedStatement(PreparedStatement stmt, CallerData[] callerDataArray)
       throws SQLException {
     CallerData callerData = callerDataArray[0];
     if (callerData != null) {

Added: logback/trunk/logback-classic/src/test/input/integration/db/mysql-with-driver.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/integration/db/mysql-with-driver.xml	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+			<driverClass>com.mysql.jdbc.Driver</driverClass>
+			<url>jdbc:mysql://localhost:3306/logback</url>
+			<user>root</user>
+			<password></password>
+		</connectionSource>
+	</appender>
+	
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+</configuration>

Added: logback/trunk/logback-classic/src/test/input/integration/db/oracle10g-with-driver.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/integration/db/oracle10g-with-driver.xml	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+			<driverClass>oracle.jdbc.OracleDriver</driverClass>
+			<url>jdbc:oracle:thin:@localhost:1522:xe</url>
+			<user>hr</user>
+			<password>hr</password>
+		</connectionSource>
+	</appender>
+	
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+</configuration>

Added: logback/trunk/logback-classic/src/test/input/integration/db/oracle11g-with-driver.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/integration/db/oracle11g-with-driver.xml	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+			<driverClass>oracle.jdbc.OracleDriver</driverClass>
+			<url>jdbc:oracle:thin:@localhost:1521:orcl</url>
+			<user>SCOTT</user>
+			<password>SCOTT</password>
+		</connectionSource>
+	</appender>
+	
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+</configuration>

Added: logback/trunk/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+			<driverClass>org.postgresql.Driver</driverClass>
+			<url>jdbc:postgresql://192.168.1.5:5432/test</url>
+			<user>logback</user>
+			<password>logback</password>
+		</connectionSource>
+	</appender>
+	
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+</configuration>

Added: logback/trunk/logback-classic/src/test/input/integration/db/sqlserver-with-driver.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/integration/db/sqlserver-with-driver.xml	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+			<driverClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</driverClass>
+			<url>jdbc:sqlserver://localhost:1987;databaseName=logback;</url>
+			<user>logback</user>
+			<password>logback</password>
+		</connectionSource>
+	</appender>
+	
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+</configuration>

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,126 @@
+package ch.qos.logback.classic.db;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.InetAddress;
+import java.util.Random;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.MDC;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class DBAppenderIntegrationTest {
+
+  static String LOCAL_HOST_NAME;
+  static String[] CONFORMING_HOST_LIST = new String[] { "Orion" };
+
+  int diff = new Random(System.nanoTime()).nextInt(10000);
+  LoggerContext lc = new LoggerContext();
+  
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    InetAddress localhostIA = InetAddress.getLocalHost();
+    LOCAL_HOST_NAME = localhostIA.getHostName();
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    lc.setName("lc"+diff);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    lc.shutdownAndReset();
+  }
+
+  public void doTest(String configFile) throws JoranException {
+    JoranConfigurator configurator = new JoranConfigurator();
+    configurator.setContext(lc);
+    configurator.doConfigure(configFile);
+
+    Logger logger = lc.getLogger(DBAppenderIntegrationTest.class);
+
+    MDC.put("userid", "user" + diff);
+    int runLength = 5;
+    for (int i = 1; i <= runLength; i++) {
+      logger.debug("This is a debug message. Message number: " + i);
+    }
+    logger.error("At last an error.", new Exception("Just testing"));
+    
+    // check that there were no errors
+    StatusPrinter.print(lc);
+    assertEquals(Status.INFO, lc.getStatusManager().getLevel());
+    
+  }
+  
+  static boolean isConformingHost() {
+    for (String conformingHost : CONFORMING_HOST_LIST) {
+      if (conformingHost.equalsIgnoreCase(LOCAL_HOST_NAME)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @Test
+  public void sqlserver() throws Exception {
+    // perform test only on conforming hosts
+    if (!isConformingHost()) {
+      return;
+    }
+    doTest("src/test/input/integration/db/sqlserver-with-driver.xml");
+  }
+
+  @Test
+  public void oracle10g() throws Exception {
+    // perform test only on conforming hosts
+    if (!isConformingHost()) {
+      return;
+    }
+    doTest("src/test/input/integration/db/oracle10g-with-driver.xml");
+  }
+
+  @Test
+  @Ignore
+  public void oracle11g() throws Exception {
+    // perform test only on conforming hosts
+    if (!isConformingHost()) {
+      return;
+    }
+    doTest("src/test/input/integration/db/oracle11g-with-driver.xml");
+  }
+  
+  @Test
+  public void mysql() throws Exception {
+    // perform test only on conforming hosts
+    if (!isConformingHost()) {
+      return;
+    }
+    doTest("src/test/input/integration/db/mysql-with-driver.xml");
+  }
+  
+  @Test
+  public void postgres() throws Exception {
+    // perform test only on conforming hosts
+    if (!isConformingHost()) {
+      return;
+    }
+    doTest("src/test/input/integration/db/postgresql-with-driver.xml");
+  }
+  
+}

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSource.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSource.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSource.java	Wed Oct 22 22:50:47 2008
@@ -12,6 +12,7 @@
 import java.sql.Connection;
 import java.sql.SQLException;
 
+import ch.qos.logback.core.db.dialect.SQLDialectCode;
 import ch.qos.logback.core.spi.LifeCycle;
 
 
@@ -27,12 +28,6 @@
  */
 public interface ConnectionSource extends LifeCycle {
 
-  final int UNKNOWN_DIALECT = 0;
-  final int POSTGRES_DIALECT = 1;
-  final int MYSQL_DIALECT = 2;
-  final int ORACLE_DIALECT = 3;
-  final int MSSQL_DIALECT = 4;
-  final int HSQL_DIALECT = 5;  
   /**
    *  Obtain a {@link java.sql.Connection} for use.  The client is
    *  responsible for closing the {@link java.sql.Connection} when it is no
@@ -48,7 +43,7 @@
    * dialect is not needed if the JDBC driver supports the getGeneratedKeys 
    * method.
    */
-  int getSQLDialectCode();
+  SQLDialectCode getSQLDialectCode();
   
   /**
    * If the connection supports the JDBC 3.0 getGeneratedKeys method, then

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSourceBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSourceBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/ConnectionSourceBase.java	Wed Oct 22 22:50:47 2008
@@ -14,6 +14,7 @@
 import java.sql.SQLException;
 
 import ch.qos.logback.core.db.dialect.DBUtil;
+import ch.qos.logback.core.db.dialect.SQLDialectCode;
 import ch.qos.logback.core.spi.ContextAwareBase;
 
 
@@ -28,7 +29,7 @@
   private String password = null;
 
   // initially we have an unkonw dialect
-  private int dialectCode = UNKNOWN_DIALECT;
+  private SQLDialectCode dialectCode = SQLDialectCode.UNKNOWN_DIALECT;
   private boolean supportsGetGeneratedKeys = false;
   private boolean supportsBatchUpdates = false;
 
@@ -50,6 +51,10 @@
       supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
       supportsBatchUpdates = util.supportsBatchUpdates(meta);
       dialectCode = DBUtil.discoverSQLDialect(meta);
+      System.out.println("Driver name="+meta.getDriverName());
+      System.out.println("Driver version="+meta.getDriverVersion());
+      System.out.println("supportsGetGeneratedKeys="+supportsGetGeneratedKeys);
+      
     } catch (SQLException se) {
       addWarn("Could not discover the dialect to use.", se);
     }
@@ -62,7 +67,7 @@
     return supportsGetGeneratedKeys;
   }
 
-  public final int getSQLDialectCode() {
+  public final SQLDialectCode getSQLDialectCode() {
     return dialectCode;
   }
 

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	Wed Oct 22 22:50:47 2008
@@ -35,8 +35,9 @@
   protected SQLDialect sqlDialect;
 
   protected abstract Method getGeneratedKeysMethod();
+
   protected abstract String getInsertSQL();
-  
+
   @Override
   public void start() {
 
@@ -45,6 +46,7 @@
           "DBAppender cannot function without a connection source");
     }
 
+    System.out.println(connectionSource.supportsGetGeneratedKeys());
     sqlDialect = DBUtil
         .getDialectFromCode(connectionSource.getSQLDialectCode());
     if (getGeneratedKeysMethod() != null) {
@@ -71,7 +73,7 @@
 
   /**
    * @param connectionSource
-   *          The connectionSource to set.
+   *                The connectionSource to set.
    */
   public void setConnectionSource(ConnectionSource connectionSource) {
     this.connectionSource = connectionSource;
@@ -83,10 +85,13 @@
     try {
       connection = connectionSource.getConnection();
       connection.setAutoCommit(false);
-
-      PreparedStatement insertStatement = connection
-          .prepareStatement(getInsertSQL());
-
+      PreparedStatement insertStatement;
+      if (cnxSupportsGetGeneratedKeys) {
+        insertStatement = connection.prepareStatement(getInsertSQL(),
+            new String[] {"EVENT_ID"});
+      } else {
+        insertStatement = connection.prepareStatement(getInsertSQL());
+      }
       subAppend(eventObject, connection, insertStatement);
 
       // we no longer need the insertStatement
@@ -94,7 +99,6 @@
         insertStatement.close();
         insertStatement = null;
       }
-
       connection.commit();
     } catch (Throwable sqle) {
       addError("problem appending event", sqle);
@@ -106,7 +110,7 @@
   protected abstract void subAppend(Object eventObject, Connection connection,
       PreparedStatement statement) throws Throwable;
 
-  protected int getEventId(PreparedStatement insertStatement,
+  protected int selectEventId(PreparedStatement insertStatement,
       Connection connection) throws SQLException, InvocationTargetException {
     ResultSet rs = null;
     Statement idStatement = null;
@@ -139,8 +143,7 @@
     }
 
     // A ResultSet cursor is initially positioned before the first row;
-    // the
-    // first call to the method next makes the first row the current row
+    // the first call to the method next makes the first row the current row
     rs.next();
     int eventId = rs.getInt(1);
 

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java	Wed Oct 22 22:50:47 2008
@@ -15,6 +15,8 @@
 
 import javax.sql.DataSource;
 
+import ch.qos.logback.core.db.dialect.SQLDialectCode;
+
 /**
  * The DataSourceConnectionSource is an implementation of
  * {@link ConnectionSource} that obtains the Connection in the recommended JDBC
@@ -47,7 +49,7 @@
         discoverConnnectionProperties();
       }
       if (!supportsGetGeneratedKeys()
-          && getSQLDialectCode() == ConnectionSource.UNKNOWN_DIALECT) {
+          && getSQLDialectCode() == SQLDialectCode.UNKNOWN_DIALECT) {
         addWarn("Connection does not support GetGeneratedKey method and could not discover the dialect.");
       }
     }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/DBUtil.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/DBUtil.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/DBUtil.java	Wed Oct 22 22:50:47 2008
@@ -12,7 +12,6 @@
 import java.sql.DatabaseMetaData;
 import java.sql.SQLException;
 
-import ch.qos.logback.core.db.ConnectionSource;
 import ch.qos.logback.core.spi.ContextAwareBase;
 
 /**
@@ -28,25 +27,25 @@
   private static final String MSSQL_PART = "microsoft";
   private static final String HSQL_PART = "hsql";
 
-  public static int discoverSQLDialect(DatabaseMetaData meta) {
-    int dialectCode = 0;
+  public static SQLDialectCode discoverSQLDialect(DatabaseMetaData meta) {
+    SQLDialectCode dialectCode = SQLDialectCode.UNKNOWN_DIALECT;
 
     try {
 
       String dbName = meta.getDatabaseProductName().toLowerCase();
 
       if (dbName.indexOf(POSTGRES_PART) != -1) {
-        return ConnectionSource.POSTGRES_DIALECT;
+        return SQLDialectCode.POSTGRES_DIALECT;
       } else if (dbName.indexOf(MYSQL_PART) != -1) {
-        return ConnectionSource.MYSQL_DIALECT;
+        return SQLDialectCode.MYSQL_DIALECT;
       } else if (dbName.indexOf(ORACLE_PART) != -1) {
-        return ConnectionSource.ORACLE_DIALECT;
+        return SQLDialectCode.ORACLE_DIALECT;
       } else if (dbName.indexOf(MSSQL_PART) != -1) {
-        return ConnectionSource.MSSQL_DIALECT;
+        return SQLDialectCode.MSSQL_DIALECT;
       } else if (dbName.indexOf(HSQL_PART) != -1) {
-        return ConnectionSource.HSQL_DIALECT;
+        return SQLDialectCode.HSQL_DIALECT;
       } else {
-        return ConnectionSource.UNKNOWN_DIALECT;
+        return SQLDialectCode.UNKNOWN_DIALECT;
       }
     } catch (SQLException sqle) {
       // we can't do much here
@@ -55,27 +54,27 @@
     return dialectCode;
   }
 
-  public static SQLDialect getDialectFromCode(int dialectCode) {
+  public static SQLDialect getDialectFromCode(SQLDialectCode sqlDialectType) {
     SQLDialect sqlDialect = null;
 
-    switch (dialectCode) {
-    case ConnectionSource.POSTGRES_DIALECT:
+    switch (sqlDialectType) {
+    case POSTGRES_DIALECT:
       sqlDialect = new PostgreSQLDialect();
 
       break;
-    case ConnectionSource.MYSQL_DIALECT:
+    case MYSQL_DIALECT:
       sqlDialect = new MySQLDialect();
 
       break;
-    case ConnectionSource.ORACLE_DIALECT:
+    case ORACLE_DIALECT:
       sqlDialect = new OracleDialect();
 
       break;
-    case ConnectionSource.MSSQL_DIALECT:
+    case MSSQL_DIALECT:
       sqlDialect = new MsSQLDialect();
 
       break;
-    case ConnectionSource.HSQL_DIALECT:
+    case HSQL_DIALECT:
       sqlDialect = new HSQLDBDialect();
 
       break;

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/HSQLDBDialect.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/HSQLDBDialect.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/HSQLDBDialect.java	Wed Oct 22 22:50:47 2008
@@ -7,17 +7,18 @@
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation.
  */
-package ch.qos.logback.core.db.dialect; 
+package ch.qos.logback.core.db.dialect;
 
-/** 
- * The HSQLDB dialect. 
+/**
+ * The HSQLDB dialect.
  * 
  * @author Ceki G&uuml;lc&uuml;
-*/ 
-public class HSQLDBDialect implements SQLDialect { 
- public static final String SELECT_CURRVAL = "CALL IDENTITY()"; 
+ */
+public class HSQLDBDialect implements SQLDialect {
+  public static final String SELECT_CURRVAL = "CALL IDENTITY()";
 
- public String getSelectInsertId() { 
-   return SELECT_CURRVAL; 
- } 
+  public String getSelectInsertId() {
+    return SELECT_CURRVAL;
+  }
+  
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialect.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialect.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialect.java	Wed Oct 22 22:50:47 2008
@@ -10,11 +10,9 @@
 package ch.qos.logback.core.db.dialect;
 
 /**
- * @author ceki
+ * @author Ceki G&uuml;c&uuml;
  *
  */
 public interface SQLDialect {
-  
   public String getSelectInsertId();
-  
 }

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialectCode.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/SQLDialectCode.java	Wed Oct 22 22:50:47 2008
@@ -0,0 +1,10 @@
+package ch.qos.logback.core.db.dialect;
+
+public enum SQLDialectCode {
+  UNKNOWN_DIALECT,
+  POSTGRES_DIALECT,
+  MYSQL_DIALECT,
+  ORACLE_DIALECT,
+  MSSQL_DIALECT,
+  HSQL_DIALECT;  
+}

Modified: logback/trunk/logback-examples/pom.xml
==============================================================================
--- logback/trunk/logback-examples/pom.xml	(original)
+++ logback/trunk/logback-examples/pom.xml	Wed Oct 22 22:50:47 2008
@@ -101,5 +101,4 @@
 			</plugin>
 		</plugins>
 	</build>
-
 </project>
\ No newline at end of file

Modified: logback/trunk/logback-site/src/site/pages/manual/appenders.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/appenders.html	(original)
+++ logback/trunk/logback-site/src/site/pages/manual/appenders.html	Wed Oct 22 22:50:47 2008
@@ -2299,8 +2299,9 @@
 
     </p>
 
-		<a name="DBAppender"></a>
-		<h3>DBAppender</h3>
+    <h3>
+      <a name="DBAppender" href="#DBAppender">DBAppender</a>
+		</h3>
 		
 		<p>The <a
 		href="../xref/ch/qos/logback/classic/db/DBAppender.html"><code>DBAppender</code></a>
@@ -2322,79 +2323,88 @@
 		to us, we will gladly include missing scripts in future releases.
 		</p>
 
-		<p>
-			If your JDBC driver supports the
-			<code>getGeneratedKeys</code> method introduced in
-			JDBC 3.0 specification, then no more steps are required, excluding usual
-			configuration. 
-		</p>
-		<p>
-			Otherwise, there must be an <code>SQLDialect</code> appropriate for your
-			database system. Currently, we have dialects for PostgreSQL,
-			MySQL, Oracle and MsSQL. As mentioned previously, an
-			<code>SQLDialect</code> is required only if the JDBC driver for your
-			database system does not support the <code>getGeneratedKeys</code>
-			method.
+		<p>If your JDBC driver supports the <code>getGeneratedKeys</code>
+		method introduced in JDBC 3.0 specification, assuming you have
+		created the appropriate database tables as mentioned above, then
+		no more steps are required, excluding usual logback configuration.
 		</p>
 
-		<p>
-			The table below summarizes the database types and their support of the 
-			<code>getGeneratedKeys()</code> method.
+    <p>Otherwise, there must be an <code>SQLDialect</code> appropriate
+    for your database system. Currently, we have dialects for
+    PostgreSQL, MySQL, Oracle and MS SQL Server. </p>
+
+		<p>The table below summarizes the database types and their support
+		of the <code>getGeneratedKeys()</code> method.
 		</p>
 
 		<table class="bodyTable" border="1" cellpadding="4">
 			<tr class="a">
 				<th>RDBMS</th>
-				<th>
+        <th>tested version(s)
+        </th>
+        <th>tested JDBC driver version(s)
+				</th>
+        <th>
 					supports
 					<br />
 					<code>getGeneratedKeys()</code>
 					method
-				</th>
-				<th>
-					specific
-					<br />
-					SQLDialect support
-				</th>
+				</th>			
 			</tr>
-			<tr class="b">
-				<td>PostgreSQL</td>
-				<td>NO</td>
-				<td>present and used</td>
-			</tr>
-			<tr class="a">
-				<td>MySQL</td>
-				<td>YES</td>
-				<td>present, but not actually needed or used</td>
+
+      <tr >
+				<td>DB2</td>
+        <td>untested</td>
+				<td>untested</td>
+				<td>unknown</td>
 			</tr>
-			<tr class="b">
-				<td>Oracle</td>
-				<td>YES</td>
-				<td>present, but not actually needed or used</td>
+
+      <tr class="alt">
+        <td>HSQL</td>
+        <td>1.8.0.7</td>
+        <td>-</td>
+				<td>NO</td>
 			</tr>
-			<tr class="a">
-				<td>DB2</td>
+
+      <tr >
+        <td>Microsoft SQL Server</td>
+        <td>2005</td>
+        <td>2.0.1008.2 (sqljdbc.jar)</td>
 				<td>YES</td>
-				<td>not present, and not needed or used</td>
 			</tr>
-			<tr class="b">
-				<td>MsSQL</td>
+
+      <tr class="alt">
+				<td>MySQL</td>
+        <td>5.0.22</td>
+        <td>5.0.8 (mysql-connector.jar)</td>        
 				<td>YES</td>
-				<td>not present, and not needed or used</td>
 			</tr>
-			<tr class="a">
-				<td>HSQL</td>
+
+			<tr>
+				<td>PostgreSQL</td>
+        <td>
+        </td>
+        <td>
+        </td>
 				<td>NO</td>
-				<td>present and used</td>
 			</tr>
+		
+			<tr >
+				<td>Oracle</td>
+        <td>10g</td>
+        <td>10.2.0.1 (ojdbc14.jar)</td>
+				<td>YES (10.2.0.1)</td>
+			</tr>
+	
+	
+			
 		</table>
 		
-		<p>
-			Experiments show that writing a single event
-			into the database takes approximately 10 milliseconds, on a
-			"standard" PC. If pooled connections are used, this figure
-			drops to around 1 milliseconds. Note that most JDBC drivers
-			already ship with connection pooling support.
+		<p>Experiments show that writing a single event into the database
+		takes approximately 10 milliseconds, on a "standard" PC. If pooled
+		connections are used, this figure drops to around 1
+		milliseconds. Note that most JDBC drivers already ship with
+		connection pooling support.
 		</p>
 		
 		<p>


More information about the logback-dev mailing list