Module io.helidon.integrations.jdbc
Package io.helidon.integrations.jdbc
Class ConditionallyCloseableConnection
- java.lang.Object
-
- io.helidon.integrations.jdbc.DelegatingConnection
-
- io.helidon.integrations.jdbc.ConditionallyCloseableConnection
-
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper
public class ConditionallyCloseableConnection extends DelegatingConnection
ADelegatingConnectionwhoseclose()method performs a close only if theisCloseable()method returnstrue.Thread Safety
Instances of this class are not necessarily safe for concurrent use by multiple threads.
- See Also:
isCloseable(),setCloseable(boolean),close()
-
-
Field Summary
-
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
-
Constructor Summary
Constructors Constructor Description ConditionallyCloseableConnection(Connection delegate)Creates a newConditionallyCloseableConnectionand sets its closeable status totrue.ConditionallyCloseableConnection(Connection delegate, boolean closeable)Creates a newConditionallyCloseableConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Overrides theDelegatingConnection.close()method so that when it is invoked thisConditionallyCloseableConnectionis closed only if it is closeable.booleanisCloseable()voidsetCloseable(boolean closeable)Sets the closeable status of thisConditionallyCloseableConnection.-
Methods inherited from class io.helidon.integrations.jdbc.DelegatingConnection
abort, 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, isWrapperFor, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid, setTransactionIsolation, setTypeMap, unwrap
-
-
-
-
Constructor Detail
-
ConditionallyCloseableConnection
public ConditionallyCloseableConnection(Connection delegate)
Creates a newConditionallyCloseableConnectionand sets its closeable status totrue.- Parameters:
delegate- theConnectionto wrap; must not benull- Throws:
NullPointerException- ifdelegateisnull- See Also:
ConditionallyCloseableConnection(Connection, boolean),setCloseable(boolean)
-
ConditionallyCloseableConnection
public ConditionallyCloseableConnection(Connection delegate, boolean closeable)
Creates a newConditionallyCloseableConnection.- Parameters:
delegate- theConnectionto wrap; must not benullcloseable- the initial value for thisConditionallyCloseableConnection's closeable status- Throws:
NullPointerException- ifdelegateisnull- See Also:
setCloseable(boolean),DelegatingConnection(Connection)
-
-
Method Detail
-
close
public void close() throws SQLExceptionOverrides theDelegatingConnection.close()method so that when it is invoked thisConditionallyCloseableConnectionis closed only if it is closeable.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:
isCloseable()
-
isCloseable
public final boolean isCloseable() throws SQLExceptionReturnstrueif a call toclose()will actually close thisConditionallyCloseableConnection.This method returns
truewhensetCloseable(boolean)has been called with a value oftrueand theDelegatingConnection.isClosed()method returnsfalse.- Returns:
trueif a call toclose()will actually close thisConditionallyCloseableConnection;falsein all other cases- Throws:
SQLException- ifDelegatingConnection.isClosed()throws aSQLException- See Also:
setCloseable(boolean),close(),DelegatingConnection.isClosed()
-
setCloseable
public final void setCloseable(boolean closeable)
Sets the closeable status of thisConditionallyCloseableConnection.Note that calling this method with a value of
truedoes not necessarily mean that theisCloseable()method will subsequently returntrue, since theDelegatingConnection.isClosed()method may returntrue.- Parameters:
closeable- whether or not a call toclose()will actually close thisConditionallyCloseableConnection- See Also:
isCloseable(),close(),Connection.close(),DelegatingConnection.isClosed()
-
-