Skip to content

Commit

Permalink
Add support for XA transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
niveathika committed Nov 11, 2022
1 parent 422159b commit 4e683f1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ public type SecureSocket record {|
# + connectTimeout - Timeout (in seconds) to be used when connecting to the Oracle server
# + socketTimeout - Socket timeout (in seconds) to be used during the read/write operations with the Oracle database server
# (0 means no socket timeout)
# + useXADatasource - If true, uses XADatasource for transactions
public type Options record {|
SecureSocket ssl?;
decimal loginTimeout = 0;
boolean autoCommit = true;
decimal connectTimeout = 30;
decimal socketTimeout?;
boolean useXADatasource = false;
|};

# Client configuration record for connection initialization.
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- [Support for XA transaction](https://github.com/ballerina-platform/ballerina-standard-library/issues/3599)

### Changed
- [Fix NullPointerException when retrieving record with default value](https://github.com/ballerina-platform/ballerina-standard-library/issues/2985)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private Options () {}
public static final BString LOGIN_TIMEOUT_SECONDS = StringUtils.fromString("loginTimeout");
public static final BString CONNECT_TIMEOUT_SECONDS = StringUtils.fromString("connectTimeout");
public static final BString SOCKET_TIMEOUT_SECONDS = StringUtils.fromString("socketTimeout");
public static final BString USE_XA_DATASOURCE = StringUtils.fromString("useXADatasource");
}

/**
Expand Down Expand Up @@ -266,5 +267,6 @@ private BallerinaArrayTypes() {}
public static final String PROTOCOL_TCP = "TCP";
public static final String PROTOCOL_TCPS = "TCPS";
public static final String ORACLE_DATASOURCE_NAME = "oracle.jdbc.pool.OracleDataSource";
public static final String ORACLE_XA_DATASOURCE_NAME = "oracle.jdbc.xa.client.OracleXADataSource";
public static final String CUSTOM_RESULT_ITERATOR_OBJECT = "CustomResultIterator";
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ public static Object createClient(
BMap<BString, Object> datasourceOptions = null;
Properties poolProperties = null;
String protocol = Constants.PROTOCOL_TCP;
String dataSourceName = Constants.ORACLE_DATASOURCE_NAME;

if (options != null) {
datasourceOptions = Utils.generateOptionsMap(options);
poolProperties = Utils.generatePoolProperties(options);
if (options.getMapValue(Constants.Options.SSL) != null) {
protocol = Constants.PROTOCOL_TCPS;
}
if (options.getBooleanValue(Constants.Options.USE_XA_DATASOURCE)) {
dataSourceName = Constants.ORACLE_XA_DATASOURCE_NAME;
}
}
StringBuilder url = new StringBuilder(Constants.DRIVER);
url.append("(DESCRIPTION=(ADDRESS=");
Expand All @@ -75,7 +79,6 @@ public static Object createClient(
url.append("(CONNECT_DATA=(SERVICE_NAME=").append(database).append("))");
url.append(")");
BMap connectionPool = clientConfig.getMapValue(Constants.ClientConfiguration.CONNECTION_POOL_OPTIONS);
String dataSourceName = Constants.ORACLE_DATASOURCE_NAME;
SQLDatasource.SQLDatasourceParams sqlDatasourceParams = new SQLDatasource.SQLDatasourceParams()
.setUrl(url.toString())
.setUser(user)
Expand Down

0 comments on commit 4e683f1

Please sign in to comment.