Class JtaDataSource
- All Implemented Interfaces:
Synchronization
,Wrapper
,CommonDataSource
,DataSource
AbstractDataSource
and a Synchronization
that wraps another DataSource
that is known to
not behave correctly in the presence of JTA transaction management, such as one supplied by any of several freely and
commercially available connection pools, and that makes such a non-JTA-aware DataSource
behave as sensibly as
possible in the presence of a JTA-managed transaction.
Thread Safety
Instances of this class are safe for concurrent use by multiple threads. No such guarantee obviously can be made
about the DataSource
wrapped by any given instance of this class.
Note that the JDBC specification places no requirement on any implementor to make any implementations of any JDBC constructs thread-safe. Nevertheless, a certain amount of unspecified thread safety must exist in all JDBC implementations or their constructs could never be enrolled in JTA-compliant transactions.
-
Constructor Summary
ConstructorDescriptionJtaDataSource
(Supplier<? extends DataSource> delegateSupplier, BooleanSupplier transactionIsActiveSupplier) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJtaDataSource
.JtaDataSource
(DataSource dataSource, BooleanSupplier transactionIsActiveSupplier) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJtaDataSource
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterCompletion
(int status) Deprecated, for removal: This API element is subject to removal in a future version.Ensures that any thread-associated connections are properly committed, restored to their initial states, closed where appropriate and removed from the system when a definitionally thread-scoped JTA transaction commits or rolls back.void
Deprecated, for removal: This API element is subject to removal in a future version.Implements theSynchronization.beforeCompletion()
method to do nothing.Deprecated, for removal: This API element is subject to removal in a future version.Returns a special kind ofConnection
that is sourced from an underlyingDataSource
.getConnection
(String username, String password) Deprecated, for removal: This API element is subject to removal in a future version.Returns a special kind ofConnection
that is sourced from an underlyingDataSource
.boolean
registerWith
(Consumer<? super Synchronization> registrar) Deprecated, for removal: This API element is subject to removal in a future version.This method is slated for removal with no replacement.Methods inherited from class io.helidon.integrations.jdbc.AbstractDataSource
isWrapperFor, unwrap
Methods inherited from class io.helidon.integrations.jdbc.AbstractCommonDataSource
getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder, getParentLogger
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
-
Constructor Details
-
JtaDataSource
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJtaDataSource
.- Parameters:
dataSource
- theDataSource
instance to which operations will be delegated; must not benull
transactionIsActiveSupplier
- aBooleanSupplier
that returnstrue
only if the current transaction, if any, is active; must not benull
- Throws:
NullPointerException
- if either parameter isnull
- See Also:
-
JtaDataSource
public JtaDataSource(Supplier<? extends DataSource> delegateSupplier, BooleanSupplier transactionIsActiveSupplier) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newJtaDataSource
.- Parameters:
delegateSupplier
- aSupplier
ofDataSource
instances to which operations will be delegated; must not benull
transactionIsActiveSupplier
- anBooleanSupplier
that returnstrue
only if the current transaction, if any, is active; must not benull
- Throws:
NullPointerException
- if either parameter isnull
-
-
Method Details
-
registerWith
@Deprecated(forRemoval=true) public boolean registerWith(Consumer<? super Synchronization> registrar) Deprecated, for removal: This API element is subject to removal in a future version.This method is slated for removal with no replacement.If there is an active transaction, registers thisJtaDataSource
with the supplied registrar, which is most commonly—but is not required to be—a reference to theTransactionSynchronizationRegistry.registerInterposedSynchronization(Synchronization)
method.If there is no currently active transaction, no action is taken.
- Parameters:
registrar
- aConsumer
that may accept thisJtaDataSource
if there is a currently active transaction; must not benull
- Returns:
true
if registration occurred;false
otherwise- Throws:
NullPointerException
- ifregistrar
isnull
RuntimeException
- if the suppliedregistrar
'saccept
method throws aRuntimeException
-
beforeCompletion
public void beforeCompletion()Deprecated, for removal: This API element is subject to removal in a future version.Implements theSynchronization.beforeCompletion()
method to do nothing.- Specified by:
beforeCompletion
in interfaceSynchronization
-
afterCompletion
public void afterCompletion(int status) Deprecated, for removal: This API element is subject to removal in a future version.Ensures that any thread-associated connections are properly committed, restored to their initial states, closed where appropriate and removed from the system when a definitionally thread-scoped JTA transaction commits or rolls back.- Specified by:
afterCompletion
in interfaceSynchronization
- Parameters:
status
- the status of the transaction after completion; must be eitherStatus.STATUS_COMMITTED
orStatus.STATUS_ROLLEDBACK
- Throws:
IllegalArgumentException
- ifstatus
is neitherStatus.STATUS_COMMITTED
norStatus.STATUS_ROLLEDBACK
-
getConnection
Deprecated, for removal: This API element is subject to removal in a future version.Returns a special kind ofConnection
that is sourced from an underlyingDataSource
.The
Connection
returned by this method:- is never
null
(unless the underlyingDataSource
is not JDBC-compliant) - is exactly the
Connection
returned by the underlyingDataSource
when there is no JTA transaction in effect at the time that this method is invoked
Otherwise, when a JTA transaction is in effect, the
Connection
returned by this method:- is the same
Connection
returned by prior invocations of this method on the same thread during the lifespan of a JTA transaction. That is, theConnection
is "pinned" to the current thread for the lifespan of the transaction. - is not actually closeable when a JTA transaction is in effect. The
Connection.close()
method will behave from the standpoint of the caller as if it functions normally, but its invocation will not actually be propagated to the underlyingDataSource
's connection. The fact that it was in fact invoked will be stored, and at such time that the JTA transaction completes thisConnection
will be closed at that point. - has its autocommit status set to
false
- will have
Connection.commit()
called on it when the JTA transaction commits - will have
Connection.rollback()
called on it when the JTA transaction rolls back - will have its autocommit status restored to its original value after the transaction completes
- Specified by:
getConnection
in interfaceDataSource
- Returns:
- a non-
null
Connection
- Throws:
SQLException
- if an error occursRuntimeException
- if theBooleanSupplier
supplied at construction time that reports a transaction's status throws aRuntimeException
, or if theSupplier
supplied at construction time that retrieves a delegateDataSource
throws aRuntimeException
- See Also:
- is never
-
getConnection
Deprecated, for removal: This API element is subject to removal in a future version.Returns a special kind ofConnection
that is sourced from an underlyingDataSource
.The
Connection
returned by this method:- is never
null
(unless the underlyingDataSource
is not JDBC-compliant) - is exactly the
Connection
returned by the underlyingDataSource
when there is no JTA transaction in effect at the time that this method is invoked
Otherwise, when a JTA transaction is in effect, the
Connection
returned by this method:- is the same
Connection
returned by prior invocations of this method with the same credentials (or no credentials) on the same thread during the lifespan of a JTA transaction. That is, theConnection
is "pinned" to the current thread for the lifespan of the transaction - is not actually closeable when a JTA transaction is in effect. The
Connection.close()
method will behave from the standpoint of the caller as if it functions normally, but its invocation will not actually be propagated to the underlyingDataSource
's connection. The fact that it was in fact invoked will be stored, and at such time that the JTA transaction completes thisConnection
will be closed at that point. - has its autocommit status set to
false
- will have
Connection.commit()
called on it when the JTA transaction commits - will have
Connection.rollback()
called on it when the JTA transaction rolls back - will have its autocommit status restored to its original value after the transaction completes
- Specified by:
getConnection
in interfaceDataSource
- Parameters:
username
- the username to use to acquire an underlyingConnection
; may benull
password
- the password to use to acquire an underlyingConnection
; may benull
- Returns:
- a non-
null
Connection
- Throws:
SQLException
- if an error occursRuntimeException
- if theBooleanSupplier
supplied at construction time that reports a transaction's status throws aRuntimeException
, or if theSupplier
supplied at construction time that retrieves a delegateDataSource
throws aRuntimeException
- See Also:
- is never
-
afterCompletion(int)
method will be invoked on the same thread as the governing transaction, which is not necessarily the case, especially in the case of asynchronous rollbacks. As a result,Connection
s acquired by instances of this class may not be closed properly.