Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a switch statement to compare transaction isolation levels and let the database do the toUpper #2998

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

Check failure on line 41 in pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java

View workflow job for this annotation

GitHub Actions / Code style

Remove 1 line: 41..41
import java.util.Map;
import java.util.StringTokenizer;

Expand Down Expand Up @@ -961,7 +961,7 @@
public int getDefaultTransactionIsolation() throws SQLException {
if (defaultTransactionIsolation == 0) {
String sql;
sql = "SELECT setting FROM pg_catalog.pg_settings WHERE name='default_transaction_isolation'";
sql = "SELECT upper(setting) FROM pg_catalog.pg_settings WHERE name='default_transaction_isolation'";
vlsi marked this conversation as resolved.
Show resolved Hide resolved

try (Statement stmt = connection.createStatement()) {
try (ResultSet rs = stmt.executeQuery(sql)) {
Expand All @@ -973,21 +973,25 @@
throw new PSQLException(
GT.tr(
"Unable to determine a value for DefaultTransactionIsolation due to missing "
+ "system catalog data."),
+ "system catalog data."),
PSQLState.UNEXPECTED_ERROR);
}

level = level.toUpperCase(Locale.US);
if (level.equals("READ COMMITTED")) {
defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED;
} else if (level.equals("READ UNCOMMITTED")) {
defaultTransactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED;
} else if (level.equals("REPEATABLE READ")) {
defaultTransactionIsolation = Connection.TRANSACTION_REPEATABLE_READ;
} else if (level.equals("SERIALIZABLE")) {
defaultTransactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
} else {
defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED; // Best guess.
switch (level) {
case "READ COMMITTED":
defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED;
break;
case "READ UNCOMMITTED":
defaultTransactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED;
break;
case "REPEATABLE READ":
defaultTransactionIsolation = Connection.TRANSACTION_REPEATABLE_READ;
break;
case "SERIALIZABLE":
defaultTransactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
break;
default:
defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED; // Best guess.
break;
}
}
}
Expand Down