import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public static final int PARTITION_SIZE_FOR_ORACLE = 1000;
+ /**
+ * @see DatabaseMetaData#getTableTypes()
+ */
+ private static final String[] TABLE_TYPE = {"TABLE"};
+
public static void closeQuietly(@Nullable Connection connection) {
if (connection != null) {
try {
* @throws SQLException
*/
public static boolean tableExists(String table, Connection connection) {
- try (ResultSet rs = connection.getMetaData().getTables(null, null, null, null)) {
+ // 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)) {
while (rs.next()) {
String name = rs.getString("TABLE_NAME");
if (table.equalsIgnoreCase(name)) {
assertThat(buildLikeValue("like-\\_%/-value", AFTER)).isEqualTo(escapedValue + wildcard);
assertThat(buildLikeValue("like-\\_%/-value", BEFORE_AND_AFTER)).isEqualTo(wildcard + escapedValue + wildcard);
}
+
+ @Test
+ public void tableExists_returns_true_if_table_is_referenced_in_db_metadata() throws Exception {
+ try (Connection connection = dbTester.openConnection()) {
+ assertThat(DatabaseUtils.tableExists("SCHEMA_MIGRATIONS", connection)).isTrue();
+ assertThat(DatabaseUtils.tableExists("schema_migrations", connection)).isTrue();
+ assertThat(DatabaseUtils.tableExists("schema_MIGRATIONS", connection)).isTrue();
+ assertThat(DatabaseUtils.tableExists("foo", connection)).isFalse();
+ }
+ }
}