Repository: karaf
Updated Branches:
  refs/heads/karaf-2.x 5fdcc4290 -> 70774bc0b


[KARAF-3562] Try to find the JDBC lock table name using upper and lower case in 
addition of the provided name


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/70774bc0
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/70774bc0
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/70774bc0

Branch: refs/heads/karaf-2.x
Commit: 70774bc0b388689947cb1f133c6eb78d7ed65e46
Parents: 5fdcc42
Author: Jean-Baptiste Onofré <[email protected]>
Authored: Wed Apr 1 10:29:59 2015 +0200
Committer: Jean-Baptiste Onofré <[email protected]>
Committed: Wed Apr 1 10:29:59 2015 +0200

----------------------------------------------------------------------
 .../org/apache/karaf/main/DefaultJDBCLock.java  | 20 ++++++++++++--------
 .../org/apache/karaf/main/BaseJDBCLockTest.java |  6 +++++-
 .../src/main/webapp/users-guide/failover.conf   |  1 +
 3 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/70774bc0/main/src/main/java/org/apache/karaf/main/DefaultJDBCLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/DefaultJDBCLock.java 
b/main/src/main/java/org/apache/karaf/main/DefaultJDBCLock.java
index 8377605..e1609f0 100644
--- a/main/src/main/java/org/apache/karaf/main/DefaultJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/DefaultJDBCLock.java
@@ -18,12 +18,7 @@
  */
 package org.apache.karaf.main;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
 import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -98,7 +93,7 @@ public class DefaultJDBCLock implements Lock {
             createDatabase();
             createSchema();
         } catch (Exception e) {
-            LOG.log(Level.SEVERE, "Error occured while attempting to obtain 
connection", e);
+            LOG.log(Level.SEVERE, "Error occurred while attempting to obtain 
connection", e);
         }
     }
 
@@ -162,8 +157,17 @@ public class DefaultJDBCLock implements Lock {
         ResultSet rs = null;
         boolean schemaExists = false;
         try {
-            rs = getConnection().getMetaData().getTables(null, null, 
tableName, new String[] {"TABLE"});
+            DatabaseMetaData metadata = getConnection().getMetaData();
+            rs = metadata.getTables(null, null, tableName, new 
String[]{"TABLE"});
             schemaExists = rs.next();
+            if (!schemaExists) {
+                rs = metadata.getTables(null, null, tableName.toLowerCase(), 
new String[] {"TABLE"});
+                schemaExists = rs.next();
+            }
+            if (!schemaExists) {
+                rs = metadata.getTables(null, null, tableName.toUpperCase(), 
new String[] {"TABLE"});
+                schemaExists = rs.next();
+            }
         } catch (Exception ignore) {
             LOG.log(Level.SEVERE, "Error testing for db table", ignore);
         } finally {

http://git-wip-us.apache.org/repos/asf/karaf/blob/70774bc0/main/src/test/java/org/apache/karaf/main/BaseJDBCLockTest.java
----------------------------------------------------------------------
diff --git a/main/src/test/java/org/apache/karaf/main/BaseJDBCLockTest.java 
b/main/src/test/java/org/apache/karaf/main/BaseJDBCLockTest.java
index 6589860..4206fa4 100644
--- a/main/src/test/java/org/apache/karaf/main/BaseJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/BaseJDBCLockTest.java
@@ -89,6 +89,10 @@ public abstract class BaseJDBCLockTest {
         connection.setAutoCommit(false);
         expect(connection.getMetaData()).andReturn(metaData);
         expect(metaData.getTables((String) isNull(), (String) isNull(), 
eq("LOCK_TABLE"), aryEq(new String[] {"TABLE"}))).andReturn(resultSet);
+        expect(metaData.getTables((String) isNull(), (String) isNull(), 
eq("LOCK_TABLE"), aryEq(new String[] {"TABLE"}))).andReturn(resultSet);
+        expect(metaData.getTables((String) isNull(), (String) isNull(), 
eq("lock_table"), aryEq(new String[] {"TABLE"}))).andReturn(resultSet);
+        expect(resultSet.next()).andReturn(false);
+        expect(resultSet.next()).andReturn(false);
         expect(resultSet.next()).andReturn(false);
         resultSet.close();
         expect(connection.isClosed()).andReturn(false);
@@ -109,7 +113,7 @@ public abstract class BaseJDBCLockTest {
     public void initShouldNotCreateTheSchemaIfItAlreadyExists() throws 
Exception {
         connection.setAutoCommit(false);
         expect(connection.getMetaData()).andReturn(metaData);
-        expect(metaData.getTables((String) isNull(), (String) isNull(), 
eq("LOCK_TABLE"), aryEq(new String[] {"TABLE"}))).andReturn(resultSet);
+        expect(metaData.getTables((String) isNull(), (String) isNull(), 
anyString(), aryEq(new String[] {"TABLE"}))).andReturn(resultSet);
         expect(resultSet.next()).andReturn(true);
         resultSet.close();
         

http://git-wip-us.apache.org/repos/asf/karaf/blob/70774bc0/manual/src/main/webapp/users-guide/failover.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/users-guide/failover.conf 
b/manual/src/main/webapp/users-guide/failover.conf
index 4a72449..92182a1 100644
--- a/manual/src/main/webapp/users-guide/failover.conf
+++ b/manual/src/main/webapp/users-guide/failover.conf
@@ -48,6 +48,7 @@ karaf.lock.jdbc.timeout=30
 * The "sample" database referred to above will be created if it does not exist.
 * The first Karaf instance to acquire the locking table is the master instance.
 * If the connection to the database is lost, the master instance tries to 
gracefully shutdown, allowing a slave instance to become master when the 
database service is restored. The former master will require a manual restart.
+* Karaf will first use the table name as defined in karaf.lock.jdbc.table 
property, it will also try upper and lower case for the table name.
 
 {warning}
 Apache Karaf won't start if the JDBC driver is not present in the {{lib/ext}} 
folder.

Reply via email to