diff --git a/ballerina/client.bal b/ballerina/client.bal index 5689e162..9d5d9912 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -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. diff --git a/changelog.md b/changelog.md index ad968c97..d7bc7d65 100644 --- a/changelog.md +++ b/changelog.md @@ -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) diff --git a/native/src/main/java/io/ballerina/stdlib/oracledb/Constants.java b/native/src/main/java/io/ballerina/stdlib/oracledb/Constants.java index 1f189313..4556a1d3 100644 --- a/native/src/main/java/io/ballerina/stdlib/oracledb/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/oracledb/Constants.java @@ -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"); } /** @@ -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"; } diff --git a/native/src/main/java/io/ballerina/stdlib/oracledb/nativeimpl/ClientProcessor.java b/native/src/main/java/io/ballerina/stdlib/oracledb/nativeimpl/ClientProcessor.java index 9fc043cf..961ab134 100644 --- a/native/src/main/java/io/ballerina/stdlib/oracledb/nativeimpl/ClientProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/oracledb/nativeimpl/ClientProcessor.java @@ -58,6 +58,7 @@ public static Object createClient( BMap datasourceOptions = null; Properties poolProperties = null; String protocol = Constants.PROTOCOL_TCP; + String dataSourceName = Constants.ORACLE_DATASOURCE_NAME; if (options != null) { datasourceOptions = Utils.generateOptionsMap(options); @@ -65,6 +66,9 @@ public static Object createClient( 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="); @@ -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)