Class Database

java.lang.Object
org.apache.derby.impl.drda.Database
Direct Known Subclasses:
XADatabase

class Database extends Object
Database stores information about the current database It is used so that a session may have more than one database
  • Field Details

    • dbName

      private String dbName
    • shortDbName

      private String shortDbName
    • attrString

      String attrString
    • securityMechanism

      protected int securityMechanism
    • userId

      protected String userId
    • password

      protected String password
    • decryptedUserId

      protected String decryptedUserId
    • decryptedPassword

      protected String 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

      protected String typDefNam
    • byteOrder

      protected int byteOrder
    • ccsidSBC

      protected int ccsidSBC
    • ccsidDBC

      protected int ccsidDBC
    • ccsidMBC

      protected int ccsidMBC
    • ccsidSBCEncoding

      protected String ccsidSBCEncoding
    • ccsidDBCEncoding

      protected String ccsidDBCEncoding
    • ccsidMBCEncoding

      protected String ccsidMBCEncoding
    • RDBUPDRM_sent

      protected boolean RDBUPDRM_sent
    • sendTRGDFTRT

      protected boolean sendTRGDFTRT
    • conn

      private EngineConnection conn
      Connection to the database in the embedded engine.
    • defaultStatement

      DRDAStatement defaultStatement
    • currentStatement

      private DRDAStatement currentStatement
    • stmtTable

      private Hashtable<Object,DRDAStatement> stmtTable
      Hash table for storing statements.
    • locatorSupport

      private boolean locatorSupport
    • locatorSupportChecked

      private boolean locatorSupportChecked
    • pbsd_

      private PiggyBackedSessionData 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

      public void setDatabaseName(String dbName)
      Take database name including attributes and set attrString and shortDbName accordingly.
      Parameters:
      dbName - database name, including attributes.
    • getDatabaseName

      public String getDatabaseName()
    • getShortDbName

      public String getShortDbName()
    • initializeDefaultStatement

      private void initializeDefaultStatement()
    • setConnection

      final void setConnection(EngineConnection conn) throws SQLException
      Set connection and create the SQL statement for the default statement
      Parameters:
      conn - Connection
      Throws:
      SQLException
    • getConnection

      final EngineConnection getConnection()
      Get the connection
      Returns:
      connection
    • getCurrentStatement

      protected DRDAStatement getCurrentStatement()
      Get current DRDA statement
      Returns:
      DRDAStatement
      Throws:
      SQLException
    • getDefaultStatement

      protected DRDAStatement getDefaultStatement()
      Get default statement for use in EXCIMM
      Returns:
      DRDAStatement
    • getDefaultStatement

      protected DRDAStatement getDefaultStatement(Pkgnamcsn pkgnamcsn)
      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

      protected DRDAStatement newDRDAStatement(Pkgnamcsn pkgnamcsn) throws SQLException
      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

      protected DRDAStatement getDRDAStatement(Pkgnamcsn pkgnamcsn)
      Get DRDA statement based on pkgnamcsn
      Parameters:
      pkgnamcsn - - key to access statement
      Returns:
      DRDAStatement
    • makeConnection

      void makeConnection(Properties p) throws SQLException
      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

      String appendAttrString(Properties p)
    • storeStatement

      protected void storeStatement(DRDAStatement stmt) throws SQLException
      Store DRDA prepared statement
      Parameters:
      stmt - DRDA prepared statement
      Throws:
      SQLException
    • removeStatement

      protected void removeStatement(DRDAStatement stmt) throws SQLException
      Throws:
      SQLException
    • setCurrentStatement

      protected void setCurrentStatement(DRDAStatement stmt)
      Make statement the current statement
      Parameters:
      stmt -
    • commit

      protected void commit() throws SQLException
      Throws:
      SQLException
    • rollback

      protected void rollback() throws SQLException
      Throws:
      SQLException
    • close

      protected void close() throws SQLException
      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

      final void setDrdaID(String drdaID)
    • setPrepareIsolation

      final void setPrepareIsolation(int level) throws SQLException
      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

      final int getPrepareIsolation() throws SQLException
      Throws:
      SQLException
    • buildRuntimeInfo

      protected String buildRuntimeInfo(String indent, LocalizedResource localLangUtil)
    • supportsLocator

      boolean supportsLocator() throws SQLException
      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

      public PiggyBackedSessionData getPiggyBackedSessionData(boolean createOnDemand) throws SQLException
      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