Class DRDAStatement


  • class DRDAStatement
    extends java.lang.Object
    DRDAStatement stores information about the statement being executed
    • Field Detail

      • 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
      • withHoldCursor

        int withHoldCursor
      • isolationLevel

        protected int isolationLevel
      • cursorName

        protected java.lang.String cursorName
      • scrollType

        protected int scrollType
      • concurType

        protected int concurType
      • rowCount

        protected long rowCount
      • rslsetflg

        protected byte[] rslsetflg
      • maxrslcnt

        protected int maxrslcnt
      • stmtPmeta

        protected java.sql.ParameterMetaData stmtPmeta
      • isCall

        protected boolean isCall
      • procName

        protected java.lang.String procName
      • outputTypes

        private int[] outputTypes
      • outputPrecision

        private int[] outputPrecision
      • outputScale

        private int[] outputScale
      • NOT_OUTPUT_PARAM

        protected static int NOT_OUTPUT_PARAM
      • outputExpected

        protected boolean outputExpected
      • resultSetKeyList

        private java.util.ArrayList<ConsistencyToken> resultSetKeyList
        Ordered list of hash keys.
      • numResultSets

        private int numResultSets
      • truncationWarnings

        private java.sql.DataTruncation truncationWarnings
        A chain of warnings indicating whether some of the data values returned by this statement had to be truncated before being sent to the client.
      • nbrrow

        protected int nbrrow
      • qryrowset

        protected int qryrowset
      • blksize

        protected int blksize
      • maxblkext

        protected int maxblkext
      • outovropt

        protected int outovropt
      • qryrfrtbl

        protected boolean qryrfrtbl
      • qryprctyp

        private int qryprctyp
      • needsToSendParamData

        boolean needsToSendParamData
      • explicitlyPrepared

        boolean explicitlyPrepared
      • versionCounter

        long versionCounter
        If this changes, we need to re-send result set metadata to client, since a change indicates the engine has recompiled the prepared statement.
    • Constructor Detail

      • DRDAStatement

        DRDAStatement​(Database database)
        DRDAStatement constructor
        Parameters:
        database -
    • Method Detail

      • setTypDefValues

        protected void setTypDefValues()
        set TypDef values
      • setDatabase

        protected void setDatabase​(Database database)
        Set database
        Parameters:
        database -
      • setStatement

        protected void setStatement​(java.sql.Connection conn)
                             throws java.sql.SQLException
        Set statement
        Parameters:
        conn - Connection
        Throws:
        java.sql.SQLException
      • getStatement

        protected EngineStatement getStatement()
                                        throws java.sql.SQLException
        Get the statement
        Returns:
        statement
        Throws:
        java.sql.SQLException
      • addTruncationWarning

        protected void addTruncationWarning​(java.sql.DataTruncation w)
        Add a warning about data having been truncated.
        Parameters:
        w - the warning to add
      • getTruncationWarnings

        protected java.sql.DataTruncation getTruncationWarnings()
        Get the chain of truncation warnings added to this statement.
        Returns:
        chain of truncation warnings, possibly null
      • clearTruncationWarnings

        protected void clearTruncationWarnings()
        Clear the chain of truncation warnings for this statement.
      • setRsDefaultOptions

        protected void setRsDefaultOptions​(DRDAResultSet drs)
        Set resultSet defaults to match the statement defaults sent on EXCSQLSTT This might be overridden on OPNQRY or CNTQRY
      • getExtDtaObjects

        protected java.util.ArrayList<java.lang.Object> getExtDtaObjects()
        Get the extData Objects
        Returns:
        ArrayList with extdta
      • setSplitQRYDTA

        public void setSplitQRYDTA​(byte[] data)
      • getSplitQRYDTA

        public byte[] getSplitQRYDTA()
      • addExtDtaObject

        protected void addExtDtaObject​(java.lang.Object o,
                                       int jdbcIndex)
        Add extDtaObject
        Parameters:
        o - - object to add
        jdbcIndex - - jdbc index for parameter
      • clearExtDtaObjects

        protected void clearExtDtaObjects()
        Clear externalized lob objects in current result set
      • isExtDtaValueNullable

        protected boolean isExtDtaValueNullable​(int index)
      • setOPNQRYOptions

        protected void setOPNQRYOptions​(int blksize,
                                        int qryblkctl,
                                        int maxblkext,
                                        int outovropt,
                                        int qryrowset,
                                        int qryclsimpl)
        Set query options sent on OPNQRY and pass options down to the current DRDAResultSet object.
        Parameters:
        blksize - QRYBLKSZ (Query Block Size)
        qryblkctl - QRYPRCTYP (Query Protocol Type)
        maxblkext - MAXBLKEXT (Maximum Number of Extra Blocks)
        outovropt - OUTOVROPT (Output Override Option)
        qryrowset - QRYROWSET (Query Rowset Size)
        qryclsimpl - QRYCLSIMP (Query Close Implicit)
        See Also:
        DRDAResultSet.setOPNQRYOptions(int, int, int, int, int, int)
      • setQueryOptions

        protected void setQueryOptions​(int blksize,
                                       boolean qryrelscr,
                                       long qryrownbr,
                                       boolean qryfrtbl,
                                       int nbrrow,
                                       int maxblkext,
                                       int qryscrorn,
                                       boolean qryrowsns,
                                       boolean qryblkrst,
                                       boolean qryrtndta,
                                       int qryrowset,
                                       int rtnextdta)
      • setQryprctyp

        protected void setQryprctyp​(int qryprctyp)
      • getQryprctyp

        protected int getQryprctyp()
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setQryrownbr

        protected void setQryrownbr​(long qryrownbr)
      • getQryrownbr

        protected long getQryrownbr()
      • getQryrowset

        protected int getQryrowset()
      • getBlksize

        protected int getBlksize()
      • setQryrtndta

        protected void setQryrtndta​(boolean qryrtndta)
      • getQryrtndta

        protected boolean getQryrtndta()
      • setQryscrorn

        protected void setQryscrorn​(int qryscrorn)
      • getQryscrorn

        protected int getQryscrorn()
      • setScrollType

        protected void setScrollType​(int scrollType)
      • getScrollType

        protected int getScrollType()
      • isScrollable

        protected boolean isScrollable()
        is this a scrollable cursor? return true if this is not a forward only cursor
      • setConcurType

        protected void setConcurType​(int scrollType)
      • getConcurType

        protected int getConcurType()
      • setOutovr_drdaType

        protected void setOutovr_drdaType​(int[] outovr_drdaType)
      • getOutovr_drdaType

        protected int[] getOutovr_drdaType()
      • hasdata

        protected boolean hasdata()
      • setHasdata

        protected void setHasdata​(boolean hasdata)
      • initialize

        protected void initialize()
        This method is used to initialize the default statement of the database for re-use. It is different from reset() method since default statements get initialized differently. e.g: stmt variable used in default statement is created only once in Database.makeConnection. The default statement will be initialized to have the same byte order etc as the server. This may be changed when a TYPEDEFNAM is received from the client in DRDAConnThread.setStmtOrDbByteOrder()
      • explicitPrepare

        protected java.sql.PreparedStatement explicitPrepare​(java.lang.String sqlStmt)
                                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • wasExplicitlyPrepared

        protected boolean wasExplicitlyPrepared()
      • prepare

        protected java.sql.PreparedStatement prepare​(java.lang.String sqlStmt)
                                              throws java.sql.SQLException
        Create a prepared statement
        Parameters:
        sqlStmt - - SQL statement
        Throws:
        java.sql.SQLException
      • getPreparedStatement

        protected EnginePreparedStatement getPreparedStatement()
                                                        throws java.sql.SQLException
        Get prepared statement
        Returns:
        prepared statement
        Throws:
        java.sql.SQLException
      • execute

        protected boolean execute()
                           throws java.sql.SQLException
        Executes the prepared statement and populates the resultSetTable. Access to the various resultSets is then possible by using setCurrentDrdaResultSet(String pkgnamcsn) to set the current resultSet and then calling getResultSet() or the other access methods to get resultset data.
        Returns:
        true if the execution has resultSets
        Throws:
        java.sql.SQLException
      • finishParams

        protected void finishParams()
        clear out type data for parameters. Unfortunately we currently overload the resultSet type info rsDRDATypes et al with parameter info. RESOLVE: Need to separate this
      • setPkgnamcsn

        protected void setPkgnamcsn​(Pkgnamcsn pkgnamcsn)
        Set the pkgid sec num for this statement and the consistency token that will be used for the first resultSet. For dyamic packages The package name is encoded as follows SYS(S/L)(H/N)xyy where 'S' represents Small package and 'L' large (ignored by Derby) Where 'H' represents WITH HOLD, and 'N' represents NO WITH HOLD. (May be overridden by SQLATTR for WITH HOLD") Where 'www' is the package iteration (ignored by Derby) Where 'x' is the isolation level: 0=NC, 1=UR, 2=CS, 3=RS, 4=RR Where 'yy' is the package iteration 00 through FF Where 'zz' is unique for each platform Happilly, these values correspond precisely to the internal Derby isolation levels in ExecutionContext.java x Isolation Level -- --------------------- 0 NC (java.sql.Connection.TRANSACTION_NONE) 1 UR (java.sql.Connection.TRANACTION_READ_UNCOMMITTED) 2 CS (java.sql.Connection.TRANSACTION_READ_COMMITTED) 3 RS (java.sql.Connection.TRANSACTION_REPEATABLE_READ) 4 RR (java.sql.Connection.TRANSACTION_SERIALIZABLE) static packages have preset isolation levels (see getStaticPackageIsolation)
        Parameters:
        pkgnamcsn - package id section number and token from the client
      • getStaticPackageIsolation

        private int getStaticPackageIsolation​(java.lang.String pkgid)
        get the isolation level for a static package.
        Parameters:
        pkgid - - Package identifier string (e.g. SYSSTAT)
        Returns:
        isolation
      • getPkgnamcsn

        protected Pkgnamcsn getPkgnamcsn()
        Get pkgnamcsn
        Returns:
        pkgnamcsn
      • getResultSet

        protected java.sql.ResultSet getResultSet()
        Get result set
        Returns:
        result set
      • getCurrentDrdaResultSet

        protected DRDAResultSet getCurrentDrdaResultSet()
        Gets the current DRDA ResultSet
        Returns:
        DRDAResultSet
      • setCurrentDrdaResultSet

        protected void setCurrentDrdaResultSet​(int rsNum)
        Set currentDrdaResultSet
        Parameters:
        rsNum - The result set number starting with 0
      • setCurrentDrdaResultSet

        protected void setCurrentDrdaResultSet​(Pkgnamcsn pkgnamcsn)
        Set currentDrdaResultSet
        Parameters:
        pkgnamcsn - The pkgid section number and unique resultset consistency token
      • getDrdaResultSet

        private DRDAResultSet getDrdaResultSet​(int rsNum)
      • addResultSet

        protected ConsistencyToken addResultSet​(java.sql.ResultSet value,
                                                int holdValue)
                                         throws java.sql.SQLException
        Add a new resultSet to this statement. Set as the current result set if there is not an existing current resultset.
        Parameters:
        value - - ResultSet to add
        holdValue - - Holdability of the ResultSet
        Returns:
        Consistency token for this resultSet For a single resultSet that is the same as the statement's For multiple resultSets just the consistency token is changed
        Throws:
        java.sql.SQLException
      • getNumResultSets

        protected int getNumResultSets()
        Returns:
        number of result sets
      • getResultSetPkgcnstkn

        protected ConsistencyToken getResultSetPkgcnstkn​(int rsNum)
        Parameters:
        rsNum - result set starting with 0
        Returns:
        consistency token (key) for the result set
      • getRsDRDATypes

        protected int[] getRsDRDATypes()
        Returns:
        ResultSet DRDA DataTypes
      • rsClose

        protected void rsClose()
                        throws java.sql.SQLException
        Close the current resultSet
        Throws:
        java.sql.SQLException
      • CLSQRY

        protected void CLSQRY()
        Explicitly close the result set by CLSQRY needed to check for double close.
      • wasExplicitlyClosed

        protected boolean wasExplicitlyClosed()
      • close

        protected void close()
                      throws java.sql.SQLException
        This method closes the JDBC objects and frees up all references held by this object.
        Throws:
        java.sql.SQLException
      • reset

        protected void reset()
        This method resets the state of this DRDAStatement object so that it can be re-used. This method should reset all variables of this class except the following: 1. database - This variable gets initialized in the constructor and by call to setDatabase. 2. members which get initialized in setPkgnamcsn (pkgnamcsn, pkgcnstkn, pkgid, pkgsn, isolationLevel, cursorName). pkgnamcsn is the key used to find if the DRDAStatement can be re-used. Hence its value will not change when the object is re-used.
      • rsIsClosed

        protected boolean rsIsClosed()
        is Statement closed
        Returns:
        whether the statement is closed
      • rsSuspend

        protected void rsSuspend()
        Set state to SUSPENDED (result set is opened)
      • setRsPrecision

        protected void setRsPrecision​(int index,
                                      int precision)
        set resultset/out parameter precision
        Parameters:
        index - - starting with 1
        precision -
      • getRsPrecision

        protected int getRsPrecision​(int index)
        get resultset /out parameter precision
        Parameters:
        index - -starting with 1
        Returns:
        precision of column
      • setRsScale

        protected void setRsScale​(int index,
                                  int scale)
        set resultset/out parameter scale
        Parameters:
        index - - starting with 1
        scale -
      • getRsScale

        protected int getRsScale​(int index)
        get resultset /out parameter scale
        Parameters:
        index - -starting with 1
        Returns:
        scale of column
      • setRsDRDAType

        protected void setRsDRDAType​(int index,
                                     int type)
        set result DRDAType
        Parameters:
        index - - starting with 1
        type -
      • clearDrdaParams

        protected void clearDrdaParams()
        Clears the parameter state (type, length and ext information) stored in this statement, but does not release any storage. This reduces the cost of re-executing the statement since no new storage needs to be allocated.
      • getExtPositionCount

        protected int getExtPositionCount()
        Get the number of external parameters in this statement. External means parameters that are transmitted in a separate DSS in the DRDA protocol.
        Returns:
        the number of external parameters
      • getExtPosition

        protected int getExtPosition​(int i)
        Get the parameter position of the i'th external parameter
        Parameters:
        i - - zero-based index into list of external parameters
        Returns:
        the parameter position of the i'th external parameter
      • addExtPosition

        protected void addExtPosition​(int pos)
        Mark the pos'th parameter as external
        Parameters:
        pos - - zero-based index into list of external parameters
      • getDrdaParamCount

        protected int getDrdaParamCount()
        Get the number of parameters, internal and external, that has been added to this statement.
        Returns:
        the number of parameters
      • addDrdaParam

        protected void addDrdaParam​(byte t,
                                    int l)
        Add another parameter to this statement.
        Parameters:
        t - - type of the parameter
        l - - length in bytes of the parameter
      • getParamDRDAType

        protected int getParamDRDAType​(int index)
        get parameter DRDAType
        Parameters:
        index - - starting with 1
        Returns:
        DRDA Type of column
      • getParamLen

        protected int getParamLen​(int index)
        returns drda length of parameter as sent by client.
        Parameters:
        index - - starting with 1
        Returns:
        data length
      • getParamPrecision

        protected int getParamPrecision​(int index)
                                 throws java.sql.SQLException
        get parameter precision or DB2 max (31)
        Parameters:
        index - parameter index starting with 1
        Returns:
        precision
        Throws:
        java.sql.SQLException
      • getParamScale

        protected int getParamScale​(int index)
                             throws java.sql.SQLException
        get parameter scale or DB2 max (31)
        Parameters:
        index - parameter index starting with 1
        Returns:
        scale
        Throws:
        java.sql.SQLException
      • getNumRsCols

        protected int getNumRsCols()
        get the number of result set columns for the current resultSet
        Returns:
        number of columns
      • getRsDRDAType

        protected int getRsDRDAType​(int index)
        get resultset/out parameter DRDAType
        Parameters:
        index - - starting with 1
        Returns:
        DRDA Type of column
      • getRsLen

        protected int getRsLen​(int index)
        get resultset/out parameter DRDALen
        Parameters:
        index - starting with 1
        Returns:
        length of drda data
      • getResultSetCursorName

        public java.lang.String getResultSetCursorName​(int rsNum)
                                                throws java.sql.SQLException
        Parameters:
        rsNum - - result set # starting with 0
        Throws:
        java.sql.SQLException
      • toDebugString

        protected java.lang.String toDebugString​(java.lang.String indent)
      • calculateResultSetPkgcnstkn

        protected ConsistencyToken calculateResultSetPkgcnstkn​(int rsNum)
        For a single result set, just echo the consistency token that the client sent us. For subsequent resultSets, just subtract the resultset number from the consistency token and that will differentiate the result sets. This seems to be what DB2 does
        Parameters:
        rsNum - - result set # starting with 0
        Returns:
        Consistency token for result set
      • isCallableStatement

        protected boolean isCallableStatement()
      • isCallableSQL

        private boolean isCallableSQL​(java.lang.String sql)
      • setupCallableStatementParams

        private void setupCallableStatementParams​(java.sql.CallableStatement cs)
                                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getOutputParameterTypeFromClassName

        protected static int getOutputParameterTypeFromClassName​(java.lang.String objectName)
        Given an object class name get the paramameter type if the parameter mode is unknown. Arrays except for byte arrrays are assumed to be output parameters TINYINT output parameters are going to be broken because there is no way to differentiate them from binary input parameters.
        Parameters:
        objectName - Class name of object being evaluated. indicating if this an output parameter
        Returns:
        type from java.sql.Types
      • registerAllOutParams

        public void registerAllOutParams()
                                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • registerOutParam

        public void registerOutParam​(int paramNum)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • hasOutputParams

        protected boolean hasOutputParams()
      • isOutputParam

        boolean isOutputParam​(int paramNum)
        is parameter an ouput parameter
        Parameters:
        paramNum - parameter number starting with 1. return true if this is an output parameter.
      • getOutputParamType

        int getOutputParamType​(int paramNum)
        get type for output parameter.
        Parameters:
        paramNum - - parameter number starting with 1
        Returns:
        jdbcType or NOT_OUTPUT_PARAM if this is not an output parameter
      • getOutputParamScale

        int getOutputParamScale​(int paramNum)
        get scale for output parameter.
        Parameters:
        paramNum - - parameter number starting with 1
        Returns:
        scale or NOT_OUTPUT_PARAM if this is not an output parameter
      • getOutputParamPrecision

        int getOutputParamPrecision​(int paramNum)
        get precision for output parameter.
        Parameters:
        paramNum - - parameter number starting with 1
        Returns:
        precision or NOT_OUTPUT_PARAM if this is not an output parameter
      • isDynamicPkgid

        private boolean isDynamicPkgid​(java.lang.String pkgid)
      • parsePkgidToFindHoldability

        private void parsePkgidToFindHoldability()
      • getParameterMetaData

        protected java.sql.ParameterMetaData getParameterMetaData()
                                                           throws java.sql.SQLException
        Retrieve the ParameterMetaData for the prepared statement.
        Returns:
        ParameterMetaData for the prepared statement. Note: there is no separate BrokeredParameterSetMetaData.
        Throws:
        java.sql.SQLException
      • getMoreResults

        private boolean getMoreResults​(int current)
                                throws java.sql.SQLException
        get more results using reflection.
        Parameters:
        current - - flag to pass to Statement.getMoreResults(current)
        Returns:
        true if there are more results.
        Throws:
        java.sql.SQLException
        See Also:
        Statement.getMoreResults()
      • getSQLText

        private java.lang.String getSQLText()
        Use reflection to retrieve SQL Text for EmbedPreparedStatement or BrokeredPreparedStatement.
        Returns:
        SQL text
      • isRSCloseImplicit

        boolean isRSCloseImplicit​(boolean lmtblkprcOK)
                           throws java.sql.SQLException
        Method to decide whether the ResultSet should be closed implicitly based on the QRYCLSIMP value sent from the client. Only forward-only result sets should be implicitly closed. Some clients do not expect result sets to be closed implicitly if the protocol is LMTBLKPRC.
        Parameters:
        lmtblkprcOK - true if the client expects QRYCLSIMP to be respected for the LMTBLKPRC protocol
        Returns:
        implicit close boolean
        Throws:
        java.sql.SQLException