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
ADelegatingConnection
whoseclose()
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 newConditionallyCloseableConnection
and 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 void
close()
Overrides theDelegatingConnection.close()
method so that when it is invoked thisConditionallyCloseableConnection
is closed only if it is closeable.boolean
isCloseable()
void
setCloseable(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 newConditionallyCloseableConnection
and sets its closeable status totrue
.- Parameters:
delegate
- theConnection
to wrap; must not benull
- Throws:
NullPointerException
- ifdelegate
isnull
- See Also:
ConditionallyCloseableConnection(Connection, boolean)
,setCloseable(boolean)
-
ConditionallyCloseableConnection
public ConditionallyCloseableConnection(Connection delegate, boolean closeable)
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:
setCloseable(boolean)
,DelegatingConnection(Connection)
-
-
Method Detail
-
close
public void close() throws SQLException
Overrides theDelegatingConnection.close()
method so that when it is invoked thisConditionallyCloseableConnection
is closed only if it is closeable.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:
isCloseable()
-
isCloseable
public final boolean isCloseable() throws SQLException
Returnstrue
if a call toclose()
will actually close thisConditionallyCloseableConnection
.This method returns
true
whensetCloseable(boolean)
has been called with a value oftrue
and theDelegatingConnection.isClosed()
method returnsfalse
.- Returns:
true
if a call toclose()
will actually close thisConditionallyCloseableConnection
;false
in 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
true
does 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()
-
-