From: Simon Brandhof Date: Sun, 13 May 2018 11:52:52 +0000 (+0200) Subject: Speed-up DatabaseUtils.tableExists() on Oracle X-Git-Tag: 7.5~1201 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=78cddc366251909c34cddbd777630260fc38d2b2;p=sonarqube.git Speed-up DatabaseUtils.tableExists() on Oracle Signed-off-by: Simon Brandhof --- diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java index 9b850e40f65..0e9c5d1169e 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java @@ -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)) {