public class LogicalConnection
extends java.lang.Object
implements java.sql.Connection
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.
Modifier and Type | Field and Description |
---|---|
private LogicalDatabaseMetaData |
logicalDatabaseMetaData
Logical database metadata object created on demand and then cached.
|
(package private) ClientConnection |
physicalConnection_
Underlying physical connection for this logical connection.
|
private ClientPooledConnection |
pooledConnection_ |
Constructor and Description |
---|
LogicalConnection(ClientConnection physicalConnection,
ClientPooledConnection pooledConnection) |
Modifier and Type | Method and Description |
---|---|
void |
abort(java.util.concurrent.Executor executor) |
protected void |
checkForNullPhysicalConnection()
Verifies that there is an underlying physical connection for this
logical connection.
|
void |
clearWarnings() |
void |
close() |
void |
closeWithoutRecyclingToPool() |
void |
commit() |
java.sql.Array |
createArrayOf(java.lang.String typeName,
java.lang.Object[] elements) |
java.sql.Blob |
createBlob() |
java.sql.Clob |
createClob() |
java.sql.NClob |
createNClob() |
java.sql.SQLXML |
createSQLXML() |
java.sql.Statement |
createStatement() |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency) |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
java.sql.Struct |
createStruct(java.lang.String typeName,
java.lang.Object[] attributes) |
protected void |
finalize() |
boolean |
getAutoCommit() |
java.lang.String |
getCatalog() |
java.util.Properties |
getClientInfo()
getClientInfo forwards to
physicalConnection_ . |
java.lang.String |
getClientInfo(java.lang.String name)
getClientInfo forwards to
physicalConnection_ . |
int |
getHoldability() |
java.sql.DatabaseMetaData |
getMetaData()
Retrieves a
DatabaseMetaData object that contains metadata about
the database to which this Connection object represents a
connection. |
int |
getNetworkTimeout() |
(package private) java.sql.DatabaseMetaData |
getRealMetaDataObject()
Returns the real underlying database metadata object.
|
java.lang.String |
getSchema()
Get the name of the current schema.
|
int |
getServerVersion() |
int |
getTransactionID()
Returns the client-side transaction id from am.Connection.
|
int |
getTransactionIsolation() |
java.util.Map<java.lang.String,java.lang.Class<?>> |
getTypeMap() |
java.sql.SQLWarning |
getWarnings() |
boolean |
isClosed() |
boolean |
isReadOnly() |
boolean |
isValid(int timeout)
Checks if the connection has not been closed and is still valid.
|
boolean |
isWrapperFor(java.lang.Class<?> interfaces) |
java.lang.String |
nativeSQL(java.lang.String sql) |
protected LogicalDatabaseMetaData |
newLogicalDatabaseMetaData()
Returns a newly created logical database metadata object.
|
(package private) void |
notifyException(java.sql.SQLException sqle)
Notifies listeners about exceptions of session level severity or higher.
|
void |
nullPhysicalConnection() |
java.sql.CallableStatement |
prepareCall(java.lang.String sql) |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int[] columnIndexes) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.lang.String[] columnNames) |
void |
releaseSavepoint(java.sql.Savepoint savepoint) |
void |
rollback() |
void |
rollback(java.sql.Savepoint savepoint) |
void |
setAutoCommit(boolean autoCommit) |
void |
setCatalog(java.lang.String catalog) |
void |
setClientInfo(java.util.Properties properties)
setClientInfo forwards to
physicalConnection_ . |
void |
setClientInfo(java.lang.String name,
java.lang.String value)
setClientInfo forwards to
physicalConnection_ . |
void |
setHoldability(int holdability) |
void |
setNetworkTimeout(java.util.concurrent.Executor executor,
int milliseconds) |
void |
setReadOnly(boolean readOnly) |
java.sql.Savepoint |
setSavepoint() |
java.sql.Savepoint |
setSavepoint(java.lang.String name) |
void |
setSchema(java.lang.String schemaName)
Set the default schema for the Connection.
|
void |
setTransactionIsolation(int level) |
void |
setTypeMap(java.util.Map map) |
<T> T |
unwrap(java.lang.Class<T> interfaces) |
ClientConnection physicalConnection_
Set to null
when this logical connection is closed.
private ClientPooledConnection pooledConnection_
private LogicalDatabaseMetaData logicalDatabaseMetaData
public LogicalConnection(ClientConnection physicalConnection, ClientPooledConnection pooledConnection) throws SqlException
SqlException
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void nullPhysicalConnection()
public void close() throws java.sql.SQLException
close
in interface java.lang.AutoCloseable
close
in interface java.sql.Connection
java.sql.SQLException
public void closeWithoutRecyclingToPool() throws SqlException
SqlException
public boolean isClosed() throws java.sql.SQLException
isClosed
in interface java.sql.Connection
java.sql.SQLException
protected final void checkForNullPhysicalConnection() throws java.sql.SQLException
If the physical connection has been nulled out it means that this logical connection has been closed.
java.sql.SQLException
- if this logical connection has been closedfinal void notifyException(java.sql.SQLException sqle)
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.
sqle
- the cause of the notificationpublic java.sql.Statement createStatement() throws java.sql.SQLException
createStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException
prepareCall
in interface java.sql.Connection
java.sql.SQLException
public java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLException
nativeSQL
in interface java.sql.Connection
java.sql.SQLException
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
setAutoCommit
in interface java.sql.Connection
java.sql.SQLException
public boolean getAutoCommit() throws java.sql.SQLException
getAutoCommit
in interface java.sql.Connection
java.sql.SQLException
public void commit() throws java.sql.SQLException
commit
in interface java.sql.Connection
java.sql.SQLException
public void rollback() throws java.sql.SQLException
rollback
in interface java.sql.Connection
java.sql.SQLException
public void setTransactionIsolation(int level) throws java.sql.SQLException
setTransactionIsolation
in interface java.sql.Connection
java.sql.SQLException
public int getTransactionIsolation() throws java.sql.SQLException
getTransactionIsolation
in interface java.sql.Connection
java.sql.SQLException
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
getWarnings
in interface java.sql.Connection
java.sql.SQLException
public void clearWarnings() throws java.sql.SQLException
clearWarnings
in interface java.sql.Connection
java.sql.SQLException
public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException
DatabaseMetaData
object that contains metadata about
the database to which this Connection
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()
.
getMetaData
in interface java.sql.Connection
java.sql.SQLException
- if an error occursprotected LogicalDatabaseMetaData newLogicalDatabaseMetaData() throws java.sql.SQLException
Subclasses should override this method to return an instance of the correct implementation class of the logical metadata object.
java.sql.SQLException
final java.sql.DatabaseMetaData getRealMetaDataObject() throws java.sql.SQLException
java.sql.SQLException
- if the logical connection has been closedpublic void setReadOnly(boolean readOnly) throws java.sql.SQLException
setReadOnly
in interface java.sql.Connection
java.sql.SQLException
public boolean isReadOnly() throws java.sql.SQLException
isReadOnly
in interface java.sql.Connection
java.sql.SQLException
public void setCatalog(java.lang.String catalog) throws java.sql.SQLException
setCatalog
in interface java.sql.Connection
java.sql.SQLException
public java.lang.String getCatalog() throws java.sql.SQLException
getCatalog
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
createStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
prepareCall
in interface java.sql.Connection
java.sql.SQLException
public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap() throws java.sql.SQLException
getTypeMap
in interface java.sql.Connection
java.sql.SQLException
public void setTypeMap(java.util.Map map) throws java.sql.SQLException
setTypeMap
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
createStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
prepareCall
in interface java.sql.Connection
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
java.sql.SQLException
public void setHoldability(int holdability) throws java.sql.SQLException
setHoldability
in interface java.sql.Connection
java.sql.SQLException
public int getHoldability() throws java.sql.SQLException
getHoldability
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Savepoint setSavepoint() throws java.sql.SQLException
setSavepoint
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Savepoint setSavepoint(java.lang.String name) throws java.sql.SQLException
setSavepoint
in interface java.sql.Connection
java.sql.SQLException
public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLException
rollback
in interface java.sql.Connection
java.sql.SQLException
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException
releaseSavepoint
in interface java.sql.Connection
java.sql.SQLException
public int getTransactionID()
NOTE: This method was added for testing purposes. Avoid use in production code if possible.
public int getServerVersion()
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements) throws java.sql.SQLException
createArrayOf
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Blob createBlob() throws java.sql.SQLException
createBlob
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Clob createClob() throws java.sql.SQLException
createClob
in interface java.sql.Connection
java.sql.SQLException
public java.sql.NClob createNClob() throws java.sql.SQLException
createNClob
in interface java.sql.Connection
java.sql.SQLException
public java.sql.SQLXML createSQLXML() throws java.sql.SQLException
createSQLXML
in interface java.sql.Connection
java.sql.SQLException
public java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes) throws java.sql.SQLException
createStruct
in interface java.sql.Connection
java.sql.SQLException
public java.util.Properties getClientInfo() throws java.sql.SQLException
getClientInfo
forwards to
physicalConnection_
.
getClientInfo
always returns an empty
Properties
object since Derby doesn't support
ClientInfoProperties.getClientInfo
in interface java.sql.Connection
Properties
objectjava.sql.SQLException
- if an error occurspublic java.lang.String getClientInfo(java.lang.String name) throws java.sql.SQLException
getClientInfo
forwards to
physicalConnection_
. Always returns a null
String
since Derby does not support
ClientInfoProperties.getClientInfo
in interface java.sql.Connection
name
- a property key to get String
String
java.sql.SQLException
- if an error occurspublic boolean isValid(int timeout) throws java.sql.SQLException
isValid
in interface java.sql.Connection
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.java.sql.SQLException
- if the call on the physical connection throws an
exception.public boolean isWrapperFor(java.lang.Class<?> interfaces) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
java.sql.SQLException
public void setClientInfo(java.util.Properties properties) throws java.sql.SQLClientInfoException
setClientInfo
forwards to
physicalConnection_
.setClientInfo
in interface java.sql.Connection
properties
- a Properties
object with the
properties to setjava.sql.SQLClientInfoException
- if an error occurspublic void setClientInfo(java.lang.String name, java.lang.String value) throws java.sql.SQLClientInfoException
setClientInfo
forwards to
physicalConnection_
.setClientInfo
in interface java.sql.Connection
name
- a property key String
value
- a property value String
java.sql.SQLClientInfoException
- if an error occurspublic <T> T unwrap(java.lang.Class<T> interfaces) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
java.sql.SQLException
public java.lang.String getSchema() throws java.sql.SQLException
getSchema
in interface java.sql.Connection
java.sql.SQLException
public void setSchema(java.lang.String schemaName) throws java.sql.SQLException
setSchema
in interface java.sql.Connection
java.sql.SQLException
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException
abort
in interface java.sql.Connection
java.sql.SQLException
public int getNetworkTimeout() throws java.sql.SQLException
getNetworkTimeout
in interface java.sql.Connection
java.sql.SQLException
public void setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds) throws java.sql.SQLException
setNetworkTimeout
in interface java.sql.Connection
java.sql.SQLException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.