You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2017/10/18 13:13:01 UTC

qpid-broker-j git commit: QPID-7974: Only search for the needed table instead of querying the whole database tables This closes #3

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master d68c89705 -> 3a6bb20dc


QPID-7974: Only search for the needed table instead of querying the whole database tables
This closes #3


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/3a6bb20d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/3a6bb20d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/3a6bb20d

Branch: refs/heads/master
Commit: 3a6bb20dc037a88d528045eae4bcc2daacf955ae
Parents: d68c897
Author: aboutros <ab...@murex.com>
Authored: Wed Oct 18 14:41:42 2017 +0200
Committer: rgodfrey <rg...@apache.org>
Committed: Wed Oct 18 15:10:56 2017 +0200

----------------------------------------------------------------------
 .../qpid/server/store/jdbc/JdbcUtils.java       | 25 ++++++++------------
 1 file changed, 10 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/3a6bb20d/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JdbcUtils.java
----------------------------------------------------------------------
diff --git a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JdbcUtils.java b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JdbcUtils.java
index aa9c8f9..795bed3 100644
--- a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JdbcUtils.java
+++ b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JdbcUtils.java
@@ -62,24 +62,19 @@ public class JdbcUtils
     public static boolean tableExists(final String tableName, final Connection conn) throws SQLException
     {
         DatabaseMetaData metaData = conn.getMetaData();
-        ResultSet rs = metaData.getTables(null, null, "%", null);
+        // Some databases are not case sensitive in their table names and/or report back a different case for the
+        // name of the table than the one originally used to create it
+        return tableExistsCase(tableName.toUpperCase(), metaData) || tableExistsCase(tableName.toLowerCase(), metaData)
+               || tableName.equals(tableName.toUpperCase()) || tableName.equals(tableName.toLowerCase())
+               || tableExistsCase(tableName, metaData);
 
-        try
-        {
+    }
 
-            while(rs.next())
-            {
-                final String table = rs.getString(3);
-                if(tableName.equalsIgnoreCase(table))
-                {
-                    return true;
-                }
-            }
-            return false;
-        }
-        finally
+    private static boolean tableExistsCase(final String tableName, final DatabaseMetaData metaData) throws SQLException
+    {
+        try (ResultSet rs = metaData.getTables(null, null, tableName, null))
         {
-            rs.close();
+            return rs.next();
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org