- 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 TypeMethodDescriptionvoidPuts the connection into a terminalAbortedSQLExceptionfail-fast state then callsdoAbort(java.lang.Throwable, java.util.concurrent.Executor).voidaddFailFastCause(Throwable cause) Registers a cause for the current failure.Clears the cause of the current fail-fast state.voidvoidclose()Puts the connection into a terminalClosedSQLExceptionfail-fast state then callsdoClose(java.lang.Throwable).voidcommit()createArrayOf(String typeName, Object[] elements) createStatement(int resultSetType, int resultSetConcurrency) createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct(String typeName, Object[] attributes) protected voidprotected voidprotected voidPerforms fail-fast check.protected voidfailFastSQLClientInfoException(Supplier<? extends Map<String, ClientInfoStatus>> failedPropertiesSupplier) Performs fail-fast check.protected voidPerforms fail-fast check.booleangetClientInfo(String name) Gets the cause of the current fail-fast state.Gets the current fail-fail state.intintintbooleanisClosed()booleanbooleanisValid(int timeout) protected FailFastArrayImplnewArrayWrapper(StatementWrapperImpl stmtWrapper, Array array) protected FailFastBlobImplnewBlobWrapper(Blob blob) protected FailFastCallableStatementImplprotected FailFastClobImplnewClobWrapper(Clob clob) protected FailFastDatabaseMetaDataImplnewDatabaseMetaDataWrapper(DatabaseMetaData metaData) protected FailFastInputStreamprotected FailFastNClobImplnewNClobWrapper(NClob nclob) protected FailFastOutputStreamprotected FailFastParameterMetaDataImplnewParameterMetaDataWrapper(ParameterMetaData metaData) protected FailFastPreparedStatementImplprotected FailFastReaderprotected FailFastRefImplnewRefWrapper(Ref ref) protected FailFastResultSetMetaDataImplnewResultSetMetaDataWrapper(ResultSetMetaData metaData) protected FailFastResultSetImplnewResultSetWrapper(StatementWrapperImpl stmtWrapper, ResultSet results) protected FailFastRowIdImplnewRowIdWrapper(RowId rowId) protected FailFastSavepointImplnewSavepointWrapper(Savepoint savepoint) protected SQLDataWrapperImplnewSQLDataWrapper(SQLData sqlData) protected FailFastSQLInputImplnewSQLInputWrapper(SQLInput sqlInput) protected FailFastSQLOutputImplnewSQLOutputWrapper(SQLOutput sqlOutput) protected FailFastSQLXMLImplnewSQLXMLWrapper(SQLXML sqlXml) protected FailFastStatementImplnewStatementWrapper(Statement stmt) protected FailFastStructImplnewStructWrapper(Struct struct) protected FailFastWriternewWriterWrapper(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) voidreleaseSavepoint(Savepoint savepoint) voidrollback()When not in a terminal fail-fast state, willclear the fail-fast stateupon a successful call tosuper.rollback().voidWhen not in a terminal fail-fast state, willclear the fail-fast stateupon a successful call tosuper.rollback(savepoint).voidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) voidsetClientInfo(Properties properties) voidsetHoldability(int holdability) voidsetNetworkTimeout(Executor executor, int milliseconds) voidsetReadOnly(boolean readOnly) setSavepoint(String name) voidvoidsetTransactionIsolation(int level) voidsetTypeMap(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, wrapWriterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValidMethods inherited from interface com.aoapps.sql.wrapper.ConnectionWrapper
getWrappedConnectionMethods inherited from interface com.aoapps.sql.failfast.FailFastConnection
getWrappedMethods inherited from interface com.aoapps.sql.wrapper.Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
FailFastConnectionImpl
-
FailFastConnectionImpl
-
-
Method Details
-
addFailFastCause
Description copied from interface:FailFastConnectionRegisters a cause for the current failure. Multiple causes are merged in the following order:TerminalSQLExceptiontake highest precedence, since these are non-recoverable.-
All other
Throwableare 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:
addFailFastCausein interfaceFailFastConnection- Parameters:
cause- The additional cause, ignored whennull
-
getFailFastCause
Description copied from interface:FailFastConnectionGets 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:
getFailFastCausein interfaceFailFastConnection- Returns:
- The cause or
nullwhen not in failure state (operating normally). - See Also:
-
getFailFastState
Description copied from interface:FailFastConnectionGets the current fail-fail state.- Specified by:
getFailFastStatein interfaceFailFastConnection- Returns:
- The state or
FailFastConnection.State.OKwhen not in failure state (operating normally). - See Also:
-
clearFailFast
Description copied from interface:FailFastConnectionClears the cause of the current fail-fast state. This will typically be invoked automatically during one of the following successful operations:- Specified by:
clearFailFastin interfaceFailFastConnection- Returns:
- The cause or
nullwhen 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:
newArrayWrapperin classConnectionWrapperImpl
-
newBlobWrapper
- Overrides:
newBlobWrapperin classConnectionWrapperImpl
-
newCallableStatementWrapper
- Overrides:
newCallableStatementWrapperin classConnectionWrapperImpl
-
newClobWrapper
- Overrides:
newClobWrapperin classConnectionWrapperImpl
-
newDatabaseMetaDataWrapper
- Overrides:
newDatabaseMetaDataWrapperin classConnectionWrapperImpl
-
newInputStreamWrapper
- Overrides:
newInputStreamWrapperin classConnectionWrapperImpl
-
newNClobWrapper
- Overrides:
newNClobWrapperin classConnectionWrapperImpl
-
newOutputStreamWrapper
- Overrides:
newOutputStreamWrapperin classConnectionWrapperImpl
-
newParameterMetaDataWrapper
- Overrides:
newParameterMetaDataWrapperin classConnectionWrapperImpl
-
newPreparedStatementWrapper
- Overrides:
newPreparedStatementWrapperin classConnectionWrapperImpl
-
newReaderWrapper
- Overrides:
newReaderWrapperin classConnectionWrapperImpl
-
newRefWrapper
- Overrides:
newRefWrapperin classConnectionWrapperImpl
-
newResultSetWrapper
protected FailFastResultSetImpl newResultSetWrapper(StatementWrapperImpl stmtWrapper, ResultSet results) - Overrides:
newResultSetWrapperin classConnectionWrapperImpl
-
newResultSetMetaDataWrapper
- Overrides:
newResultSetMetaDataWrapperin classConnectionWrapperImpl
-
newRowIdWrapper
- Overrides:
newRowIdWrapperin classConnectionWrapperImpl
-
newSQLDataWrapper
- Overrides:
newSQLDataWrapperin classConnectionWrapperImpl
-
newSQLInputWrapper
- Overrides:
newSQLInputWrapperin classConnectionWrapperImpl
-
newSQLOutputWrapper
- Overrides:
newSQLOutputWrapperin classConnectionWrapperImpl
-
newSQLXMLWrapper
- Overrides:
newSQLXMLWrapperin classConnectionWrapperImpl
-
newSavepointWrapper
- Overrides:
newSavepointWrapperin classConnectionWrapperImpl
-
newStatementWrapper
- Overrides:
newStatementWrapperin classConnectionWrapperImpl
-
newStructWrapper
- Overrides:
newStructWrapperin classConnectionWrapperImpl
-
newWriterWrapper
- Overrides:
newWriterWrapperin classConnectionWrapperImpl
-
createStatement
- Specified by:
createStatementin interfaceConnection- Specified by:
createStatementin interfaceConnectionWrapper- Overrides:
createStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Specified by:
prepareStatementin interfaceConnectionWrapper- Overrides:
prepareStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Specified by:
prepareCallin interfaceConnectionWrapper- Overrides:
prepareCallin classConnectionWrapperImpl- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQLin interfaceConnection- Specified by:
nativeSQLin interfaceConnectionWrapper- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Specified by:
setAutoCommitin interfaceConnectionWrapper- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Specified by:
getAutoCommitin interfaceConnectionWrapper- Throws:
SQLException
-
commit
- Specified by:
commitin interfaceConnection- Specified by:
commitin interfaceConnectionWrapper- Throws:
SQLException
-
rollback
Description copied from interface:FailFastConnectionWhen not in a terminal fail-fast state, willclear the fail-fast stateupon a successful call tosuper.rollback().- Specified by:
rollbackin interfaceConnection- Specified by:
rollbackin interfaceConnectionWrapper- Specified by:
rollbackin interfaceFailFastConnection- Throws:
TerminalSQLException- if already in a terminal fail-fast stateSQLException- if any other failure occurs during rollback
-
close
Description copied from interface:FailFastConnectionPuts the connection into a terminalClosedSQLExceptionfail-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:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Specified by:
closein interfaceConnectionWrapper- Specified by:
closein interfaceFailFastConnection- Overrides:
closein classConnectionWrapperImpl- Throws:
SQLException- See Also:
-
isClosed
- Specified by:
isClosedin interfaceConnection- Specified by:
isClosedin interfaceConnectionWrapper- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfaceConnection- Specified by:
getMetaDatain interfaceConnectionWrapper- Overrides:
getMetaDatain classConnectionWrapperImpl- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnlyin interfaceConnection- Specified by:
setReadOnlyin interfaceConnectionWrapper- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnlyin interfaceConnection- Specified by:
isReadOnlyin interfaceConnectionWrapper- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalogin interfaceConnection- Specified by:
setCatalogin interfaceConnectionWrapper- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalogin interfaceConnection- Specified by:
getCatalogin interfaceConnectionWrapper- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Specified by:
setTransactionIsolationin interfaceConnectionWrapper- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Specified by:
getTransactionIsolationin interfaceConnectionWrapper- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceConnection- Specified by:
getWarningsin interfaceConnectionWrapper- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Specified by:
clearWarningsin interfaceConnectionWrapper- Throws:
SQLException
-
createStatement
public FailFastStatementImpl createStatement(int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
createStatementin interfaceConnection- Specified by:
createStatementin interfaceConnectionWrapper- Overrides:
createStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Specified by:
prepareStatementin interfaceConnectionWrapper- Overrides:
prepareStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareCall
public FailFastCallableStatementImpl prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCallin interfaceConnection- Specified by:
prepareCallin interfaceConnectionWrapper- Overrides:
prepareCallin classConnectionWrapperImpl- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfaceConnection- Specified by:
getTypeMapin interfaceConnectionWrapper- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMapin interfaceConnection- Specified by:
setTypeMapin interfaceConnectionWrapper- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Specified by:
setHoldabilityin interfaceConnectionWrapper- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Specified by:
getHoldabilityin interfaceConnectionWrapper- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Specified by:
setSavepointin interfaceConnectionWrapper- Overrides:
setSavepointin classConnectionWrapperImpl- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Specified by:
setSavepointin interfaceConnectionWrapper- Overrides:
setSavepointin classConnectionWrapperImpl- Throws:
SQLException
-
rollback
Description copied from interface:FailFastConnectionWhen not in a terminal fail-fast state, willclear the fail-fast stateupon a successful call tosuper.rollback(savepoint).- Specified by:
rollbackin interfaceConnection- Specified by:
rollbackin interfaceConnectionWrapper- Specified by:
rollbackin interfaceFailFastConnection- Overrides:
rollbackin classConnectionWrapperImpl- Throws:
SQLException- if any other failure occurs during rollback
-
releaseSavepoint
- Specified by:
releaseSavepointin interfaceConnection- Specified by:
releaseSavepointin interfaceConnectionWrapper- Overrides:
releaseSavepointin classConnectionWrapperImpl- Throws:
SQLException
-
createStatement
public FailFastStatementImpl createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatementin interfaceConnection- Specified by:
createStatementin interfaceConnectionWrapper- Overrides:
createStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Specified by:
prepareStatementin interfaceConnectionWrapper- Overrides:
prepareStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareCall
public FailFastCallableStatementImpl prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Specified by:
prepareCallin interfaceConnectionWrapper- Overrides:
prepareCallin classConnectionWrapperImpl- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int autoGeneratedKeys) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Specified by:
prepareStatementin interfaceConnectionWrapper- Overrides:
prepareStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, int[] columnIndexes) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Specified by:
prepareStatementin interfaceConnectionWrapper- Overrides:
prepareStatementin classConnectionWrapperImpl- Throws:
SQLException
-
prepareStatement
public FailFastPreparedStatementImpl prepareStatement(String sql, String[] columnNames) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Specified by:
prepareStatementin interfaceConnectionWrapper- Overrides:
prepareStatementin classConnectionWrapperImpl- Throws:
SQLException
-
createClob
- Specified by:
createClobin interfaceConnection- Specified by:
createClobin interfaceConnectionWrapper- Overrides:
createClobin classConnectionWrapperImpl- Throws:
SQLException
-
createBlob
- Specified by:
createBlobin interfaceConnection- Specified by:
createBlobin interfaceConnectionWrapper- Overrides:
createBlobin classConnectionWrapperImpl- Throws:
SQLException
-
createNClob
- Specified by:
createNClobin interfaceConnection- Specified by:
createNClobin interfaceConnectionWrapper- Overrides:
createNClobin classConnectionWrapperImpl- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Specified by:
createSQLXMLin interfaceConnectionWrapper- Overrides:
createSQLXMLin classConnectionWrapperImpl- Throws:
SQLException
-
isValid
- Specified by:
isValidin interfaceConnection- Specified by:
isValidin interfaceConnectionWrapper- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Specified by:
setClientInfoin interfaceConnectionWrapper- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Specified by:
setClientInfoin interfaceConnectionWrapper- Throws:
SQLClientInfoException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Specified by:
getClientInfoin interfaceConnectionWrapper- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Specified by:
getClientInfoin interfaceConnectionWrapper- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOfin interfaceConnection- Specified by:
createArrayOfin interfaceConnectionWrapper- Overrides:
createArrayOfin classConnectionWrapperImpl- Throws:
SQLException
-
createStruct
- Specified by:
createStructin interfaceConnection- Specified by:
createStructin interfaceConnectionWrapper- Overrides:
createStructin classConnectionWrapperImpl- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Specified by:
getNetworkTimeoutin interfaceConnectionWrapper- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Specified by:
setNetworkTimeoutin interfaceConnectionWrapper- Throws:
SQLException
-
setSchema
- Specified by:
setSchemain interfaceConnection- Specified by:
setSchemain interfaceConnectionWrapper- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Specified by:
getSchemain interfaceConnectionWrapper- Throws:
SQLException
-
abort
Description copied from interface:FailFastConnectionPuts the connection into a terminalAbortedSQLExceptionfail-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:
abortin interfaceConnection- Specified by:
abortin interfaceConnectionWrapper- Specified by:
abortin interfaceFailFastConnection- Overrides:
abortin 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
-
