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

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

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

Cherry-picked from master 3a6bb20dc037a88d528045eae4bcc2daacf955ae


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/696107df
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/696107df
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/696107df

Branch: refs/heads/6.1.x
Commit: 696107df078c420394bed8594d8e50dfc283dc84
Parents: 848a209
Author: aboutros <ab...@murex.com>
Authored: Wed Oct 18 14:41:42 2017 +0200
Committer: Keith Wall <kw...@apache.org>
Committed: Wed Nov 8 10:14:14 2017 +0000

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


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/696107df/broker-core/src/main/java/org/apache/qpid/server/store/JdbcUtils.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/store/JdbcUtils.java b/broker-core/src/main/java/org/apache/qpid/server/store/JdbcUtils.java
index 6267586..9b09c68 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/store/JdbcUtils.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/store/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