Skip to content

Commit f4650e1

Browse files
psainicssgarg-CS
authored andcommitted
Set TRANSACTION_ISOLATION_LEVEL config in MySQL, PostgreSQL & MSSQL plugins
Add transaction isolation level to PostgreSQL, MYSQL and MSSQL Plugins.
1 parent cde7167 commit f4650e1

27 files changed

+277
-17
lines changed

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

+1
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

+25-1
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

+8
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

+8
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

+8
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

+5
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

+5
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

+14
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

+18
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

+18
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
},

mysql-plugin/docs/MySQL-connector.md

+8
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 databse 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 MySQL, refer to the [MySQL documentation](https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html)
32+
2533
**Connection Arguments:** A list of arbitrary string tag/value pairs as connection arguments. These arguments
2634
will be passed to the JDBC driver, as connection arguments, for JDBC drivers that may need additional configurations.
2735
This is a semicolon-separated list of key-value pairs, where each pair is separated by a equals '=' and specifies

mysql-plugin/docs/Mysql-batchsink.md

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ You also can use the macro function ${conn(connection-name)}.
3939

4040
**Password:** Password to use to connect to the specified database.
4141

42+
**Transaction Isolation Level** The transaction isolation level of the databse connection
43+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
44+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
45+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
46+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
47+
48+
For more details on the Transaction Isolation Levels supported in MySQL, refer to the [MySQL documentation](https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html)
49+
4250
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
4351
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.
4452

mysql-plugin/docs/Mysql-batchsource.md

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ For example, 'SELECT MIN(id),MAX(id) FROM table'. Not required if numSplits is s
4949

5050
**Password:** Password to use to connect to the specified database.
5151

52+
**Transaction Isolation Level** The transaction isolation level of the database connection
53+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
54+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
55+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
56+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
57+
58+
For more details on the Transaction Isolation Levels supported in MySQL, refer to the [MySQL documentation](https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html)
59+
5260
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
5361
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.
5462

mysql-plugin/src/main/java/io/cdap/plugin/mysql/MysqlSink.java

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ public Map<String, String> getDBSpecificArguments() {
194194
trustCertificateKeyStorePassword, false);
195195
}
196196

197+
@Override
198+
public String getTransactionIsolationLevel() {
199+
return connection.getTransactionIsolationLevel();
200+
}
201+
197202
@Override
198203
public MysqlConnectorConfig getConnection() {
199204
return connection;

mysql-plugin/src/main/java/io/cdap/plugin/mysql/MysqlSource.java

+5
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ public MysqlConnectorConfig getConnection() {
197197
return connection;
198198
}
199199

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

mysql-plugin/widgets/MySQL-connector.json

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@
3030
"widget-attributes": {
3131
"default": "3306"
3232
}
33+
},
34+
{
35+
"widget-type": "select",
36+
"label": "Transaction Isolation Level",
37+
"name": "transactionIsolationLevel",
38+
"widget-attributes": {
39+
"values": [
40+
"TRANSACTION_READ_UNCOMMITTED",
41+
"TRANSACTION_READ_COMMITTED",
42+
"TRANSACTION_REPEATABLE_READ",
43+
"TRANSACTION_SERIALIZABLE"
44+
],
45+
"default": "TRANSACTION_SERIALIZABLE"
46+
}
3347
}
3448
]
3549
},

mysql-plugin/widgets/Mysql-batchsink.json

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@
6565
"label": "Password",
6666
"name": "password"
6767
},
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+
}
81+
},
6882
{
6983
"widget-type": "keyvalue",
7084
"label": "Connection Arguments",
@@ -225,6 +239,10 @@
225239
"type": "property",
226240
"name": "password"
227241
},
242+
{
243+
"type": "property",
244+
"name": "transactionIsolationLevel"
245+
},
228246
{
229247
"type": "property",
230248
"name": "host"

mysql-plugin/widgets/Mysql-batchsource.json

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@
6565
"label": "Password",
6666
"name": "password"
6767
},
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+
}
81+
},
6882
{
6983
"widget-type": "keyvalue",
7084
"label": "Connection Arguments",
@@ -277,6 +291,10 @@
277291
"type": "property",
278292
"name": "password"
279293
},
294+
{
295+
"type": "property",
296+
"name": "transactionIsolationLevel"
297+
},
280298
{
281299
"type": "property",
282300
"name": "host"

0 commit comments

Comments
 (0)