Class Database

  • Direct Known Subclasses:
    XADatabase

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

      • dbName

        private java.lang.String dbName
      • shortDbName

        private java.lang.String shortDbName
      • attrString

        java.lang.String attrString
      • securityMechanism

        protected int securityMechanism
      • userId

        protected java.lang.String userId
      • password

        protected java.lang.String password
      • decryptedUserId

        protected java.lang.String decryptedUserId
      • decryptedPassword

        protected java.lang.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 java.lang.String typDefNam
      • byteOrder

        protected int byteOrder
      • ccsidSBC

        protected int ccsidSBC
      • ccsidDBC

        protected int ccsidDBC
      • ccsidMBC

        protected int ccsidMBC
      • ccsidSBCEncoding

        protected java.lang.String ccsidSBCEncoding
      • ccsidDBCEncoding

        protected java.lang.String ccsidDBCEncoding
      • ccsidMBCEncoding

        protected java.lang.String ccsidMBCEncoding
      • RDBUPDRM_sent

        protected boolean RDBUPDRM_sent
      • sendTRGDFTRT

        protected boolean sendTRGDFTRT
      • conn

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

        private java.util.Hashtable<java.lang.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 Detail

      • Database

        Database​(java.lang.String dbName)
        Database constructor
        Parameters:
        dbName - database name
    • Method Detail

      • setDatabaseName

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

        public java.lang.String getDatabaseName()
      • getShortDbName

        public java.lang.String getShortDbName()
      • initializeDefaultStatement

        private void initializeDefaultStatement()
      • setConnection

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

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

        protected DRDAStatement getCurrentStatement()
        Get current DRDA statement
        Returns:
        DRDAStatement
        Throws:
        java.sql.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 java.sql.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:
        java.sql.SQLException
      • getDRDAStatement

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

        void makeConnection​(java.util.Properties p)
                     throws java.sql.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:
        java.sql.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

        java.lang.String appendAttrString​(java.util.Properties p)
      • storeStatement

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

        protected void removeStatement​(DRDAStatement stmt)
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setCurrentStatement

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

        protected void commit()
                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • rollback

        protected void rollback()
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • close

        protected void close()
                      throws java.sql.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:
        java.sql.SQLException - on conn.close() error to be handled in DRDAConnThread.
      • setDrdaID

        final void setDrdaID​(java.lang.String drdaID)
      • setPrepareIsolation

        final void setPrepareIsolation​(int level)
                                throws java.sql.SQLException
        Set the internal isolation level to use for preparing statements. Subsequent prepares will use this isoalation level
        Parameters:
        level - internal isolation level
        Throws:
        java.sql.SQLException
        See Also:
        EngineConnection.setPrepareIsolation(int)
      • getPrepareIsolation

        final int getPrepareIsolation()
                               throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • buildRuntimeInfo

        protected java.lang.String buildRuntimeInfo​(java.lang.String indent,
                                                    LocalizedResource localLangUtil)
      • supportsLocator

        boolean supportsLocator()
                         throws java.sql.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:
        java.sql.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 java.sql.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:
        java.sql.SQLException