From 327d80296aa1755150fac518c3115b0d874ec580 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Thu, 15 Feb 2024 02:26:50 -0800 Subject: [PATCH] Fix check-style --- .../net/snowflake/client/core/SFSession.java | 1 - .../jdbc/SnowflakeDatabaseMetaData.java | 57 +++++++------ .../client/jdbc/DatabaseMetaDataLatestIT.java | 82 ++++++++++++------- 3 files changed, 84 insertions(+), 56 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SFSession.java b/src/main/java/net/snowflake/client/core/SFSession.java index 20b0ee484..a603fd4b3 100644 --- a/src/main/java/net/snowflake/client/core/SFSession.java +++ b/src/main/java/net/snowflake/client/core/SFSession.java @@ -470,7 +470,6 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro } break; - default: break; } diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeDatabaseMetaData.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeDatabaseMetaData.java index 6e17051f1..43512d9c8 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeDatabaseMetaData.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeDatabaseMetaData.java @@ -2091,7 +2091,8 @@ public ResultSet getPrimaryKeys(String originalCatalog, String originalSchema, f } final String catalogIn = catalog; - // These values for Schema and Table will only be used to filter results if the connection property + // These values for Schema and Table will only be used to filter results if the connection + // property // enablePatternSearch=false final String schemaIn = schema; final String tableIn = table; @@ -2120,10 +2121,10 @@ public boolean next() throws SQLException { // Post filter based on the input if (isPatternMatchingEnabled) { if ((catalogIn == null || catalogIn.equals(table_cat)) - && (compiledSchemaPattern == null + && (compiledSchemaPattern == null || compiledSchemaPattern.equals(table_schem) || compiledSchemaPattern.matcher(table_schem).matches()) - && (compiledTablePattern == null + && (compiledTablePattern == null || compiledTablePattern.equals(table_name) || compiledTablePattern.matcher(table_name).matches())) { nextRow[0] = table_cat; @@ -2136,8 +2137,8 @@ public boolean next() throws SQLException { } } else { if ((catalogIn == null || catalogIn.equals(table_cat)) - && (schemaIn == null || schemaIn.equals(table_schem)) - && (tableIn == null || tableIn.equals(table_name))) { + && (schemaIn == null || schemaIn.equals(table_schem)) + && (tableIn == null || tableIn.equals(table_name))) { nextRow[0] = table_cat; nextRow[1] = table_schem; nextRow[2] = table_name; @@ -2186,7 +2187,8 @@ private ResultSet getForeignKeys( final String parentCatalog = resPair.left; final String parentSchema = resPair.right; - // These Patterns will only be used to filter results if the connection property enablePatternSearch=true + // These Patterns will only be used to filter results if the connection property + // enablePatternSearch=true final Pattern compiledSchemaPattern = Wildcard.toRegexPattern(parentSchema, true); final Pattern compiledParentTablePattern = Wildcard.toRegexPattern(parentTable, true); final Pattern compiledForeignSchemaPattern = Wildcard.toRegexPattern(foreignSchema, true); @@ -2206,7 +2208,8 @@ private ResultSet getForeignKeys( return SnowflakeDatabaseMetaDataResultSet.getEmptyResultSet(GET_FOREIGN_KEYS, statement); } else { String unescapedParentCatalog = escapeSqlQuotes(parentCatalog); - if (parentSchema == null || (isSchemaNameWildcardPattern(parentSchema) && isPatternMatchingEnabled)) { + if (parentSchema == null + || (isSchemaNameWildcardPattern(parentSchema) && isPatternMatchingEnabled)) { commandBuilder.append("database \"" + unescapedParentCatalog + "\""); } else if (parentSchema.isEmpty()) { return SnowflakeDatabaseMetaDataResultSet.getEmptyResultSet(GET_FOREIGN_KEYS, statement); @@ -2233,7 +2236,8 @@ private ResultSet getForeignKeys( final String finalParentCatalog = parentCatalog; final String finalForeignCatalog = foreignCatalog; - // These values will only be used to filter results if the connection property enablePatternSearch=true + // These values will only be used to filter results if the connection property + // enablePatternSearch=true final String finalParentSchema = parentSchema; final String finalParentTable = parentTable; final String finalForeignSchema = foreignSchema; @@ -2284,10 +2288,10 @@ public boolean next() throws SQLException { if (client.equals("import")) { // For imported keys, filter on the foreign key table if ((finalParentCatalog == null || finalParentCatalog.equals(fktable_cat)) - && (compiledSchemaPattern == null + && (compiledSchemaPattern == null || compiledSchemaPattern.equals(fktable_schem) || compiledSchemaPattern.matcher(fktable_schem).matches()) - && (compiledParentTablePattern == null + && (compiledParentTablePattern == null || compiledParentTablePattern.equals(fktable_name) || compiledParentTablePattern.matcher(fktable_name).matches())) { passedFilter = true; @@ -2295,10 +2299,10 @@ public boolean next() throws SQLException { } else if (client.equals("export")) { // For exported keys, filter on the primary key table if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat)) - && (compiledSchemaPattern == null + && (compiledSchemaPattern == null || compiledSchemaPattern.equals(pktable_schem) || compiledSchemaPattern.matcher(pktable_schem).matches()) - && (compiledParentTablePattern == null + && (compiledParentTablePattern == null || compiledParentTablePattern.equals(pktable_name) || compiledParentTablePattern.matcher(pktable_name).matches())) { passedFilter = true; @@ -2307,17 +2311,17 @@ public boolean next() throws SQLException { // For cross references, filter on both the primary key and foreign // key table if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat)) - && (compiledSchemaPattern == null + && (compiledSchemaPattern == null || compiledSchemaPattern.equals(pktable_schem) || compiledSchemaPattern.matcher(pktable_schem).matches()) - && (compiledParentTablePattern == null + && (compiledParentTablePattern == null || compiledParentTablePattern.equals(pktable_name) || compiledParentTablePattern.matcher(pktable_name).matches()) - && (foreignCatalog == null || foreignCatalog.equals(fktable_cat)) - && (compiledForeignSchemaPattern == null + && (foreignCatalog == null || foreignCatalog.equals(fktable_cat)) + && (compiledForeignSchemaPattern == null || compiledForeignSchemaPattern.equals(fktable_schem) || compiledForeignSchemaPattern.matcher(fktable_schem).matches()) - && (compiledForeignTablePattern == null + && (compiledForeignTablePattern == null || compiledForeignTablePattern.equals(fktable_name) || compiledForeignTablePattern.matcher(fktable_name).matches())) { passedFilter = true; @@ -2328,30 +2332,29 @@ public boolean next() throws SQLException { if (client.equals("import")) { // For imported keys, filter on the foreign key table if ((finalParentCatalog == null || finalParentCatalog.equals(fktable_cat)) - && (finalParentSchema == null || finalParentSchema.equals(fktable_schem)) - && (finalParentTable == null || finalParentTable.equals(fktable_name))) { + && (finalParentSchema == null || finalParentSchema.equals(fktable_schem)) + && (finalParentTable == null || finalParentTable.equals(fktable_name))) { passedFilter = true; } } else if (client.equals("export")) { // For exported keys, filter on the primary key table if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat)) - && (finalParentSchema == null || finalParentSchema.equals(pktable_schem)) - && (finalParentTable == null || finalParentTable.equals(pktable_name))) { + && (finalParentSchema == null || finalParentSchema.equals(pktable_schem)) + && (finalParentTable == null || finalParentTable.equals(pktable_name))) { passedFilter = true; } } else if (client.equals("cross")) { // For cross references, filter on both the primary key and foreign // key table if ((finalParentCatalog == null || finalParentCatalog.equals(pktable_cat)) - && (finalParentSchema == null || finalParentSchema.equals(pktable_schem)) - && (finalParentTable == null || finalParentTable.equals(pktable_name)) - && (finalForeignCatalog == null || finalForeignCatalog.equals(fktable_cat)) - && (finalForeignSchema == null || finalForeignSchema.equals(fktable_schem)) - && (finalForeignTable == null || finalForeignTable.equals(fktable_name))) { + && (finalParentSchema == null || finalParentSchema.equals(pktable_schem)) + && (finalParentTable == null || finalParentTable.equals(pktable_name)) + && (finalForeignCatalog == null || finalForeignCatalog.equals(fktable_cat)) + && (finalForeignSchema == null || finalForeignSchema.equals(fktable_schem)) + && (finalForeignTable == null || finalForeignTable.equals(fktable_name))) { passedFilter = true; } } - } if (passedFilter) { diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataLatestIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataLatestIT.java index e11e67054..d1d60b97e 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataLatestIT.java @@ -1714,16 +1714,16 @@ public void testNoPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcep final String table2 = "T2"; connection - .createStatement() - .execute("create or replace table " + table1 + "(C1 int primary key, C2 string)"); + .createStatement() + .execute("create or replace table " + table1 + "(C1 int primary key, C2 string)"); connection - .createStatement() - .execute( - "create or replace table " - + table2 - + "(C1 int primary key, C2 string, C3 int references " - + table1 - + ")"); + .createStatement() + .execute( + "create or replace table " + + table2 + + "(C1 int primary key, C2 string, C3 int references " + + table1 + + ")"); DatabaseMetaData dbmd = connection.getMetaData(); @@ -1755,13 +1755,26 @@ public void testNoPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcep assertEquals(0, getSizeOfResultSet(dbmd.getExportedKeys(database, null, "T%"))); // Should return result for matching schema and table name - assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, schema, table2))); + assertEquals( + 1, + getSizeOfResultSet( + dbmd.getCrossReference(database, schema, table1, database, schema, table2))); // Should return an empty result if we try a pattern match on any of the table or schema names - assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2))); - assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2))); - assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2))); - assertEquals(0, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%"))); + assertEquals( + 0, + getSizeOfResultSet( + dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2))); + assertEquals( + 0, + getSizeOfResultSet( + dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2))); + assertEquals( + 0, + getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2))); + assertEquals( + 0, + getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%"))); } @Test @@ -1783,16 +1796,16 @@ public void testPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcepti final String table2 = "T2"; connection - .createStatement() - .execute("create or replace table " + table1 + "(C1 int primary key, C2 string)"); + .createStatement() + .execute("create or replace table " + table1 + "(C1 int primary key, C2 string)"); connection - .createStatement() - .execute( - "create or replace table " - + table2 - + "(C1 int primary key, C2 string, C3 int references " - + table1 - + ")"); + .createStatement() + .execute( + "create or replace table " + + table2 + + "(C1 int primary key, C2 string, C3 int references " + + table1 + + ")"); DatabaseMetaData dbmd = connection.getMetaData(); @@ -1824,12 +1837,25 @@ public void testPatternSearchAllowedForPrimaryAndForeignKeys() throws SQLExcepti assertEquals(1, getSizeOfResultSet(dbmd.getExportedKeys(database, null, "T%"))); // Should return result for matching schema and table name - assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, schema, table2))); + assertEquals( + 1, + getSizeOfResultSet( + dbmd.getCrossReference(database, schema, table1, database, schema, table2))); // Should return a result if we try a pattern match on any of the table or schema names - assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2))); - assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2))); - assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2))); - assertEquals(1, getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%"))); + assertEquals( + 1, + getSizeOfResultSet( + dbmd.getCrossReference(database, "TEST%", table1, database, schema, table2))); + assertEquals( + 1, + getSizeOfResultSet( + dbmd.getCrossReference(database, schema, table1, database, "TEST%", table2))); + assertEquals( + 1, + getSizeOfResultSet(dbmd.getCrossReference(database, null, "T%", database, schema, table2))); + assertEquals( + 1, + getSizeOfResultSet(dbmd.getCrossReference(database, schema, table1, database, null, "T%"))); } }