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 LogicalDatabaseMetaDataLogical database metadata object created on demand and then cached.(package private) ClientConnectionUnderlying physical connection for this logical connection.private ClientPooledConnectionFields inherited from interface 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 TypeMethodDescriptionvoidprotected final voidVerifies that there is an underlying physical connection for this logical connection.voidvoidclose()voidvoidcommit()createArrayOf(String typeName, Object[] elements) /////////////////////////////////////////////////////////////////createStatement(int resultSetType, int resultSetConcurrency) createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct(String typeName, Object[] attributes) protected voidfinalize()booleangetClientInfoforwards tophysicalConnection_.getClientInfo(String name) getClientInfoforwards tophysicalConnection_.intRetrieves aDatabaseMetaDataobject that contains metadata about the database to which thisConnectionobject represents a connection.int(package private) final DatabaseMetaDataReturns the real underlying database metadata object.Get the name of the current schema.intintReturns the client-side transaction id from am.Connection.intbooleanisClosed()booleanbooleanisValid(int timeout) Checks if the connection has not been closed and is still valid.booleanisWrapperFor(Class<?> interfaces) protected LogicalDatabaseMetaDataReturns a newly created logical database metadata object.(package private) final voidnotifyException(SQLException sqle) Notifies listeners about exceptions of session level severity or higher.voidprepareCall(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) voidreleaseSavepoint(Savepoint savepoint) voidrollback()voidvoidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) setClientInfoforwards tophysicalConnection_.voidsetClientInfo(Properties properties) setClientInfoforwards tophysicalConnection_.voidsetHoldability(int holdability) voidsetNetworkTimeout(Executor executor, int milliseconds) voidsetReadOnly(boolean readOnly) setSavepoint(String name) voidSet the default schema for the Connection.voidsetTransactionIsolation(int level) voidsetTypeMap(Map map) <T> TMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Field Details
-
physicalConnection_
ClientConnection physicalConnection_Underlying physical connection for this logical connection.Set to
nullwhen 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
closeWithoutRecyclingToPool
- Throws:
SqlException
-
isClosed
- Specified by:
isClosedin 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:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
commit
- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
getMetaData
Retrieves aDatabaseMetaDataobject that contains metadata about the database to which thisConnectionobject 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:
getMetaDatain 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:
setReadOnlyin interfaceConnection- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnlyin interfaceConnection- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalogin interfaceConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepointin 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:
createArrayOfin interfaceConnection- Throws:
SQLException
-
createBlob
- Specified by:
createBlobin interfaceConnection- Throws:
SQLException
-
createClob
- Specified by:
createClobin interfaceConnection- Throws:
SQLException
-
createNClob
- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Throws:
SQLException
-
createStruct
- Specified by:
createStructin interfaceConnection- Throws:
SQLException
-
getClientInfo
getClientInfoforwards tophysicalConnection_.getClientInfoalways returns an emptyPropertiesobject since Derby doesn't support ClientInfoProperties.- Specified by:
getClientInfoin interfaceConnection- Returns:
- an empty
Propertiesobject - Throws:
SQLException- if an error occurs
-
getClientInfo
getClientInfoforwards tophysicalConnection_. Always returns anull Stringsince Derby does not support ClientInfoProperties.- Specified by:
getClientInfoin 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:
isValidin 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:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
setClientInfo
setClientInfoforwards tophysicalConnection_.- Specified by:
setClientInfoin interfaceConnection- Parameters:
properties- aPropertiesobject with the properties to set- Throws:
SQLClientInfoException- if an error occurs
-
setClientInfo
setClientInfoforwards tophysicalConnection_.- Specified by:
setClientInfoin interfaceConnection- Parameters:
name- a property keyStringvalue- a property valueString- Throws:
SQLClientInfoException- if an error occurs
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
getSchema
Get the name of the current schema.- Specified by:
getSchemain interfaceConnection- Throws:
SQLException
-
setSchema
Set the default schema for the Connection.- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-