Class JdbcCoordinatorImpl
- java.lang.Object
-
- org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl
-
- All Implemented Interfaces:
Serializable
,JdbcCoordinator
,JdbcResourceTransactionAccess
,TransactionCoordinatorOwner
public class JdbcCoordinatorImpl extends Object implements JdbcCoordinator
Standard implementation ofJdbcCoordinator
.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JdbcCoordinatorImpl(Connection userSuppliedConnection, JdbcSessionOwner owner, JdbcServices jdbcServices)
Constructs aJdbcCoordinatorImpl
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortBatch()
Abort the currently managed batch (if any)void
afterStatementExecution()
Used to signify that a statement has completed execution which may indicate that this logical connection need to perform an aggressive release of its physical connection.void
afterTransaction()
Signals the end of transaction.void
afterTransactionBegin()
A after-begin callback from the coordinator to its owner.void
afterTransactionCompletion(boolean successful, boolean delayed)
An after-completion callback from the coordinator to its owner.void
beforeTransactionCompletion()
A before-completion callback from the coordinator to its owner.void
cancelLastQuery()
Attempt to cancel the last query sent to the JDBC driver.Connection
close()
Close this coordinator and release and resources.protected void
close(ResultSet resultSet)
protected void
close(Statement statement)
void
conditionallyExecuteBatch(BatchKey key)
Conditionally execute the currently managed batch (if any), if the keys do not match<T> T
coordinateWork(WorkExecutorVisitable<T> work)
Perform the requested work handling exceptions, coordinating and handling return processing.static JdbcCoordinatorImpl
deserialize(ObjectInputStream ois, JdbcSessionOwner owner)
JDK deserialization hookint
determineRemainingTransactionTimeOutPeriod()
Calculate the amount of time, in seconds, still remaining before transaction timeout occurs.void
disableReleases()
Disable connection releasesvoid
enableReleases()
Enable connection releasesvoid
executeBatch()
Execute the currently managed batch (if any)void
flushBeforeTransactionCompletion()
void
flushBeginning()
Callback to let us know that a flush is beginning.void
flushEnding()
Callback to let us know that a flush is ending.Batch
getBatch(BatchKey key, Integer batchSize, Supplier<PreparedStatementGroup> statementGroupSupplier)
Get the batch for the supplied key, creating one if needed using the supplied statementGroupSupplier.JdbcSessionOwner
getJdbcSessionOwner()
LogicalConnectionImplementor
getLogicalConnection()
Retrieves the logical connection associated with this JDBC coordinator.MutationStatementPreparer
getMutationStatementPreparer()
The builder of prepared and callable JDBC statements for mutation operations (insert, update and delete) originating from persistent context events, as opposed to Query handlingJdbcResourceTransaction
getResourceLocalTransaction()
Provides access to the resource local transaction of this data store, which is used by theTransactionCoordinator
to manage transactions against the data store when not using JTA.ResultSetReturn
getResultSetReturn()
Obtain theResultSet
extractor associated with this JDBC coordinator.StatementPreparer
getStatementPreparer()
Obtain the statement preparer associated with this JDBC coordinator.boolean
isActive()
Is the TransactionCoordinator owner considered active?boolean
isReadyForSerialization()
Can this coordinator be serialized?void
registerLastQuery(Statement statement)
Register a query statement as being able to be cancelled.void
serialize(ObjectOutputStream oos)
JDK serialization hookvoid
setTransactionTimeOut(int seconds)
Set the effective transaction timeout period for the current transaction, in seconds.SqlExceptionHelper
sqlExceptionHelper()
Access to theSqlExceptionHelper
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner
startTransactionBoundary
-
-
-
-
Constructor Detail
-
JdbcCoordinatorImpl
public JdbcCoordinatorImpl(Connection userSuppliedConnection, JdbcSessionOwner owner, JdbcServices jdbcServices)
Constructs aJdbcCoordinatorImpl
- Parameters:
userSuppliedConnection
- The user supplied connection (may be null)
-
-
Method Detail
-
getLogicalConnection
public LogicalConnectionImplementor getLogicalConnection()
Description copied from interface:JdbcCoordinator
Retrieves the logical connection associated with this JDBC coordinator.- Specified by:
getLogicalConnection
in interfaceJdbcCoordinator
- Returns:
- The logical connection
-
sqlExceptionHelper
public SqlExceptionHelper sqlExceptionHelper()
Access to theSqlExceptionHelper
- Returns:
- The
SqlExceptionHelper
-
flushBeginning
public void flushBeginning()
Description copied from interface:JdbcCoordinator
Callback to let us know that a flush is beginning. We use this fact to temporarily circumvent aggressive connection releasing until after the flush cycle is completeJdbcCoordinator.flushEnding()
- Specified by:
flushBeginning
in interfaceJdbcCoordinator
-
flushEnding
public void flushEnding()
Description copied from interface:JdbcCoordinator
Callback to let us know that a flush is ending. We use this fact to stop circumventing aggressive releasing connections.- Specified by:
flushEnding
in interfaceJdbcCoordinator
-
close
public Connection close()
Description copied from interface:JdbcCoordinator
Close this coordinator and release and resources.- Specified by:
close
in interfaceJdbcCoordinator
- Returns:
- The
Connection
associated with the managedlogical connection
- See Also:
LogicalConnection.close()
-
getBatch
public Batch getBatch(BatchKey key, Integer batchSize, Supplier<PreparedStatementGroup> statementGroupSupplier)
Description copied from interface:JdbcCoordinator
Get the batch for the supplied key, creating one if needed using the supplied statementGroupSupplier.- Specified by:
getBatch
in interfaceJdbcCoordinator
-
executeBatch
public void executeBatch()
Description copied from interface:JdbcCoordinator
Execute the currently managed batch (if any)- Specified by:
executeBatch
in interfaceJdbcCoordinator
-
conditionallyExecuteBatch
public void conditionallyExecuteBatch(BatchKey key)
Description copied from interface:JdbcCoordinator
Conditionally execute the currently managed batch (if any), if the keys do not match- Specified by:
conditionallyExecuteBatch
in interfaceJdbcCoordinator
-
abortBatch
public void abortBatch()
Description copied from interface:JdbcCoordinator
Abort the currently managed batch (if any)- Specified by:
abortBatch
in interfaceJdbcCoordinator
-
getStatementPreparer
public StatementPreparer getStatementPreparer()
Description copied from interface:JdbcCoordinator
Obtain the statement preparer associated with this JDBC coordinator.- Specified by:
getStatementPreparer
in interfaceJdbcCoordinator
- Returns:
- This coordinator's statement preparer
-
getMutationStatementPreparer
public MutationStatementPreparer getMutationStatementPreparer()
Description copied from interface:JdbcCoordinator
The builder of prepared and callable JDBC statements for mutation operations (insert, update and delete) originating from persistent context events, as opposed to Query handling- Specified by:
getMutationStatementPreparer
in interfaceJdbcCoordinator
-
getResultSetReturn
public ResultSetReturn getResultSetReturn()
Description copied from interface:JdbcCoordinator
Obtain theResultSet
extractor associated with this JDBC coordinator.- Specified by:
getResultSetReturn
in interfaceJdbcCoordinator
- Returns:
- This coordinator's resultset extractor
-
setTransactionTimeOut
public void setTransactionTimeOut(int seconds)
Description copied from interface:TransactionCoordinatorOwner
Set the effective transaction timeout period for the current transaction, in seconds.- Specified by:
setTransactionTimeOut
in interfaceTransactionCoordinatorOwner
- Parameters:
seconds
- The number of seconds before a time out should occur.
-
flushBeforeTransactionCompletion
public void flushBeforeTransactionCompletion()
- Specified by:
flushBeforeTransactionCompletion
in interfaceTransactionCoordinatorOwner
-
determineRemainingTransactionTimeOutPeriod
public int determineRemainingTransactionTimeOutPeriod()
Description copied from interface:JdbcCoordinator
Calculate the amount of time, in seconds, still remaining before transaction timeout occurs.- Specified by:
determineRemainingTransactionTimeOutPeriod
in interfaceJdbcCoordinator
- Returns:
- The number of seconds remaining until a transaction timeout occurs. A negative value indicates no timeout was requested.
-
afterStatementExecution
public void afterStatementExecution()
Description copied from interface:JdbcCoordinator
Used to signify that a statement has completed execution which may indicate that this logical connection need to perform an aggressive release of its physical connection.- Specified by:
afterStatementExecution
in interfaceJdbcCoordinator
-
afterTransaction
public void afterTransaction()
Description copied from interface:JdbcCoordinator
Signals the end of transaction.Intended for use from the transaction coordinator, after local transaction completion. Used to conditionally release the JDBC connection aggressively if the configured release mode indicates.
- Specified by:
afterTransaction
in interfaceJdbcCoordinator
-
coordinateWork
public <T> T coordinateWork(WorkExecutorVisitable<T> work)
Description copied from interface:JdbcCoordinator
Perform the requested work handling exceptions, coordinating and handling return processing.- Specified by:
coordinateWork
in interfaceJdbcCoordinator
- Type Parameters:
T
- The result type.- Parameters:
work
- The work to be performed.- Returns:
- The work result.
-
isReadyForSerialization
public boolean isReadyForSerialization()
Description copied from interface:JdbcCoordinator
Can this coordinator be serialized?- Specified by:
isReadyForSerialization
in interfaceJdbcCoordinator
- Returns:
true
indicates the coordinator can be serialized.
-
registerLastQuery
public void registerLastQuery(Statement statement)
Description copied from interface:JdbcCoordinator
Register a query statement as being able to be cancelled.- Specified by:
registerLastQuery
in interfaceJdbcCoordinator
- Parameters:
statement
- The cancel-able query statement.
-
cancelLastQuery
public void cancelLastQuery()
Description copied from interface:JdbcCoordinator
Attempt to cancel the last query sent to the JDBC driver.- Specified by:
cancelLastQuery
in interfaceJdbcCoordinator
-
enableReleases
public void enableReleases()
Description copied from interface:JdbcCoordinator
Enable connection releases- Specified by:
enableReleases
in interfaceJdbcCoordinator
-
disableReleases
public void disableReleases()
Description copied from interface:JdbcCoordinator
Disable connection releases- Specified by:
disableReleases
in interfaceJdbcCoordinator
-
close
protected void close(Statement statement)
-
close
protected void close(ResultSet resultSet)
-
isActive
public boolean isActive()
Description copied from interface:TransactionCoordinatorOwner
Is the TransactionCoordinator owner considered active?- Specified by:
isActive
in interfaceTransactionCoordinatorOwner
- Returns:
true
indicates the owner is still active;false
indicates it is not.
-
afterTransactionBegin
public void afterTransactionBegin()
Description copied from interface:TransactionCoordinatorOwner
A after-begin callback from the coordinator to its owner.- Specified by:
afterTransactionBegin
in interfaceTransactionCoordinatorOwner
-
beforeTransactionCompletion
public void beforeTransactionCompletion()
Description copied from interface:TransactionCoordinatorOwner
A before-completion callback from the coordinator to its owner.- Specified by:
beforeTransactionCompletion
in interfaceTransactionCoordinatorOwner
-
afterTransactionCompletion
public void afterTransactionCompletion(boolean successful, boolean delayed)
Description copied from interface:TransactionCoordinatorOwner
An after-completion callback from the coordinator to its owner.- Specified by:
afterTransactionCompletion
in interfaceTransactionCoordinatorOwner
- Parameters:
successful
- Was the transaction successful?delayed
- Is this delayed after transaction completion call (aka after a timeout)?
-
getJdbcSessionOwner
public JdbcSessionOwner getJdbcSessionOwner()
- Specified by:
getJdbcSessionOwner
in interfaceTransactionCoordinatorOwner
-
getResourceLocalTransaction
public JdbcResourceTransaction getResourceLocalTransaction()
Description copied from interface:JdbcResourceTransactionAccess
Provides access to the resource local transaction of this data store, which is used by theTransactionCoordinator
to manage transactions against the data store when not using JTA.- Specified by:
getResourceLocalTransaction
in interfaceJdbcResourceTransactionAccess
- Returns:
- The resource-local transaction
-
serialize
public void serialize(ObjectOutputStream oos) throws IOException
JDK serialization hook- Specified by:
serialize
in interfaceJdbcCoordinator
- Parameters:
oos
- The stream into which to write our state- Throws:
IOException
- Trouble accessing the stream
-
deserialize
public static JdbcCoordinatorImpl deserialize(ObjectInputStream ois, JdbcSessionOwner owner) throws IOException, ClassNotFoundException
JDK deserialization hook- Parameters:
ois
- The stream into which to write our stateowner
- The Jdbc Session owner which owns the JdbcCoordinatorImpl to be deserialized.- Returns:
- The deserialized
JdbcCoordinatorImpl
- Throws:
IOException
- Trouble accessing the streamClassNotFoundException
- Trouble reading the stream
-
-