Skip to content

Commit

Permalink
fix dialect detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiyvamz committed Jan 22, 2025
1 parent b50c060 commit 7811fae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class GlobalAuroraMysqlDialect extends AuroraMysqlDialect {
"SELECT 1 AS tmp FROM information_schema.tables WHERE"
+ " upper(table_schema) = 'INFORMATION_SCHEMA' AND upper(table_name) = 'AURORA_GLOBAL_DB_STATUS'";

protected final String globalDbStatusQuery =
"SELECT count(1) FROM information_schema.aurora_global_db_status";

protected final String globalDbInstanceStatusTableExistQuery =
"SELECT 1 AS tmp FROM information_schema.tables WHERE"
+ " upper(table_schema) = 'INFORMATION_SCHEMA' AND upper(table_name) = 'AURORA_GLOBAL_DB_INSTANCE_STATUS'";
Expand Down Expand Up @@ -59,7 +62,18 @@ public boolean isDialect(final Connection connection) {
stmt = connection.createStatement();
rs = stmt.executeQuery(this.globalDbInstanceStatusTableExistQuery);

return rs.next();
if (rs.next()) {
rs.close();
stmt.close();

stmt = connection.createStatement();
rs = stmt.executeQuery(this.globalDbStatusQuery);

if (rs.next()) {
int awsRegionCount = rs.getInt(1);
return awsRegionCount > 1;
}
}
}
return false;
} catch (final SQLException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class GlobalAuroraPgDialect extends AuroraPgDialect {
+ "VISIBILITY_LAG_IN_MSEC, AWS_REGION "
+ "FROM aurora_global_db_instance_status()";

protected final String globalDbStatusQuery =
"SELECT count(1) FROM aurora_global_db_status()";

protected final String regionByNodeIdQuery =
"SELECT AWS_REGION FROM aurora_global_db_instance_status() WHERE SERVER_ID = ?";

Expand Down Expand Up @@ -72,7 +75,18 @@ public boolean isDialect(final Connection connection) {
stmt = connection.createStatement();
rs = stmt.executeQuery(this.globalDbInstanceStatusFuncExistQuery);

return rs.next();
if (rs.next()) {
rs.close();
stmt.close();

stmt = connection.createStatement();
rs = stmt.executeQuery(this.globalDbStatusQuery);

if (rs.next()) {
int awsRegionCount = rs.getInt(1);
return awsRegionCount > 1;
}
}
}
return false;
} catch (final SQLException ex) {
Expand Down

0 comments on commit 7811fae

Please sign in to comment.