Class ConditionallyCloseableConnection
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper
DelegatingConnection whose close() method may or may not close it depending on
other partial state.
Thread Safety
Instances of this class are not necessarily safe for concurrent use by multiple threads because their Connection delegates may not be. JDBC 4.3 does not require thread safety from any JDBC construct.
- See Also:
-
Field Summary
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescriptionConditionallyCloseableConnection(Connection delegate) Deprecated.This constructor continues to exist for backwards compatibility only and its use is strongly discouraged.ConditionallyCloseableConnection(Connection delegate, boolean closeable) Deprecated.This constructor continues to exist for backwards compatibility only and its use is strongly discouraged.ConditionallyCloseableConnection(Connection delegate, boolean closeable, boolean strictClosedChecking) Creates a newConditionallyCloseableConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidvoidclose()Overrides theDelegatingConnection.close()method so that when it is invoked thisConditionallyCloseableConnectionis closed only if it is closeable.voidcommit()createArrayOf(String typeName, Object[] elements) createStatement(int resultSetType, int resultSetConcurrency) createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct(String typeName, Object[] attributes) voidprotected final voidInvokes theisClosed()method, and, if it returnstrue, throws a newSQLExceptionindicating that because the connection is closed the operation cannot proceed.booleangetClientInfo(String name) intintintbooleanbooleanisClosed()Returnstrueif and only if thisConditionallyCloseableConnectioneither is, or is to be considered to be, closed, such that operations which must throw aSQLExceptionwhen invoked on a closed connection will do so.booleanReturnstrueif and only if thisConditionallyCloseableConnectionis behaving as if theclose()method has been invoked while thisConditionallyCloseableConnectionwas not closeable.booleanbooleanisValid(int timeout) booleanisWrapperFor(Class<?> iface) protected voidonClose()Called by theclose()method to perform work after an actual close operation has completed.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()voidvoidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) voidsetClientInfo(Properties properties) voidsetCloseable(boolean closeable) Sets the closeable status of thisConditionallyCloseableConnectionand, if the suppliedcloseableagrument istrue, sets the close pending status tofalse.voidsetHoldability(int holdability) voidsetNetworkTimeout(Executor executor, int milliseconds) voidsetReadOnly(boolean readOnly) setSavepoint(String name) voidvoidsetShardingKey(ShardingKey shardingKey) voidsetShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) booleansetShardingKeyIfValid(ShardingKey shardingKey, int timeout) booleansetShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) voidsetTransactionIsolation(int level) voidsetTypeMap(Map<String, Class<?>> map) <T> TMethods inherited from class io.helidon.integrations.jdbc.DelegatingConnection
delegate
-
Constructor Details
-
ConditionallyCloseableConnection
Deprecated.This constructor continues to exist for backwards compatibility only and its use is strongly discouraged. Please use theConditionallyCloseableConnection(Connection, boolean, boolean)constructor instead and consider supplyingtruefor itsstrictClosedCheckingparameter. In the future, this constructor may change, without prior notice, to cause newConditionallyCloseableConnectioninstances created by it to behave as if they were created by invocations of theConditionallyCloseableConnection(Connection, boolean, boolean)constructor instead, withtruesupplied for itsstrictClosedCheckingparameter.Creates a newConditionallyCloseableConnectionand sets its closeable status totrue.- Parameters:
delegate- theConnectionto wrap; must not benull- Throws:
NullPointerException- ifdelegateisnull- See Also:
-
ConditionallyCloseableConnection
@Deprecated(since="3.0.3") public ConditionallyCloseableConnection(Connection delegate, boolean closeable) Deprecated.This constructor continues to exist for backwards compatibility only and its use is strongly discouraged. Please use theConditionallyCloseableConnection(Connection, boolean, boolean)constructor instead and consider supplyingtruefor itsstrictClosedCheckingparameter. In the future, this constructor may change, without prior notice, to cause newConditionallyCloseableConnectioninstances created by it to behave as if they were created by invocations of theConditionallyCloseableConnection(Connection, boolean, boolean)constructor instead, withtruesupplied for itsstrictClosedCheckingparameter.Creates a newConditionallyCloseableConnection.- Parameters:
delegate- theConnectionto wrap; must not benullcloseable- the initial value for thisConditionallyCloseableConnection's closeable status- Throws:
NullPointerException- ifdelegateisnull- See Also:
-
ConditionallyCloseableConnection
public ConditionallyCloseableConnection(Connection delegate, boolean closeable, boolean strictClosedChecking) Creates a newConditionallyCloseableConnection.- Parameters:
delegate- theConnectionto wrap; must not benullcloseable- the initial value for thisConditionallyCloseableConnection's closeable statusstrictClosedChecking- iftrue, then thisConditionallyCloseableConnection'sisClosed()method will be invoked before every operation that cannot take place on a closed connection, and, if it returnstrue, the operation in question will fail with aSQLException; it is strongly recommended to supplytrueas the argument for this parameter (falseis permitted for backwards compatibility reasons only)- Throws:
NullPointerException- ifdelegateisnull- See Also:
-
-
Method Details
-
close
Overrides theDelegatingConnection.close()method so that when it is invoked thisConditionallyCloseableConnectionis closed only if it is closeable.Subclasses that override this method must not directly or indirectly call
failWhenClosed()or undefined behavior may result.If
strictClosedCheckingwastrueat construction time (strongly recommended), then the following pre- and post-conditions apply:If
isCloseable()returnstrueat the point of an invocation of this method, then after this method completes, successfully or not,isClosePending()will returnfalse.If
isCloseable()returnsfalseat the point of an invocation of this method, then after this method completes, successfully or not,isClosePending()will returntrue.Overrides should normally call
super.close()as part of their implementation.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classDelegatingConnection- Throws:
SQLException- if an error occurs- See Also:
-
onClose
Called by theclose()method to perform work after an actual close operation has completed.During an invocation of this method by the
close()method:- The
isClosed()method will returntrue. - The
isCloseable()method will returnfalse. - The
isClosePending()method will returnfalse.
The default implementation of this method does nothing.
Invoking this method directly may result in undefined behavior, depending on how it is overridden.
Overrides of this method must not call
close()or undefined behavior, such as an infinite loop, may result.Overrides of this method must be idempotent.
- Throws:
SQLException- if a database error occurs- See Also:
- The
-
isCloseable
Returnstrueif a call toclose()will actually close thisConditionallyCloseableConnection.This method returns
truewhensetCloseable(boolean)has been called with a value oftrueand theisClosed()method returnsfalse.Subclasses that override this method must not directly or indirectly call
failWhenClosed()or undefined behavior may result.- Returns:
trueif a call toclose()will actually close thisConditionallyCloseableConnection;falsein all other cases- Throws:
SQLException- ifisClosed()throws aSQLException- See Also:
-
setCloseable
public void setCloseable(boolean closeable) Sets the closeable status of thisConditionallyCloseableConnectionand, if the suppliedcloseableagrument istrue, sets the close pending status tofalse.Subclasses that override this method must not directly or indirectly call
failWhenClosed()or undefined behavior may result.Note that calling this method with a value of
truedoes not necessarily mean that theisCloseable()method will subsequently returntrue, since theisClosed()method may returntrue.Design Note
This method does not throw
SQLExceptiononly because of an oversight in the design of the original version of this class. Callers should consider catchingUncheckedSQLExceptionwhere appropriate instead. The default implementation of this method does not throw any exceptions of any kind.- Parameters:
closeable- whether or not a call toclose()will actually close thisConditionallyCloseableConnection- See Also:
-
isClosePending
public boolean isClosePending()Returnstrueif and only if thisConditionallyCloseableConnectionis behaving as if theclose()method has been invoked while thisConditionallyCloseableConnectionwas not closeable.Subclasses that override this method must not directly or indirectly call
failWhenClosed()or undefined behavior may result.Subclasses that override this method must not directly or indirectly mutate the state of this
ConditionallyCloseableConnectionor undefined behavior may result.- Returns:
trueif and only if a close operation is pending- See Also:
-
createStatement
- Specified by:
createStatementin interfaceConnection- Overrides:
createStatementin classDelegatingConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQLin interfaceConnection- Overrides:
nativeSQLin classDelegatingConnection- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Overrides:
setAutoCommitin classDelegatingConnection- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Overrides:
getAutoCommitin classDelegatingConnection- Throws:
SQLException
-
commit
- Specified by:
commitin interfaceConnection- Overrides:
commitin classDelegatingConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Overrides:
rollbackin classDelegatingConnection- Throws:
SQLException
-
isClosed
Returnstrueif and only if thisConditionallyCloseableConnectioneither is, or is to be considered to be, closed, such that operations which must throw aSQLExceptionwhen invoked on a closed connection will do so.If
truewas supplied for thestrictClosedCheckingparameter at construction time (strongly recommended), the default implementation of this method returns a value as if produced by the following implementation:this.isClosePending()|| super.isClosed().If
falsewas supplied for thestrictClosedCheckingparameter at construction time (not recommended), the default implementation of this method returns a value as if produced by the following implementation:super.isClosed().Subclasses that override this method must not directly or indirectly call
failWhenClosed()or undefined behavior may result.- Specified by:
isClosedin interfaceConnection- Overrides:
isClosedin classDelegatingConnection- Returns:
trueif and only if thisConditionallyCloseableConnectioneither is, or is to be considered to be, closed- Throws:
SQLException- if a database access error occurs- See Also:
-
getMetaData
- Specified by:
getMetaDatain interfaceConnection- Overrides:
getMetaDatain classDelegatingConnection- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnlyin interfaceConnection- Overrides:
setReadOnlyin classDelegatingConnection- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnlyin interfaceConnection- Overrides:
isReadOnlyin classDelegatingConnection- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalogin interfaceConnection- Overrides:
setCatalogin classDelegatingConnection- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalogin interfaceConnection- Overrides:
getCatalogin classDelegatingConnection- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Overrides:
setTransactionIsolationin classDelegatingConnection- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Overrides:
getTransactionIsolationin classDelegatingConnection- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceConnection- Overrides:
getWarningsin classDelegatingConnection- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Overrides:
clearWarningsin classDelegatingConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Overrides:
createStatementin classDelegatingConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfaceConnection- Overrides:
getTypeMapin classDelegatingConnection- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMapin interfaceConnection- Overrides:
setTypeMapin classDelegatingConnection- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Overrides:
setHoldabilityin classDelegatingConnection- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Overrides:
getHoldabilityin classDelegatingConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Overrides:
setSavepointin classDelegatingConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Overrides:
setSavepointin classDelegatingConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Overrides:
rollbackin classDelegatingConnection- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepointin interfaceConnection- Overrides:
releaseSavepointin classDelegatingConnection- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatementin interfaceConnection- Overrides:
createStatementin classDelegatingConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Throws:
SQLException
-
createClob
- Specified by:
createClobin interfaceConnection- Overrides:
createClobin classDelegatingConnection- Throws:
SQLException
-
createBlob
- Specified by:
createBlobin interfaceConnection- Overrides:
createBlobin classDelegatingConnection- Throws:
SQLException
-
createNClob
- Specified by:
createNClobin interfaceConnection- Overrides:
createNClobin classDelegatingConnection- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Overrides:
createSQLXMLin classDelegatingConnection- Throws:
SQLException
-
isValid
- Specified by:
isValidin interfaceConnection- Overrides:
isValidin classDelegatingConnection- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Overrides:
setClientInfoin classDelegatingConnection- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Overrides:
setClientInfoin classDelegatingConnection- Throws:
SQLClientInfoException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Overrides:
getClientInfoin classDelegatingConnection- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Overrides:
getClientInfoin classDelegatingConnection- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOfin interfaceConnection- Overrides:
createArrayOfin classDelegatingConnection- Throws:
SQLException
-
createStruct
- Specified by:
createStructin interfaceConnection- Overrides:
createStructin classDelegatingConnection- Throws:
SQLException
-
setSchema
- Specified by:
setSchemain interfaceConnection- Overrides:
setSchemain classDelegatingConnection- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Overrides:
getSchemain classDelegatingConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Overrides:
abortin classDelegatingConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Overrides:
setNetworkTimeoutin classDelegatingConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Overrides:
getNetworkTimeoutin classDelegatingConnection- Throws:
SQLException
-
beginRequest
- Specified by:
beginRequestin interfaceConnection- Overrides:
beginRequestin classDelegatingConnection- Throws:
SQLException
-
endRequest
- Specified by:
endRequestin interfaceConnection- Overrides:
endRequestin classDelegatingConnection- Throws:
SQLException
-
setShardingKeyIfValid
public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) throws SQLException - Specified by:
setShardingKeyIfValidin interfaceConnection- Overrides:
setShardingKeyIfValidin classDelegatingConnection- Throws:
SQLException
-
setShardingKeyIfValid
- Specified by:
setShardingKeyIfValidin interfaceConnection- Overrides:
setShardingKeyIfValidin classDelegatingConnection- Throws:
SQLException
-
setShardingKey
public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException - Specified by:
setShardingKeyin interfaceConnection- Overrides:
setShardingKeyin classDelegatingConnection- Throws:
SQLException
-
setShardingKey
- Specified by:
setShardingKeyin interfaceConnection- Overrides:
setShardingKeyin classDelegatingConnection- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Overrides:
unwrapin classDelegatingConnection- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Overrides:
isWrapperForin classDelegatingConnection- Throws:
SQLException
-
failWhenClosed
Invokes theisClosed()method, and, if it returnstrue, throws a newSQLExceptionindicating that because the connection is closed the operation cannot proceed.If this
ConditionallyCloseableConnectionwas created with strict closed checking enabled (strongly recommended), then this method will be called where appropriate. Otherwise this method is not called internally by default implementations of the methods in theConditionallyCloseableConnectionclass. Subclasses may, and often will, call this method directly for any reason.- Throws:
SQLNonTransientConnectionException- when an invocation of theisClosed()method returnstrue; its SQLState will begin with08SQLException- ifisClosed()throws aSQLException- See Also:
-