Package org.apache.derby.iapi.jdbc
Class BrokeredConnection
java.lang.Object
org.apache.derby.iapi.jdbc.BrokeredConnection
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
,EngineConnection
- Direct Known Subclasses:
BrokeredConnection42
This is a rudimentary connection that delegates
EVERYTHING to Connection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
(package private) final BrokeredConnectionControl
protected boolean
private boolean
(package private) int
private int
Maintain state as seen by this Connection handle, not the state of the underlying Connection it is attached to.private boolean
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
final void
Add a SQLWarning to this Connection object.final void
final void
close()
final void
commit()
final Array
createArrayOf
(String typeName, Object[] elements) final Blob
Constructs an object that implements theBlob
interface.final Clob
Constructs an object that implements theClob
interface.final NClob
final SQLXML
final Statement
final Statement
createStatement
(int resultSetType, int resultSetConcurrency) final Statement
createStatement
(int resultSetType, int resultSetConcurrency, int resultSetHoldability) final Struct
createStruct
(String typeName, Object[] attributes) final boolean
final String
final Properties
getClientInfo
forwards to the real connection.final String
getClientInfo
(String name) getClientInfo
forwards to the real connection.Obtain the name of the current schema.final int
Get the holdability for statements created by this connection when holdability is not passed in.void
Isolation level state in BrokeredConnection can get out of sync if the isolation is set using SQL rather than JDBC.getLOBMapping
(int key) Get the LOB reference corresponding to the locator.final DatabaseMetaData
int
final int
get the isolation level that is currently being used to prepare statements (used for network server)(package private) final EngineConnection
A little indirection for getting the real connection.Get the name of the current schema.final int
final SQLWarning
final boolean
isClosed()
boolean
Is this a global transactionfinal boolean
final boolean
isValid
(int timeout) Checks if the connection has not been closed and is still valid.final boolean
isWrapperFor
(Class<?> iface) Returns false unlessiface
is implemented.final String
final BrokeredStatement
newBrokeredStatement
(BrokeredStatementControl statementControl) newBrokeredStatement
(BrokeredStatementControl statementControl, String sql) newBrokeredStatement
(BrokeredStatementControl statementControl, String sql, Object generatedKeys) (package private) final SQLException
Generate an exception reporting that there is no current connection.(package private) final void
notifyException
(SQLException sqle) final CallableStatement
prepareCall
(String sql) final CallableStatement
prepareCall
(String sql, int resultSetType, int resultSetConcurrency) final CallableStatement
prepareCall
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) final PreparedStatement
prepareStatement
(String sql) final PreparedStatement
prepareStatement
(String sql, int autoGeneratedKeys) final PreparedStatement
prepareStatement
(String sql, int[] columnIndexes) final PreparedStatement
prepareStatement
(String sql, int resultSetType, int resultSetConcurrency) final PreparedStatement
prepareStatement
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Prepare statement with explicit holdability.final PreparedStatement
prepareStatement
(String sql, String[] columnNames) final void
releaseSavepoint
(Savepoint savepoint) void
Resets the connection before it is returned from a PooledConnection to a new application request (wrapped by a BrokeredConnection).final void
rollback()
final void
final void
setAutoCommit
(boolean autoCommit) final void
setCatalog
(String catalog) final void
setClientInfo
(String name, String value) setClientInfo
forwards to the real connection.final void
setClientInfo
(Properties properties) setClientInfo
forwards to the real connection.final void
set the DrdaId for this connection.final void
setHoldability
(int holdability) void
setNetworkTimeout
(Executor executor, int milliseconds) final void
setPrepareIsolation
(int level) Set the internal isolation level to use for preparing statements.final void
setReadOnly
(boolean readOnly) final Savepoint
final Savepoint
setSavepoint
(String name) void
Set the default schema for the Connection.void
setState
(boolean complete) Set the state of the underlying connection according to the state of this connection's view of state.final void
setTransactionIsolation
(int level) final void
setTypeMap
(Map<String, Class<?>> map) (package private) final int
statementHoldabilityCheck
(int resultSetHoldability) Check the result set holdability when creating a statement object.void
Sync up the state of the underlying connection with the state of this new handle.toString()
Get the string representation for this connection.final <T> T
Returnsthis
if this class implements the interface.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Field Details
-
stateHoldability
int stateHoldability -
control
-
isClosed
protected boolean isClosed -
connString
-
stateIsolationLevel
private int stateIsolationLevelMaintain state as seen by this Connection handle, not the state of the underlying Connection it is attached to. -
stateReadOnly
private boolean stateReadOnly -
stateAutoCommit
private boolean stateAutoCommit
-
-
Constructor Details
-
BrokeredConnection
- Throws:
SQLException
-
-
Method Details
-
setAutoCommit
- Specified by:
setAutoCommit
in interfaceConnection
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Throws:
SQLException
-
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
-
commit
- Specified by:
commit
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
-
isClosed
- Specified by:
isClosed
in interfaceConnection
- Throws:
SQLException
-
getWarnings
- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfaceConnection
- Throws:
SQLException
-
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
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
createStatement
public final Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public final 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 final Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCall
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
-
setHoldability
- Specified by:
setHoldability
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
noCurrentConnection
Generate an exception reporting that there is no current connection.- Returns:
- a no-current-connection exception
-
getRealConnection
A little indirection for getting the real connection.- Returns:
- the current connection
- Throws:
SQLException
-
notifyException
-
syncState
Sync up the state of the underlying connection with the state of this new handle.- Throws:
SQLException
-
getIsolationUptoDate
Isolation level state in BrokeredConnection can get out of sync if the isolation is set using SQL rather than JDBC. In order to ensure correct state level information, this method is called at the start and end of a global transaction.- Throws:
SQLException
-
setState
Set the state of the underlying connection according to the state of this connection's view of state.- Parameters:
complete
- If true set the complete state of the underlying Connection, otherwise set only the Connection related state (ie. the non-transaction specific state).- Throws:
SQLException
-
newBrokeredStatement
public final BrokeredStatement newBrokeredStatement(BrokeredStatementControl statementControl) throws SQLException - Throws:
SQLException
-
newBrokeredStatement
public BrokeredPreparedStatement newBrokeredStatement(BrokeredStatementControl statementControl, String sql, Object generatedKeys) throws SQLException - Throws:
SQLException
-
newBrokeredStatement
public BrokeredCallableStatement newBrokeredStatement(BrokeredStatementControl statementControl, String sql) throws SQLException - Throws:
SQLException
-
setDrdaID
set the DrdaId for this connection. The drdaID prints with the statement text to the errror log- Specified by:
setDrdaID
in interfaceEngineConnection
- Parameters:
drdaID
- drdaID to be used for this connection
-
isInGlobalTransaction
public boolean isInGlobalTransaction()Description copied from interface:EngineConnection
Is this a global transaction- Specified by:
isInGlobalTransaction
in interfaceEngineConnection
- Returns:
- true if this is a global XA transaction
- See Also:
-
setPrepareIsolation
Set the internal isolation level to use for preparing statements. Subsequent prepares will use this isoalation level- Specified by:
setPrepareIsolation
in interfaceEngineConnection
- Parameters:
level
- - internal isolation level- Throws:
SQLException
- See EmbedConnection#setPrepareIsolation
-
getPrepareIsolation
get the isolation level that is currently being used to prepare statements (used for network server)- Specified by:
getPrepareIsolation
in interfaceEngineConnection
- Returns:
- current prepare isolation level See EmbedConnection#getPrepareIsolation
- Throws:
SQLException
-
addWarning
Add a SQLWarning to this Connection object.- Specified by:
addWarning
in interfaceEngineConnection
- Parameters:
w
- Warning to be added, will be chained to any existing warnings.- Throws:
SQLException
-
toString
Get the string representation for this connection. Return the class name/hash code and various debug information. -
prepareStatement
public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Prepare statement with explicit holdability.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
getHoldability
Get the holdability for statements created by this connection when holdability is not passed in.- Specified by:
getHoldability
in interfaceConnection
- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOf
in interfaceConnection
- Throws:
SQLException
-
createBlob
Constructs an object that implements theBlob
interface. The object returned initially contains no data. ThesetBinaryStream
andsetBytes
methods of theBlob
interface may be used to add data to theBlob
.- Specified by:
createBlob
in interfaceConnection
- Returns:
- An object that implements the
Blob
interface - Throws:
SQLException
- if an object that implements theBlob
interface can not be constructed, this method is called on a closed connection or a database access error occurs.
-
createClob
Constructs an object that implements theClob
interface. The object returned initially contains no data. ThesetAsciiStream
,setCharacterStream
andsetString
methods of theClob
interface may be used to add data to theClob
.- Specified by:
createClob
in interfaceConnection
- Returns:
- An object that implements the
Clob
interface - Throws:
SQLException
- if an object that implements theClob
interface can not be constructed, this method is called on a closed connection or a database access error occurs.
-
createNClob
- Specified by:
createNClob
in interfaceConnection
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Throws:
SQLException
-
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.
-
setClientInfo
setClientInfo
forwards to the real connection.- Specified by:
setClientInfo
in interfaceConnection
- Parameters:
name
- the property keyString
value
- the property valueString
- Throws:
SQLClientInfoException
- if the property is not supported or the real connection could not be obtained.
-
setClientInfo
setClientInfo
forwards to the real connection. If the call togetRealConnection
fails the resultingSQLException
is wrapped in aSQLClientInfoException
to satisfy the specified signature.- Specified by:
setClientInfo
in interfaceConnection
- Parameters:
properties
- aProperties
object with the properties to set.- Throws:
SQLClientInfoException
- if the properties are not supported or the real connection could not be obtained.
-
getClientInfo
getClientInfo
forwards to the real connection.- Specified by:
getClientInfo
in interfaceConnection
- Parameters:
name
- aString
that is the property key to get.- Returns:
- a
String
that is returned from the real connection. - Throws:
SQLException
- if a database access error occurs.
-
getClientInfo
getClientInfo
forwards to the real connection.- Specified by:
getClientInfo
in interfaceConnection
- Returns:
- a
Properties
object from the real connection. - Throws:
SQLException
- if a database access error occurs.
-
isWrapperFor
Returns false unlessiface
is implemented.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
SQLException
- if an error occurs while determining whether this is a wrapper for an object with the given interface.
-
unwrap
Returnsthis
if this class implements the interface.- Specified by:
unwrap
in interfaceWrapper
- Parameters:
iface
- a Class defining an interface- Returns:
- an object that implements the interface
- Throws:
SQLException
- if no object if found that implements the interface
-
statementHoldabilityCheck
Check the result set holdability when creating a statement object. Section 16.1.3.1 of JDBC 4.0 (proposed final draft) says the driver may change the holdabilty and add a SQLWarning to the Connection object. This work-in-progress implementation throws an exception to match the old behaviour just as part of incremental development.- Throws:
SQLException
-
getLOBMapping
Get the LOB reference corresponding to the locator.- Specified by:
getLOBMapping
in interfaceEngineConnection
- Parameters:
key
- the integer that represents the LOB locator value.- Returns:
- the LOB Object corresponding to this locator.
- Throws:
SQLException
-
getCurrentSchemaName
Obtain the name of the current schema. Not part of the java.sql.Connection interface, but is accessible through the EngineConnection interface, so that the NetworkServer can get at the current schema for piggy-backing- Specified by:
getCurrentSchemaName
in interfaceEngineConnection
- Returns:
- the current schema name
- Throws:
SQLException
-
resetFromPool
Description copied from interface:EngineConnection
Resets the connection before it is returned from a PooledConnection to a new application request (wrapped by a BrokeredConnection).Note that resetting the transaction isolation level is not performed as part of this method. Temporary tables, IDENTITY_VAL_LOCAL and current schema are reset.
- Specified by:
resetFromPool
in interfaceEngineConnection
- Throws:
SQLException
- See Also:
-
getSchema
Get the name of the current schema.- Specified by:
getSchema
in interfaceConnection
- Specified by:
getSchema
in interfaceEngineConnection
- Throws:
SQLException
-
setSchema
Set the default schema for the Connection.- Specified by:
setSchema
in interfaceConnection
- Specified by:
setSchema
in interfaceEngineConnection
- Throws:
SQLException
-
abort
- Specified by:
abort
in interfaceConnection
- Specified by:
abort
in interfaceEngineConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Specified by:
getNetworkTimeout
in interfaceEngineConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Specified by:
setNetworkTimeout
in interfaceEngineConnection
- Throws:
SQLException
-