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 BrokeredConnectionControlprotected booleanprivate boolean(package private) intprivate intMaintain state as seen by this Connection handle, not the state of the underlying Connection it is attached to.private booleanFields inherited from interface Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescription////////////////////////////////////////////////////////////////////// -
Method Summary
Modifier and TypeMethodDescriptionvoidfinal voidAdd a SQLWarning to this Connection object.final voidfinal voidclose()final voidcommit()final ArraycreateArrayOf(String typeName, Object[] elements) final BlobConstructs an object that implements theBlobinterface.final ClobConstructs an object that implements theClobinterface.final NClobfinal SQLXMLfinal Statementfinal StatementcreateStatement(int resultSetType, int resultSetConcurrency) final StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) final StructcreateStruct(String typeName, Object[] attributes) final booleanfinal Stringfinal PropertiesgetClientInfoforwards to the real connection.final StringgetClientInfo(String name) getClientInfoforwards to the real connection.Obtain the name of the current schema.final intGet the holdability for statements created by this connection when holdability is not passed in.voidIsolation 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 DatabaseMetaDataintfinal intget the isolation level that is currently being used to prepare statements (used for network server)(package private) final EngineConnectionA little indirection for getting the real connection.Get the name of the current schema.final intfinal SQLWarningfinal booleanisClosed()booleanIs this a global transactionfinal booleanfinal booleanisValid(int timeout) Checks if the connection has not been closed and is still valid.final booleanisWrapperFor(Class<?> iface) Returns false unlessifaceis implemented.final Stringfinal BrokeredStatementnewBrokeredStatement(BrokeredStatementControl statementControl) newBrokeredStatement(BrokeredStatementControl statementControl, String sql) newBrokeredStatement(BrokeredStatementControl statementControl, String sql, Object generatedKeys) (package private) final SQLExceptionGenerate an exception reporting that there is no current connection.(package private) final voidnotifyException(SQLException sqle) final CallableStatementprepareCall(String sql) final CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency) final CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) final PreparedStatementprepareStatement(String sql) final PreparedStatementprepareStatement(String sql, int autoGeneratedKeys) final PreparedStatementprepareStatement(String sql, int[] columnIndexes) final PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency) final PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Prepare statement with explicit holdability.final PreparedStatementprepareStatement(String sql, String[] columnNames) final voidreleaseSavepoint(Savepoint savepoint) voidResets the connection before it is returned from a PooledConnection to a new application request (wrapped by a BrokeredConnection).final voidrollback()final voidfinal voidsetAutoCommit(boolean autoCommit) final voidsetCatalog(String catalog) final voidsetClientInfo(String name, String value) setClientInfoforwards to the real connection.final voidsetClientInfo(Properties properties) setClientInfoforwards to the real connection.final voidset the DrdaId for this connection.final voidsetHoldability(int holdability) voidsetNetworkTimeout(Executor executor, int milliseconds) final voidsetPrepareIsolation(int level) Set the internal isolation level to use for preparing statements.final voidsetReadOnly(boolean readOnly) final Savepointfinal SavepointsetSavepoint(String name) voidSet the default schema for the Connection.voidsetState(boolean complete) Set the state of the underlying connection according to the state of this connection's view of state.final voidsetTransactionIsolation(int level) final voidsetTypeMap(Map<String, Class<?>> map) (package private) final intstatementHoldabilityCheck(int resultSetHoldability) Check the result set holdability when creating a statement object.voidSync up the state of the underlying connection with the state of this new handle.toString()Get the string representation for this connection.final <T> TReturnsthisif this class implements the interface.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
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
-
commit
- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
isClosed
- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
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
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
createStatement
public final Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public final 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 final Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin 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
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException - Specified by:
prepareStatementin 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:
setDrdaIDin interfaceEngineConnection- Parameters:
drdaID- drdaID to be used for this connection
-
isInGlobalTransaction
public boolean isInGlobalTransaction()Description copied from interface:EngineConnectionIs this a global transaction- Specified by:
isInGlobalTransactionin 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:
setPrepareIsolationin 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:
getPrepareIsolationin interfaceEngineConnection- Returns:
- current prepare isolation level See EmbedConnection#getPrepareIsolation
- Throws:
SQLException
-
addWarning
Add a SQLWarning to this Connection object.- Specified by:
addWarningin interfaceEngineConnection- Parameters:
w- Warning to be added, will be chained to any existing warnings.- Throws:
SQLException
-
toString
-
prepareStatement
public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Prepare statement with explicit holdability.- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
getHoldability
Get the holdability for statements created by this connection when holdability is not passed in.- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOfin interfaceConnection- Throws:
SQLException
-
createBlob
Constructs an object that implements theBlobinterface. The object returned initially contains no data. ThesetBinaryStreamandsetBytesmethods of theBlobinterface may be used to add data to theBlob.- Specified by:
createBlobin interfaceConnection- Returns:
- An object that implements the
Blobinterface - Throws:
SQLException- if an object that implements theBlobinterface can not be constructed, this method is called on a closed connection or a database access error occurs.
-
createClob
Constructs an object that implements theClobinterface. The object returned initially contains no data. ThesetAsciiStream,setCharacterStreamandsetStringmethods of theClobinterface may be used to add data to theClob.- Specified by:
createClobin interfaceConnection- Returns:
- An object that implements the
Clobinterface - Throws:
SQLException- if an object that implements theClobinterface can not be constructed, this method is called on a closed connection or a database access error occurs.
-
createNClob
- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Throws:
SQLException
-
createStruct
- Specified by:
createStructin 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:
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.
-
setClientInfo
setClientInfoforwards to the real connection.- Specified by:
setClientInfoin interfaceConnection- Parameters:
name- the property keyStringvalue- the property valueString- Throws:
SQLClientInfoException- if the property is not supported or the real connection could not be obtained.
-
setClientInfo
setClientInfoforwards to the real connection. If the call togetRealConnectionfails the resultingSQLExceptionis wrapped in aSQLClientInfoExceptionto satisfy the specified signature.- Specified by:
setClientInfoin interfaceConnection- Parameters:
properties- aPropertiesobject with the properties to set.- Throws:
SQLClientInfoException- if the properties are not supported or the real connection could not be obtained.
-
getClientInfo
getClientInfoforwards to the real connection.- Specified by:
getClientInfoin interfaceConnection- Parameters:
name- aStringthat is the property key to get.- Returns:
- a
Stringthat is returned from the real connection. - Throws:
SQLException- if a database access error occurs.
-
getClientInfo
getClientInfoforwards to the real connection.- Specified by:
getClientInfoin interfaceConnection- Returns:
- a
Propertiesobject from the real connection. - Throws:
SQLException- if a database access error occurs.
-
isWrapperFor
Returns false unlessifaceis implemented.- Specified by:
isWrapperForin 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
Returnsthisif this class implements the interface.- Specified by:
unwrapin 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:
getLOBMappingin 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:
getCurrentSchemaNamein interfaceEngineConnection- Returns:
- the current schema name
- Throws:
SQLException
-
resetFromPool
Description copied from interface:EngineConnectionResets 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:
resetFromPoolin interfaceEngineConnection- Throws:
SQLException- See Also:
-
getSchema
Get the name of the current schema.- Specified by:
getSchemain interfaceConnection- Specified by:
getSchemain interfaceEngineConnection- Throws:
SQLException
-
setSchema
Set the default schema for the Connection.- Specified by:
setSchemain interfaceConnection- Specified by:
setSchemain interfaceEngineConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Specified by:
abortin interfaceEngineConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Specified by:
getNetworkTimeoutin interfaceEngineConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Specified by:
setNetworkTimeoutin interfaceEngineConnection- Throws:
SQLException
-