|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.jdbc.EmbedConnection
Local implementation of Connection for a JDBC driver in the same process as the database.
There is always a single root (parent) connection. The initial JDBC connection is the root connection. A call to getCurrentConnection() or with the URL jdbc:default:connection yields a nested connection that shares the same root connection as the parent. A nested connection is implemented using this class. The nested connection copies the state of the parent connection and shares some of the same objects (e.g. ContextManager) that are shared across all nesting levels. The proxy also maintains its own state that is distinct from its parent connection (e.g. autocommit or warnings).
SYNCHRONIZATION: Just about all JDBC actions are synchronized across all connections stemming from the same root connection. The synchronization is upon the a synchronized object return by the rootConnection.
TransactionResourceImpl
Field Summary | |
private boolean |
active
|
private java.sql.Connection |
applicationConnection
The Connection object the application is using when accessing the database through this connection. |
protected boolean |
autoCommit
|
protected int |
connectionHoldAbility
|
protected java.sql.DatabaseMetaData |
dbMetadata
|
private static StandardException |
exceptionClose
|
Driver169 |
factory
Factory for JDBC objects to be created. |
(package private) boolean |
needCommit
|
private int |
resultSetId
An increasing counter to assign to a ResultSet on its creation. |
protected EmbedConnection |
rootConnection
|
private java.sql.SQLWarning |
topWarning
|
protected TransactionResourceImpl |
tr
|
Fields inherited from interface java.sql.Connection |
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE |
Constructor Summary | |
EmbedConnection(Driver169 driver,
java.lang.String url,
java.util.Properties info)
|
|
EmbedConnection(EmbedConnection inputConnection)
Create a new connection based off of the connection passed in. |
Method Summary | |
void |
addWarning(java.sql.SQLWarning newWarning)
Add a warning to the current list of warnings, to follow this note from Connection.getWarnings. |
private boolean |
bootDatabase(java.util.Properties info)
Return false iff the monitor cannot handle a service of the type indicated by the protocol within the name. |
private void |
checkUserCredentials(java.lang.String dbname,
java.util.Properties userInfo)
|
void |
clearWarnings()
After this call, getWarnings returns null until a new warning is reported for this Connection. |
void |
close()
In some cases, it is desirable to immediately release a Connection's database and JDBC resources instead of waiting for them to be automatically released; the close method provides this immediate release. |
private void |
close(java.lang.Exception e)
|
void |
commit()
Commit makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection. |
protected void |
commitIfAutoCommit()
If in autocommit, then commit. |
protected void |
commitIfNeeded()
if a commit is needed, perform it. |
private boolean |
createBoot(java.util.Properties p)
Examine the attributes set provided and determine if this is a create boot. |
private Database |
createDatabase(java.lang.String dbname,
java.util.Properties info)
Create a new database. |
java.sql.Statement |
createStatement()
SQL statements without parameters are normally executed using Statement objects. |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
JDBC 2.0 Same as createStatement() above, but allows the default result set type and result set concurrency type to be overridden. |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
JDBC 3.0 Same as createStatement() above, but allows the default result set type, result set concurrency type and result set holdability type to be overridden. |
private java.util.Properties |
filterProperties(java.util.Properties inputSet)
|
protected void |
finalize()
|
java.sql.Connection |
getApplicationConnection()
|
boolean |
getAutoCommit()
Get the current auto-commit state. |
java.lang.String |
getCatalog()
Return the Connection's current catalog name. |
protected java.lang.Object |
getConnectionSynchronization()
|
ContextManager |
getContextManager()
Return the context manager for this connection. |
protected Database |
getDatabase()
|
java.lang.String |
getDBName()
Return the dbname for this connection. |
int |
getEngineType()
Gets the EngineType of the connected database. |
int |
getHoldability()
JDBC 3.0 Retrieves the current holdability of ResultSet objects created using this Connection object. |
LanguageConnectionContext |
getLanguageConnection()
|
Driver169 |
getLocalDriver()
|
java.sql.DatabaseMetaData |
getMetaData()
A Connection's database is able to provide information describing its tables, its supported SQL grammar, its stored procedures, the capabilities of this connection, etc. |
int |
getPrepareIsolation()
Return prepare isolation |
(package private) int |
getResultSetOrderId()
Return a unique order number for a result set. |
protected TransactionResourceImpl |
getTR()
|
int |
getTransactionIsolation()
Get this Connection's current transaction isolation mode. |
java.sql.SQLWarning |
getWarnings()
The first warning reported by calls on this Connection is returned. |
java.sql.SQLException |
handleException(java.lang.Throwable thrownException)
|
(package private) java.sql.SQLException |
handleException(java.lang.Throwable thrownException,
boolean rollbackOnAutoCommit)
Handle any type of Exception. |
boolean |
isClosed()
Tests to see if a Connection is closed. |
boolean |
isReadOnly()
Tests to see if the connection is in read-only mode. |
java.lang.String |
nativeSQL(java.lang.String sql)
A driver may convert the JDBC sql grammar into its system's native SQL grammar prior to sending it; nativeSQL returns the native form of the statement that the driver would have sent. |
protected void |
needCommit()
if auto commit is on, remember that we need to commit the current statement. |
protected java.sql.SQLException |
newSQLException(java.lang.String messageId)
|
protected java.sql.SQLException |
newSQLException(java.lang.String messageId,
java.lang.Object arg1)
|
protected java.sql.SQLException |
newSQLException(java.lang.String messageId,
java.lang.Object arg1,
java.lang.Object arg2)
|
java.sql.CallableStatement |
prepareCall(java.lang.String sql)
A SQL stored procedure call statement is handled by creating a CallableStatement for it. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
JDBC 2.0 Same as prepareCall() above, but allows the default result set type and result set concurrency type to be overridden. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
JDBC 3.0 Same as prepareCall() above, but allows the default result set type, result set concurrency type and result set holdability to be overridden. |
(package private) java.sql.PreparedStatement |
prepareMetaDataStatement(java.lang.String sql)
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql)
A SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
Creates a default PreparedStatement object that has the capability to retieve auto-generated keys. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int[] columnIndexes)
Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
JDBC 2.0 Same as prepareStatement() above, but allows the default result set type and result set concurrency type to be overridden. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
JDBC 3.0 Same as prepareStatement() above, but allows the default result set type, result set concurrency type and result set holdability to be overridden. |
private java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability,
int autoGeneratedKeys,
int[] columnIndexes,
java.lang.String[] columnNames)
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.lang.String[] columnNames)
Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. |
private EmbedConnectionContext |
pushConnectionContext(ContextManager cm)
|
protected void |
restoreContextStack()
|
void |
rollback()
Rollback drops all changes made since the previous commit/rollback and releases any database locks currently held by the Connection. |
void |
setApplicationConnection(java.sql.Connection applicationConnection)
|
void |
setAutoCommit(boolean autoCommit)
If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. |
void |
setCatalog(java.lang.String catalog)
A sub-space of this Connection's database may be selected by setting a catalog name. |
void |
setDrdaID(java.lang.String drdaID)
|
void |
setHoldability(int holdability)
JDBC 3.0 Changes the holdability of ResultSet objects created using this Connection object to the given holdability. |
void |
setInactive()
Close the connection when processing errors, or when closing a nested connection. |
void |
setPrepareIsolation(int level)
Set the transaction isolation level that will be used for the next prepare. |
void |
setReadOnly(boolean readOnly)
You can put a connection in read-only mode as a hint to enable database optimizations. |
private int |
setResultSetConcurrency(int resultSetConcurrency)
|
private int |
setResultSetType(int resultSetType)
|
void |
setTransactionIsolation(int level)
You can call this method to try to change the transaction isolation level using one of the TRANSACTION_* values. |
protected void |
setupContextStack()
Install the context manager for this thread. |
java.lang.String |
toString()
|
boolean |
transactionIsIdle()
returns false if there is an underlying transaction and that transaction has done work. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.sql.Connection |
getTypeMap, releaseSavepoint, rollback, setSavepoint, setSavepoint, setTypeMap |
Field Detail |
private static final StandardException exceptionClose
protected java.sql.DatabaseMetaData dbMetadata
protected final TransactionResourceImpl tr
private boolean active
protected boolean autoCommit
boolean needCommit
protected int connectionHoldAbility
protected final EmbedConnection rootConnection
private java.sql.SQLWarning topWarning
public Driver169 factory
private java.sql.Connection applicationConnection
private int resultSetId
Constructor Detail |
public EmbedConnection(Driver169 driver, java.lang.String url, java.util.Properties info) throws java.sql.SQLException
public EmbedConnection(EmbedConnection inputConnection)
inputConnection
- the input connectionMethod Detail |
private boolean createBoot(java.util.Properties p) throws java.sql.SQLException
java.sql.SQLException
- Ooops.private void checkUserCredentials(java.lang.String dbname, java.util.Properties userInfo) throws java.sql.SQLException
java.sql.SQLException
public int getEngineType()
public final java.sql.Statement createStatement() throws java.sql.SQLException
createStatement
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.public final java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
createStatement
in interface java.sql.Connection
resultSetType
- a result set type, see ResultSet.TYPE_XXXresultSetConcurrency
- a concurrency type, see ResultSet.CONCUR_XXX
java.sql.SQLException
- if a database-access error occurs.public final java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
createStatement
in interface java.sql.Connection
resultSetType
- a result set type, see ResultSet.TYPE_XXXresultSetConcurrency
- a concurrency type, see ResultSet.CONCUR_XXXresultSetHoldability
- a holdability type,
ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
java.sql.SQLException
- if a database-access error occurs.public final java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement is executed. This has no direct affect on users; however, it does affect which method throws certain SQLExceptions. JDBC 2.0 Result sets created using the returned PreparedStatement will have forward-only type, and read-only concurrency, by default.
prepareStatement
in interface java.sql.Connection
sql
- a SQL statement that may contain one or more '?' IN
parameter placeholders
java.sql.SQLException
- if a database-access error occurs.public final java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
resultSetType
- a result set type, see ResultSet.TYPE_XXXresultSetConcurrency
- a concurrency type, see ResultSet.CONCUR_XXX
java.sql.SQLException
- if a database-access error occurs.public final java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
resultSetType
- a result set type, see ResultSet.TYPE_XXXresultSetConcurrency
- a concurrency type, see ResultSet.CONCUR_XXXresultSetHoldability
- - one of the following ResultSet constants:
ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
java.sql.SQLException
- if a database-access error occurs.public final java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
sql
- An SQL statement that may contain one or more ? IN parameter placeholderscolumnIndexes
- An array of column indexes indicating the columns
that should be returned from the inserted row or rows
java.sql.SQLException
- Feature not implemented for now.public final java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
sql
- An SQL statement that may contain one or more ? IN parameter placeholderscolumnNames
- An array of column names indicating the columns
that should be returned from the inserted row or rows
java.sql.SQLException
- Feature not implemented for now.public final java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
sql
- A SQL statement that may contain one or more ? IN parameter placeholdersautoGeneratedKeys
- A flag indicating whether auto-generated keys
should be returned
java.sql.SQLException
- Feature not implemented for now.private java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, int autoGeneratedKeys, int[] columnIndexes, java.lang.String[] columnNames) throws java.sql.SQLException
java.sql.SQLException
public final java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException
Note: This method is optimized for handling stored procedure call statements. Some drivers may send the call statement to the database when the prepareCall is done; others may wait until the CallableStatement is executed. This has no direct affect on users; however, it does affect which method throws certain SQLExceptions. JDBC 2.0 Result sets created using the returned CallableStatement will have forward-only type, and read-only concurrency, by default.
prepareCall
in interface java.sql.Connection
sql
- a SQL statement that may contain one or more '?'
parameter placeholders. Typically this statement is a JDBC
function call escape string.
java.sql.SQLException
- if a database-access error occurs.public final java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
prepareCall
in interface java.sql.Connection
resultSetType
- a result set type, see ResultSet.TYPE_XXXresultSetConcurrency
- a concurrency type, see ResultSet.CONCUR_XXX
java.sql.SQLException
- if a database-access error occurs.public final java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
prepareCall
in interface java.sql.Connection
resultSetType
- a result set type, see ResultSet.TYPE_XXXresultSetConcurrency
- a concurrency type, see ResultSet.CONCUR_XXXresultSetHoldability
- - one of the following ResultSet constants:
ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
java.sql.SQLException
- if a database-access error occurs.public java.lang.String nativeSQL(java.lang.String sql)
nativeSQL
in interface java.sql.Connection
sql
- a SQL statement that may contain one or more '?'
parameter placeholders
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
setAutoCommit
in interface java.sql.Connection
autoCommit
- true enables auto-commit; false disables
auto-commit.
java.sql.SQLException
- if a database-access error occurs.public boolean getAutoCommit()
getAutoCommit
in interface java.sql.Connection
setAutoCommit(boolean)
public void commit() throws java.sql.SQLException
commit
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.setAutoCommit(boolean)
public void rollback() throws java.sql.SQLException
rollback
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.setAutoCommit(boolean)
public void close() throws java.sql.SQLException
Note: A Connection is automatically closed when it is garbage collected. Certain fatal errors also result in a closed Connection.
close
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.private void close(java.lang.Exception e) throws java.sql.SQLException
java.sql.SQLException
public final boolean isClosed()
isClosed
in interface java.sql.Connection
public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException
getMetaData
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.public final int getHoldability()
getHoldability
in interface java.sql.Connection
public final void setHoldability(int holdability)
setHoldability
in interface java.sql.Connection
holdability
- A ResultSet holdability constant, one of ResultSet.HOLD_CURSORS_OVER_COMMIT
or ResultSet.CLOSE_CURSORS_AT_COMMITpublic final void setReadOnly(boolean readOnly) throws java.sql.SQLException
Note: setReadOnly cannot be called while in the middle of a transaction.
setReadOnly
in interface java.sql.Connection
readOnly
- true enables read-only mode; false disables
read-only mode.
java.sql.SQLException
- if a database-access error occurs.public final boolean isReadOnly() throws java.sql.SQLException
isReadOnly
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.public void setCatalog(java.lang.String catalog) throws java.sql.SQLException
setCatalog
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.public java.lang.String getCatalog() throws java.sql.SQLException
getCatalog
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.public void setTransactionIsolation(int level) throws java.sql.SQLException
Note: setTransactionIsolation causes the current transaction to commit
setTransactionIsolation
in interface java.sql.Connection
level
- one of the TRANSACTION_* isolation values with the
exception of TRANSACTION_NONE; some databases may not support
other values
java.sql.SQLException
- if a database-access error occurs.DatabaseMetaData.supportsTransactionIsolationLevel(int)
public final int getTransactionIsolation() throws java.sql.SQLException
getTransactionIsolation
in interface java.sql.Connection
java.sql.SQLException
- if a database-access error occurs.public final java.sql.SQLWarning getWarnings()
Note: Subsequent warnings will be chained to this SQLWarning.
getWarnings
in interface java.sql.Connection
public final void clearWarnings()
clearWarnings
in interface java.sql.Connection
public final void addWarning(java.sql.SQLWarning newWarning)
Connection.getWarnings()
public java.lang.String getDBName()
public final LanguageConnectionContext getLanguageConnection()
public java.sql.SQLException handleException(java.lang.Throwable thrownException) throws java.sql.SQLException
java.sql.SQLException
final java.sql.SQLException handleException(java.lang.Throwable thrownException, boolean rollbackOnAutoCommit) throws java.sql.SQLException
thrownException
- the exceptionrollbackOnAutoCommit
- rollback the xact on if autocommit is
on, otherwise rollback stmt but leave xact open (and
continue to hold on to locks). Most of the time, this
will be true, excepting operations on result sets, like
getInt().
java.sql.SQLException
public final void setInactive()
This only marks it as closed and frees up its resources; any closing of the underlying connection or commit work is assumed to be done elsewhere. Called from EmbedConnectionContext's cleanup routine, and by proxy.close().
protected void finalize() throws java.lang.Throwable
java.lang.Throwable
- standard error policyprotected void needCommit()
protected void commitIfNeeded() throws java.sql.SQLException
java.sql.SQLException
- if commit returns errorprotected void commitIfAutoCommit() throws java.sql.SQLException
java.sql.SQLException
- if commit returns errorprotected final java.lang.Object getConnectionSynchronization()
protected final void setupContextStack() throws java.sql.SQLException
java.sql.SQLException
- if failsprotected final void restoreContextStack() throws java.sql.SQLException
java.sql.SQLException
private Database createDatabase(java.lang.String dbname, java.util.Properties info) throws java.sql.SQLException
dbname
- the database nameinfo
- the properties
java.sql.SQLException
- if fails to create databaseprivate boolean bootDatabase(java.util.Properties info) throws java.lang.Throwable
java.lang.Throwable
java.sql.PreparedStatement prepareMetaDataStatement(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
public final Driver169 getLocalDriver()
public final ContextManager getContextManager()
private java.util.Properties filterProperties(java.util.Properties inputSet)
protected Database getDatabase()
protected final TransactionResourceImpl getTR()
private EmbedConnectionContext pushConnectionContext(ContextManager cm)
public final void setApplicationConnection(java.sql.Connection applicationConnection)
public final java.sql.Connection getApplicationConnection()
public void setDrdaID(java.lang.String drdaID)
public final boolean transactionIsIdle()
private int setResultSetType(int resultSetType)
public void setPrepareIsolation(int level) throws java.sql.SQLException
level
- Isolation level to change to. level is the DB2 level
specified in the package names which happen to correspond
to our internal levels. If
level == ExecutionContext.UNSPECIFIED_ISOLATION,
the statement won't be prepared with an isolation level.
java.sql.SQLException
public int getPrepareIsolation()
private int setResultSetConcurrency(int resultSetConcurrency)
final int getResultSetOrderId()
protected java.sql.SQLException newSQLException(java.lang.String messageId)
protected java.sql.SQLException newSQLException(java.lang.String messageId, java.lang.Object arg1)
protected java.sql.SQLException newSQLException(java.lang.String messageId, java.lang.Object arg1, java.lang.Object arg2)
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |