📄 drdaconnthread.java
字号:
* If TYPDEFNAM and TYPDEFOVR are supplied, they apply to the objects * sent with the statement. Once the statement is over, the default values * sent in the ACCRDB are once again in effect. If no values are supplied, * the values sent in the ACCRDB are used. * Objects may follow in one DSS or in several DSS chained together. * * @exception DRDAProtocolException, SQLException */ private void parseOPNQRYobjects(DRDAStatement stmt) throws DRDAProtocolException, SQLException { int codePoint; do { correlationID = reader.readDssHeader(); while (reader.moreDssData()) { codePoint = reader.readLengthAndCodePoint(); switch(codePoint) { // optional case CodePoint.TYPDEFNAM: setStmtOrDbByteOrder(false, stmt, parseTYPDEFNAM()); break; // optional case CodePoint.TYPDEFOVR: parseTYPDEFOVR(stmt); break; // optional case CodePoint.SQLDTA: parseSQLDTA(stmt); break; // optional case CodePoint.EXTDTA: readAndSetAllExtParams(stmt); break; default: invalidCodePoint(codePoint); } } } while (reader.isChainedWithSameID()); } /** * Parse OUTOVROPT - this indicates whether output description can be * overridden on just the first CNTQRY or on any CNTQRY * * @return output override option * @exception DRDAProtocolException */ private int parseOUTOVROPT() throws DRDAProtocolException { checkLength(CodePoint.OUTOVROPT, 1); int outovropt = reader.readUnsignedByte(); if (SanityManager.DEBUG) trace("output override option: "+outovropt); if (outovropt != CodePoint.OUTOVRFRS && outovropt != CodePoint.OUTOVRANY) invalidValue(CodePoint.OUTOVROPT); return outovropt; } /** * Parse QRYBLSZ - this gives the maximum size of the query blocks that * can be returned to the requester * * @return query block size * @exception DRDAProtocolException */ private int parseQRYBLKSZ() throws DRDAProtocolException { checkLength(CodePoint.QRYBLKSZ, 4); int blksize = reader.readNetworkInt(); if (SanityManager.DEBUG) trace("qryblksz = "+blksize); if (blksize < CodePoint.QRYBLKSZ_MIN || blksize > CodePoint.QRYBLKSZ_MAX) invalidValue(CodePoint.QRYBLKSZ); return blksize; } /** * Parse QRYROWSET - this is the number of rows to return * * @param minVal - minimum value * @return query row set size * @exception DRDAProtocolException */ private int parseQRYROWSET(int minVal) throws DRDAProtocolException { checkLength(CodePoint.QRYROWSET, 4); int qryrowset = reader.readNetworkInt(); if (SanityManager.DEBUG) trace("qryrowset = " + qryrowset); if (qryrowset < minVal || qryrowset > CodePoint.QRYROWSET_MAX) invalidValue(CodePoint.QRYROWSET); return qryrowset; } /** Parse a QRYCLSIMP - Implicitly close non-scrollable cursor * after end of data. * @return true to close on end of data */ private int parseQRYCLSIMP() throws DRDAProtocolException { checkLength(CodePoint.QRYCLSIMP, 1); int qryclsimp = reader.readUnsignedByte(); if (SanityManager.DEBUG) trace ("qryclsimp = " + qryclsimp); if (qryclsimp != CodePoint.QRYCLSIMP_SERVER_CHOICE && qryclsimp != CodePoint.QRYCLSIMP_YES && qryclsimp != CodePoint.QRYCLSIMP_NO ) invalidValue(CodePoint.QRYCLSIMP); return qryclsimp; } private int parseQRYCLSRLS() throws DRDAProtocolException { reader.skipBytes(); return 0; } private int parseQRYOPTVAL() throws DRDAProtocolException { reader.skipBytes(); return 0; } /** * Write a QRYPOPRM - Query Previously opened * Instance Variables * SVRCOD - Severity Code - required - 8 ERROR * RDBNAM - Relational Database Name - required * PKGNAMCSN - RDB Package Name, Consistency Token, and Section Number - required * * @exception DRDAProtocolException */ private void writeQRYPOPRM() throws DRDAProtocolException { writer.createDssReply(); writer.startDdm(CodePoint.QRYPOPRM); writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR); writeRDBNAM(database.dbName); writePKGNAMCSN(); writer.endDdmAndDss(); } /** * Write a QRYNOPRM - Query Not Opened * Instance Variables * SVRCOD - Severity Code - required - 4 Warning 8 ERROR * RDBNAM - Relational Database Name - required * PKGNAMCSN - RDB Package Name, Consistency Token, and Section Number - required * * @param svrCod Severity Code * @exception DRDAProtocolException */ private void writeQRYNOPRM(int svrCod) throws DRDAProtocolException { writer.createDssReply(); writer.startDdm(CodePoint.QRYNOPRM); writer.writeScalar2Bytes(CodePoint.SVRCOD, svrCod); writeRDBNAM(database.dbName); writePKGNAMCSN(); writer.endDdmAndDss(); } /** * Write a OPNQFLRM - Open Query Failure * Instance Variables * SVRCOD - Severity Code - required - 8 ERROR * RDBNAM - Relational Database Name - required * * @param e Exception describing failure * * @exception DRDAProtocolException */ private void writeOPNQFLRM(SQLException e) throws DRDAProtocolException { writer.createDssReply(); writer.startDdm(CodePoint.OPNQFLRM); writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR); writeRDBNAM(database.dbName); writer.endDdm(); writer.startDdm(CodePoint.SQLCARD); writeSQLCAGRP(e, getSqlCode(getExceptionSeverity(e)), 0, 0); writer.endDdmAndDss(); } /** * Write PKGNAMCSN * Instance Variables * NAMESYMDR - database name - not validated * RDBCOLID - RDB Collection Identifier * PKGID - RDB Package Identifier * PKGCNSTKN - RDB Package Consistency Token * PKGSN - RDB Package Section Number * * There are two possible formats, fixed and extended which includes length * information for the strings * * @exception throws DRDAProtocolException */ private void writePKGNAMCSN(byte[] pkgcnstkn) throws DRDAProtocolException { writer.startDdm(CodePoint.PKGNAMCSN); if (rdbnam.length() <= CodePoint.RDBNAM_LEN && rdbcolid.length() <= CodePoint.RDBCOLID_LEN && pkgid.length() <= CodePoint.PKGID_LEN) { // if none of RDBNAM, RDBCOLID and PKGID have a length of // more than 18, use fixed format writer.writeScalarPaddedString(rdbnam, CodePoint.RDBNAM_LEN); writer.writeScalarPaddedString(rdbcolid, CodePoint.RDBCOLID_LEN); writer.writeScalarPaddedString(pkgid, CodePoint.PKGID_LEN); writer.writeScalarPaddedBytes(pkgcnstkn, CodePoint.PKGCNSTKN_LEN, (byte) 0); writer.writeShort(pkgsn); } else // extended format { int len = Math.max(CodePoint.RDBNAM_LEN, rdbnam.length()); writer.writeShort(len); writer.writeScalarPaddedString(rdbnam, len); len = Math.max(CodePoint.RDBCOLID_LEN, rdbcolid.length()); writer.writeShort(len); writer.writeScalarPaddedString(rdbcolid, len); len = Math.max(CodePoint.PKGID_LEN, pkgid.length()); writer.writeShort(len); writer.writeScalarPaddedString(pkgid, len); writer.writeScalarPaddedBytes(pkgcnstkn, CodePoint.PKGCNSTKN_LEN, (byte) 0); writer.writeShort(pkgsn); } writer.endDdm(); } private void writePKGNAMCSN() throws DRDAProtocolException { writePKGNAMCSN(pkgcnstkn.getBytes()); } /** * Parse CNTQRY - Continue Query * Instance Variables * RDBNAM - Relational Database Name - optional * PKGNAMCSN - RDB Package Name, Consistency Token, and Section Number - required * QRYBLKSZ - Query Block Size - required * QRYRELSCR - Query Relative Scrolling Action - optional * QRYSCRORN - Query Scroll Orientation - optional - level 7 * QRYROWNBR - Query Row Number - optional * QRYROWSNS - Query Row Sensitivity - optional - level 7 * QRYBLKRST - Query Block Reset - optional - level 7 * QRYRTNDTA - Query Returns Data - optional - level 7 * QRYROWSET - Query Rowset Size - optional - level 7 * QRYRFRTBL - Query Refresh Answer Set Table - optional * NBRROW - Number of Fetch or Insert Rows - optional * MAXBLKEXT - Maximum number of extra blocks - optional * RTNEXTDTA - Return of EXTDTA Option - optional * MONITOR - Monitor events - optional. * * @return DRDAStatement we are continuing * @exception DRDAProtocolException, SQLException */ private DRDAStatement parseCNTQRY() throws DRDAProtocolException, SQLException { byte val; Pkgnamcsn pkgnamcsn = null; boolean gotQryblksz = false; boolean qryrelscr = true; long qryrownbr = 1; boolean qryrfrtbl = false; int nbrrow = 1; int blksize = 0; int maxblkext = -1; long qryinsid; boolean gotQryinsid = false; int qryscrorn = CodePoint.QRYSCRREL; boolean qryrowsns = false; boolean gotQryrowsns = false; boolean qryblkrst = false; boolean qryrtndta = true; int qryrowset = CodePoint.QRYROWSET_DEFAULT; int rtnextdta = CodePoint.RTNEXTROW; reader.markCollection(); int codePoint = reader.getCodePoint(); while (codePoint != -1) { switch(codePoint) { //optional case CodePoint.RDBNAM: setDatabase(CodePoint.CNTQRY); break; //required case CodePoint.PKGNAMCSN: pkgnamcsn = parsePKGNAMCSN(); break; //required case CodePoint.QRYBLKSZ: blksize = parseQRYBLKSZ(); gotQryblksz = true; break; //optional case CodePoint.QRYRELSCR: qryrelscr = readBoolean(CodePoint.QRYRELSCR); if (SanityManager.DEBUG) trace("qryrelscr = "+qryrelscr); break; //optional case CodePoint.QRYSCRORN: checkLength(CodePoint.QRYSCRORN, 1); qryscrorn = reader.readUnsignedByte(); if (SanityManager.DEBUG) trace("qryscrorn = "+qryscrorn); switch (qryscrorn) { case CodePoint.QRYSCRREL: case CodePoint.QRYSCRABS: case CodePoint.QRYSCRAFT: case CodePoint.QRYSCRBEF: break; default: invalidValue(CodePoint.QRYSCRORN); } break; //optional case CodePoint.QRYROWNBR: checkLength(CodePoint.QRYROWNBR, 8); qryrownbr = reader.readNetworkLong(); if (SanityManager.DEBUG) trace("qryrownbr = "+qryrownbr); break; //optional case CodePoint.QRYROWSNS: checkLength(CodePoint.QRYROWSNS, 1); qryrowsns = readBoolean(CodePoint.QRYROWSNS); if (SanityManager.DEBUG) trace("qryrowsns = "+qryrowsns); gotQryrowsns = true; break; //optional case CodePoint.QRYBLKRST: checkLength(CodePoint.QRYBLKRST, 1); qryblkrst = readBoolean(CodePoint.QRYBLKRST); if (SanityManager.DEBUG) trace("qryblkrst = "+qryblkrst); break; //optional case CodePoint.QRYRTNDTA: qryrtndta = readBoolean(CodePoint.QRYRTNDTA); if (SanityManager.DEBUG) trace("qryrtndta = "+qryrtndta); break; //optional case CodePoint.QRYROWSET: //Note minimum for CNTQRY is 1 qryrowset = parseQRYROWSET(1); if (SanityManager.DEBUG) trace("qryrowset = "+qryrowset); break; //optional case CodePoint.QRYRFRTBL: qryrfrtbl = readBoolean(CodePoint.QRYRFRTBL); if (SanityManager.DEBUG) trace("qryrfrtbl = "+qryrfrtbl); break; //optional case CodePoint.NBRROW: checkLength(CodePoint.NBRROW, 4); nbrrow = reader.readNetworkInt(); if (SanityManager.DEBUG) trace("nbrrow = "+nbrrow); break; //optional case CodePoint.MAXBLKEXT: checkLength(CodePoint.MAXBLKEXT, 2); maxblkext = reader.readSignedNetworkShort(); if (SanityManager.DEBUG) trace("maxblkext = "+maxblkext); break; //optional case CodePoint.RTNEXTDTA: checkLength(CodePoint.RTNEXTDTA, 1); rtnextdta = reader.readUnsignedByte(); if (rtnextdta != CodePoint.RTNEXTROW && rtnextdta != CodePoint.RTNEXTALL) invalidValue(CodePoint.RTNEXTDTA); if (SanityManager.DEBUG) trace("rtnextdta = "+rtnextdta); break; // required for SQLAM >= 7 case CodePoint.QRYINSID: checkLength(CodePoint.QRYINSID, 8); qryinsid = reader.readNetworkLong(); gotQryinsid = true; if (SanityManager.DEBUG) trace("qryinsid = "+qryinsid); break; // optional case CodePoint.MONITOR: parseMONITOR(); break; default: invalidCodePoint(codePoint); } codePoint = reader.getCodePoint(); } // check for required variables if (pkgnamcsn == null) missingCodePoint(CodePoint.PKGNAMCSN); if (!gotQryblksz) missingCodePoint(CodePoint.QRYBLKSZ); if (sqlamLevel >= MGRLVL_7 && !gotQryinsid) missingCodePoint(CodePoint.QRYINSID); // get the statement we are continuing DRDAStatement stmt = database.getDRDAStatement(pkgnamcsn); if (stmt == null) { //XXX should really throw a SQL Exception here invalidValue(CodePoint.CNTQRY); } if (stmt.rsIsClosed()) { writeQRYNOPRM(CodePoint.SVRCOD_ERROR); skipRemainder(true); return null; } stmt.setQueryOptions(blksize,qryrelscr,qryrownbr,qryrfrtbl,nbrrow,maxblkext, qryscrorn,qryrowsns,qryblkrst,qryrtndta,qryrowset, rtnextdta); if (reader.isChainedWithSameID()) parseCNTQRYobjects(stmt); return stmt; } /** * Skip remainder of current DSS and all chained DSS'es * * @param onlySkipSameIds True if we _only_ want to skip DSS'es * that are chained with the SAME id as the current DSS. * False means skip ALL chained DSSes, whether they're * chained with same or different ids. * @exception DRDAProt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -