Class LogicalConnection
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
- Direct Known Subclasses:
CachingLogicalConnection
All methods of the Connection
interface are forwarded to the
underlying physical connection, except for close()
and
isClosed()
. When a physical connection is wrapped, it is non-null,
when the logical connection is closed, the wrapped physical connection is
always set to null
.
Both the finalizer and the close
-methods will always set the
physical connection to null
. After the physical connection has been
nulled out, only the PooledConnection
instance will maintain a
handle to the physical connection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LogicalDatabaseMetaData
Logical database metadata object created on demand and then cached.(package private) ClientConnection
Underlying physical connection for this logical connection.private ClientPooledConnection
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
ConstructorsConstructorDescriptionLogicalConnection
(ClientConnection physicalConnection, ClientPooledConnection pooledConnection) -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected final void
Verifies that there is an underlying physical connection for this logical connection.void
void
close()
void
void
commit()
createArrayOf
(String typeName, Object[] elements) createStatement
(int resultSetType, int resultSetConcurrency) createStatement
(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct
(String typeName, Object[] attributes) protected void
finalize()
boolean
getClientInfo
forwards tophysicalConnection_
.getClientInfo
(String name) getClientInfo
forwards tophysicalConnection_
.int
Retrieves aDatabaseMetaData
object that contains metadata about the database to which thisConnection
object represents a connection.int
(package private) final DatabaseMetaData
Returns the real underlying database metadata object.Get the name of the current schema.int
int
Returns the client-side transaction id from am.Connection.int
boolean
isClosed()
boolean
boolean
isValid
(int timeout) Checks if the connection has not been closed and is still valid.boolean
isWrapperFor
(Class<?> interfaces) protected LogicalDatabaseMetaData
Returns a newly created logical database metadata object.(package private) final void
notifyException
(SQLException sqle) Notifies listeners about exceptions of session level severity or higher.void
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) setClientInfo
forwards tophysicalConnection_
.void
setClientInfo
(Properties properties) setClientInfo
forwards tophysicalConnection_
.void
setHoldability
(int holdability) void
setNetworkTimeout
(Executor executor, int milliseconds) void
setReadOnly
(boolean readOnly) setSavepoint
(String name) void
Set the default schema for the Connection.void
setTransactionIsolation
(int level) void
setTypeMap
(Map map) <T> T
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Field Details
-
physicalConnection_
ClientConnection physicalConnection_Underlying physical connection for this logical connection.Set to
null
when this logical connection is closed. -
pooledConnection_
-
logicalDatabaseMetaData
Logical database metadata object created on demand and then cached. The lifetime of the metadata object is the same as this logical connection, in the sense that it will raise exceptions on method invocations after the logical connection has been closed.
-
-
Constructor Details
-
LogicalConnection
public LogicalConnection(ClientConnection physicalConnection, ClientPooledConnection pooledConnection) throws SqlException - Throws:
SqlException
-
-
Method Details
-
finalize
-
nullPhysicalConnection
public void nullPhysicalConnection() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
-
closeWithoutRecyclingToPool
- Throws:
SqlException
-
isClosed
- Specified by:
isClosed
in interfaceConnection
- Throws:
SQLException
-
checkForNullPhysicalConnection
Verifies that there is an underlying physical connection for this logical connection.If the physical connection has been nulled out it means that this logical connection has been closed.
- Throws:
SQLException
- if this logical connection has been closed
-
notifyException
Notifies listeners about exceptions of session level severity or higher.The exception, even if the severity is sufficiently high, is ignored if the underlying physical connection has been nulled out. Otherwise a
connectionErrorOccurred
-event is sent to all the registered listeners.- Parameters:
sqle
- the cause of the notification
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQL
in interfaceConnection
- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommit
in interfaceConnection
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Throws:
SQLException
-
commit
- Specified by:
commit
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
getWarnings
- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
-
getMetaData
Retrieves aDatabaseMetaData
object that contains metadata about the database to which thisConnection
object represents a connection.The database metadata object is logical in the sense that it has the same lifetime as the logical connection. If the logical connection is closed, the underlying physical connection will not be accessed to obtain metadata, even if it is still open. Also, the reference to the logical connection instead of the underlying physical connection will be returned by
LogicalDatabaseMetaData.getConnection()
.- Specified by:
getMetaData
in interfaceConnection
- Returns:
- A database metadata object.
- Throws:
SQLException
- if an error occurs
-
newLogicalDatabaseMetaData
Returns a newly created logical database metadata object.Subclasses should override this method to return an instance of the correct implementation class of the logical metadata object.
- Returns:
- A logical database metadata object.
- Throws:
SQLException
-
getRealMetaDataObject
Returns the real underlying database metadata object.- Returns:
- The metadata object from the underlying physical connection.
- Throws:
SQLException
- if the logical connection has been closed
-
setReadOnly
- Specified by:
setReadOnly
in interfaceConnection
- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnly
in interfaceConnection
- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalog
in interfaceConnection
- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalog
in interfaceConnection
- Throws:
SQLException
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMap
in interfaceConnection
- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMap
in interfaceConnection
- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldability
in interfaceConnection
- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldability
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepoint
in interfaceConnection
- Throws:
SQLException
-
getTransactionID
public int getTransactionID()Returns the client-side transaction id from am.Connection.NOTE: This method was added for testing purposes. Avoid use in production code if possible.
-
getServerVersion
public int getServerVersion() -
createArrayOf
- Specified by:
createArrayOf
in interfaceConnection
- Throws:
SQLException
-
createBlob
- Specified by:
createBlob
in interfaceConnection
- Throws:
SQLException
-
createClob
- Specified by:
createClob
in interfaceConnection
- Throws:
SQLException
-
createNClob
- Specified by:
createNClob
in interfaceConnection
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Throws:
SQLException
-
getClientInfo
getClientInfo
forwards tophysicalConnection_
.getClientInfo
always returns an emptyProperties
object since Derby doesn't support ClientInfoProperties.- Specified by:
getClientInfo
in interfaceConnection
- Returns:
- an empty
Properties
object - Throws:
SQLException
- if an error occurs
-
getClientInfo
getClientInfo
forwards tophysicalConnection_
. Always returns anull String
since Derby does not support ClientInfoProperties.- Specified by:
getClientInfo
in interfaceConnection
- Parameters:
name
- a property key to getString
- Returns:
- a property value
String
- Throws:
SQLException
- if an error occurs
-
isValid
Checks if the connection has not been closed and is still valid. The validity is checked by running a simple query against the database.- Specified by:
isValid
in interfaceConnection
- Parameters:
timeout
- The time in seconds to wait for the database operation used to validate the connection to complete. If the timeout period expires before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database operation.- Returns:
- true if the connection is valid, false otherwise
- Throws:
SQLException
- if the call on the physical connection throws an exception.
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
setClientInfo
setClientInfo
forwards tophysicalConnection_
.- Specified by:
setClientInfo
in interfaceConnection
- Parameters:
properties
- aProperties
object with the properties to set- Throws:
SQLClientInfoException
- if an error occurs
-
setClientInfo
setClientInfo
forwards tophysicalConnection_
.- Specified by:
setClientInfo
in interfaceConnection
- Parameters:
name
- a property keyString
value
- a property valueString
- Throws:
SQLClientInfoException
- if an error occurs
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
getSchema
Get the name of the current schema.- Specified by:
getSchema
in interfaceConnection
- Throws:
SQLException
-
setSchema
Set the default schema for the Connection.- Specified by:
setSchema
in interfaceConnection
- Throws:
SQLException
-
abort
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-