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
ConstructorsConstructorDescriptionJtaDataSource(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 TypeMethodDescriptionvoidafterCompletion(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.voidDeprecated, 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 ofConnectionthat 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 ofConnectionthat is sourced from an underlyingDataSource.booleanregisterWith(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, unwrapMethods inherited from class io.helidon.integrations.jdbc.AbstractCommonDataSource
getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder, getParentLoggerMethods 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- theDataSourceinstance to which operations will be delegated; must not benulltransactionIsActiveSupplier- aBooleanSupplierthat returnstrueonly 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- aSupplierofDataSourceinstances to which operations will be delegated; must not benulltransactionIsActiveSupplier- anBooleanSupplierthat returnstrueonly 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 thisJtaDataSourcewith 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- aConsumerthat may accept thisJtaDataSourceif there is a currently active transaction; must not benull- Returns:
trueif registration occurred;falseotherwise- Throws:
NullPointerException- ifregistrarisnullRuntimeException- if the suppliedregistrar'sacceptmethod 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:
beforeCompletionin 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:
afterCompletionin interfaceSynchronization- Parameters:
status- the status of the transaction after completion; must be eitherStatus.STATUS_COMMITTEDorStatus.STATUS_ROLLEDBACK- Throws:
IllegalArgumentException- ifstatusis neitherStatus.STATUS_COMMITTEDnorStatus.STATUS_ROLLEDBACK
-
getConnection
Deprecated, for removal: This API element is subject to removal in a future version.Returns a special kind ofConnectionthat is sourced from an underlyingDataSource.The
Connectionreturned by this method:- is never
null(unless the underlyingDataSourceis not JDBC-compliant) - is exactly the
Connectionreturned by the underlyingDataSourcewhen there is no JTA transaction in effect at the time that this method is invoked
Otherwise, when a JTA transaction is in effect, the
Connectionreturned by this method:- is the same
Connectionreturned by prior invocations of this method on the same thread during the lifespan of a JTA transaction. That is, theConnectionis "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 thisConnectionwill 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:
getConnectionin interfaceDataSource- Returns:
- a non-
nullConnection - Throws:
SQLException- if an error occursRuntimeException- if theBooleanSuppliersupplied at construction time that reports a transaction's status throws aRuntimeException, or if theSuppliersupplied at construction time that retrieves a delegateDataSourcethrows aRuntimeException- See Also:
- is never
-
getConnection
Deprecated, for removal: This API element is subject to removal in a future version.Returns a special kind ofConnectionthat is sourced from an underlyingDataSource.The
Connectionreturned by this method:- is never
null(unless the underlyingDataSourceis not JDBC-compliant) - is exactly the
Connectionreturned by the underlyingDataSourcewhen there is no JTA transaction in effect at the time that this method is invoked
Otherwise, when a JTA transaction is in effect, the
Connectionreturned by this method:- is the same
Connectionreturned 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, theConnectionis "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 thisConnectionwill 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:
getConnectionin interfaceDataSource- Parameters:
username- the username to use to acquire an underlyingConnection; may benullpassword- the password to use to acquire an underlyingConnection; may benull- Returns:
- a non-
nullConnection - Throws:
SQLException- if an error occursRuntimeException- if theBooleanSuppliersupplied at construction time that reports a transaction's status throws aRuntimeException, or if theSuppliersupplied at construction time that retrieves a delegateDataSourcethrows 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,Connections acquired by instances of this class may not be closed properly.