Package org.apache.derby.impl.drda
Class Database
java.lang.Object
org.apache.derby.impl.drda.Database
- Direct Known Subclasses:
XADatabase
Database stores information about the current database
It is used so that a session may have more than one database
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
(package private) String
protected int
protected int
protected String
protected int
protected String
protected int
protected String
private EngineConnection
Connection to the database in the embedded engine.protected byte[]
private DRDAStatement
private String
protected String
protected String
(package private) DRDAStatement
private boolean
private boolean
protected String
protected byte[]
private PiggyBackedSessionData
Piggy-backed session data.protected boolean
protected boolean
protected byte[]
protected byte[]
protected int
protected boolean
private String
private Hashtable
<Object, DRDAStatement> Hash table for storing statements.protected String
protected String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) String
protected String
buildRuntimeInfo
(String indent, LocalizedResource localLangUtil) protected void
close()
Database close does following cleanup tasks 1)Rollback any pending transaction on the Connection object (except for a global-XA Connection obejct) before closing the Connection.protected void
commit()
(package private) final EngineConnection
Get the connectionprotected DRDAStatement
Get current DRDA statementprotected DRDAStatement
Get default statement for use in EXCIMMprotected DRDAStatement
getDefaultStatement
(Pkgnamcsn pkgnamcsn) Get default statement for use in EXCIMM with specified pkgnamcsn The pkgnamcsn has the encoded isolation levelprotected DRDAStatement
getDRDAStatement
(Pkgnamcsn pkgnamcsn) Get DRDA statement based on pkgnamcsngetPiggyBackedSessionData
(boolean createOnDemand) Get a reference (handle) to the PiggyBackedSessionData object.(package private) final int
private void
(package private) void
Make a new connection using the database name and set the connection in the database(package private) void
This makes a dummy connection to the database in order to boot and/or create this last one.protected DRDAStatement
newDRDAStatement
(Pkgnamcsn pkgnamcsn) Get a new DRDA statement and store it in the stmtTable if stortStmt is true.protected void
removeStatement
(DRDAStatement stmt) void
reset()
This method resets the state of this Database object so that it can be re-used.protected void
rollback()
(package private) final void
Set connection and create the SQL statement for the default statementprotected void
Make statement the current statementvoid
setDatabaseName
(String dbName) Take database name including attributes and set attrString and shortDbName accordingly.(package private) final void
(package private) final void
setPrepareIsolation
(int level) Set the internal isolation level to use for preparing statements.protected void
storeStatement
(DRDAStatement stmt) Store DRDA prepared statement(package private) boolean
Checks whether database can support locators.
-
Field Details
-
dbName
-
shortDbName
-
attrString
String attrString -
securityMechanism
protected int securityMechanism -
userId
-
password
-
decryptedUserId
-
decryptedPassword
-
passwordSubstitute
protected byte[] passwordSubstitute -
rdbAllowUpdates
protected boolean rdbAllowUpdates -
accessCount
protected int accessCount -
secTokenIn
protected byte[] secTokenIn -
secTokenOut
protected byte[] secTokenOut -
crrtkn
protected byte[] crrtkn -
typDefNam
-
byteOrder
protected int byteOrder -
ccsidSBC
protected int ccsidSBC -
ccsidDBC
protected int ccsidDBC -
ccsidMBC
protected int ccsidMBC -
ccsidSBCEncoding
-
ccsidDBCEncoding
-
ccsidMBCEncoding
-
RDBUPDRM_sent
protected boolean RDBUPDRM_sent -
sendTRGDFTRT
protected boolean sendTRGDFTRT -
conn
Connection to the database in the embedded engine. -
defaultStatement
DRDAStatement defaultStatement -
currentStatement
-
stmtTable
Hash table for storing statements. -
locatorSupport
private boolean locatorSupport -
locatorSupportChecked
private boolean locatorSupportChecked -
pbsd_
Piggy-backed session data. Null if no piggy-backing has happened yet. Lazy initialization is acceptable since the client's cache initially is empty so that any request made prior to the first round of piggy-backing will trigger an actual request to the server.
-
-
Constructor Details
-
Database
Database(String dbName) Database constructor- Parameters:
dbName
- database name
-
-
Method Details
-
setDatabaseName
Take database name including attributes and set attrString and shortDbName accordingly.- Parameters:
dbName
- database name, including attributes.
-
getDatabaseName
-
getShortDbName
-
initializeDefaultStatement
private void initializeDefaultStatement() -
setConnection
Set connection and create the SQL statement for the default statement- Parameters:
conn
- Connection- Throws:
SQLException
-
getConnection
Get the connection- Returns:
- connection
-
getCurrentStatement
Get current DRDA statement- Returns:
- DRDAStatement
- Throws:
SQLException
-
getDefaultStatement
Get default statement for use in EXCIMM- Returns:
- DRDAStatement
-
getDefaultStatement
Get default statement for use in EXCIMM with specified pkgnamcsn The pkgnamcsn has the encoded isolation level- Parameters:
pkgnamcsn
- package/ section # for statement- Returns:
- DRDAStatement
-
newDRDAStatement
Get a new DRDA statement and store it in the stmtTable if stortStmt is true. If possible recycle an existing statement. When the server gets a new statement with a previously used pkgnamcsn, it means that client-side statement associated with this pkgnamcsn has been closed. In this case, server can re-use the DRDAStatement by doing the following: 1) Retrieve the old DRDAStatement associated with this pkgnamcsn and close it. 2) Reset the DRDAStatement state for re-use.- Parameters:
pkgnamcsn
- Package name and section- Returns:
- DRDAStatement
- Throws:
SQLException
-
getDRDAStatement
Get DRDA statement based on pkgnamcsn- Parameters:
pkgnamcsn
- - key to access statement- Returns:
- DRDAStatement
-
makeConnection
Make a new connection using the database name and set the connection in the database- Parameters:
p
- Properties for connection attributes to pass to connect- Throws:
SQLException
-
makeDummyConnection
void makeDummyConnection()This makes a dummy connection to the database in order to boot and/or create this last one. If database cannot be found or authentication does not succeed, this will throw a SQLException which we catch and do nothing. We don't pass a userid and password here as we don't need to for the purpose of this method - main goal is to cause the database to be booted via a dummy connection. -
appendAttrString
-
storeStatement
Store DRDA prepared statement- Parameters:
stmt
- DRDA prepared statement- Throws:
SQLException
-
removeStatement
- Throws:
SQLException
-
setCurrentStatement
Make statement the current statement- Parameters:
stmt
-
-
commit
- Throws:
SQLException
-
rollback
- Throws:
SQLException
-
close
Database close does following cleanup tasks 1)Rollback any pending transaction on the Connection object (except for a global-XA Connection obejct) before closing the Connection. Without the rollback, the Connection close will result into an exception if there is a pending transaction on that Connection. 2)Clean up the statement table- Throws:
SQLException
- on conn.close() error to be handled in DRDAConnThread.
-
setDrdaID
-
setPrepareIsolation
Set the internal isolation level to use for preparing statements. Subsequent prepares will use this isoalation level- Parameters:
level
- internal isolation level- Throws:
SQLException
- See Also:
-
getPrepareIsolation
- Throws:
SQLException
-
buildRuntimeInfo
-
supportsLocator
Checks whether database can support locators. This is done by checking whether one of the stored procedures needed for locators exists. (If the database has been soft-upgraded from an earlier version, the procedures will not exist).- Returns:
true
if locators are supported,false
otherwise- Throws:
SQLException
- if metadata call fails
-
reset
public void reset()This method resets the state of this Database object so that it can be re-used. Note: currently this method resets the variables related to security mechanisms that have been investigated as needing a reset. TODO: Investigate what all variables in this class need to be reset when this database object is re-used on a connection pooling or transaction pooling. see DRDAConnThread.parseACCSEC (CodePoint.RDBNAM) where database object is re-used on a connection reset. -
getPiggyBackedSessionData
Get a reference (handle) to the PiggyBackedSessionData object. Null will be returned either if Database.conn is not a valid connection, or if the create argument is false and no object has yet been created.- Parameters:
createOnDemand
- if true create the PiggyBackedSessionData on demand- Returns:
- a reference to the PBSD object or null
- Throws:
SQLException
-