]> source.dussan.org Git - sonarqube.git/commitdiff
Speed-up DatabaseUtils.tableExists() on Oracle
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 13 May 2018 11:52:52 +0000 (13:52 +0200)
committerSonarTech <sonartech@sonarsource.com>
Mon, 14 May 2018 18:20:48 +0000 (20:20 +0200)
Signed-off-by: Simon Brandhof <simon.brandhof@sonarsource.com>
server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java

index 9b850e40f655c2f24dd69519fb02cc2a1f8ccb8e..0e9c5d1169e0c6e551570c79383c783704a443e8 100644 (file)
@@ -38,6 +38,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.function.IntFunction;
@@ -309,8 +310,15 @@ public class DatabaseUtils {
     * @throws SQLException
     */
   public static boolean tableExists(String table, Connection connection) {
+    return doTableExists(table, connection) ||
+      doTableExists(table.toLowerCase(Locale.ENGLISH), connection) ||
+      doTableExists(table.toUpperCase(Locale.ENGLISH), connection);
+
+  }
+
+  private static boolean doTableExists(String table, Connection connection) {
     // table type is used to speed-up Oracle by removing introspection of system tables and aliases.
-    try (ResultSet rs = connection.getMetaData().getTables(null, null, null, TABLE_TYPE)) {
+    try (ResultSet rs = connection.getMetaData().getTables(null, null, table, TABLE_TYPE)) {
       while (rs.next()) {
         String name = rs.getString("TABLE_NAME");
         if (table.equalsIgnoreCase(name)) {