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
A
DelegatingConnection whose close() method
performs a close only if the isCloseable() method returns
true.
Thread Safety
Instances of this class are not necessarily safe for concurrent use by multiple threads.
- 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) Creates a newConditionallyCloseableConnectionand sets its closeable status totrue.ConditionallyCloseableConnection(Connection delegate, boolean closeable) Creates a newConditionallyCloseableConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Overrides theDelegatingConnection.close()method so that when it is invoked thisConditionallyCloseableConnectionis closed only if it is closeable.final booleanfinal 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 Details
-
ConditionallyCloseableConnection
Creates a newConditionallyCloseableConnectionand sets its closeable status totrue.- Parameters:
delegate- theConnectionto wrap; must not benull- Throws:
NullPointerException- ifdelegateisnull- See Also:
-
ConditionallyCloseableConnection
Creates a newConditionallyCloseableConnection.- Parameters:
delegate- theConnectionto wrap; must not benullcloseable- the initial value for thisConditionallyCloseableConnection's closeable status- 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.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
Returnstrueif 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
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:
-