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.
-
Field Summary
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
ConstructorDescriptionConditionallyCloseableConnection
(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 TypeMethodDescriptionvoid
void
void
void
close()
Overrides theDelegatingConnection.close()
method so that when it is invoked thisConditionallyCloseableConnection
is closed only if it is closeable.void
commit()
createArrayOf
(String typeName, Object[] elements) createStatement
(int resultSetType, int resultSetConcurrency) createStatement
(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct
(String typeName, Object[] attributes) void
protected final void
Invokes theisClosed()
method, and, if it returnstrue
, throws a newSQLException
indicating that because the connection is closed the operation cannot proceed.boolean
getClientInfo
(String name) int
int
int
boolean
boolean
isClosed()
Returnstrue
if and only if thisConditionallyCloseableConnection
either is, or is to be considered to be, closed, such that operations which must throw aSQLException
when invoked on a closed connection will do so.boolean
Returnstrue
if and only if thisConditionallyCloseableConnection
is behaving as if theclose()
method has been invoked while thisConditionallyCloseableConnection
was not closeable.boolean
boolean
isValid
(int timeout) boolean
isWrapperFor
(Class<?> iface) protected void
onClose()
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) void
releaseSavepoint
(Savepoint savepoint) void
rollback()
void
void
setAutoCommit
(boolean autoCommit) void
setCatalog
(String catalog) void
setClientInfo
(String name, String value) void
setClientInfo
(Properties properties) void
setCloseable
(boolean closeable) Sets the closeable status of thisConditionallyCloseableConnection
and, if the suppliedcloseable
agrument istrue
, sets the close pending status tofalse
.void
setHoldability
(int holdability) void
setNetworkTimeout
(Executor executor, int milliseconds) void
setReadOnly
(boolean readOnly) setSavepoint
(String name) void
void
setShardingKey
(ShardingKey shardingKey) void
setShardingKey
(ShardingKey shardingKey, ShardingKey superShardingKey) boolean
setShardingKeyIfValid
(ShardingKey shardingKey, int timeout) boolean
setShardingKeyIfValid
(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) void
setTransactionIsolation
(int level) void
setTypeMap
(Map<String, Class<?>> map) <T> T
Methods 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 supplyingtrue
for itsstrictClosedChecking
parameter. In the future, this constructor may change, without prior notice, to cause newConditionallyCloseableConnection
instances created by it to behave as if they were created by invocations of theConditionallyCloseableConnection(Connection, boolean, boolean)
constructor instead, withtrue
supplied for itsstrictClosedChecking
parameter.Creates a newConditionallyCloseableConnection
and sets its closeable status totrue
.- Parameters:
delegate
- theConnection
to wrap; must not benull
- Throws:
NullPointerException
- ifdelegate
isnull
- 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 supplyingtrue
for itsstrictClosedChecking
parameter. In the future, this constructor may change, without prior notice, to cause newConditionallyCloseableConnection
instances created by it to behave as if they were created by invocations of theConditionallyCloseableConnection(Connection, boolean, boolean)
constructor instead, withtrue
supplied for itsstrictClosedChecking
parameter.Creates a newConditionallyCloseableConnection
.- Parameters:
delegate
- theConnection
to wrap; must not benull
closeable
- the initial value for thisConditionallyCloseableConnection
's closeable status- Throws:
NullPointerException
- ifdelegate
isnull
- See Also:
-
ConditionallyCloseableConnection
public ConditionallyCloseableConnection(Connection delegate, boolean closeable, boolean strictClosedChecking) Creates a newConditionallyCloseableConnection
.- Parameters:
delegate
- theConnection
to wrap; must not benull
closeable
- 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 supplytrue
as the argument for this parameter (false
is permitted for backwards compatibility reasons only)- Throws:
NullPointerException
- ifdelegate
isnull
- See Also:
-
-
Method Details
-
close
Overrides theDelegatingConnection.close()
method so that when it is invoked thisConditionallyCloseableConnection
is closed only if it is closeable.Subclasses that override this method must not directly or indirectly call
failWhenClosed()
or undefined behavior may result.If
strictClosedChecking
wastrue
at construction time (strongly recommended), then the following pre- and post-conditions apply:If
isCloseable()
returnstrue
at the point of an invocation of this method, then after this method completes, successfully or not,isClosePending()
will returnfalse
.If
isCloseable()
returnsfalse
at 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Overrides:
close
in 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
Returnstrue
if a call toclose()
will actually close thisConditionallyCloseableConnection
.This method returns
true
whensetCloseable(boolean)
has been called with a value oftrue
and theisClosed()
method returnsfalse
.Subclasses that override this method must not directly or indirectly call
failWhenClosed()
or undefined behavior may result.- Returns:
true
if a call toclose()
will actually close thisConditionallyCloseableConnection
;false
in all other cases- Throws:
SQLException
- ifisClosed()
throws aSQLException
- See Also:
-
setCloseable
public void setCloseable(boolean closeable) Sets the closeable status of thisConditionallyCloseableConnection
and, if the suppliedcloseable
agrument 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
true
does not necessarily mean that theisCloseable()
method will subsequently returntrue
, since theisClosed()
method may returntrue
.Design Note
This method does not throw
SQLException
only because of an oversight in the design of the original version of this class. Callers should consider catchingUncheckedSQLException
where 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()Returnstrue
if and only if thisConditionallyCloseableConnection
is behaving as if theclose()
method has been invoked while thisConditionallyCloseableConnection
was 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
ConditionallyCloseableConnection
or undefined behavior may result.- Returns:
true
if and only if a close operation is pending- See Also:
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Overrides:
createStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCall
in interfaceConnection
- Overrides:
prepareCall
in classDelegatingConnection
- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQL
in interfaceConnection
- Overrides:
nativeSQL
in classDelegatingConnection
- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommit
in interfaceConnection
- Overrides:
setAutoCommit
in classDelegatingConnection
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Overrides:
getAutoCommit
in classDelegatingConnection
- Throws:
SQLException
-
commit
- Specified by:
commit
in interfaceConnection
- Overrides:
commit
in classDelegatingConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Overrides:
rollback
in classDelegatingConnection
- Throws:
SQLException
-
isClosed
Returnstrue
if and only if thisConditionallyCloseableConnection
either is, or is to be considered to be, closed, such that operations which must throw aSQLException
when invoked on a closed connection will do so.If
true
was supplied for thestrictClosedChecking
parameter 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
false
was supplied for thestrictClosedChecking
parameter 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:
isClosed
in interfaceConnection
- Overrides:
isClosed
in classDelegatingConnection
- Returns:
true
if and only if thisConditionallyCloseableConnection
either is, or is to be considered to be, closed- Throws:
SQLException
- if a database access error occurs- See Also:
-
getMetaData
- Specified by:
getMetaData
in interfaceConnection
- Overrides:
getMetaData
in classDelegatingConnection
- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnly
in interfaceConnection
- Overrides:
setReadOnly
in classDelegatingConnection
- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnly
in interfaceConnection
- Overrides:
isReadOnly
in classDelegatingConnection
- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalog
in interfaceConnection
- Overrides:
setCatalog
in classDelegatingConnection
- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalog
in interfaceConnection
- Overrides:
getCatalog
in classDelegatingConnection
- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Overrides:
setTransactionIsolation
in classDelegatingConnection
- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolation
in interfaceConnection
- Overrides:
getTransactionIsolation
in classDelegatingConnection
- Throws:
SQLException
-
getWarnings
- Specified by:
getWarnings
in interfaceConnection
- Overrides:
getWarnings
in classDelegatingConnection
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceConnection
- Overrides:
clearWarnings
in classDelegatingConnection
- Throws:
SQLException
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Overrides:
createStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Overrides:
prepareCall
in classDelegatingConnection
- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMap
in interfaceConnection
- Overrides:
getTypeMap
in classDelegatingConnection
- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMap
in interfaceConnection
- Overrides:
setTypeMap
in classDelegatingConnection
- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldability
in interfaceConnection
- Overrides:
setHoldability
in classDelegatingConnection
- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldability
in interfaceConnection
- Overrides:
getHoldability
in classDelegatingConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Overrides:
setSavepoint
in classDelegatingConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Overrides:
setSavepoint
in classDelegatingConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Overrides:
rollback
in classDelegatingConnection
- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepoint
in interfaceConnection
- Overrides:
releaseSavepoint
in classDelegatingConnection
- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Overrides:
createStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Overrides:
prepareCall
in classDelegatingConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection
- Throws:
SQLException
-
createClob
- Specified by:
createClob
in interfaceConnection
- Overrides:
createClob
in classDelegatingConnection
- Throws:
SQLException
-
createBlob
- Specified by:
createBlob
in interfaceConnection
- Overrides:
createBlob
in classDelegatingConnection
- Throws:
SQLException
-
createNClob
- Specified by:
createNClob
in interfaceConnection
- Overrides:
createNClob
in classDelegatingConnection
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Overrides:
createSQLXML
in classDelegatingConnection
- Throws:
SQLException
-
isValid
- Specified by:
isValid
in interfaceConnection
- Overrides:
isValid
in classDelegatingConnection
- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Overrides:
setClientInfo
in classDelegatingConnection
- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Overrides:
setClientInfo
in classDelegatingConnection
- Throws:
SQLClientInfoException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Overrides:
getClientInfo
in classDelegatingConnection
- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Overrides:
getClientInfo
in classDelegatingConnection
- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOf
in interfaceConnection
- Overrides:
createArrayOf
in classDelegatingConnection
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Overrides:
createStruct
in classDelegatingConnection
- Throws:
SQLException
-
setSchema
- Specified by:
setSchema
in interfaceConnection
- Overrides:
setSchema
in classDelegatingConnection
- Throws:
SQLException
-
getSchema
- Specified by:
getSchema
in interfaceConnection
- Overrides:
getSchema
in classDelegatingConnection
- Throws:
SQLException
-
abort
- Specified by:
abort
in interfaceConnection
- Overrides:
abort
in classDelegatingConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Overrides:
setNetworkTimeout
in classDelegatingConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Overrides:
getNetworkTimeout
in classDelegatingConnection
- Throws:
SQLException
-
beginRequest
- Specified by:
beginRequest
in interfaceConnection
- Overrides:
beginRequest
in classDelegatingConnection
- Throws:
SQLException
-
endRequest
- Specified by:
endRequest
in interfaceConnection
- Overrides:
endRequest
in classDelegatingConnection
- Throws:
SQLException
-
setShardingKeyIfValid
public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) throws SQLException - Specified by:
setShardingKeyIfValid
in interfaceConnection
- Overrides:
setShardingKeyIfValid
in classDelegatingConnection
- Throws:
SQLException
-
setShardingKeyIfValid
- Specified by:
setShardingKeyIfValid
in interfaceConnection
- Overrides:
setShardingKeyIfValid
in classDelegatingConnection
- Throws:
SQLException
-
setShardingKey
public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException - Specified by:
setShardingKey
in interfaceConnection
- Overrides:
setShardingKey
in classDelegatingConnection
- Throws:
SQLException
-
setShardingKey
- Specified by:
setShardingKey
in interfaceConnection
- Overrides:
setShardingKey
in classDelegatingConnection
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Overrides:
unwrap
in classDelegatingConnection
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Overrides:
isWrapperFor
in classDelegatingConnection
- Throws:
SQLException
-
failWhenClosed
Invokes theisClosed()
method, and, if it returnstrue
, throws a newSQLException
indicating that because the connection is closed the operation cannot proceed.If this
ConditionallyCloseableConnection
was 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 theConditionallyCloseableConnection
class. 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 with08
SQLException
- ifisClosed()
throws aSQLException
- See Also:
-