Skip to content

Commit 7340037

Browse files
authored
Merge pull request #583 from cloudsufi/patch/PLUGIN-1779
[PLUGIN-1779] Add TRANSACTION_ISOLATION_LEVEL config in MySQL, PostgreSQL & SQL Server plugins
2 parents cde7167 + f4650e1 commit 7340037

27 files changed

+277
-17
lines changed

database-commons/src/main/java/io/cdap/plugin/db/ConnectionConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public abstract class ConnectionConfig extends PluginConfig implements DatabaseC
4545
public static final String CONNECTION_ARGUMENTS = "connectionArguments";
4646
public static final String JDBC_PLUGIN_NAME = "jdbcPluginName";
4747
public static final String JDBC_PLUGIN_TYPE = "jdbc";
48+
public static final String TRANSACTION_ISOLATION_LEVEL = "transactionIsolationLevel";
4849

4950
@Name(JDBC_PLUGIN_NAME)
5051
@Description("Name of the JDBC driver to use. This is the value of the 'jdbcPluginName' key defined in the JSON " +

database-commons/src/main/java/io/cdap/plugin/db/connector/AbstractDBSpecificConnectorConfig.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import io.cdap.cdap.api.annotation.Macro;
2121
import io.cdap.cdap.api.annotation.Name;
2222
import io.cdap.plugin.db.ConnectionConfig;
23+
import io.cdap.plugin.db.TransactionIsolationLevel;
2324

24-
import java.util.Collections;
25+
import java.util.HashMap;
2526
import java.util.Map;
2627
import javax.annotation.Nullable;
2728

@@ -42,6 +43,12 @@ public abstract class AbstractDBSpecificConnectorConfig extends AbstractDBConnec
4243
@Nullable
4344
protected Integer port;
4445

46+
@Name(ConnectionConfig.TRANSACTION_ISOLATION_LEVEL)
47+
@Description("The transaction isolation level for the database session.")
48+
@Macro
49+
@Nullable
50+
protected String transactionIsolationLevel;
51+
4552
public String getHost() {
4653
return host;
4754
}
@@ -55,4 +62,21 @@ public int getPort() {
5562
public boolean canConnect() {
5663
return super.canConnect() && !containsMacro(ConnectionConfig.HOST) && !containsMacro(ConnectionConfig.PORT);
5764
}
65+
66+
@Override
67+
public Map<String, String> getAdditionalArguments() {
68+
Map<String, String> additonalArguments = new HashMap<>();
69+
if (getTransactionIsolationLevel() != null) {
70+
additonalArguments.put(TransactionIsolationLevel.CONF_KEY, getTransactionIsolationLevel());
71+
}
72+
return additonalArguments;
73+
}
74+
75+
public String getTransactionIsolationLevel() {
76+
if (transactionIsolationLevel == null) {
77+
return null;
78+
}
79+
return TransactionIsolationLevel.Level.valueOf(transactionIsolationLevel).name();
80+
}
5881
}
82+

mssql-plugin/docs/SQL Server-connector.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ authentication. Optional for databases that do not require authentication.
2222

2323
**Password:** Password to use to connect to the specified database.
2424

25+
**Transaction Isolation Level** The transaction isolation level of the database connection
26+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
27+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
28+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
29+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
30+
31+
For more details on the Transaction Isolation Levels supported in SQL Server, refer to the [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver16)
32+
2533
**Authentication Type:** Indicates which authentication method will be used for the connection. Use 'SQL Login'. to
2634
connect to a SQL Server using username and password properties. Use 'Active Directory Password' to connect to an Azure
2735
SQL Database/Data Warehouse using an Azure AD principal name and password.

mssql-plugin/docs/SqlServer-batchsink.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ an Azure SQL Database/Data Warehouse using an Azure AD principal name and passwo
4646

4747
**Password:** Password to use to connect to the specified database.
4848

49+
**Transaction Isolation Level** The transaction isolation level of the database connection
50+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
51+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
52+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
53+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
54+
55+
For more details on the Transaction Isolation Levels supported in SQL Server, refer to the [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver16)
56+
4957
**Instance Name:** SQL Server instance name to connect to. When it is not specified, a
5058
connection is made to the default instance. For the case where both the instanceName and port are specified,
5159
see the notes for port. If you specify a Virtual Network Name in the Server connection property, you cannot

mssql-plugin/docs/SqlServer-batchsource.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ an Azure SQL Database/Data Warehouse using an Azure AD principal name and passwo
5656

5757
**Password:** Password to use to connect to the specified database.
5858

59+
**Transaction Isolation Level** The transaction isolation level of the database connection
60+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
61+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
62+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
63+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
64+
65+
For more details on the Transaction Isolation Levels supported in SQL Server, refer to the [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver16)
66+
5967
**Instance Name:** SQL Server instance name to connect to. When it is not specified, a
6068
connection is made to the default instance. For the case where both the instanceName and port are specified,
6169
see the notes for port. If you specify a Virtual Network Name in the Server connection property, you cannot

mssql-plugin/src/main/java/io/cdap/plugin/mssql/SqlServerSink.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public Map<String, String> getDBSpecificArguments() {
177177
packetSize, queryTimeout);
178178
}
179179

180+
@Override
181+
public String getTransactionIsolationLevel() {
182+
return connection.getTransactionIsolationLevel();
183+
}
184+
180185
@Override
181186
public String getConnectionString() {
182187
return String.format(SqlServerConstants.SQL_SERVER_CONNECTION_STRING_FORMAT,

mssql-plugin/src/main/java/io/cdap/plugin/mssql/SqlServerSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ public List<String> getInitQueries() {
198198
return Collections.emptyList();
199199
}
200200

201+
@Override
202+
public String getTransactionIsolationLevel() {
203+
return connection.getTransactionIsolationLevel();
204+
}
205+
201206
@Override
202207
public void validate(FailureCollector collector) {
203208
ConfigUtil.validateConnection(this, useConnection, connection, collector);

mssql-plugin/widgets/SQL Server-connector.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@
6464
"widget-type": "password",
6565
"label": "Password",
6666
"name": "password"
67+
},
68+
{
69+
"widget-type": "select",
70+
"label": "Transaction Isolation Level",
71+
"name": "transactionIsolationLevel",
72+
"widget-attributes": {
73+
"values": [
74+
"TRANSACTION_READ_UNCOMMITTED",
75+
"TRANSACTION_READ_COMMITTED",
76+
"TRANSACTION_REPEATABLE_READ",
77+
"TRANSACTION_SERIALIZABLE"
78+
],
79+
"default": "TRANSACTION_SERIALIZABLE"
80+
}
6781
}
6882
]
6983
},

mssql-plugin/widgets/SqlServer-batchsink.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@
8484
"label": "Password",
8585
"name": "password"
8686
},
87+
{
88+
"widget-type": "select",
89+
"label": "Transaction Isolation Level",
90+
"name": "transactionIsolationLevel",
91+
"widget-attributes": {
92+
"values": [
93+
"TRANSACTION_READ_UNCOMMITTED",
94+
"TRANSACTION_READ_COMMITTED",
95+
"TRANSACTION_REPEATABLE_READ",
96+
"TRANSACTION_SERIALIZABLE"
97+
],
98+
"default": "TRANSACTION_SERIALIZABLE"
99+
}
100+
},
87101
{
88102
"widget-type": "keyvalue",
89103
"label": "Connection Arguments",
@@ -280,6 +294,10 @@
280294
{
281295
"type": "property",
282296
"name": "connectionArguments"
297+
},
298+
{
299+
"type": "property",
300+
"name": "transactionIsolationLevel"
283301
}
284302
]
285303
},

mssql-plugin/widgets/SqlServer-batchsource.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@
8484
"label": "Password",
8585
"name": "password"
8686
},
87+
{
88+
"widget-type": "select",
89+
"label": "Transaction Isolation Level",
90+
"name": "transactionIsolationLevel",
91+
"widget-attributes": {
92+
"values": [
93+
"TRANSACTION_READ_UNCOMMITTED",
94+
"TRANSACTION_READ_COMMITTED",
95+
"TRANSACTION_REPEATABLE_READ",
96+
"TRANSACTION_SERIALIZABLE"
97+
],
98+
"default": "TRANSACTION_SERIALIZABLE"
99+
}
100+
},
87101
{
88102
"widget-type": "keyvalue",
89103
"label": "Connection Arguments",
@@ -316,6 +330,10 @@
316330
{
317331
"type": "property",
318332
"name": "connectionArguments"
333+
},
334+
{
335+
"type": "property",
336+
"name": "transactionIsolationLevel"
319337
}
320338
]
321339
},

0 commit comments

Comments
 (0)