📄 drdastatement.java
字号:
// also have to reset our 'numResultSets' counter, since // all previously opened result sets are now invalid. numResultSets = 0; ResultSet rs = null; boolean isCallable = (ps instanceof java.sql.CallableStatement); if (isCallable) needsToSendParamData = true; do { rs = ps.getResultSet(); if (rs !=null) { //For callable statement, get holdability of statement generating the result set if(isCallable) addResultSet(rs,getResultSetHoldability(rs)); else addResultSet(rs,withHoldCursor); hasResultSet = true; } // For normal selects we are done, but procedures might // have more resultSets }while (isCallable && getMoreResults(JDBC30Translation.KEEP_CURRENT_RESULT)); return hasResultSet; } /** * 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 */ protected void finishParams() { needsToSendParamData = false; } /** * 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 cloudscape) * 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 cloudcape) * 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 cloudscape * 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) * @param pkgnamcsn package id section number and token from the client */ protected void setPkgnamcsn(Pkgnamcsn pkgnamcsn) { this.pkgnamcsn = pkgnamcsn; // Store the consistency string for the first ResultSet. // this will be used to calculate consistency strings for the // other result sets. pkgid = pkgnamcsn.getPkgid(); if (isDynamicPkgid(pkgid)) { isolationLevel = Integer.parseInt(pkgid.substring(5,6)); /* * generate DB2-style cursorname * example value : SQL_CURSN200C1 * where * SQL_CUR is db2 cursor name prefix; * S - Small package , L -Large package * N - normal cursor, H - hold cursor * 200 - package id as sent by jcc * C - tack-on code for cursors * 1 - section number sent by jcc */ // cursor name // trim the SYS off the pkgid so it wont' be in the cursor name String shortPkgid = pkgid.substring(pkgid.length() -5 , pkgid.length()); pkgsn = pkgnamcsn.getPkgsn(); this.cursorName = "SQL_CUR" + shortPkgid + "C" + pkgsn ; } else // static package { isolationLevel = getStaticPackageIsolation(pkgid); } this.pkgcnstkn = pkgnamcsn.getPkgcnstkn(); } /** * get the isolation level for a static package. * @param pkgid - Package identifier string (e.g. SYSSTAT) * @return isolation */ private int getStaticPackageIsolation(String pkgid) { // SYSSTAT is used for metadata. and is the only static package used // for JCC. Other static packages will need to be supported for // CCC. Maybe a static hash table would then be in order. if (pkgid.equals("SYSSTAT")) return ExecutionContext.READ_UNCOMMITTED_ISOLATION_LEVEL; else return ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL; } /** * Get pkgnamcsn * * @return pkgnamcsn */ protected Pkgnamcsn getPkgnamcsn() { return pkgnamcsn; } /** * Get result set * * @return result set */ protected ResultSet getResultSet() { return currentDrdaRs.getResultSet(); } /** * Just get the resultset. Don't set it to current * Assumes resultSet rsnum exists. * * @param rsNum resultSetNumber starting with 0 * @return The result set in the order it was retrieved * * with getMoreResults() **/ private ResultSet getResultSet(int rsNum) { if (rsNum == 0) return currentDrdaRs.getResultSet(); else { ConsistencyToken key = (ConsistencyToken) resultSetKeyList.get(rsNum); return ((DRDAResultSet) (resultSetTable.get( key))).getResultSet(); } } /** * Set result set * * @param value */ protected void setResultSet(ResultSet value) throws SQLException { if (currentDrdaRs.getResultSet() == null) numResultSets = 1; currentDrdaRs.setResultSet(value); setRsDefaultOptions(currentDrdaRs); } /** * Gets the current DRDA ResultSet * * @return DRDAResultSet */ protected DRDAResultSet getCurrentDrdaResultSet() { return currentDrdaRs ; } /** * Set currentDrdaResultSet * * @param rsNum The result set number starting with 0 * */ protected void setCurrentDrdaResultSet(int rsNum) { ConsistencyToken consistToken = getResultSetPkgcnstkn(rsNum); if (currentDrdaRs.pkgcnstkn == consistToken) return; currentDrdaRs = getDrdaResultSet(consistToken); } /** * Set currentDrdaResultSet * * @param pkgnamcsn The pkgid section number and unique resultset * consistency token * */ protected void setCurrentDrdaResultSet(Pkgnamcsn pkgnamcsn) { pkgid = pkgnamcsn.getPkgid(); pkgsn = pkgnamcsn.getPkgsn(); ConsistencyToken consistToken = pkgnamcsn.getPkgcnstkn(); DRDAResultSet newDrdaRs = getDrdaResultSet(consistToken); if (newDrdaRs != null) currentDrdaRs = newDrdaRs; } /* * get DRDAResultSet by consistency token * */ private DRDAResultSet getDrdaResultSet(ConsistencyToken consistToken) { if ( resultSetTable == null || (currentDrdaRs != null && currentDrdaRs.pkgcnstkn == consistToken )) { return currentDrdaRs; } else { return (DRDAResultSet) (resultSetTable.get(consistToken)); } } /* * get DRDAResultSet by result set number * */ private DRDAResultSet getDrdaResultSet(int rsNum) { ConsistencyToken consistToken = getResultSetPkgcnstkn(rsNum); return getDrdaResultSet(consistToken); } /** Add a new resultSet to this statement. * Set as the current result set if there is not an * existing current resultset. * @param value - ResultSet to add * @param holdValue - Holdability of the ResultSet * @return 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 */ protected ConsistencyToken addResultSet(ResultSet value, int holdValue) throws SQLException { DRDAResultSet newDrdaRs = null; int rsNum = numResultSets; ConsistencyToken newRsPkgcnstkn = calculateResultSetPkgcnstkn(rsNum); if (rsNum == 0) newDrdaRs = currentDrdaRs; else { newDrdaRs = new DRDAResultSet(); // Multiple resultSets we neeed to setup the hash table if (resultSetTable == null) { // If hashtable doesn't exist, create it and store resultSet 0 // before we store our new resultSet. // For just a single resultSet we don't ever create the Hashtable. resultSetTable = new Hashtable(); resultSetTable.put(pkgcnstkn, currentDrdaRs); resultSetKeyList = new ArrayList(); resultSetKeyList.add(0, pkgcnstkn); } resultSetTable.put(newRsPkgcnstkn, newDrdaRs); resultSetKeyList.add(rsNum, newRsPkgcnstkn); } newDrdaRs.setResultSet(value); newDrdaRs.setPkgcnstkn(newRsPkgcnstkn); newDrdaRs.withHoldCursor = holdValue; setRsDefaultOptions(newDrdaRs); newDrdaRs.suspend(); numResultSets++; return newRsPkgcnstkn; } /** * * @return number of result sets */ protected int getNumResultSets() { return numResultSets; } /** * @param rsNum result set starting with 0 * @return consistency token (key) for the result set */ protected ConsistencyToken getResultSetPkgcnstkn(int rsNum) { if (rsNum == 0) return pkgcnstkn; else return (ConsistencyToken) resultSetKeyList.get(rsNum); } /** * Set ResultSet DRDA DataTypes * @param value drdaTypes for columns. **/ protected void setRsDRDATypes(int [] value) { currentDrdaRs.setRsDRDATypes(value); } /** *@return ResultSet DRDA DataTypes **/ protected int[] getRsDRDATypes() { return currentDrdaRs.getRsDRDATypes(); } /** * Set ResultSet DRDA DataTypes Lengths * @param value drdaTypes for columns. **/ protected void setRsLens(int [] value) { currentDrdaRs.rsLens = value; } /** *@return ResultSet DRDA DataTypes Lengths **/ protected int[] getRsLens() { return currentDrdaRs.rsLens; } /** * Close the current resultSet */ protected void rsClose() throws SQLException { if (currentDrdaRs.getResultSet() == null) return; currentDrdaRs.close(); needsToSendParamData = false; numResultSets--; } /** * Explicitly close the result set by CLSQRY * needed to check for double close. */ protected void CLSQRY() { currentDrdaRs.CLSQRY(); } /* * @return whether CLSQRY has been called on the * current result set. */ protected boolean wasExplicitlyClosed() { return currentDrdaRs.wasExplicitlyClosed(); } /** * This method closes the JDBC objects and frees up all references held by * this object. * * @throws SQLException */ protected void close() throws SQLException { if (ps != null) ps.close(); if (stmt != null) stmt.close(); currentDrdaRs.close(); resultSetTable = null; resultSetKeyList = null; ps = null; stmtPmeta = null; stmt = null; rslsetflg = null; procName = null; outputTypes = null; cliParamDrdaTypes = null; cliParamLens = null; cliParamExtPositions = null; } /** * 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. * */ protected void reset() { setTypDefValues(); withHoldCursor = -1; scrollType = ResultSet.TYPE_FORWARD_ONLY; concurType = ResultSet.CONCUR_READ_ONLY;; rowCount = 0; rslsetflg = null; maxrslcnt = 0; ps = null; stmtPmeta = null; isCall = false; procName = null; outputTypes = null; outputExpected = false; stmt = null; currentDrdaRs.reset(); resultSetTable = null; resultSetKeyList = null; numResultSets = 0; cliParamDrdaTypes = new Vector(); cliParamLens = new Vector(); cliParamExtPositions = null; nbrrow = 0; qryrowset = 0; blksize = 0; maxblkext = 0; outovropt = 0; qryrfrtbl = false; qryprctyp = CodePoint.QRYBLKCTL_DEFAULT; needsToSendParamData = false; explicitlyPrepared = false; } /** * is Statement closed * @return whether the statement is closed */ protected boolean rsIsClosed() { return currentDrdaRs.isClosed(); } /** * Set state to SUSPENDED (result set is opened) */ protected void rsSuspend() { currentDrdaRs.suspend(); } /** * set resultset/out parameter precision * * @param index - starting with 1 * @param precision */ protected void setRsPrecision(int index, int precision) { currentDrdaRs.setRsPrecision(index,precision); } /** * get resultset /out paramter precision * @param index -starting with 1 * @return precision of column */ protected int getRsPrecision(int index) { return currentDrdaRs.getRsPrecision(index); } /** * set resultset/out parameter scale * * @param index - starting with 1 * @param scale */ protected void setRsScale(int index, int scale) { currentDrdaRs.setRsScale(index, scale); } /** * get resultset /out paramter scale * @param index -starting with 1 * @return scale of column */ protected int getRsScale(int index) { return currentDrdaRs.getRsScale(index); } /** * set result DRDAType * * @param index - starting with 1 * @param type */ protected void setRsDRDAType(int index, int type) { currentDrdaRs.setRsDRDAType(index,type); } /** * get parameter DRDAType * * @param index - starting with 1 * @return DRDA Type of column */ protected int getParamDRDAType(int index) { return ((Byte)cliParamDrdaTypes.get(index -1)).intValue(); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -