Skip to content

Commit d30d86c

Browse files
committed
Add TRANSACTION_ISOLATION_LEVEL config in PostgreSQL plugins
1 parent cde7167 commit d30d86c

File tree

17 files changed

+172
-17
lines changed

17 files changed

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

mysql-plugin/docs/MySQL-connector.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ 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+
2531
**Connection Arguments:** A list of arbitrary string tag/value pairs as connection arguments. These arguments
2632
will be passed to the JDBC driver, as connection arguments, for JDBC drivers that may need additional configurations.
2733
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ 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+
4248
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
4349
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.
4450

mysql-plugin/docs/Mysql-batchsource.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ 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 databse 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+
5258
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
5359
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.
5460

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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
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"

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleConnectorConfig.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ public String getConnectionString() {
8181
@Macro
8282
private String database;
8383

84-
@Name(OracleConstants.TRANSACTION_ISOLATION_LEVEL)
85-
@Description("The transaction isolation level for the database session.")
86-
@Macro
87-
@Nullable
88-
private String transactionIsolationLevel;
89-
9084
@Name(OracleConstants.USE_SSL)
9185
@Description("Turns on SSL encryption. Connection will fail if SSL is not available")
9286
@Nullable
@@ -124,6 +118,7 @@ public Properties getConnectionArgumentsProperties() {
124118
return prop;
125119
}
126120

121+
@Override
127122
public String getTransactionIsolationLevel() {
128123
//if null default to the highest isolation level possible
129124
if (transactionIsolationLevel == null) {
@@ -133,16 +128,7 @@ public String getTransactionIsolationLevel() {
133128
//This ensures that the role is mapped to the right serialization level, even w/ incorrect user input
134129
//if role is SYSDBA or SYSOP it will map to read_committed. else serialized
135130
return (!getRole().equals(ROLE_NORMAL)) ? TransactionIsolationLevel.Level.TRANSACTION_READ_COMMITTED.name() :
136-
TransactionIsolationLevel.Level.valueOf(transactionIsolationLevel).name();
137-
}
138-
139-
@Override
140-
public Map<String, String> getAdditionalArguments() {
141-
Map<String, String> additonalArguments = new HashMap<>();
142-
if (getTransactionIsolationLevel() != null) {
143-
additonalArguments.put(TransactionIsolationLevel.CONF_KEY, getTransactionIsolationLevel());
144-
}
145-
return additonalArguments;
131+
TransactionIsolationLevel.Level.valueOf(transactionIsolationLevel).name();
146132
}
147133

148134
@Override

0 commit comments

Comments
 (0)