Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 33518 invoked from network); 2 May 2005 06:33:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 May 2005 06:33:48 -0000 Received: (qmail 92366 invoked by uid 500); 2 May 2005 06:35:07 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 92275 invoked by uid 500); 2 May 2005 06:35:06 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 92208 invoked by uid 500); 2 May 2005 06:35:05 -0000 Delivered-To: apmail-incubator-derby-cvs@incubator.apache.org Received: (qmail 92184 invoked by uid 99); 2 May 2005 06:35:04 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 01 May 2005 23:34:56 -0700 Received: (qmail 31680 invoked by uid 65534); 2 May 2005 06:26:45 -0000 Message-ID: <20050502062645.31675.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r165585 [30/42] - in /incubator/derby/code/trunk/java/client/org/apache/derby: client/ client/am/ client/net/ client/resources/ jdbc/ Date: Mon, 02 May 2005 06:26:03 -0000 To: derby-cvs@incubator.apache.org From: jboynes@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/ne= t/NetIndoubtTransaction.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/net/NetIndoubtTransaction.java?rev=3D165585&r1=3D165= 584&r2=3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetI= ndoubtTransaction.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetI= ndoubtTransaction.java Sun May 1 23:25:59 2005 @@ -19,16 +19,15 @@ */ package org.apache.derby.client.net; =20 -import javax.transaction.xa.*; +import javax.transaction.xa.Xid; =20 /** - *

Title: dnc Project

- *

Description:

+ *

Title: dnc Project

Description:

+ * * @version 1.0 */ =20 -public class NetIndoubtTransaction -{ +public class NetIndoubtTransaction { =20 Xid xid_; byte[] uowid_; @@ -38,47 +37,40 @@ int port_; =20 protected NetIndoubtTransaction(Xid xid, - byte[] uowid, - byte[] cSyncLog, - byte[] pSyncLog, - String ipaddr, - int port) - { - xid_ =3D xid; - uowid_ =3D uowid; - cSyncLog_ =3D cSyncLog; - pSyncLog_ =3D pSyncLog; - ipaddr_ =3D ipaddr; - port_ =3D port; + byte[] uowid, + byte[] cSyncLog, + byte[] pSyncLog, + String ipaddr, + int port) { + xid_ =3D xid; + uowid_ =3D uowid; + cSyncLog_ =3D cSyncLog; + pSyncLog_ =3D pSyncLog; + ipaddr_ =3D ipaddr; + port_ =3D port; } =20 - protected Xid getXid() - { - return xid_; + protected Xid getXid() { + return xid_; } =20 - protected byte[] getUOWID() - { - return uowid_; + protected byte[] getUOWID() { + return uowid_; } =20 - protected byte[] getCSyncLog() - { - return cSyncLog_; + protected byte[] getCSyncLog() { + return cSyncLog_; } =20 - protected byte[] getPSyncLog() - { - return pSyncLog_; + protected byte[] getPSyncLog() { + return pSyncLog_; } =20 - protected String getIpAddr() - { - return ipaddr_; + protected String getIpAddr() { + return ipaddr_; } =20 - protected int getPort() - { - return port_; + protected int getPort() { + return port_; } } Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/ne= t/NetLogWriter.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/net/NetLogWriter.java?rev=3D165585&r1=3D165584&r2=3D= 165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetL= ogWriter.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetL= ogWriter.java Sun May 1 23:25:59 2005 @@ -23,394 +23,385 @@ // network traffic tracer. // This class traces communication buffers for both sends and receives. // The value of the hex bytes are traced along with the ascii and ebcdic t= ranslations. -public class NetLogWriter extends org.apache.derby.client.am.LogWriter -{ =20 - // The recevie constant is used to indicate that the bytes were read to = a Stream. - // It indicates to this class that a receive header should be used. - public static final int TYPE_TRACE_RECEIVE =3D 2; - - // The send constant is used to indicate that the bytes were written to - // a Stream. It indicates to this class that a send header should be us= ed. - public static final int TYPE_TRACE_SEND =3D 1; - - //------------------------------ internal constants --------------------= ------ - - // This class was implemented using character arrays to translate bytes - // into ascii and ebcdic. The goal was to be able to quickly index into= the - // arrays to find the characters. Char arrays instead of strings were u= sed as - // much as possible in an attempt to help speed up performance. - - // An array of characters used to translate bytes to ascii. - // The position in the array corresponds to the hex value of the charact= er. - private static final char asciiChar__ [] =3D { - // 0 1 2 3 4 5 6 7 8 9 A B C D E F - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //0 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //1 - ' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/', //2 - '0','1','2','3','4','5','6','7','8','9',':',';','<','=3D','>','?', //3 - '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', //4 - 'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_', //5 - '`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', //6 - 'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','.', //7 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //8 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //9 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //A - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //B - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //C - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //D - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //E - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' //F - }; - - // This column position header is used to mark offsets into the trace. - private static final String colPosHeader__ =3D - " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 01234567= 89ABCDEF"; - - // An array of characters used to translate bytes to ebcdic. - // The position in the array corresponds to the hex value of the - // character. - private static final char ebcdicChar__[] =3D { - // 0 1 2 3 4 5 6 7 8 9 A B C D E F - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //0 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //1 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //2 - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //3 - ' ','.','.','.','.','.','.','.','.','.','.','.','<','(','+','|', //4 - '&','.','.','.','.','.','.','.','.','.','!','$','*',')',';','.', //5 - '-','/','.','.','.','.','.','.','.','.','|',',','%','_','>','?', //6 - '.','.','.','.','.','.','.','.','.','`',':','#','@','\'','=3D','"', //7 - '.','a','b','c','d','e','f','g','h','i','.','.','.','.','.','.', //8 - '.','j','k','l','m','n','o','p','q','r','.','.','.','.','.','.', //9 - '.','~','s','t','u','v','w','x','y','z','.','.','.','.','.','.', //A - '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', //B - '{','A','B','C','D','E','F','G','H','I','.','.','.','.','.','.', //C - '}','J','K','L','M','N','O','P','Q','R','.','.','.','.','.','.', //D - '\\','.','S','T','U','V','W','X','Y','Z','.','.','.','.','.','.', //E - '0','1','2','3','4','5','6','7','8','9','.','.','.','.','.','.' //F - }; - - // An array of characters representing hex numbers. - private static final char hexDigit__ [] =3D { - '0','1','2','3','4','5','6','7', - '8','9','A','B','C','D','E','F' - }; - - // The receive header comes befor bytes which would be read from a strea= m=2E - private static final String receiveHeader__ =3D - " RECEIVE BUFFER: (ASCII) (EBCDIC)= "; - - // The send header comes before bytes which would be written to a stream. - private static final String sendHeader__ =3D - " SEND BUFFER: (ASCII) (EBCDIC)= "; - - private static final char spaceChar__ =3D ' '; - - private static final char zeroChar__ =3D '0'; - - // This mapping table associates a codepoint to a String describing the = codepoint. - // This is needed because the trace prints the first codepoint in send a= nd receive buffers. - // This is created lazily because there is no need to create the mapping= if tracing isn't used. - // So this array will only be created when the com buffer trace is start= ed. - private static CodePointNameTable codePointNameTable__ =3D null; - - //-----------------------------internal state---------------------------= ------ - - //-----------------------------constructors/finalizer-------------------= ------ - - // One NetLogWriter object is created per data source, iff tracing is en= abled. - public NetLogWriter (java.io.PrintWriter printWriter, int traceLevel) - { - super (printWriter, traceLevel); - - // Initialize the codepoint name table if not previously initialized. - // This is done lazily so that it is not created if the trace isn't us= ed (save some init time). - if (codePointNameTable__ =3D=3D null) { - codePointNameTable__ =3D new CodePointNameTable(); - } - } - - //------------------------------entry points----------------------------= ------ - - // Specialization of LogWriter.traceConnectsExit() - public void traceConnectsExit (org.apache.derby.client.am.Connection con= nection) - { - if (traceSuspended()) return; - NetConnection c =3D (NetConnection) connection; - synchronized (printWriter_) { - super.traceConnectsExit (c); - dncnetprint (" PROTOCOL manager levels: { "); - printWriter_.print ("SQLAM=3D" + c.getSQLAM() + ", "); - printWriter_.print ("AGENT=3D" + c.getAGENT() + ", "); - printWriter_.print ("CMNTCPIP=3D" + c.getCMNTCPIP() + ", "); - printWriter_.print ("RDB=3D" + c.getRDB() + ", "); - printWriter_.print ("SECMGR=3D" + c.getSECMGR() + ", "); - printWriter_.print ("XAMGR=3D" + c.getXAMGR() + ", "); - printWriter_.print ("SYNCPTMGR=3D" + c.getSYNCPTMGR() + ", "); - printWriter_.print ("RSYNCMGR=3D" + c.getRSYNCMGR()); - printWriter_.println (" }"); - printWriter_.flush(); - } - } - - public void traceConnectsResetExit (org.apache.derby.client.am.Connectio= n connection) - { - if (traceSuspended()) return; - NetConnection c =3D (NetConnection) connection; - synchronized (printWriter_) { - super.traceConnectsResetExit (c); - dncnetprint (" PROTOCOL manager levels: { "); - printWriter_.print ("SQLAM=3D" + c.getSQLAM() + ", "); - printWriter_.print ("AGENT=3D" + c.getAGENT() + ", "); - printWriter_.print ("CMNTCPIP=3D" + c.getCMNTCPIP() + ", "); - printWriter_.print ("RDB=3D" + c.getRDB() + ", "); - printWriter_.print ("SECMGR=3D" + c.getSECMGR() + ", "); - printWriter_.print ("XAMGR=3D" + c.getXAMGR() + ", "); - printWriter_.print ("SYNCPTMGR=3D" + c.getSYNCPTMGR() + ", "); - printWriter_.print ("RSYNCMGR=3D" + c.getRSYNCMGR()); - printWriter_.println (" }"); - printWriter_.flush(); - } - } - - // Pass the connection handle and print it in the header=20 - // What exactly is supposed to be passed, assume one complete DSS packet - // Write the communication buffer data to the trace. - // The data is passed in via a byte array. The start and length of the = data is given. - // The type is needed to indicate if the data is part of the send or rec= eive buffer. - // The class name, method name, and trcPt number are also written to the= trace. - // Not much checking is performed on the parameters. This is done to he= lp performance. - synchronized public void traceProtocolFlow (byte[] buff, - int offset, - int len, - int type, - String className, - String methodName, - int tracepoint) - { - if (traceSuspended()) return; - if (!loggingEnabled (org.apache.derby.jdbc.ClientDataSource.TRACE_PROT= OCOL_FLOWS)) return; - synchronized (printWriter_) { - super.tracepoint ("[net]", tracepoint, className, methodName); - - int fullLen =3D len; - boolean printColPos =3D true; - while( fullLen >=3D 2 ) - { // format each DssHdr seperately - // get the length of this DssHdr - len =3D ((buff[offset] & 0xff) << 8) + ((buff[offset+1] & 0xff) <<= 0); - - // check for valid dss header or not all of dss block - if ((len < 10) || (len > fullLen)) - len =3D fullLen; - - // subtract that length from the full length - fullLen -=3D len; - // The data will only be written if there is a non-zero positive len= gth. - if (len !=3D 0) { - String codePointName =3D null; - // If the length <=3D 10, lookup the first codepoint so it's name can be = printed - if (len >=3D 10) { - // Get the int value of the two byte unsigned codepoint. - int codePoint =3D getCodePoint (buff, offset+8); - codePointName =3D codePointNameTable__.lookup (codePoint); - - // if this is not a valid codepoint then format the entire buffer - // as one block. - if (codePointName =3D=3D null) - { - len +=3D fullLen; - fullLen =3D 0; - } - } - - if( !printColPos ) - { // not 1st Dss header of this buffer, write seperator - dncnetprintln( "" ); - } - - if (codePointName =3D=3D null) { - // codePointName was still null so either < 10 bytes were given or - // the codepoint wasn't found in the table. Just print the plain send = header. - dncnetprintln (getHeader (type)); - } - else { - // codePointName isn't null so the name of the codepoint will be printe= d=2E - printHeaderWithCodePointName (codePointName, type); - } - - // Print the col position header in the trace. - if( printColPos ) - { // first Dss header of buffer, need column position header - dncnetprintln (colPosHeader__); - printColPos =3D false; - } - - // A char array will be used to translate the bytes to their character - // representations along with ascii and ebcdic representations. - char trcDump[] =3D new char[77]; - - // bCounter, aCounter, eCounter are offsets used to help position the cha= racters - short bCounter =3D 7; - short aCounter =3D 43; - short eCounter =3D 61; - - // The lines will be counted starting at zero. - // This is hard coded since we are at the beginning. - trcDump[0] =3D zeroChar__; - trcDump[1] =3D zeroChar__; - trcDump[2] =3D zeroChar__; - trcDump[3] =3D zeroChar__; - - // The 0's are already in the trace so bump the line counter up a row. - int lineCounter =3D 0x10; - - // Make sure the character array has all blanks in it. - // Some of these blanks will be replaced later with values. - // The 0's were not wrote over. - for (int j =3D 4; j < 77; j++) { - trcDump[j] =3D spaceChar__; - } - - // i will maintain the position in the byte array to be traced. - int i =3D 0; - - do { - // Get the unsigned value of the byte. - // int num =3D b[off++] & 0xff; - int num =3D (buff[offset] < 0)? buff[offset] + 256 : buff[offset]; - offset++; - i++; - // Place the characters representing the bytes in the array. - trcDump[bCounter++] =3D hexDigit__[((num >>> 4) & 0xf)]; - trcDump[bCounter++] =3D hexDigit__[(num & 0xf)]; - - // Place the ascii and ebcdc representations in the array. - trcDump[aCounter++] =3D asciiChar__[num]; - trcDump[eCounter++] =3D ebcdicChar__[num]; - - if (((i%8) =3D=3D 0)) { - if (((i%16) =3D=3D 0)) { - // Print the array each time 16 bytes are processed. - dncnetprintln (trcDump); - if (i !=3D len) { - // Not yet at the end of the byte array. - if ((len - i) < 16) { - // This is the last line so blank it all out. - // This keeps the last line looking pretty in case - // < 16 bytes remain. - for (int j =3D 0; j < trcDump.length; j++) { - trcDump[j] =3D spaceChar__; - } - } - // Reset the counters. - bCounter =3D 0; - aCounter =3D 43; - eCounter =3D 61; - // Reset the lineCounter if it starts to get too large. - if (lineCounter =3D=3D 0x100000) { - lineCounter =3D 0; - } - // Place the characters representing the line counter in the array. - trcDump[bCounter++] =3D hexDigit__[((lineCounter >>> 12) & 0xf)]; - trcDump[bCounter++] =3D hexDigit__[((lineCounter >>> 8) & 0xf)]; - trcDump[bCounter++] =3D hexDigit__[((lineCounter >>> 4) & 0xf)]; - trcDump[bCounter++] =3D hexDigit__[(lineCounter & 0xf)]; - bCounter +=3D 3; - // Bump up the line counter. - lineCounter +=3D 0x10; - } - } - else { - // 8 bytes were processed so move the counter to adjust for - // spaces between the columns of bytes. - bCounter +=3D 2; - } - } - // do this until we all the data has been traced. - } - while (i < len); - - // print the last line and add some blank lines to make it easier to read. - if (len % 16 !=3D 0) { - dncnetprintln (trcDump); - } - } - } - dncnetprintln (""); - } - } - - // Gets the int value of the two byte unsigned codepoint. - private static int getCodePoint (byte[] buff, int offset) - { - return ((buff[offset++] & 0xff) << 8) + - ((buff[offset] & 0xff) << 0); - } - - private static String getHeader (int type) - { - switch (type) { - case TYPE_TRACE_SEND: - return sendHeader__; - case TYPE_TRACE_RECEIVE: - return receiveHeader__; - default: - return null; - } - } - - private static int getStartPosition (int type) - { - switch (type) { - case TYPE_TRACE_SEND: - return 20; // This is right after 'SEND BUFFER: '. - case TYPE_TRACE_RECEIVE: - return 23; // This is right after 'RECEIVE BUFFER: '. - default: - return 0; - } - } - - private void printHeaderWithCodePointName (String codePointName, int typ= e) - { - // Create a char array so some of the characters - // can be replaced with the name of the codepoint. - char headerArray[] =3D getHeader(type).toCharArray(); - - // At most, 16 character name will be used. This is so - // the headers on top of the ascii and ebcdic rows aren't shifted. - int replaceLen =3D (codePointName.length() < 17) ? codePointName.lengt= h() : 16; - - int offset =3D getStartPosition (type); - for (int i =3D 0; i < replaceLen; i++) { - headerArray[offset++] =3D codePointName.charAt (i);=20 - } - dncnetprintln (headerArray); - } - - private void dncnetprint (String s) - { - synchronized (printWriter_) { - printWriter_.print ("[derby] " + s); - printWriter_.flush(); - } - } - - private void dncnetprintln (String s) - { - synchronized (printWriter_) { - printWriter_.println ("[derby] " + s); - printWriter_.flush(); - } - } - - private void dncnetprintln (char[] s) - { - synchronized (printWriter_) { - printWriter_.print ("[derby] "); - printWriter_.println (s); - printWriter_.flush(); +public class NetLogWriter extends org.apache.derby.client.am.LogWriter { + + // The recevie constant is used to indicate that the bytes were read t= o a Stream. + // It indicates to this class that a receive header should be used. + public static final int TYPE_TRACE_RECEIVE =3D 2; + + // The send constant is used to indicate that the bytes were written to + // a Stream. It indicates to this class that a send header should be = used. + public static final int TYPE_TRACE_SEND =3D 1; + + //------------------------------ internal constants ------------------= -------- + + // This class was implemented using character arrays to translate bytes + // into ascii and ebcdic. The goal was to be able to quickly index in= to the + // arrays to find the characters. Char arrays instead of strings were= used as + // much as possible in an attempt to help speed up performance. + + // An array of characters used to translate bytes to ascii. + // The position in the array corresponds to the hex value of the chara= cter. + private static final char asciiChar__ [] =3D { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //0 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //1 + ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', = '-', '.', '/', //2 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '= =3D', '>', '?', //3 + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', '= M', 'N', 'O', //4 + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', = ']', '^', '_', //5 + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', '= m', 'n', 'o', //6 + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '= }', '~', '.', //7 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //8 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //9 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //A + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //B + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //C + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //D + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //E + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.' //F + }; + + // This column position header is used to mark offsets into the trace. + private static final String colPosHeader__ =3D + " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF = 0123456789ABCDEF"; + + // An array of characters used to translate bytes to ebcdic. + // The position in the array corresponds to the hex value of the + // character. + private static final char ebcdicChar__[] =3D { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //0 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //1 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //2 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //3 + ' ', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '<', '= (', '+', '|', //4 + '&', '.', '.', '.', '.', '.', '.', '.', '.', '.', '!', '$', '*', '= )', ';', '.', //5 + '-', '/', '.', '.', '.', '.', '.', '.', '.', '.', '|', ',', '%', '= _', '>', '?', //6 + '.', '.', '.', '.', '.', '.', '.', '.', '.', '`', ':', '#', '@', '= \'', '=3D', '"', //7 + '.', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', '.', '.', '.', '= .', '.', '.', //8 + '.', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', '.', '.', '.', '= .', '.', '.', //9 + '.', '~', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '.', '.', '.', '= .', '.', '.', //A + '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '= .', '.', '.', //B + '{', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', '.', '.', '.', '= .', '.', '.', //C + '}', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', '.', '.', '.', '= .', '.', '.', //D + '\\', '.', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.', '.', '.', = '=2E', '.', '.', //E + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '.', '.', '= .', '.', '.' //F + }; + + // An array of characters representing hex numbers. + private static final char hexDigit__ [] =3D { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' + }; + + // The receive header comes befor bytes which would be read from a str= eam. + private static final String receiveHeader__ =3D + " RECEIVE BUFFER: (ASCII) = (EBCDIC)"; + + // The send header comes before bytes which would be written to a stre= am. + private static final String sendHeader__ =3D + " SEND BUFFER: (ASCII) = (EBCDIC)"; + + private static final char spaceChar__ =3D ' '; + + private static final char zeroChar__ =3D '0'; + + // This mapping table associates a codepoint to a String describing th= e codepoint. + // This is needed because the trace prints the first codepoint in send= and receive buffers. + // This is created lazily because there is no need to create the mappi= ng if tracing isn't used. + // So this array will only be created when the com buffer trace is sta= rted. + private static CodePointNameTable codePointNameTable__ =3D null; + + //-----------------------------internal state-------------------------= -------- + + //-----------------------------constructors/finalizer-----------------= -------- + + // One NetLogWriter object is created per data source, iff tracing is = enabled. + public NetLogWriter(java.io.PrintWriter printWriter, int traceLevel) { + super(printWriter, traceLevel); + + // Initialize the codepoint name table if not previously initializ= ed. + // This is done lazily so that it is not created if the trace isn'= t used (save some init time). + if (codePointNameTable__ =3D=3D null) { + codePointNameTable__ =3D new CodePointNameTable(); + } + } + + //------------------------------entry points--------------------------= -------- + + // Specialization of LogWriter.traceConnectsExit() + public void traceConnectsExit(org.apache.derby.client.am.Connection co= nnection) { + if (traceSuspended()) { + return; + } + NetConnection c =3D (NetConnection) connection; + synchronized (printWriter_) { + super.traceConnectsExit(c); + dncnetprint(" PROTOCOL manager levels: { "); + printWriter_.print("SQLAM=3D" + c.getSQLAM() + ", "); + printWriter_.print("AGENT=3D" + c.getAGENT() + ", "); + printWriter_.print("CMNTCPIP=3D" + c.getCMNTCPIP() + ", "); + printWriter_.print("RDB=3D" + c.getRDB() + ", "); + printWriter_.print("SECMGR=3D" + c.getSECMGR() + ", "); + printWriter_.print("XAMGR=3D" + c.getXAMGR() + ", "); + printWriter_.print("SYNCPTMGR=3D" + c.getSYNCPTMGR() + ", "); + printWriter_.print("RSYNCMGR=3D" + c.getRSYNCMGR()); + printWriter_.println(" }"); + printWriter_.flush(); + } + } + + public void traceConnectsResetExit(org.apache.derby.client.am.Connecti= on connection) { + if (traceSuspended()) { + return; + } + NetConnection c =3D (NetConnection) connection; + synchronized (printWriter_) { + super.traceConnectsResetExit(c); + dncnetprint(" PROTOCOL manager levels: { "); + printWriter_.print("SQLAM=3D" + c.getSQLAM() + ", "); + printWriter_.print("AGENT=3D" + c.getAGENT() + ", "); + printWriter_.print("CMNTCPIP=3D" + c.getCMNTCPIP() + ", "); + printWriter_.print("RDB=3D" + c.getRDB() + ", "); + printWriter_.print("SECMGR=3D" + c.getSECMGR() + ", "); + printWriter_.print("XAMGR=3D" + c.getXAMGR() + ", "); + printWriter_.print("SYNCPTMGR=3D" + c.getSYNCPTMGR() + ", "); + printWriter_.print("RSYNCMGR=3D" + c.getRSYNCMGR()); + printWriter_.println(" }"); + printWriter_.flush(); + } + } + + // Pass the connection handle and print it in the header + // What exactly is supposed to be passed, assume one complete DSS pac= ket + // Write the communication buffer data to the trace. + // The data is passed in via a byte array. The start and length of th= e data is given. + // The type is needed to indicate if the data is part of the send or r= eceive buffer. + // The class name, method name, and trcPt number are also written to t= he trace. + // Not much checking is performed on the parameters. This is done to = help performance. + synchronized public void traceProtocolFlow(byte[] buff, + int offset, + int len, + int type, + String className, + String methodName, + int tracepoint) { + if (traceSuspended()) { + return; + } + if (!loggingEnabled(org.apache.derby.jdbc.ClientDataSource.TRACE_P= ROTOCOL_FLOWS)) { + return; + } + synchronized (printWriter_) { + super.tracepoint("[net]", tracepoint, className, methodName); + + int fullLen =3D len; + boolean printColPos =3D true; + while (fullLen >=3D 2) { // format each DssHdr seperately + // get the length of this DssHdr + len =3D ((buff[offset] & 0xff) << 8) + ((buff[offset + 1] = & 0xff) << 0); + + // check for valid dss header or not all of dss block + if ((len < 10) || (len > fullLen)) { + len =3D fullLen; + } + + // subtract that length from the full length + fullLen -=3D len; + // The data will only be written if there is a non-zero po= sitive length. + if (len !=3D 0) { + String codePointName =3D null; + // If the length <=3D 10, lookup the first codepoint s= o it's name can be printed + if (len >=3D 10) { + // Get the int value of the two byte unsigned code= point. + int codePoint =3D getCodePoint(buff, offset + 8); + codePointName =3D codePointNameTable__.lookup(code= Point); + + // if this is not a valid codepoint then format th= e entire buffer + // as one block. + if (codePointName =3D=3D null) { + len +=3D fullLen; + fullLen =3D 0; + } + } + + if (!printColPos) { // not 1st Dss header of this buff= er, write seperator + dncnetprintln(""); + } + + if (codePointName =3D=3D null) { + // codePointName was still null so either < 10 byt= es were given or + // the codepoint wasn't found in the table. Just = print the plain send header. + dncnetprintln(getHeader(type)); + } else { + // codePointName isn't null so the name of the cod= epoint will be printed. + printHeaderWithCodePointName(codePointName, type); + } + + // Print the col position header in the trace. + if (printColPos) { // first Dss header of buffer, need= column position header + dncnetprintln(colPosHeader__); + printColPos =3D false; + } + + // A char array will be used to translate the bytes to= their character + // representations along with ascii and ebcdic represe= ntations. + char trcDump[] =3D new char[77]; + + // bCounter, aCounter, eCounter are offsets used to he= lp position the characters + short bCounter =3D 7; + short aCounter =3D 43; + short eCounter =3D 61; + + // The lines will be counted starting at zero. + // This is hard coded since we are at the beginning. + trcDump[0] =3D zeroChar__; + trcDump[1] =3D zeroChar__; + trcDump[2] =3D zeroChar__; + trcDump[3] =3D zeroChar__; + + // The 0's are already in the trace so bump the line c= ounter up a row. + int lineCounter =3D 0x10; + + // Make sure the character array has all blanks in it. + // Some of these blanks will be replaced later with va= lues. + // The 0's were not wrote over. + for (int j =3D 4; j < 77; j++) { + trcDump[j] =3D spaceChar__; + } + + // i will maintain the position in the byte array to b= e traced. + int i =3D 0; + + do { + // Get the unsigned value of the byte. + // int num =3D b[off++] & 0xff; + int num =3D (buff[offset] < 0) ? buff[offset] + 25= 6 : buff[offset]; + offset++; + i++; + // Place the characters representing the bytes in = the array. + trcDump[bCounter++] =3D hexDigit__[((num >>> 4) & = 0xf)]; + trcDump[bCounter++] =3D hexDigit__[(num & 0xf)]; + + // Place the ascii and ebcdc representations in th= e array. + trcDump[aCounter++] =3D asciiChar__[num]; + trcDump[eCounter++] =3D ebcdicChar__[num]; + + if (((i % 8) =3D=3D 0)) { + if (((i % 16) =3D=3D 0)) { + // Print the array each time 16 bytes are = processed. + dncnetprintln(trcDump); + if (i !=3D len) { + // Not yet at the end of the byte arra= y=2E + if ((len - i) < 16) { + // This is the last line so blank = it all out. + // This keeps the last line lookin= g pretty in case + // < 16 bytes remain. + for (int j =3D 0; j < trcDump.leng= th; j++) { + trcDump[j] =3D spaceChar__; + } + } + // Reset the counters. + bCounter =3D 0; + aCounter =3D 43; + eCounter =3D 61; + // Reset the lineCounter if it starts = to get too large. + if (lineCounter =3D=3D 0x100000) { + lineCounter =3D 0; + } + // Place the characters representing t= he line counter in the array. + trcDump[bCounter++] =3D hexDigit__[((l= ineCounter >>> 12) & 0xf)]; + trcDump[bCounter++] =3D hexDigit__[((l= ineCounter >>> 8) & 0xf)]; + trcDump[bCounter++] =3D hexDigit__[((l= ineCounter >>> 4) & 0xf)]; + trcDump[bCounter++] =3D hexDigit__[(li= neCounter & 0xf)]; + bCounter +=3D 3; + // Bump up the line counter. + lineCounter +=3D 0x10; + } + } else { + // 8 bytes were processed so move the coun= ter to adjust for + // spaces between the columns of bytes. + bCounter +=3D 2; + } + } + // do this until we all the data has been traced. + } while (i < len); + + // print the last line and add some blank lines to mak= e it easier to read. + if (len % 16 !=3D 0) { + dncnetprintln(trcDump); + } + } + } + dncnetprintln(""); + } + } + + // Gets the int value of the two byte unsigned codepoint. + private static int getCodePoint(byte[] buff, int offset) { + return ((buff[offset++] & 0xff) << 8) + + ((buff[offset] & 0xff) << 0); + } + + private static String getHeader(int type) { + switch (type) { + case TYPE_TRACE_SEND: + return sendHeader__; + case TYPE_TRACE_RECEIVE: + return receiveHeader__; + default: + return null; + } + } + + private static int getStartPosition(int type) { + switch (type) { + case TYPE_TRACE_SEND: + return 20; // This is right after 'SEND BUFFER: '. + case TYPE_TRACE_RECEIVE: + return 23; // This is right after 'RECEIVE BUFFER: '. + default: + return 0; + } + } + + private void printHeaderWithCodePointName(String codePointName, int ty= pe) { + // Create a char array so some of the characters + // can be replaced with the name of the codepoint. + char headerArray[] =3D getHeader(type).toCharArray(); + + // At most, 16 character name will be used. This is so + // the headers on top of the ascii and ebcdic rows aren't shifted. + int replaceLen =3D (codePointName.length() < 17) ? codePointName.l= ength() : 16; + + int offset =3D getStartPosition(type); + for (int i =3D 0; i < replaceLen; i++) { + headerArray[offset++] =3D codePointName.charAt(i); + } + dncnetprintln(headerArray); + } + + private void dncnetprint(String s) { + synchronized (printWriter_) { + printWriter_.print("[derby] " + s); + printWriter_.flush(); + } + } + + private void dncnetprintln(String s) { + synchronized (printWriter_) { + printWriter_.println("[derby] " + s); + printWriter_.flush(); + } + } + + private void dncnetprintln(char[] s) { + synchronized (printWriter_) { + printWriter_.print("[derby] "); + printWriter_.println(s); + printWriter_.flush(); + } } - } } Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/ne= t/NetPackageReply.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/net/NetPackageReply.java?rev=3D165585&r1=3D165584&r2= =3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetP= ackageReply.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetP= ackageReply.java Sun May 1 23:25:59 2005 @@ -22,194 +22,189 @@ =20 import org.apache.derby.client.am.DisconnectException; =20 -public class NetPackageReply extends NetConnectionReply -{ - NetPackageReply (NetAgent netAgent, int bufferSize) - { - super (netAgent, bufferSize); - } - - - NetSqlca parseSqlErrorCondition () throws DisconnectException - { - parseSQLERRRM(); - parseTypdefsOrMgrlvlovrs (); - NetSqlca netSqlca =3D parseSQLCARD (null); - return netSqlca; - } - - - // Also called by NetStatementReply - void parseDTAMCHRM () throws DisconnectException - { - boolean svrcodReceived =3D false; - int svrcod =3D CodePoint.SVRCOD_INFO; - boolean rdbnamReceived =3D false; - String rdbnam =3D null; - - parseLengthAndMatchCodePoint (CodePoint.DTAMCHRM); - pushLengthOnCollectionStack(); - int peekCP =3D peekCodePoint(); - - while (peekCP !=3D Reply.END_OF_COLLECTION) { - - boolean foundInPass =3D false; - - if (peekCP =3D=3D CodePoint.SVRCOD) { - foundInPass =3D true; - svrcodReceived =3D checkAndGetReceivedFlag (svrcodReceived); - svrcod =3D parseSVRCOD (CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_E= RROR); - peekCP =3D peekCodePoint(); - } - - if (peekCP =3D=3D CodePoint.RDBNAM) { - foundInPass =3D true; - rdbnamReceived =3D checkAndGetReceivedFlag (rdbnamReceived); - rdbnam =3D parseRDBNAM (true); - peekCP =3D peekCodePoint(); - } - - if (!foundInPass) - doPrmnsprmSemantics (peekCP); - - } - popCollectionStack(); - checkRequiredObjects (svrcodReceived, rdbnamReceived); - - netAgent_.setSvrcod (svrcod); - doDtamchrmSemantics(); - } - - // RDB Update Reply Message indicates that a DDM command resulted - // in an update at the target relational database. If a command - // generated multiple reply messages including an RDBUPDRM, then - // the RDBUPDRM must be the first reply message for the command. - // For each target server, the RDBUPDRM must be returned the first - // time an update is made to the target RDB within a unit of work. - // The target server may optionally return the RDBUPDRM after subsequent - // updates within the UOW. If multiple target RDBs are involved with - // the current UOW and updates are made with any of them, then the RDBUP= DRM - // must be returned in response to the first update at each of them. - protected void parseRDBUPDRM () throws DisconnectException - { - boolean svrcodReceived =3D false; - int svrcod =3D CodePoint.SVRCOD_INFO; - boolean rdbnamReceived =3D false; - String rdbnam =3D null; - - parseLengthAndMatchCodePoint (CodePoint.RDBUPDRM); - pushLengthOnCollectionStack(); - - // in XA Global transaction we need to know if we have a read-only - // transaction, if we get a RDBUPDRM this is NOT a read-only transact= ion - // currently only XAConnections care about read-only transactions, if - // non-XA wants this information they will need to initialize the flag - // at start of UOW - netAgent_.netConnection_.setReadOnlyTransactionFlag( false ); - - int peekCP =3D peekCodePoint(); - - while (peekCP !=3D Reply.END_OF_COLLECTION) { - - boolean foundInPass =3D false; - - if (peekCP =3D=3D CodePoint.SVRCOD) { - foundInPass =3D true; - svrcodReceived =3D checkAndGetReceivedFlag (svrcodReceived); - svrcod =3D parseSVRCOD (CodePoint.SVRCOD_INFO, CodePoint.SVRCOD_IN= FO); - peekCP =3D peekCodePoint(); - } - - if (peekCP =3D=3D CodePoint.RDBNAM) { - foundInPass =3D true; - rdbnamReceived =3D checkAndGetReceivedFlag (rdbnamReceived); - rdbnam =3D parseRDBNAM (true); - peekCP =3D peekCodePoint(); - } - - if (!foundInPass) - doPrmnsprmSemantics (peekCP); - - } - popCollectionStack(); - checkRequiredObjects (svrcodReceived, rdbnamReceived); - - // call an event to indicate the server has been updated=20 - netAgent_.setSvrcod (svrcod); - - } - - // SQL Error Condition Reply Message indicates that an SQL error - // has occurred. It may be sent even though no reply message - // precedes the SQLCARD object that is the normal - // response to a command when an exception occurs. - // The SQLERRM is also used when a BNDSQLSTT command is terminated - // by an INTRRDBRQS command. - // This reply message must precede an SQLCARD object. - // The SQLSTATE is returned in the SQLCARD. - // - // Returned from Server: - // SVRCOD - required (8 - ERROR) - // RDBNAM - optional - // - // Also called by NetResultSetReply and NetStatementReply - void parseSQLERRRM () throws DisconnectException - { - boolean svrcodReceived =3D false; - int svrcod =3D CodePoint.SVRCOD_INFO; - boolean rdbnamReceived =3D false; - String rdbnam =3D null; - - parseLengthAndMatchCodePoint (CodePoint.SQLERRRM); - pushLengthOnCollectionStack(); - int peekCP =3D peekCodePoint(); - - while (peekCP !=3D Reply.END_OF_COLLECTION) { - - boolean foundInPass =3D false; - - if (peekCP =3D=3D CodePoint.SVRCOD) { - foundInPass =3D true; - svrcodReceived =3D checkAndGetReceivedFlag (svrcodReceived); - svrcod =3D parseSVRCOD (CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_E= RROR); - peekCP =3D peekCodePoint(); - } - - if (peekCP =3D=3D CodePoint.RDBNAM) { - foundInPass =3D true; - rdbnamReceived =3D checkAndGetReceivedFlag (rdbnamReceived); - rdbnam =3D parseRDBNAM (true); - peekCP =3D peekCodePoint(); - } - - if (!foundInPass) - doPrmnsprmSemantics (peekCP); - - } - popCollectionStack(); - checkRequiredObjects (svrcodReceived); - - // move into a method - netAgent_.setSvrcod (svrcod); - } - - //--------------------- parse DDM Reply Data----------------------------= ---------- - - //------------------------parse DDM Scalars----------------------------- - - // RDB Package Name and Consistency token Scalar Object specifies the - // fully qualified name of a relational database package and its - // consistency token. - protected Object parsePKGNAMCT (boolean skip) throws DisconnectException - { - parseLengthAndMatchCodePoint (CodePoint.PKGNAMCT); - if (skip) { - skipBytes(); - return null; - } - agent_.accumulateChainBreakingReadExceptionAndThrow (new DisconnectExc= eption ( - agent_, - "parsePKGNAMCT not yet implemented")); - return null; // to make compiler happy - } +public class NetPackageReply extends NetConnectionReply { + NetPackageReply(NetAgent netAgent, int bufferSize) { + super(netAgent, bufferSize); + } + + + NetSqlca parseSqlErrorCondition() throws DisconnectException { + parseSQLERRRM(); + parseTypdefsOrMgrlvlovrs(); + NetSqlca netSqlca =3D parseSQLCARD(null); + return netSqlca; + } + + + // Also called by NetStatementReply + void parseDTAMCHRM() throws DisconnectException { + boolean svrcodReceived =3D false; + int svrcod =3D CodePoint.SVRCOD_INFO; + boolean rdbnamReceived =3D false; + String rdbnam =3D null; + + parseLengthAndMatchCodePoint(CodePoint.DTAMCHRM); + pushLengthOnCollectionStack(); + int peekCP =3D peekCodePoint(); + + while (peekCP !=3D Reply.END_OF_COLLECTION) { + + boolean foundInPass =3D false; + + if (peekCP =3D=3D CodePoint.SVRCOD) { + foundInPass =3D true; + svrcodReceived =3D checkAndGetReceivedFlag(svrcodReceived); + svrcod =3D parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.S= VRCOD_ERROR); + peekCP =3D peekCodePoint(); + } + + if (peekCP =3D=3D CodePoint.RDBNAM) { + foundInPass =3D true; + rdbnamReceived =3D checkAndGetReceivedFlag(rdbnamReceived); + rdbnam =3D parseRDBNAM(true); + peekCP =3D peekCodePoint(); + } + + if (!foundInPass) { + doPrmnsprmSemantics(peekCP); + } + + } + popCollectionStack(); + checkRequiredObjects(svrcodReceived, rdbnamReceived); + + netAgent_.setSvrcod(svrcod); + doDtamchrmSemantics(); + } + + // RDB Update Reply Message indicates that a DDM command resulted + // in an update at the target relational database. If a command + // generated multiple reply messages including an RDBUPDRM, then + // the RDBUPDRM must be the first reply message for the command. + // For each target server, the RDBUPDRM must be returned the first + // time an update is made to the target RDB within a unit of work. + // The target server may optionally return the RDBUPDRM after subseque= nt + // updates within the UOW. If multiple target RDBs are involved with + // the current UOW and updates are made with any of them, then the RDB= UPDRM + // must be returned in response to the first update at each of them. + protected void parseRDBUPDRM() throws DisconnectException { + boolean svrcodReceived =3D false; + int svrcod =3D CodePoint.SVRCOD_INFO; + boolean rdbnamReceived =3D false; + String rdbnam =3D null; + + parseLengthAndMatchCodePoint(CodePoint.RDBUPDRM); + pushLengthOnCollectionStack(); + + // in XA Global transaction we need to know if we have a read-only + // transaction, if we get a RDBUPDRM this is NOT a read-only tran= saction + // currently only XAConnections care about read-only transactions= , if + // non-XA wants this information they will need to initialize the= flag + // at start of UOW + netAgent_.netConnection_.setReadOnlyTransactionFlag(false); + + int peekCP =3D peekCodePoint(); + + while (peekCP !=3D Reply.END_OF_COLLECTION) { + + boolean foundInPass =3D false; + + if (peekCP =3D=3D CodePoint.SVRCOD) { + foundInPass =3D true; + svrcodReceived =3D checkAndGetReceivedFlag(svrcodReceived); + svrcod =3D parseSVRCOD(CodePoint.SVRCOD_INFO, CodePoint.SV= RCOD_INFO); + peekCP =3D peekCodePoint(); + } + + if (peekCP =3D=3D CodePoint.RDBNAM) { + foundInPass =3D true; + rdbnamReceived =3D checkAndGetReceivedFlag(rdbnamReceived); + rdbnam =3D parseRDBNAM(true); + peekCP =3D peekCodePoint(); + } + + if (!foundInPass) { + doPrmnsprmSemantics(peekCP); + } + + } + popCollectionStack(); + checkRequiredObjects(svrcodReceived, rdbnamReceived); + + // call an event to indicate the server has been updated + netAgent_.setSvrcod(svrcod); + + } + + // SQL Error Condition Reply Message indicates that an SQL error + // has occurred. It may be sent even though no reply message + // precedes the SQLCARD object that is the normal + // response to a command when an exception occurs. + // The SQLERRM is also used when a BNDSQLSTT command is terminated + // by an INTRRDBRQS command. + // This reply message must precede an SQLCARD object. + // The SQLSTATE is returned in the SQLCARD. + // + // Returned from Server: + // SVRCOD - required (8 - ERROR) + // RDBNAM - optional + // + // Also called by NetResultSetReply and NetStatementReply + void parseSQLERRRM() throws DisconnectException { + boolean svrcodReceived =3D false; + int svrcod =3D CodePoint.SVRCOD_INFO; + boolean rdbnamReceived =3D false; + String rdbnam =3D null; + + parseLengthAndMatchCodePoint(CodePoint.SQLERRRM); + pushLengthOnCollectionStack(); + int peekCP =3D peekCodePoint(); + + while (peekCP !=3D Reply.END_OF_COLLECTION) { + + boolean foundInPass =3D false; + + if (peekCP =3D=3D CodePoint.SVRCOD) { + foundInPass =3D true; + svrcodReceived =3D checkAndGetReceivedFlag(svrcodReceived); + svrcod =3D parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.S= VRCOD_ERROR); + peekCP =3D peekCodePoint(); + } + + if (peekCP =3D=3D CodePoint.RDBNAM) { + foundInPass =3D true; + rdbnamReceived =3D checkAndGetReceivedFlag(rdbnamReceived); + rdbnam =3D parseRDBNAM(true); + peekCP =3D peekCodePoint(); + } + + if (!foundInPass) { + doPrmnsprmSemantics(peekCP); + } + + } + popCollectionStack(); + checkRequiredObjects(svrcodReceived); + + // move into a method + netAgent_.setSvrcod(svrcod); + } + + //--------------------- parse DDM Reply Data--------------------------= ------------ + + //------------------------parse DDM Scalars---------------------------= -- + + // RDB Package Name and Consistency token Scalar Object specifies the + // fully qualified name of a relational database package and its + // consistency token. + protected Object parsePKGNAMCT(boolean skip) throws DisconnectExceptio= n { + parseLengthAndMatchCodePoint(CodePoint.PKGNAMCT); + if (skip) { + skipBytes(); + return null; + } + agent_.accumulateChainBreakingReadExceptionAndThrow(new Disconnect= Exception(agent_, + "parsePKGNAMCT not yet implemented")); + return null; // to make compiler happy + } } Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/ne= t/NetPackageRequest.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/net/NetPackageRequest.java?rev=3D165585&r1=3D165584&= r2=3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetP= ackageRequest.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetP= ackageRequest.java Sun May 1 23:25:59 2005 @@ -24,287 +24,271 @@ import org.apache.derby.client.am.SqlException; =20 =20 -public class NetPackageRequest extends NetConnectionRequest -{ - static final String COLLECTIONNAME =3D "NULLID"; - - NetPackageRequest (NetAgent netAgent, CcsidManager ccsidManager, int buf= ferSize) - { - super (netAgent, ccsidManager, bufferSize); - } - - // RDB Package Name, Consistency Token - // Scalar Object specifies the fully qualified name of a relational - // database package and its consistency token. - // - // To accomodate larger lengths, the Scalar Data Length - // (SCLDTALEN) Field is used to specify the length of the instance - // variable which follows. - static final String collectionName =3D "NULLID"; - void buildCommonPKGNAMinfo (Section section) throws SqlException - { - String collectionToFlow =3D COLLECTIONNAME; - // the scalar data length field may or may not be required. it depends - // on the level of support and length of the data. - // check the lengths of the RDBNAM, RDBCOLID, and PKGID. - // Determine if the lengths require an SCLDTALEN object. - // Note: if an SQLDTALEN is required for ONE of them, - // it is needed for ALL of them. This is why this check is - // up front. - // the SQLAM level dictates the maximum size for - // RDB Collection Identifier (RDBCOLID) - // Relational Database Name (RDBNAM) - // RDB Package Identifier (PKGID) - int maxIdentifierLength =3D NetConfiguration.PKG_IDENTIFIER_MAX_LEN; - - boolean scldtalenRequired =3D false; - scldtalenRequired =3D checkPKGNAMlengths (netAgent_.netConnection_.dat= abaseName_, - maxIdentifierLength, - NetConfiguration.PKG_IDENTIFIE= R_FIXED_LEN); - - if (!scldtalenRequired) - scldtalenRequired =3D checkPKGNAMlengths (collectionToFlow, - maxIdentifierLength, - NetConfiguration.PKG_IDENTIF= IER_FIXED_LEN); - - if (!scldtalenRequired) - scldtalenRequired =3D checkPKGNAMlengths (section.getPackageName(), - maxIdentifierLength, - NetConfiguration.PKG_IDENTIF= IER_FIXED_LEN); - - // the format is different depending on if an SCLDTALEN is required. - if (!scldtalenRequired) { - writeScalarPaddedString (netAgent_.netConnection_.databaseName_, - NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); - writeScalarPaddedString (collectionToFlow, - NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); - writeScalarPaddedString (section.getPackageName(), - NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); - } - else { - buildSCLDTA (netAgent_.netConnection_.databaseName_, NetConfiguratio= n=2EPKG_IDENTIFIER_FIXED_LEN); - buildSCLDTA (collectionToFlow, NetConfiguration.PKG_IDENTIFIER_FIXED= _LEN); - buildSCLDTA (section.getPackageName(), NetConfiguration.PKG_IDENTIFI= ER_FIXED_LEN); - } - } - - private void buildSCLDTA (String identifier, int minimumLength) throws S= qlException - { - if (identifier.length() <=3D minimumLength) { - write2Bytes (minimumLength); - writeScalarPaddedString (identifier, minimumLength); - } - else { - write2Bytes (identifier.length()); - writeScalarPaddedString (identifier, identifier.length()); - } - } - - - // this specifies the fully qualified package name, - // consistency token, and section number within the package being used - // to execute the SQL. If the connection supports reusing the previous - // package information and this information is the same except for the s= ection - // number then only the section number needs to be sent to the server. - void buildPKGNAMCSN (Section section) throws SqlException - { - if (!canCommandUseDefaultPKGNAMCSN ()) { - markLengthBytes (CodePoint.PKGNAMCSN); - // If PKGNAMCBytes is already available, copy the bytes to the reque= st buffer directly. - if (section.getPKGNAMCBytes() !=3D null) - writeStoredPKGNAMCBytes (section); - else { - // Mark the beginning of PKGNAMCSN bytes. - markForCachingPKGNAMCSN (); - buildCommonPKGNAMinfo (section); - writeScalarPaddedBytes (Configuration.dncPackageConsistencyToken, - NetConfiguration.PKGCNSTKN_FIXED_LEN, - NetConfiguration.NON_CHAR_DDM_DATA_PAD_BYTE); - // store the PKGNAMCbytes=20 - storePKGNAMCBytes (section); - } - write2Bytes (section.getSectionNumber()); - updateLengthBytes(); - } - else - writeScalar2Bytes (CodePoint.PKGSN, section.getSectionNumber()); - } - - private void storePKGNAMCBytes (Section section) - { - // Get the locaton where we started writing PKGNAMCSN - int startPos =3D popMarkForCachingPKGNAMCSN (); - int copyLength =3D offset_ - startPos; - byte[] b =3D new byte[copyLength]; - System.arraycopy (bytes_, - startPos, - b, - 0, - copyLength); - section.setPKGNAMCBytes(b); - } - - private void writeStoredPKGNAMCBytes (Section section) - { - byte[] b =3D section.getPKGNAMCBytes(); - - // Mare sure request buffer has enough space to write this byte array. - ensureLength (offset_ + b.length); - - System.arraycopy (b, - 0, - bytes_, - offset_, - b.length); - - offset_ +=3D b.length; - } - - private boolean canCommandUseDefaultPKGNAMCSN () - { - return false; - } - - - // throws an exception if lengths exceed the maximum. - // returns a boolean indicating if SLCDTALEN is required. - private boolean checkPKGNAMlengths (String identifier, - int maxIdentifierLength, - int lengthRequiringScldta) throws Sq= lException - { - int length =3D identifier.length(); - if (length > maxIdentifierLength) - throw new SqlException (netAgent_.logWriter_, "" + identifier + " ex= ceeds maximum identifier length of ' " + - maxIdentifierLength + "'"); - - return (length > lengthRequiringScldta); - } - - private byte[] getBytes (String string, String encoding) throws SqlExcep= tion - { - try { - return string.getBytes (encoding); - } - catch (java.lang.Exception e) { - throw new SqlException (netAgent_.logWriter_, e, "error on getBytes"= ); - } - } - - private void buildNOCMorNOCS (String string) throws SqlException - { - if (string =3D=3D null) { - write2Bytes (0xffff); - } - else { - byte[] sqlBytes =3D null; - - if (netAgent_.typdef_.isCcsidMbcSet()) { - sqlBytes =3D getBytes (string, netAgent_.typdef_.getCcsidMbcEncodi= ng()); - write1Byte (0x00); - write4Bytes (sqlBytes.length); - writeBytes (sqlBytes, sqlBytes.length); - write1Byte (0xff); - } - else { - sqlBytes =3D getBytes (string, netAgent_.typdef_.getCcsidSbcEncodi= ng()); - write1Byte (0xff); - write1Byte (0x00); - write4Bytes (sqlBytes.length); - writeBytes (sqlBytes, sqlBytes.length); - } - } - } - - // SQLSTTGRP : FDOCA EARLY GROUP - // SQL Statement Group Description - // - // FORMAT FOR SQLAM <=3D 6 - // SQLSTATEMENT_m; PROTOCOL TYPE LVCM; ENVLID 0x40; Length Override 32= 767 - // SQLSTATEMENT_s; PROTOCOL TYPE LVCS; ENVLID 0x34; Length Override 32= 767 - // - // FORMAT FOR SQLAM >=3D 7 - // SQLSTATEMENT_m; PROTOCOL TYPE NOCM; ENVLID 0xCF; Length Override 4 - // SQLSTATEMENT_s; PROTOCOL TYPE NOCS; ENVLID 0xCB; Length Override 4 - private void buildSQLSTTGRP (String string) throws SqlException - { - buildNOCMorNOCS (string); - return; - } - - // SQLSTT : FDOCA EARLY ROW - // SQL Statement Row Description - // - // FORMAT FOR ALL SQLAM LEVELS - // SQLSTTGRP; GROUP LID 0x5C; ELEMENT TAKEN 0(all); REP FACTOR 1 - private void buildSQLSTT (String string) throws SqlException - { - buildSQLSTTGRP (string); - } - - protected void buildSQLSTTcommandData (String sql) throws SqlException - { - createEncryptedCommandData (); - int loc =3D offset_; - markLengthBytes (CodePoint.SQLSTT); - buildSQLSTT (sql); - updateLengthBytes(); - if (netAgent_.netConnection_.getSecurityMechanism() =3D=3D - NetConfiguration.SECMEC_EUSRIDDTA || - netAgent_.netConnection_.getSecurityMechanism() =3D=3D - NetConfiguration.SECMEC_EUSRPWDDTA) - encryptDataStream(loc); - - } - - - - protected void buildSQLATTRcommandData (String sql) throws SqlException - { - createEncryptedCommandData (); - int loc =3D offset_; - markLengthBytes (CodePoint.SQLATTR); - buildSQLSTT (sql); - updateLengthBytes(); - if (netAgent_.netConnection_.getSecurityMechanism() =3D=3D - NetConfiguration.SECMEC_EUSRIDDTA || - netAgent_.netConnection_.getSecurityMechanism() =3D=3D - NetConfiguration.SECMEC_EUSRPWDDTA) - encryptDataStream (loc); - - } - - - public void encryptDataStream(int lengthLocation) throws SqlException - { - byte[] clearedBytes =3D new byte[offset_ - lengthLocation]; - byte[] encryptedBytes; - for (int i =3D lengthLocation; i < offset_; i++) - clearedBytes[i - lengthLocation] =3D bytes_[i]; - - encryptedBytes =3D netAgent_.netConnection_.getEncryptionManager(). - encryptData( - clearedBytes, - NetConfiguration.SECMEC_EUSRIDPWD, - netAgent_.netConnection_.getTargetPublicKey(), - netAgent_.netConnection_.getTargetPublicKey()); - - int length =3D encryptedBytes.length; - - if(bytes_.length >=3D lengthLocation + length) - System.arraycopy(encryptedBytes, 0, bytes_, lengthLocation, length= ); - else { - byte[] largeByte =3D new byte[lengthLocation + length]; - System.arraycopy(bytes_,0,largeByte,0,lengthLocation); - System.arraycopy(encryptedBytes, 0, largeByte, lengthLocation, len= gth); - bytes_ =3D largeByte; - } - - offset_ +=3D length - clearedBytes.length; - - //we need to update the length in DSS header here. - - bytes_[lengthLocation - 6] =3D (byte) ( (length >>> 8) & 0xff); - bytes_[lengthLocation - 5] =3D (byte) (length & 0xff); - } +public class NetPackageRequest extends NetConnectionRequest { + static final String COLLECTIONNAME =3D "NULLID"; + + NetPackageRequest(NetAgent netAgent, CcsidManager ccsidManager, int bu= fferSize) { + super(netAgent, ccsidManager, bufferSize); + } + + // RDB Package Name, Consistency Token + // Scalar Object specifies the fully qualified name of a relational + // database package and its consistency token. + // + // To accomodate larger lengths, the Scalar Data Length + // (SCLDTALEN) Field is used to specify the length of the instance + // variable which follows. + static final String collectionName =3D "NULLID"; + + void buildCommonPKGNAMinfo(Section section) throws SqlException { + String collectionToFlow =3D COLLECTIONNAME; + // the scalar data length field may or may not be required. it de= pends + // on the level of support and length of the data. + // check the lengths of the RDBNAM, RDBCOLID, and PKGID. + // Determine if the lengths require an SCLDTALEN object. + // Note: if an SQLDTALEN is required for ONE of them, + // it is needed for ALL of them. This is why this check is + // up front. + // the SQLAM level dictates the maximum size for + // RDB Collection Identifier (RDBCOLID) + // Relational Database Name (RDBNAM) + // RDB Package Identifier (PKGID) + int maxIdentifierLength =3D NetConfiguration.PKG_IDENTIFIER_MAX_LE= N; + + boolean scldtalenRequired =3D false; + scldtalenRequired =3D checkPKGNAMlengths(netAgent_.netConnection_.= databaseName_, + maxIdentifierLength, + NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); + + if (!scldtalenRequired) { + scldtalenRequired =3D checkPKGNAMlengths(collectionToFlow, + maxIdentifierLength, + NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); + } + + if (!scldtalenRequired) { + scldtalenRequired =3D checkPKGNAMlengths(section.getPackageNam= e(), + maxIdentifierLength, + NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); + } + + // the format is different depending on if an SCLDTALEN is require= d=2E + if (!scldtalenRequired) { + writeScalarPaddedString(netAgent_.netConnection_.databaseName_, + NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); + writeScalarPaddedString(collectionToFlow, + NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); + writeScalarPaddedString(section.getPackageName(), + NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); + } else { + buildSCLDTA(netAgent_.netConnection_.databaseName_, NetConfigu= ration.PKG_IDENTIFIER_FIXED_LEN); + buildSCLDTA(collectionToFlow, NetConfiguration.PKG_IDENTIFIER_= FIXED_LEN); + buildSCLDTA(section.getPackageName(), NetConfiguration.PKG_IDE= NTIFIER_FIXED_LEN); + } + } + + private void buildSCLDTA(String identifier, int minimumLength) throws = SqlException { + if (identifier.length() <=3D minimumLength) { + write2Bytes(minimumLength); + writeScalarPaddedString(identifier, minimumLength); + } else { + write2Bytes(identifier.length()); + writeScalarPaddedString(identifier, identifier.length()); + } + } + + + // this specifies the fully qualified package name, + // consistency token, and section number within the package being used + // to execute the SQL. If the connection supports reusing the previous + // package information and this information is the same except for the= section + // number then only the section number needs to be sent to the server. + void buildPKGNAMCSN(Section section) throws SqlException { + if (!canCommandUseDefaultPKGNAMCSN()) { + markLengthBytes(CodePoint.PKGNAMCSN); + // If PKGNAMCBytes is already available, copy the bytes to the= request buffer directly. + if (section.getPKGNAMCBytes() !=3D null) { + writeStoredPKGNAMCBytes(section); + } else { + // Mark the beginning of PKGNAMCSN bytes. + markForCachingPKGNAMCSN(); + buildCommonPKGNAMinfo(section); + writeScalarPaddedBytes(Configuration.dncPackageConsistency= Token, + NetConfiguration.PKGCNSTKN_FIXED_LEN, + NetConfiguration.NON_CHAR_DDM_DATA_PAD_BYTE); + // store the PKGNAMCbytes + storePKGNAMCBytes(section); + } + write2Bytes(section.getSectionNumber()); + updateLengthBytes(); + } else { + writeScalar2Bytes(CodePoint.PKGSN, section.getSectionNumber()); + } + } + + private void storePKGNAMCBytes(Section section) { + // Get the locaton where we started writing PKGNAMCSN + int startPos =3D popMarkForCachingPKGNAMCSN(); + int copyLength =3D offset_ - startPos; + byte[] b =3D new byte[copyLength]; + System.arraycopy(bytes_, + startPos, + b, + 0, + copyLength); + section.setPKGNAMCBytes(b); + } + + private void writeStoredPKGNAMCBytes(Section section) { + byte[] b =3D section.getPKGNAMCBytes(); + + // Mare sure request buffer has enough space to write this byte ar= ray. + ensureLength(offset_ + b.length); + + System.arraycopy(b, + 0, + bytes_, + offset_, + b.length); + + offset_ +=3D b.length; + } + + private boolean canCommandUseDefaultPKGNAMCSN() { + return false; + } + + + // throws an exception if lengths exceed the maximum. + // returns a boolean indicating if SLCDTALEN is required. + private boolean checkPKGNAMlengths(String identifier, + int maxIdentifierLength, + int lengthRequiringScldta) throws S= qlException { + int length =3D identifier.length(); + if (length > maxIdentifierLength) { + throw new SqlException(netAgent_.logWriter_, "" + identifier += " exceeds maximum identifier length of ' " + + maxIdentifierLength + "'"); + } + + return (length > lengthRequiringScldta); + } + + private byte[] getBytes(String string, String encoding) throws SqlExce= ption { + try { + return string.getBytes(encoding); + } catch (java.lang.Exception e) { + throw new SqlException(netAgent_.logWriter_, e, "error on getB= ytes"); + } + } + + private void buildNOCMorNOCS(String string) throws SqlException { + if (string =3D=3D null) { + write2Bytes(0xffff); + } else { + byte[] sqlBytes =3D null; + + if (netAgent_.typdef_.isCcsidMbcSet()) { + sqlBytes =3D getBytes(string, netAgent_.typdef_.getCcsidMb= cEncoding()); + write1Byte(0x00); + write4Bytes(sqlBytes.length); + writeBytes(sqlBytes, sqlBytes.length); + write1Byte(0xff); + } else { + sqlBytes =3D getBytes(string, netAgent_.typdef_.getCcsidSb= cEncoding()); + write1Byte(0xff); + write1Byte(0x00); + write4Bytes(sqlBytes.length); + writeBytes(sqlBytes, sqlBytes.length); + } + } + } + + // SQLSTTGRP : FDOCA EARLY GROUP + // SQL Statement Group Description + // + // FORMAT FOR SQLAM <=3D 6 + // SQLSTATEMENT_m; PROTOCOL TYPE LVCM; ENVLID 0x40; Length Override = 32767 + // SQLSTATEMENT_s; PROTOCOL TYPE LVCS; ENVLID 0x34; Length Override = 32767 + // + // FORMAT FOR SQLAM >=3D 7 + // SQLSTATEMENT_m; PROTOCOL TYPE NOCM; ENVLID 0xCF; Length Override 4 + // SQLSTATEMENT_s; PROTOCOL TYPE NOCS; ENVLID 0xCB; Length Override 4 + private void buildSQLSTTGRP(String string) throws SqlException { + buildNOCMorNOCS(string); + return; + } + + // SQLSTT : FDOCA EARLY ROW + // SQL Statement Row Description + // + // FORMAT FOR ALL SQLAM LEVELS + // SQLSTTGRP; GROUP LID 0x5C; ELEMENT TAKEN 0(all); REP FACTOR 1 + private void buildSQLSTT(String string) throws SqlException { + buildSQLSTTGRP(string); + } + + protected void buildSQLSTTcommandData(String sql) throws SqlException { + createEncryptedCommandData(); + int loc =3D offset_; + markLengthBytes(CodePoint.SQLSTT); + buildSQLSTT(sql); + updateLengthBytes(); + if (netAgent_.netConnection_.getSecurityMechanism() =3D=3D + NetConfiguration.SECMEC_EUSRIDDTA || + netAgent_.netConnection_.getSecurityMechanism() =3D=3D + NetConfiguration.SECMEC_EUSRPWDDTA) { + encryptDataStream(loc); + } + + } + + + protected void buildSQLATTRcommandData(String sql) throws SqlException= { + createEncryptedCommandData(); + int loc =3D offset_; + markLengthBytes(CodePoint.SQLATTR); + buildSQLSTT(sql); + updateLengthBytes(); + if (netAgent_.netConnection_.getSecurityMechanism() =3D=3D + NetConfiguration.SECMEC_EUSRIDDTA || + netAgent_.netConnection_.getSecurityMechanism() =3D=3D + NetConfiguration.SECMEC_EUSRPWDDTA) { + encryptDataStream(loc); + } + + } + + + public void encryptDataStream(int lengthLocation) throws SqlException { + byte[] clearedBytes =3D new byte[offset_ - lengthLocation]; + byte[] encryptedBytes; + for (int i =3D lengthLocation; i < offset_; i++) { + clearedBytes[i - lengthLocation] =3D bytes_[i]; + } + + encryptedBytes =3D netAgent_.netConnection_.getEncryptionManager(). + encryptData(clearedBytes, + NetConfiguration.SECMEC_EUSRIDPWD, + netAgent_.netConnection_.getTargetPublicKey(), + netAgent_.netConnection_.getTargetPublicKey()); + + int length =3D encryptedBytes.length; + + if (bytes_.length >=3D lengthLocation + length) { + System.arraycopy(encryptedBytes, 0, bytes_, lengthLocation, le= ngth); + } else { + byte[] largeByte =3D new byte[lengthLocation + length]; + System.arraycopy(bytes_, 0, largeByte, 0, lengthLocation); + System.arraycopy(encryptedBytes, 0, largeByte, lengthLocation,= length); + bytes_ =3D largeByte; + } + + offset_ +=3D length - clearedBytes.length; + + //we need to update the length in DSS header here. + + bytes_[lengthLocation - 6] =3D (byte) ((length >>> 8) & 0xff); + bytes_[lengthLocation - 5] =3D (byte) (length & 0xff); + } =20 } Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/ne= t/NetPreparedStatement.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/net/NetPreparedStatement.java?rev=3D165585&r1=3D1655= 84&r2=3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetP= reparedStatement.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetP= reparedStatement.java Sun May 1 23:25:59 2005 @@ -19,147 +19,140 @@ */ package org.apache.derby.client.net; =20 -import org.apache.derby.client.am.Section; import org.apache.derby.client.am.ColumnMetaData; import org.apache.derby.client.am.PreparedStatement; +import org.apache.derby.client.am.Section; import org.apache.derby.client.am.SqlException; =20 =20 public class NetPreparedStatement extends NetStatement - implements org.apache.derby.client.am.MaterialPreparedStatement -{ - - // Alias for (NetPreparedStatement) super.statement. - /*final*/ org.apache.derby.client.am.PreparedStatement preparedStatement= _; + implements org.apache.derby.client.am.MaterialPreparedStatement { =20 + // Alias for (NetPreparedStatement) super.statement. + /*final*/ + org.apache.derby.client.am.PreparedStatement preparedStatement_; + + + // Relay constructor for NetCallableStatement. + NetPreparedStatement(org.apache.derby.client.am.PreparedStatement stat= ement, + NetAgent netAgent, + NetConnection netConnection) { + super(statement, netAgent, netConnection); + initNetPreparedStatement(statement); + } + + void resetNetPreparedStatement(org.apache.derby.client.am.PreparedStat= ement statement, + NetAgent netAgent, + NetConnection netConnection) { + super.resetNetStatement(statement, netAgent, netConnection); + initNetPreparedStatement(statement); + } + + private void initNetPreparedStatement(org.apache.derby.client.am.Prepa= redStatement statement) { + preparedStatement_ =3D statement; + preparedStatement_.materialPreparedStatement_ =3D this; + } + + // Called by abstract Connection.prepareStatment().newPreparedStatemen= t() for jdbc 2 prepared statements + // with scroll attributes. + NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, S= tring sql, int type, int concurrency, int holdability, int autoGeneratedKey= s, String[] columnNames) throws SqlException { + this(new PreparedStatement(netAgent, netConnection, sql, type, con= currency, holdability, autoGeneratedKeys, columnNames), + netAgent, + netConnection); + } + + void resetNetPreparedStatement(NetAgent netAgent, NetConnection netCon= nection, String sql, int type, int concurrency, int holdability, int autoGe= neratedKeys, String[] columnNames) throws SqlException { + preparedStatement_.resetPreparedStatement(netAgent, netConnection,= sql, type, concurrency, holdability, autoGeneratedKeys, columnNames); + resetNetPreparedStatement(preparedStatement_, netAgent, netConnect= ion); + } + + // For JDBC 3.0 positioned updates. + NetPreparedStatement(NetAgent netAgent, + NetConnection netConnection, + String sql, + Section section) throws SqlException { + this(new PreparedStatement(netAgent, netConnection, sql, section), + netAgent, + netConnection); + } + + void resetNetPreparedStatement(NetAgent netAgent, + NetConnection netConnection, + String sql, + Section section) throws SqlException { + preparedStatement_.resetPreparedStatement(netAgent, netConnection,= sql, section); + resetNetPreparedStatement(preparedStatement_, netAgent, netConnect= ion); + } + + void resetNetPreparedStatement(NetAgent netAgent, + NetConnection netConnection, + String sql, + Section section, + ColumnMetaData parameterMetaData, + ColumnMetaData resultSetMetaData) throw= s SqlException { + preparedStatement_.resetPreparedStatement(netAgent, netConnection,= sql, section, parameterMetaData, resultSetMetaData); + this.resetNetPreparedStatement(preparedStatement_, netAgent, netCo= nnection); + } + + protected void finalize() throws java.lang.Throwable { + super.finalize(); + } =20 - // Relay constructor for NetCallableStatement. - NetPreparedStatement (org.apache.derby.client.am.PreparedStatement state= ment, - NetAgent netAgent, - NetConnection netConnection) - { - super (statement, netAgent, netConnection); - initNetPreparedStatement (statement); - } - - void resetNetPreparedStatement (org.apache.derby.client.am.PreparedState= ment statement, - NetAgent netAgent, - NetConnection netConnection) - { - super.resetNetStatement(statement, netAgent, netConnection); - initNetPreparedStatement(statement); - } - - private void initNetPreparedStatement (org.apache.derby.client.am.Prepar= edStatement statement) - { - preparedStatement_ =3D statement; - preparedStatement_.materialPreparedStatement_ =3D this; - } - - // Called by abstract Connection.prepareStatment().newPreparedStatement(= ) for jdbc 2 prepared statements - // with scroll attributes. - NetPreparedStatement (NetAgent netAgent, NetConnection netConnection, St= ring sql, int type, int concurrency, int holdability, int autoGeneratedKeys= , String[] columnNames) throws SqlException - { - this (new PreparedStatement (netAgent, netConnection, sql, type, concu= rrency, holdability, autoGeneratedKeys, columnNames), - netAgent, - netConnection); - } - - void resetNetPreparedStatement (NetAgent netAgent, NetConnection netConn= ection, String sql, int type, int concurrency, int holdability, int autoGen= eratedKeys, String[] columnNames) throws SqlException - { - preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql= , type, concurrency, holdability, autoGeneratedKeys, columnNames); - resetNetPreparedStatement(preparedStatement_, netAgent, netConnection); - } - - // For JDBC 3.0 positioned updates. - NetPreparedStatement (NetAgent netAgent, - NetConnection netConnection, - String sql, - Section section) throws SqlException - { - this (new PreparedStatement (netAgent, netConnection, sql, section), - netAgent, - netConnection); - } - - void resetNetPreparedStatement (NetAgent netAgent, - NetConnection netConnection, - String sql, - Section section) throws SqlException - { - preparedStatement_.resetPreparedStatement (netAgent, netConnection, sq= l, section); - resetNetPreparedStatement (preparedStatement_, netAgent, netConnection= ); - } - - void resetNetPreparedStatement (NetAgent netAgent, - NetConnection netConnection, - String sql, - Section section, - ColumnMetaData parameterMetaData, - ColumnMetaData resultSetMetaData) throws = SqlException - { - preparedStatement_.resetPreparedStatement(netAgent,netConnection,sql,s= ection,parameterMetaData,resultSetMetaData); - this.resetNetPreparedStatement(preparedStatement_, netAgent, netConnec= tion); - } - - protected void finalize () throws java.lang.Throwable - { - super.finalize(); - } - - public void writeExecute_ (Section section, - ColumnMetaData parameterMetaData, - Object[] inputs, - int numInputColumns, - boolean outputExpected, - // This is a hint to the material layer that m= ore write commands will follow. - // It is ignored by the driver in all cases ex= cept when blob data is written, - // in which case this boolean is used to optim= ize the implementation. - // Otherwise we wouldn't be able to chain afte= r blob data is sent. - // If we could always chain a no-op DDM after = every execute that writes blobs - // then we could just always set the chaining = flag to on for blob send data=20 - boolean chainedWritesFollowingSetLob - ) throws SqlException - { - netAgent_.statementRequest_.writeExecute ( - this, - section, - parameterMetaData, - inputs, - numInputColumns, - outputExpected, - chainedWritesFollowingSetLob); - } - - - public void readExecute_ () throws SqlException - { netAgent_.statementReply_.readExecute (preparedStatement_); } - - public void writeOpenQuery_ (Section section, - int fetchSize, - int resultSetType, - int numInputColumns, + public void writeExecute_(Section section, ColumnMetaData parameterMetaData, - Object[] inputs) throws SqlException - { - netAgent_.statementRequest_.writeOpenQuery ( - this, - section, - fetchSize, - resultSetType, - numInputColumns, - parameterMetaData, - inputs); - } - // super.readOpenQuery() - - public void writeDescribeInput_ (Section section) throws SqlException - { netAgent_.statementRequest_.writeDescribeInput (this, section); } - public void readDescribeInput_ () throws SqlException - { netAgent_.statementReply_.readDescribeInput (preparedStatement_); } - - public void writeDescribeOutput_ (Section section) throws SqlException - { netAgent_.statementRequest_.writeDescribeOutput (this, section); } - public void readDescribeOutput_ () throws SqlException - { netAgent_.statementReply_.readDescribeOutput (preparedStatement_); } + Object[] inputs, + int numInputColumns, + boolean outputExpected, + // This is a hint to the material layer that= more write commands will follow. + // It is ignored by the driver in all cases = except when blob data is written, + // in which case this boolean is used to opt= imize the implementation. + // Otherwise we wouldn't be able to chain af= ter blob data is sent. + // If we could always chain a no-op DDM afte= r every execute that writes blobs + // then we could just always set the chainin= g flag to on for blob send data + boolean chainedWritesFollowingSetLob) throws= SqlException { + netAgent_.statementRequest_.writeExecute(this, + section, + parameterMetaData, + inputs, + numInputColumns, + outputExpected, + chainedWritesFollowingSetLob); + } + + + public void readExecute_() throws SqlException { + netAgent_.statementReply_.readExecute(preparedStatement_); + } + + public void writeOpenQuery_(Section section, + int fetchSize, + int resultSetType, + int numInputColumns, + ColumnMetaData parameterMetaData, + Object[] inputs) throws SqlException { + netAgent_.statementRequest_.writeOpenQuery(this, + section, + fetchSize, + resultSetType, + numInputColumns, + parameterMetaData, + inputs); + } + // super.readOpenQuery() + + public void writeDescribeInput_(Section section) throws SqlException { + netAgent_.statementRequest_.writeDescribeInput(this, section); + } + + public void readDescribeInput_() throws SqlException { + netAgent_.statementReply_.readDescribeInput(preparedStatement_); + } + + public void writeDescribeOutput_(Section section) throws SqlException { + netAgent_.statementRequest_.writeDescribeOutput(this, section); + } + + public void readDescribeOutput_() throws SqlException { + netAgent_.statementReply_.readDescribeOutput(preparedStatement_); + } }