- All Implemented Interfaces:
FailFastConnection
,ConnectionWrapper
,Wrapper
,AutoCloseable
,Connection
,Wrapper
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
Nested classes/interfaces inherited from interface com.aoapps.sql.failfast.FailFastConnection
FailFastConnection.State
-
Field Summary
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
ConstructorsConstructorDescriptionFailFastConnectionImpl
(FailFastDriver driver, Connection wrapped) FailFastConnectionImpl
(Connection wrapped) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Puts the connection into a terminalAbortedSQLException
fail-fast state then callsdoAbort(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
void
close()
Puts the connection into a terminalClosedSQLException
fail-fast state then callsdoClose(java.lang.Throwable)
.void
commit()
createArrayOf
(String typeName, Object[] elements) createStatement
(int resultSetType, int resultSetConcurrency) createStatement
(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct
(String typeName, Object[] attributes) protected void
protected void
protected void
Performs fail-fast check.protected void
failFastSQLClientInfoException
(Supplier<? extends Map<String, ClientInfoStatus>> failedPropertiesSupplier) Performs fail-fast check.protected void
Performs fail-fast check.boolean
getClientInfo
(String name) Gets the cause of the current fail-fast state.Gets the current fail-fail state.int
int
int
boolean
isClosed()
boolean
boolean
isValid
(int timeout) protected FailFastArrayImpl
newArrayWrapper
(StatementWrapperImpl stmtWrapper, Array array) protected FailFastBlobImpl
newBlobWrapper
(Blob blob) protected FailFastCallableStatementImpl
protected FailFastClobImpl
newClobWrapper
(Clob clob) protected FailFastDatabaseMetaDataImpl
newDatabaseMetaDataWrapper
(DatabaseMetaData metaData) protected FailFastInputStream
protected FailFastNClobImpl
newNClobWrapper
(NClob nclob) protected FailFastOutputStream
protected FailFastParameterMetaDataImpl
newParameterMetaDataWrapper
(ParameterMetaData metaData) protected FailFastPreparedStatementImpl
protected FailFastReader
protected FailFastRefImpl
newRefWrapper
(Ref ref) protected FailFastResultSetMetaDataImpl
newResultSetMetaDataWrapper
(ResultSetMetaData metaData) protected FailFastResultSetImpl
newResultSetWrapper
(StatementWrapperImpl stmtWrapper, ResultSet results) protected FailFastRowIdImpl
newRowIdWrapper
(RowId rowId) protected FailFastSavepointImpl
newSavepointWrapper
(Savepoint savepoint) protected SQLDataWrapperImpl
newSQLDataWrapper
(SQLData sqlData) protected FailFastSQLInputImpl
newSQLInputWrapper
(SQLInput sqlInput) protected FailFastSQLOutputImpl
newSQLOutputWrapper
(SQLOutput sqlOutput) protected FailFastSQLXMLImpl
newSQLXMLWrapper
(SQLXML sqlXml) protected FailFastStatementImpl
newStatementWrapper
(Statement stmt) protected FailFastStructImpl
newStructWrapper
(Struct struct) protected FailFastWriter
newWriterWrapper
(Writer out) prepareCall
(String sql) prepareCall
(String sql, int resultSetType, int resultSetConcurrency) prepareCall
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement
(String sql) prepareStatement
(String sql, int autoGeneratedKeys) prepareStatement
(String sql, int[] columnIndexes) prepareStatement
(String sql, int resultSetType, int resultSetConcurrency) prepareStatement
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement
(String sql, String[] columnNames) void
releaseSavepoint
(Savepoint savepoint) 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)
.void
setAutoCommit
(boolean autoCommit) void
setCatalog
(String catalog) void
setClientInfo
(String name, String value) void
setClientInfo
(Properties properties) void
setHoldability
(int holdability) void
setNetworkTimeout
(Executor executor, int milliseconds) void
setReadOnly
(boolean readOnly) setSavepoint
(String name) void
void
setTransactionIsolation
(int level) void
setTypeMap
(Map<String, Class<?>> map) Methods inherited from class com.aoapps.sql.wrapper.ConnectionWrapperImpl
getDriver, getWrapped, toString, unwrapArray, unwrapBlob, unwrapClob, unwrapInputStream, unwrapNClob, unwrapReader, unwrapRef, unwrapRowId, unwrapSavepoint, unwrapSQLXML, unwrapStruct, wrapArray, wrapBlob, wrapCallableStatement, wrapClob, wrapDatabaseMetaData, wrapInputStream, wrapNClob, wrapOutputStream, wrapParameterMetaData, wrapPreparedStatement, wrapReader, wrapRef, wrapResultSet, wrapResultSetMetaData, wrapRowId, wrapSavepoint, wrapSQLData, wrapSQLInput, wrapSQLOutput, wrapSQLXML, wrapStatement, wrapStruct, wrapWriter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
Methods inherited from interface com.aoapps.sql.wrapper.ConnectionWrapper
getWrappedConnection
Methods inherited from interface com.aoapps.sql.failfast.FailFastConnection
getWrapped
Methods inherited from interface com.aoapps.sql.wrapper.Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
FailFastConnectionImpl
-
FailFastConnectionImpl
-
-
Method Details
-
addFailFastCause
Description copied from interface:FailFastConnection
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 throughFailFastConnection.rollback()
orFailFastConnection.rollback(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)
.- Specified by:
addFailFastCause
in interfaceFailFastConnection
- Parameters:
cause
- The additional cause, ignored whennull
-
getFailFastCause
Description copied from interface:FailFastConnection
Gets the cause of the current fail-fast state.This might involve creating a new exception, so
FailFastConnection.getFailFastState()
may be faster when the exact cause is not required.- Specified by:
getFailFastCause
in interfaceFailFastConnection
- Returns:
- The cause or
null
when not in failure state (operating normally). - See Also:
-
getFailFastState
Description copied from interface:FailFastConnection
Gets the current fail-fail state.- Specified by:
getFailFastState
in interfaceFailFastConnection
- Returns:
- The state or
FailFastConnection.State.OK
when not in failure state (operating normally). - See Also:
-
clearFailFast
Description copied from interface:FailFastConnection
Clears the cause of the current fail-fast state. This will typically be invoked automatically during one of the following successful operations:- Specified by:
clearFailFast
in interfaceFailFastConnection
- 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:
-
failFastSQLException
Performs fail-fast check.- Throws:
SQLException
- if currently in a fail-fast state- See Also:
-
failFastSQLClientInfoException
protected void failFastSQLClientInfoException(Supplier<? extends Map<String, ClientInfoStatus>> failedPropertiesSupplier) throws SQLClientInfoExceptionPerforms fail-fast check.- Throws:
SQLClientInfoException
- if currently in a fail-fast state
-
failFastIOException
Performs fail-fast check.- Throws:
IOException
- if currently in a fail-fast state- See Also:
-
newArrayWrapper
- Overrides:
newArrayWrapper
in classConnectionWrapperImpl
-
newBlobWrapper
- Overrides:
newBlobWrapper
in classConnectionWrapperImpl
-
newCallableStatementWrapper
- Overrides:
newCallableStatementWrapper
in classConnectionWrapperImpl
-
newClobWrapper
- Overrides:
newClobWrapper
in classConnectionWrapperImpl
-
newDatabaseMetaDataWrapper
- Overrides:
newDatabaseMetaDataWrapper
in classConnectionWrapperImpl
-
newInputStreamWrapper
- Overrides:
newInputStreamWrapper
in classConnectionWrapperImpl
-
newNClobWrapper
- Overrides:
newNClobWrapper
in classConnectionWrapperImpl
-
newOutputStreamWrapper
- Overrides:
newOutputStreamWrapper
in classConnectionWrapperImpl
-
newParameterMetaDataWrapper
- Overrides:
newParameterMetaDataWrapper
in classConnectionWrapperImpl
-
newPreparedStatementWrapper
- Overrides:
newPreparedStatementWrapper
in classConnectionWrapperImpl
-
newReaderWrapper
- Overrides:
newReaderWrapper
in classConnectionWrapperImpl
-
newRefWrapper
- Overrides:
newRefWrapper
in classConnectionWrapperImpl
-
newResultSetWrapper
protected FailFastResultSetImpl newResultSetWrapper(StatementWrapperImpl stmtWrapper, ResultSet results) - Overrides:
newResultSetWrapper
in classConnectionWrapperImpl
-
newResultSetMetaDataWrapper
- Overrides:
newResultSetMetaDataWrapper
in classConnectionWrapperImpl
-
newRowIdWrapper
- Overrides:
newRowIdWrapper
in classConnectionWrapperImpl
-
newSQLDataWrapper
- Overrides:
newSQLDataWrapper
in classConnectionWrapperImpl
-
newSQLInputWrapper
- Overrides:
newSQLInputWrapper
in classConnectionWrapperImpl
-
newSQLOutputWrapper
- Overrides:
newSQLOutputWrapper
in classConnectionWrapperImpl
-
newSQLXMLWrapper
- Overrides:
newSQLXMLWrapper
in classConnectionWrapperImpl
-
newSavepointWrapper
- Overrides:
newSavepointWrapper
in classConnectionWrapperImpl
-
newStatementWrapper
- Overrides:
newStatementWrapper
in classConnectionWrapperImpl
-
newStructWrapper
- Overrides:
newStructWrapper
in classConnectionWrapperImpl
-
newWriterWrapper
- Overrides:
newWriterWrapper
in classConnectionWrapperImpl
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Specified by:
createStatement
in interfaceConnectionWrapper
- Overrides:
createStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Specified by:
prepareStatement
in interfaceConnectionWrapper
- Overrides:
prepareStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCall
in interfaceConnection
- Specified by:
prepareCall
in interfaceConnectionWrapper
- Overrides:
prepareCall
in classConnectionWrapperImpl
- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQL
in interfaceConnection
- Specified by:
nativeSQL
in interfaceConnectionWrapper
- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommit
in interfaceConnection
- Specified by:
setAutoCommit
in interfaceConnectionWrapper
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Specified by:
getAutoCommit
in interfaceConnectionWrapper
- Throws:
SQLException
-
commit
- Specified by:
commit
in interfaceConnection
- Specified by:
commit
in interfaceConnectionWrapper
- Throws:
SQLException
-
rollback
Description copied from interface:FailFastConnection
When not in a terminal fail-fast state, willclear the fail-fast state
upon a successful call tosuper.rollback()
.- Specified by:
rollback
in interfaceConnection
- Specified by:
rollback
in interfaceConnectionWrapper
- Specified by:
rollback
in interfaceFailFastConnection
- Throws:
TerminalSQLException
- if already in a terminal fail-fast stateSQLException
- if any other failure occurs during rollback
-
close
Description copied from interface:FailFastConnection
Puts the connection into a terminalClosedSQLException
fail-fast state then callsdoClose(java.lang.Throwable)
.When already in a terminal state (closed or aborted), is a no-op and does not call
doClose(java.lang.Throwable)
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Specified by:
close
in interfaceConnectionWrapper
- Specified by:
close
in interfaceFailFastConnection
- Overrides:
close
in classConnectionWrapperImpl
- Throws:
SQLException
- See Also:
-
isClosed
- Specified by:
isClosed
in interfaceConnection
- Specified by:
isClosed
in interfaceConnectionWrapper
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfaceConnection
- Specified by:
getMetaData
in interfaceConnectionWrapper
- Overrides:
getMetaData
in classConnectionWrapperImpl
- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnly
in interfaceConnection
- Specified by:
setReadOnly
in interfaceConnectionWrapper
- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnly
in interfaceConnection
- Specified by:
isReadOnly
in interfaceConnectionWrapper
- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalog
in interfaceConnection
- Specified by:
setCatalog
in interfaceConnectionWrapper
- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalog
in interfaceConnection
- Specified by:
getCatalog
in interfaceConnectionWrapper
- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Specified by:
setTransactionIsolation
in interfaceConnectionWrapper
- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolation
in interfaceConnection
- Specified by:
getTransactionIsolation
in interfaceConnectionWrapper
- Throws:
SQLException
-
getWarnings
- Specified by:
getWarnings
in interfaceConnection
- Specified by:
getWarnings
in interfaceConnectionWrapper
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceConnection
- Specified by:
clearWarnings
in interfaceConnectionWrapper
- Throws:
SQLException
-
createStatement
public FailFastStatementImpl createStatement(int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Specified by:
createStatement
in interfaceConnectionWrapper
- Overrides:
createStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Specified by:
prepareStatement
in interfaceConnectionWrapper
- Overrides:
prepareStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareCall
public FailFastCallableStatementImpl prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Specified by:
prepareCall
in interfaceConnectionWrapper
- Overrides:
prepareCall
in classConnectionWrapperImpl
- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMap
in interfaceConnection
- Specified by:
getTypeMap
in interfaceConnectionWrapper
- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMap
in interfaceConnection
- Specified by:
setTypeMap
in interfaceConnectionWrapper
- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldability
in interfaceConnection
- Specified by:
setHoldability
in interfaceConnectionWrapper
- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldability
in interfaceConnection
- Specified by:
getHoldability
in interfaceConnectionWrapper
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Specified by:
setSavepoint
in interfaceConnectionWrapper
- Overrides:
setSavepoint
in classConnectionWrapperImpl
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Specified by:
setSavepoint
in interfaceConnectionWrapper
- Overrides:
setSavepoint
in classConnectionWrapperImpl
- Throws:
SQLException
-
rollback
Description copied from interface:FailFastConnection
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
- Specified by:
rollback
in interfaceConnectionWrapper
- Specified by:
rollback
in interfaceFailFastConnection
- Overrides:
rollback
in classConnectionWrapperImpl
- Throws:
SQLException
- if any other failure occurs during rollback
-
releaseSavepoint
- Specified by:
releaseSavepoint
in interfaceConnection
- Specified by:
releaseSavepoint
in interfaceConnectionWrapper
- Overrides:
releaseSavepoint
in classConnectionWrapperImpl
- Throws:
SQLException
-
createStatement
public FailFastStatementImpl createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Specified by:
createStatement
in interfaceConnectionWrapper
- Overrides:
createStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Specified by:
prepareStatement
in interfaceConnectionWrapper
- Overrides:
prepareStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareCall
public FailFastCallableStatementImpl prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Specified by:
prepareCall
in interfaceConnectionWrapper
- Overrides:
prepareCall
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int autoGeneratedKeys) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Specified by:
prepareStatement
in interfaceConnectionWrapper
- Overrides:
prepareStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int[] columnIndexes) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Specified by:
prepareStatement
in interfaceConnectionWrapper
- Overrides:
prepareStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, String[] columnNames) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Specified by:
prepareStatement
in interfaceConnectionWrapper
- Overrides:
prepareStatement
in classConnectionWrapperImpl
- Throws:
SQLException
-
createClob
- Specified by:
createClob
in interfaceConnection
- Specified by:
createClob
in interfaceConnectionWrapper
- Overrides:
createClob
in classConnectionWrapperImpl
- Throws:
SQLException
-
createBlob
- Specified by:
createBlob
in interfaceConnection
- Specified by:
createBlob
in interfaceConnectionWrapper
- Overrides:
createBlob
in classConnectionWrapperImpl
- Throws:
SQLException
-
createNClob
- Specified by:
createNClob
in interfaceConnection
- Specified by:
createNClob
in interfaceConnectionWrapper
- Overrides:
createNClob
in classConnectionWrapperImpl
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Specified by:
createSQLXML
in interfaceConnectionWrapper
- Overrides:
createSQLXML
in classConnectionWrapperImpl
- Throws:
SQLException
-
isValid
- Specified by:
isValid
in interfaceConnection
- Specified by:
isValid
in interfaceConnectionWrapper
- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Specified by:
setClientInfo
in interfaceConnectionWrapper
- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Specified by:
setClientInfo
in interfaceConnectionWrapper
- Throws:
SQLClientInfoException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Specified by:
getClientInfo
in interfaceConnectionWrapper
- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Specified by:
getClientInfo
in interfaceConnectionWrapper
- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOf
in interfaceConnection
- Specified by:
createArrayOf
in interfaceConnectionWrapper
- Overrides:
createArrayOf
in classConnectionWrapperImpl
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Specified by:
createStruct
in interfaceConnectionWrapper
- Overrides:
createStruct
in classConnectionWrapperImpl
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Specified by:
getNetworkTimeout
in interfaceConnectionWrapper
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Specified by:
setNetworkTimeout
in interfaceConnectionWrapper
- Throws:
SQLException
-
setSchema
- Specified by:
setSchema
in interfaceConnection
- Specified by:
setSchema
in interfaceConnectionWrapper
- Throws:
SQLException
-
getSchema
- Specified by:
getSchema
in interfaceConnection
- Specified by:
getSchema
in interfaceConnectionWrapper
- Throws:
SQLException
-
abort
Description copied from interface:FailFastConnection
Puts the connection into a terminalAbortedSQLException
fail-fast state then callsdoAbort(java.lang.Throwable, java.util.concurrent.Executor)
.When already in a terminal state (closed or aborted), is a no-op and does not call
doAbort(java.lang.Throwable, java.util.concurrent.Executor)
- Specified by:
abort
in interfaceConnection
- Specified by:
abort
in interfaceConnectionWrapper
- Specified by:
abort
in interfaceFailFastConnection
- Overrides:
abort
in classConnectionWrapperImpl
- Throws:
SQLException
- See Also:
-
doClose
Either this method or
doAbort(java.lang.Throwable, java.util.concurrent.Executor)
is called, and at most once. Once either is called, additional close/abort requests are ignored.This default implementation calls
super.close()
.- Parameters:
failFastCause
- The fail-fast state before close.- Throws:
SQLException
-
doAbort
Either this method or
doClose(java.lang.Throwable)
is called, and at most once. Once either is called, additional close/abort requests are ignored.This default implementation calls
super.abort(executor)
.- Parameters:
failFastCause
- The fail-fast state before close.- Throws:
SQLException
-