- All Superinterfaces:
AutoCloseable
,Connection
,Wrapper
,Wrapper
- All Known Implementing Classes:
FailFastConnectionImpl
Connection
perform in a fail-fast manner. All access to the connection will fail once a
Throwable
has been thrown by the underlying driver, with this state only being cleared by rollback.- Author:
- AO Industries, Inc.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
The set of possible fail-fast states. -
Field Summary
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Puts the connection into a terminalAbortedSQLException
fail-fast state then callsFailFastConnectionImpl.doAbort(java.lang.Throwable, java.util.concurrent.Executor)
.void
addFailFastCause
(Throwable cause) Registers a cause for the current failure.Clears the cause of the current fail-fast state.void
close()
Puts the connection into a terminalClosedSQLException
fail-fast state then callsFailFastConnectionImpl.doClose(java.lang.Throwable)
.Gets the cause of the current fail-fast state.Gets the current fail-fail state.Gets the connection that is wrapped.void
rollback()
When not in a terminal fail-fast state, willclear the fail-fast state
upon a successful call tosuper.rollback()
.void
When not in a terminal fail-fast state, willclear the fail-fast state
upon a successful call tosuper.rollback(savepoint)
.Methods inherited from interface java.sql.Connection
beginRequest, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, endRequest, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid, setTransactionIsolation, setTypeMap
Methods inherited from interface com.aoapps.sql.wrapper.Wrapper
isWrapperFor, unwrap
-
Method Details
-
getWrapped
Connection getWrapped()Gets the connection that is wrapped.- Specified by:
getWrapped
in interfaceWrapper
-
addFailFastCause
Registers a cause for the current failure. Multiple causes are merged in the following order:TerminalSQLException
take highest precedence, since these are non-recoverable.-
All other
Throwable
are next precedence. These might be recoverable throughrollback()
orrollback(java.sql.Savepoint)
.
Higher precedence causes will suppress any existing cause of a lower precedence (new adds the current as suppressed).
Lower precedence causes will be suppressed by any existing cause of higher precedence (current adds the new as suppressed).
Causes within the same precedence are merged via
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
.- Parameters:
cause
- The additional cause, ignored whennull
-
getFailFastCause
Throwable getFailFastCause()Gets the cause of the current fail-fast state.This might involve creating a new exception, so
getFailFastState()
may be faster when the exact cause is not required.- Returns:
- The cause or
null
when not in failure state (operating normally). - See Also:
-
getFailFastState
FailFastConnection.State getFailFastState()Gets the current fail-fail state.- Returns:
- The state or
FailFastConnection.State.OK
when not in failure state (operating normally). - See Also:
-
clearFailFast
Clears the cause of the current fail-fast state. This will typically be invoked automatically during one of the following successful operations:- Returns:
- The cause or
null
when was not in failure state (operating normally). - Throws:
TerminalSQLException
- if the connection is in a terminal fail-fast state, such as closed or aborted.- See Also:
-
rollback
When not in a terminal fail-fast state, willclear the fail-fast state
upon a successful call tosuper.rollback()
.- Specified by:
rollback
in interfaceConnection
- Throws:
TerminalSQLException
- if already in a terminal fail-fast stateSQLException
- if any other failure occurs during rollback
-
close
Puts the connection into a terminalClosedSQLException
fail-fast state then callsFailFastConnectionImpl.doClose(java.lang.Throwable)
.When already in a terminal state (closed or aborted), is a no-op and does not call
FailFastConnectionImpl.doClose(java.lang.Throwable)
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
- See Also:
-
rollback
When not in a terminal fail-fast state, willclear the fail-fast state
upon a successful call tosuper.rollback(savepoint)
.- Specified by:
rollback
in interfaceConnection
- Throws:
FailFastSQLException
- if already in a terminal fail-fast stateSQLException
- if any other failure occurs during rollbackTerminalSQLException
-
abort
Puts the connection into a terminalAbortedSQLException
fail-fast state then callsFailFastConnectionImpl.doAbort(java.lang.Throwable, java.util.concurrent.Executor)
.When already in a terminal state (closed or aborted), is a no-op and does not call
FailFastConnectionImpl.doAbort(java.lang.Throwable, java.util.concurrent.Executor)
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
- See Also:
-