Skip to content

feat: Default transaction isolation #1998

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

Merged
merged 7 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ public Class<PgTransactionMode> getParameterClass() {
public PgTransactionMode convert(String value) {
PgTransactionMode mode = new PgTransactionMode();
// Transaction mode may contain multiple spaces.
String valueWithoutNotDeferrable = value.replaceAll("(?i)(not\\s+deferrable)", " ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please check for a better variable name for valueWithoutNotDeferrable, the double negative makes it slightly confusing to read.

String valueWithSingleSpaces =
value.replaceAll("\\s+", " ").toLowerCase(Locale.ENGLISH).trim();
valueWithoutNotDeferrable.replaceAll("\\s+", " ").toLowerCase(Locale.ENGLISH).trim();
int currentIndex = 0;
while (currentIndex < valueWithSingleSpaces.length()) {
// This will use the last access mode and isolation level that is encountered in the string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@
"exampleStatements": []
},
{
"name": "{START | BEGIN} [TRANSACTION | WORK] [{ (READ ONLY|READ WRITE) [[,] (ISOLATION LEVEL (DEFAULT|SERIALIZABLE))] }]",
"name": "{START | BEGIN} [TRANSACTION | WORK] [{ (READ ONLY|READ WRITE) [[,] (ISOLATION LEVEL (DEFAULT|SERIALIZABLE))] [[,] NOT DEFERRABLE]}]",
"executorName": "ClientSideStatementPgBeginExecutor",
"resultType": "NO_RESULT",
"statementType": "BEGIN",
"regex": "(?is)\\A\\s*(?:begin|start)(?:\\s+transaction|\\s+work)?((?:(?:\\s+|\\s*,\\s*)read\\s+only|(?:\\s+|\\s*,\\s*)read\\s+write|(?:\\s+|\\s*,\\s*)isolation\\s+level\\s+default|(?:\\s+|\\s*,\\s*)isolation\\s+level\\s+serializable)*)?\\s*\\z",
"regex": "(?is)\\A\\s*(?:begin|start)(?:\\s+transaction|\\s+work)?((?:(?:\\s+|\\s*,\\s*)read\\s+only|(?:\\s+|\\s*,\\s*)read\\s+write|(?:\\s+|\\s*,\\s*)isolation\\s+level\\s+default|(?:\\s+|\\s*,\\s*)isolation\\s+level\\s+serializable|(?:\\s+|\\s*,\\s*)not\\s+deferrable)*)?\\s*\\z",
"method": "statementBeginPgTransaction",
"exampleStatements": [
"begin", "start", "begin transaction", "start transaction", "begin work", "start work",
Expand All @@ -173,7 +173,16 @@
"begin isolation level serializable", "start isolation level serializable", "begin transaction isolation level serializable", "start transaction isolation level serializable", "begin work isolation level serializable", "start work isolation level serializable",
"begin isolation level default read write", "start isolation level default read only", "begin transaction isolation level default read only", "start transaction isolation level default read write", "begin work isolation level default read write", "start work isolation level default read only",
"begin isolation level serializable read write", "start isolation level serializable read write", "begin transaction isolation level serializable read only", "start transaction isolation level serializable read write", "begin work isolation level serializable read write", "start work isolation level serializable read only",
"begin isolation level serializable, read write", "start isolation level serializable, read write", "begin transaction isolation level serializable, read only", "start transaction isolation level serializable, read write", "begin work isolation level serializable, read write", "start work isolation level serializable, read only"
"begin isolation level serializable, read write", "start isolation level serializable, read write", "begin transaction isolation level serializable, read only", "start transaction isolation level serializable, read write", "begin work isolation level serializable, read write", "start work isolation level serializable, read only",
"begin not deferrable", "start not deferrable", "begin transaction not deferrable", "start transaction not deferrable", "begin work not deferrable", "start work not deferrable",
"begin read only not deferrable", "start read only not deferrable", "begin transaction read only not deferrable", "start transaction read only not deferrable", "begin work read only not deferrable", "start work read only not deferrable",
"begin read write not deferrable", "start read write not deferrable", "begin transaction read write not deferrable", "start transaction read write not deferrable", "begin work read write not deferrable", "start work read write not deferrable",
"begin isolation level default not deferrable", "start isolation level default not deferrable", "begin transaction isolation level default not deferrable", "start transaction isolation level default not deferrable", "begin work isolation level default not deferrable", "start work isolation level default not deferrable",
"begin isolation level serializable not deferrable", "start isolation level serializable not deferrable", "begin transaction isolation level serializable not deferrable", "start transaction isolation level serializable not deferrable", "begin work isolation level serializable not deferrable", "start work isolation level serializable not deferrable",
"begin isolation level default read write not deferrable", "start isolation level default read only not deferrable", "begin transaction isolation level default read only not deferrable", "start transaction isolation level default read write not deferrable", "begin work isolation level default read write not deferrable", "start work isolation level default read only not deferrable",
"begin isolation level serializable read write not deferrable", "start isolation level serializable read write not deferrable", "begin transaction isolation level serializable read only not deferrable", "start transaction isolation level serializable read write not deferrable", "begin work isolation level serializable read write not deferrable", "start work isolation level serializable read only not deferrable",
"begin isolation level serializable, read write, not deferrable", "start isolation level serializable, read write, not deferrable", "begin transaction isolation level serializable, read only, not deferrable", "start transaction isolation level serializable, read write, not deferrable", "begin work isolation level serializable, read write, not deferrable", "start work isolation level serializable, read only"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness (and to prevent potential regressions in the future), could we also add a couple of tests with not deferrable as not the last option. So for example:

begin not deferrable read write;
begin not deferrable isolation level default;


]
},
{
Expand Down Expand Up @@ -360,7 +369,7 @@
}
},
{
"name": "SET DEFAULT_TRANSACTION_ISOLATION =|TO 'SERIALIZABLE'|SERIALIZABLE",
"name": "SET DEFAULT_TRANSACTION_ISOLATION =|TO 'SERIALIZABLE'|SERIALIZABLE|DEFAULT",
"executorName": "ClientSideStatementSetExecutor",
"resultType": "NO_RESULT",
"statementType": "SET_READONLY",
Expand All @@ -371,12 +380,14 @@
"set default_transaction_isolation to serializable",
"set default_transaction_isolation to 'serializable'",
"set default_transaction_isolation = 'serializable'",
"set default_transaction_isolation = \"SERIALIZABLE\""
"set default_transaction_isolation = \"SERIALIZABLE\"",
"set default_transaction_isolation = DEFAULT",
"set default_transaction_isolation to DEFAULT"
],
"setStatement": {
"propertyName": "default_transaction_isolation",
"separator": "(?:=|\\s+TO\\s+)",
"allowedValues": "(SERIALIZABLE|'SERIALIZABLE'|\"SERIALIZABLE\")",
"allowedValues": "(SERIALIZABLE|'SERIALIZABLE'|\"SERIALIZABLE\"|DEFAULT)",
"converterName": "ClientSideStatementValueConverters$PgTransactionIsolationConverter"
}
},
Expand Down