Class DRDAStatement
java.lang.Object
org.apache.derby.impl.drda.DRDAStatement
DRDAStatement stores information about the statement being executed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis class is used to keep track of the statement's parameters as they are received from the client. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected intprotected Stringprotected intprotected Stringprotected intprotected Stringprotected intprivate DRDAResultSetprotected Stringprotected Databaseprivate DRDAStatement.DrdaParamState(package private) booleanprotected booleanprotected intprotected intprotected intprotected int(package private) booleanprotected static intprivate intprotected intprotected booleanprivate int[]private int[]private int[]private Pkgnamcsnprotected Stringprotected EnginePreparedStatementprivate intprotected booleanprotected intprivate ArrayList<ConsistencyToken> Ordered list of hash keys.private Hashtable<ConsistencyToken, DRDAResultSet> Hashtable with resultsets.protected longprotected byte[]protected int(package private) intSaved value returned fromDRDAConnThread.parsePRPSQLSTT().private EngineStatementprotected ParameterMetaDataprivate DataTruncationA chain of warnings indicating whether some of the data values returned by this statement had to be truncated before being sent to the client.protected String(package private) longIf this changes, we need to re-send result set metadata to client, since a change indicates the engine has recompiled the prepared statement.(package private) int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDrdaParam(byte t, int l) Add another parameter to this statement.protected voidaddExtDtaObject(Object o, int jdbcIndex) Add extDtaObjectprotected voidaddExtPosition(int pos) Mark the pos'th parameter as externalprotected ConsistencyTokenaddResultSet(ResultSet value, int holdValue) Add a new resultSet to this statement.protected voidAdd a warning about data having been truncated.protected ConsistencyTokencalculateResultSetPkgcnstkn(int rsNum) For a single result set, just echo the consistency token that the client sent us.protected voidClears the parameter state (type, length and ext information) stored in this statement, but does not release any storage.protected voidClear externalized lob objects in current result setprotected voidClear the chain of truncation warnings for this statement.protected voidclose()This method closes the JDBC objects and frees up all references held by this object.protected voidCLSQRY()Explicitly close the result set by CLSQRY needed to check for double close.protected booleanexecute()Executes the prepared statement and populates the resultSetTable.protected PreparedStatementexplicitPrepare(String sqlStmt) protected voidclear out type data for parameters.protected intprotected intprotected DRDAResultSetGets the current DRDA ResultSetprotected intGet the number of parameters, internal and external, that has been added to this statement.private DRDAResultSetgetDrdaResultSet(int rsNum) private DRDAResultSetgetDrdaResultSet(ConsistencyToken consistToken) Get the extData Objectsprotected intgetExtPosition(int i) Get the parameter position of the i'th external parameterprotected intGet the number of external parameters in this statement.private booleangetMoreResults(int current) get more results using reflection.protected intprotected intget the number of result set columns for the current resultSetprotected int[]protected static intgetOutputParameterTypeFromClassName(String objectName) Given an object class name get the paramameter type if the parameter mode is unknown.(package private) intgetOutputParamPrecision(int paramNum) get precision for output parameter.(package private) intgetOutputParamScale(int paramNum) get scale for output parameter.(package private) intgetOutputParamType(int paramNum) get type for output parameter.protected intgetParamDRDAType(int index) get parameter DRDATypeprotected ParameterMetaDataRetrieve the ParameterMetaData for the prepared statement.protected intgetParamLen(int index) returns drda length of parameter as sent by client.protected intgetParamPrecision(int index) get parameter precision or DB2 max (31)protected intgetParamScale(int index) get parameter scale or DB2 max (31)protected PkgnamcsnGet pkgnamcsnprotected EnginePreparedStatementGet prepared statementprotected intprotected longprotected intprotected booleanprotected intprotected ResultSetGet result setgetResultSetCursorName(int rsNum) protected ConsistencyTokengetResultSetPkgcnstkn(int rsNum) protected intgetRsDRDAType(int index) get resultset/out parameter DRDATypeprotected int[]protected intgetRsLen(int index) get resultset/out parameter DRDALenprotected intgetRsPrecision(int index) get resultset /out parameter precisionprotected intgetRsScale(int index) get resultset /out parameter scaleprotected intbyte[]private StringUse reflection to retrieve SQL Text for EmbedPreparedStatement or BrokeredPreparedStatement.protected EngineStatementGet the statementprivate intgetStaticPackageIsolation(String pkgid) get the isolation level for a static package.protected DataTruncationGet the chain of truncation warnings added to this statement.protected booleanhasdata()protected booleanprotected voidThis method is used to initialize the default statement of the database for re-use.private booleanisCallableSQL(String sql) protected booleanprivate booleanisDynamicPkgid(String pkgid) protected booleanisExtDtaValueNullable(int index) (package private) booleanisOutputParam(int paramNum) is parameter an ouput parameter(package private) booleanisRSCloseImplicit(boolean lmtblkprcOK) Method to decide whether the ResultSet should be closed implicitly based on the QRYCLSIMP value sent from the client.protected booleanis this a scrollable cursor?private voidprotected PreparedStatementCreate a prepared statementvoidvoidregisterOutParam(int paramNum) protected voidreset()This method resets the state of this DRDAStatement object so that it can be re-used.protected voidrsClose()Close the current resultSetprotected booleanis Statement closedprotected voidSet state to SUSPENDED (result set is opened)protected voidsetConcurType(int scrollType) protected voidsetCurrentDrdaResultSet(int rsNum) Set currentDrdaResultSetprotected voidsetCurrentDrdaResultSet(Pkgnamcsn pkgnamcsn) Set currentDrdaResultSetprotected voidsetDatabase(Database database) Set databaseprotected voidsetHasdata(boolean hasdata) protected voidsetOPNQRYOptions(int blksize, int qryblkctl, int maxblkext, int outovropt, int qryrowset, int qryclsimpl) Set query options sent on OPNQRY and pass options down to the currentDRDAResultSetobject.protected voidsetOutovr_drdaType(int[] outovr_drdaType) protected voidsetPkgnamcsn(Pkgnamcsn pkgnamcsn) Set the pkgid sec num for this statement and the consistency token that will be used for the first resultSet.protected voidsetQryprctyp(int qryprctyp) protected voidsetQryrownbr(long qryrownbr) protected voidsetQryrtndta(boolean qryrtndta) protected voidsetQryscrorn(int qryscrorn) protected voidsetQueryOptions(int blksize, boolean qryrelscr, long qryrownbr, boolean qryfrtbl, int nbrrow, int maxblkext, int qryscrorn, boolean qryrowsns, boolean qryblkrst, boolean qryrtndta, int qryrowset, int rtnextdta) protected voidSet resultSet defaults to match the statement defaults sent on EXCSQLSTT This might be overridden on OPNQRY or CNTQRYprotected voidsetRsDRDAType(int index, int type) set result DRDATypeprotected voidsetRsPrecision(int index, int precision) set resultset/out parameter precisionprotected voidsetRsScale(int index, int scale) set resultset/out parameter scaleprotected voidsetScrollType(int scrollType) voidsetSplitQRYDTA(byte[] data) protected voidsetStatement(Connection conn) Set statementprotected voidprotected voidset TypDef valuesprivate voidprotected StringtoDebugString(String indent) protected booleanprotected boolean
-
Field Details
-
typDefNam
-
byteOrder
protected int byteOrder -
ccsidSBC
protected int ccsidSBC -
ccsidDBC
protected int ccsidDBC -
ccsidMBC
protected int ccsidMBC -
ccsidSBCEncoding
-
ccsidDBCEncoding
-
ccsidMBCEncoding
-
database
-
pkgnamcsn
-
withHoldCursor
int withHoldCursor -
isolationLevel
protected int isolationLevel -
cursorName
-
scrollType
protected int scrollType -
concurType
protected int concurType -
rowCount
protected long rowCount -
rslsetflg
protected byte[] rslsetflg -
maxrslcnt
protected int maxrslcnt -
ps
-
stmtPmeta
-
isCall
protected boolean isCall -
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 -
stmt
-
currentDrdaRs
-
resultSetTable
Hashtable with resultsets. -
resultSetKeyList
Ordered list of hash keys. -
numResultSets
private int numResultSets -
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. -
drdaParamState_
-
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 versionCounterIf this changes, we need to re-send result set metadata to client, since a change indicates the engine has recompiled the prepared statement. -
sqldaType
int sqldaTypeSaved value returned fromDRDAConnThread.parsePRPSQLSTT(). Used to determine if the statement is such that we may need to re-send metadata at execute time, seeversionCounter.
-
-
Constructor Details
-
DRDAStatement
-
-
Method Details
-
setTypDefValues
protected void setTypDefValues()set TypDef values -
setDatabase
-
setStatement
Set statement- Parameters:
conn- Connection- Throws:
SQLException
-
getStatement
Get the statement- Returns:
- statement
- Throws:
SQLException
-
addTruncationWarning
Add a warning about data having been truncated.- Parameters:
w- the warning to add
-
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
Set resultSet defaults to match the statement defaults sent on EXCSQLSTT This might be overridden on OPNQRY or CNTQRY -
getExtDtaObjects
-
setSplitQRYDTA
public void setSplitQRYDTA(byte[] data) -
getSplitQRYDTA
public byte[] getSplitQRYDTA() -
addExtDtaObject
Add extDtaObject- Parameters:
o- - object to addjdbcIndex- - 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 currentDRDAResultSetobject.- 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:
-
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
- Throws:
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
- Throws:
SQLException
-
wasExplicitlyPrepared
protected boolean wasExplicitlyPrepared() -
prepare
Create a prepared statement- Parameters:
sqlStmt- - SQL statement- Throws:
SQLException
-
getPreparedStatement
Get prepared statement- Returns:
- prepared statement
- Throws:
SQLException
-
execute
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:
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
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
get the isolation level for a static package.- Parameters:
pkgid- - Package identifier string (e.g. SYSSTAT)- Returns:
- isolation
-
getPkgnamcsn
-
getResultSet
-
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
Set currentDrdaResultSet- Parameters:
pkgnamcsn- The pkgid section number and unique resultset consistency token
-
getDrdaResultSet
-
getDrdaResultSet
-
addResultSet
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 addholdValue- - 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:
SQLException
-
getNumResultSets
protected int getNumResultSets()- Returns:
- number of result sets
-
getResultSetPkgcnstkn
- Parameters:
rsNum- result set starting with 0- Returns:
- consistency token (key) for the result set
-
getRsDRDATypes
protected int[] getRsDRDATypes()- Returns:
- ResultSet DRDA DataTypes
-
rsClose
-
CLSQRY
protected void CLSQRY()Explicitly close the result set by CLSQRY needed to check for double close. -
wasExplicitlyClosed
protected boolean wasExplicitlyClosed() -
close
This method closes the JDBC objects and frees up all references held by this object.- Throws:
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 1precision-
-
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 1scale-
-
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 1type-
-
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 parameterl- - length in bytes of the parameter
-
setStreamedParameter
-
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
get parameter precision or DB2 max (31)- Parameters:
index- parameter index starting with 1- Returns:
- precision
- Throws:
SQLException
-
getParamScale
get parameter scale or DB2 max (31)- Parameters:
index- parameter index starting with 1- Returns:
- scale
- Throws:
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
- Parameters:
rsNum- - result set # starting with 0- Throws:
SQLException
-
toDebugString
-
calculateResultSetPkgcnstkn
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
-
setupCallableStatementParams
- Throws:
SQLException
-
getOutputParameterTypeFromClassName
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
- Throws:
SQLException
-
registerOutParam
- Throws:
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
-
parsePkgidToFindHoldability
private void parsePkgidToFindHoldability() -
getParameterMetaData
Retrieve the ParameterMetaData for the prepared statement.- Returns:
- ParameterMetaData for the prepared statement. Note: there is no separate BrokeredParameterSetMetaData.
- Throws:
SQLException
-
getMoreResults
get more results using reflection.- Parameters:
current- - flag to pass to Statement.getMoreResults(current)- Returns:
- true if there are more results.
- Throws:
SQLException- See Also:
-
getSQLText
Use reflection to retrieve SQL Text for EmbedPreparedStatement or BrokeredPreparedStatement.- Returns:
- SQL text
-
isRSCloseImplicit
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-trueif the client expects QRYCLSIMP to be respected for the LMTBLKPRC protocol- Returns:
- implicit close boolean
- Throws:
SQLException
-