You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by db...@apache.org on 2016/05/02 18:12:10 UTC
[31/60] incubator-trafodion git commit: TRAFODION-1933 JDBC TYpe4
driver build scripts migrated to use maven instead of ant
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
new file mode 100644
index 0000000..95fa7f9
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
@@ -0,0 +1,235 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.jdbc.t4;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Hashtable;
+
+public class InterfaceUtilities {
+ static private Hashtable valueToCharset;
+ static {
+ valueToCharset = new Hashtable(11);
+ valueToCharset.put(new Integer(1), "ISO8859_1"); // ISO
+ valueToCharset.put(new Integer(10), "MS932"); // SJIS
+ valueToCharset.put(new Integer(11), "UTF-16BE"); // UCS2
+ valueToCharset.put(new Integer(12), "EUCJP"); // EUCJP
+ valueToCharset.put(new Integer(13), "MS950"); // BIG5
+ valueToCharset.put(new Integer(14), "GB18030"); // GB18030
+ valueToCharset.put(new Integer(15), "UTF-8"); // UTF8
+ valueToCharset.put(new Integer(16), "MS949"); // MB_KSC5601
+ valueToCharset.put(new Integer(17), "GB2312"); // GB2312
+ }
+ static private Hashtable charsetToValue;
+ static {
+ charsetToValue = new Hashtable(11);
+ charsetToValue.put("ISO8859_1", new Integer(1)); // ISO
+ charsetToValue.put("MS932", new Integer(10)); // SJIS
+ charsetToValue.put("UTF-16BE", new Integer(11)); // UCS2
+ charsetToValue.put("EUCJP", new Integer(12)); // EUCJP
+ charsetToValue.put("MS950", new Integer(13)); // BIG5
+ charsetToValue.put("GB18030", new Integer(14)); // GB18030
+ charsetToValue.put("UTF-8", new Integer(15)); // UTF8
+ charsetToValue.put("MS949", new Integer(16)); // MB_KSC5601
+ charsetToValue.put("GB2312", new Integer(17)); // GB2312
+ }
+
+ static final int SQLCHARSETCODE_UNKNOWN = 0;
+ static final String SQLCHARSET_UNKNOWN = "UNKNOWN";
+
+ // these are the only real column types
+ static final int SQLCHARSETCODE_ISO88591 = 1;
+ static final String SQLCHARSET_ISO88591 = "ISO88591";
+ static final int SQLCHARSETCODE_UNICODE = 11;
+ static final String SQLCHARSET_UNICODE = "UCS2";
+
+ // ISO_MAPPING values
+ static final int SQLCHARSETCODE_SJIS = 10;
+ static final int SQLCHARSETCODE_UTF8 = 15;
+
+ static String getCharsetName(int charset) {
+ String ret = (String) valueToCharset.get(new Integer(charset));
+
+ if (ret == null)
+ ret = SQLCHARSET_UNKNOWN;
+
+ return ret;
+ }
+
+ static int getCharsetValue(String charset) {
+ Integer i = (Integer) charsetToValue.get(charset);
+ int ret;
+
+ if (i == null)
+ ret = SQLCHARSETCODE_UNKNOWN;
+ else
+ ret = i.intValue();
+
+ return ret;
+ }
+
+ static private final int[] powersOfTen = { 10, 100, 1000, 10000 };
+
+ public static byte[] convertBigDecimalToSQLBigNum(BigDecimal bd, int targetLength, int targetScale) {
+ byte[] sourceData = bd.setScale(targetScale, BigDecimal.ROUND_DOWN).unscaledValue().toString().getBytes(); // add
+ // trailing
+ // 0s,
+ // remove decimal point,
+ // get the chars
+ byte[] targetData = new byte[targetLength];
+ int[] targetInShorts = new int[targetLength / 2];
+
+ int length;
+ int temp;
+ int tarPos = 1;
+
+ // remove leading 0s and sign character
+ int zeros = 0;
+ while (zeros < sourceData.length && (sourceData[zeros] == '0' || sourceData[zeros] == '-'))
+ zeros++;
+
+ // convert from characters to values
+ for (int i = zeros; i < sourceData.length; i++)
+ sourceData[i] -= '0';
+
+ length = sourceData.length - zeros; // we have a new length
+
+ // iterate through 4 bytes at a time
+ for (int i = 0; i < length; i += 4) {
+ int temp1 = 0;
+ int j = 0;
+
+ // get 4 bytes worth of data or as much that is left
+ for (j = 0; j < 4 && i + j < length; j++)
+ temp1 = temp1 * 10 + sourceData[zeros + i + j];
+
+ int power = powersOfTen[j - 1]; // get the power of ten based on how
+ // many digits we got
+
+ temp = targetInShorts[0] * power + temp1; // move the current
+ // digits over and then
+ // add our new value in
+ targetInShorts[0] = temp & 0xFFFF; // we save only up to 16bits --
+ // the rest gets carried over
+
+ // we do the same thing for the rest of the digits now that we have
+ // an upper bound
+ for (j = 1; j < targetInShorts.length; j++) {
+ int t = (temp & 0xFFFF0000) >> 16;
+ temp = targetInShorts[j] * power + t;
+
+ targetInShorts[j] = temp & 0xFFFF;
+ }
+
+ int carry = (temp & 0xFFFF0000) >> 16;
+ if (carry > 0) {
+ targetInShorts[tarPos++] = carry;
+ }
+ }
+
+ // convert the data back to bytes
+ for (int i = 0; i < targetInShorts.length; i++) {
+// targetData[i * 2] = (byte) ((targetInShorts[i] & 0xFF00) >> 8);
+// targetData[i * 2 + 1] = (byte) (targetInShorts[i] & 0xFF);
+ targetData[i * 2 ] = (byte) (targetInShorts[i] & 0xFF);
+ targetData[i * 2 + 1] = (byte) ((targetInShorts[i] & 0xFF00) >> 8);
+ }
+
+ // add sign
+ if ((bd.signum() < 0))
+ targetData[targetData.length - 2] |= 0x80;
+
+ return targetData;
+ }
+
+ public static BigDecimal convertSQLBigNumToBigDecimal(byte[] sourceData, int scale, boolean swap) {
+ String strVal = ""; // our final String
+
+ // we need the data in an array which can hold UNSIGNED 16 bit values
+ // in java we dont have unsigned datatypes so 32-bit signed is the best
+ // we can do
+ int[] dataInShorts = new int[sourceData.length / 2];
+ for (int i = 0; i < dataInShorts.length; i++)
+ dataInShorts[i] = Bytes.extractUShort(sourceData, i * 2, swap); // copy
+ // the
+ // data
+
+ boolean negative = ((dataInShorts[dataInShorts.length - 1] & 0x8000) > 0);
+ dataInShorts[dataInShorts.length - 1] &= 0x7FFF; // force sign to 0, continue
+ // normally
+
+ int curPos = dataInShorts.length - 1; // start at the end
+ while (curPos >= 0 && dataInShorts[curPos] == 0)
+ // get rid of any trailing 0's
+ curPos--;
+
+ int remainder = 0;
+ long temp; // we need to use a LONG since we will have to hold up to
+ // 32-bit UNSIGNED values
+
+ // we now have the huge value stored in 2 bytes chunks
+ // we will divide by 10000 many times, converting the remainder to
+ // String
+ // when we are left with a single chunk <10000 we will handle it using a
+ // special case
+ while (curPos >= 0 || dataInShorts[0] >= 10000) {
+ // start on the right, divide the 16 bit value by 10000
+ // use the remainder as the upper 16 bits for the next division
+ for (int j = curPos; j >= 0; j--) {
+ // these operations got messy when java tried to infer what size
+ // to store the value in
+ // leave these as separate operations for now...always casting
+ // back to a 64 bit value to avoid sign problems
+ temp = remainder;
+ temp &= 0xFFFF;
+ temp = temp << 16;
+ temp += dataInShorts[j];
+
+ dataInShorts[j] = (int) (temp / 10000);
+ remainder = (int) (temp % 10000);
+ }
+
+ // if we are done with the current 16bits, move on
+ if (dataInShorts[curPos] == 0)
+ curPos--;
+
+ // go through the remainder and add each digit to the final String
+ for (int j = 0; j < 4; j++) {
+ strVal = (remainder % 10) + strVal;
+ remainder /= 10;
+ }
+ }
+
+ // when we finish the above loop we still have 1 <10000 value to include
+ remainder = dataInShorts[0];
+ for (int j = 0; j < 4; j++) {
+ strVal = (remainder % 10) + strVal;
+ remainder /= 10;
+ }
+
+ BigInteger bi = new BigInteger(strVal); // create a java BigInt
+ if (negative)
+ bi = bi.negate();
+
+ return new BigDecimal(bi, scale); // create a new BigDecimal with the
+ // descriptor's scale
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Key.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Key.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Key.java
new file mode 100644
index 0000000..b143866
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Key.java
@@ -0,0 +1,161 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+//
+**********************************************************************/
+
+/**
+ * Key.java
+ */
+
+package org.trafodion.jdbc.t4;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+import java.security.KeyFactory;
+import java.security.interfaces.RSAPublicKey;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import javax.crypto.KeyGenerator;
+
+
+public class Key {
+ public Key(){}
+
+ /** Reads the public key from the certificate file and
+ * stores the key and the length of the public key
+ * in member data.
+ * @param X509Certificate - The certificate stored
+ * the public key
+ */
+ public void getPubKeyFromFile(X509Certificate cert)
+ {
+ m_pubKey = (RSAPublicKey) cert.getPublicKey();
+ if (((m_pubKey.getModulus().bitLength()) / 8) > 128)
+ m_pubKeyLen = 256;
+ else
+ m_pubKeyLen = 128;
+ }
+
+ /** Reads the private key from certificate file and
+ * stores the key in the member data.
+ * @param String - The file stored the private key
+ * @throw SecurityException
+ */
+ public void getPrivKeyFromFile(String inFile) throws SecurityException
+ {
+ InputStream inStream=null;
+
+ try{
+ // Loading private key file
+ inStream=new FileInputStream(inFile);
+ byte[] keyBytes=new byte[inStream.available()];
+ inStream.read(keyBytes);
+ inStream.close();
+
+ // Read the private key from file
+ PKCS8EncodedKeySpec privKeySpec=new PKCS8EncodedKeySpec(keyBytes);
+ KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+ m_privKey= (RSAPrivateKey) keyFactory.generatePrivate
+ (privKeySpec);
+
+ }catch (FileNotFoundException fnf) {
+ throw new SecurityException(SecClientMsgKeys.FILE_NOTFOUND, new Object[]{inFile});
+ }catch (IOException io) {
+ throw new SecurityException(SecClientMsgKeys.ERR_OPEN_INPUT_FILE, new Object[]{inFile});
+ }catch (Exception e) {
+ throw new SecurityException(SecClientMsgKeys.ERR_RETRIEVE_KEY_FROM_FILE, new Object[]{inFile});
+ }finally {
+ try {
+ if (inStream != null)
+ inStream.close();
+ }catch (IOException io) {
+ // not much we can do at this point
+ }
+ }
+ }
+
+ /**
+ * Generates a secret key using AES algorithm and 128 bits key
+ * @param sessionKey the session key byte array used for symmetric key
+ * generation
+ * @return the SecretKey
+ * @throws SecurityException
+ */
+ static SecretKey generateSymmetricKey(byte [] sKey) throws SecurityException
+ {
+ if (sKey == null)
+ throw new SecurityException(SecClientMsgKeys.INPUT_PARAMETER_IS_NULL, new Object[]{"sKey"});
+ try {
+ // Get the KeyGenerator
+ KeyGenerator kgen = KeyGenerator.getInstance("AES");
+ synchronized(kgen) {
+ kgen.init(128);
+ }
+ // Use the lower 16 bytes of the session key to generate the 128 bits secret
+ // key used for data encryption
+
+ SecretKey skey = new SecretKeySpec(sKey, kgen.getAlgorithm());
+
+ return skey;
+ }catch (NoSuchAlgorithmException nae) {
+ throw new SecurityException(SecClientMsgKeys.ERR_CREATE_SYMMETRIC_KEY, null);
+ }
+ }
+
+ /**
+ *
+ * @return the public key
+ */
+ public RSAPublicKey getPubKey()
+ {
+ return m_pubKey;
+ }
+
+ /**
+ *
+ * @return the private key
+ */
+ public RSAPrivateKey getPrivKey()
+ {
+ return m_privKey;
+ }
+
+ /**
+ *
+ * @return the length of the public key
+ */
+ public int getPubKeyLen()
+ {
+ return m_pubKeyLen;
+ }
+
+ private RSAPublicKey m_pubKey;
+ private RSAPrivateKey m_privKey;
+ private int m_pubKeyLen;
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/LogicalByteArray.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/LogicalByteArray.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/LogicalByteArray.java
new file mode 100644
index 0000000..ce0e3ac
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/LogicalByteArray.java
@@ -0,0 +1,345 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.ByteBuffer;
+
+class LogicalByteArray {
+ static private java.lang.ThreadLocal threadArray = new java.lang.ThreadLocal();
+
+ private byte[] array;
+ private ByteBuffer dataBuffer;
+ private byte[] trailer;
+
+ private boolean swap; // should we swap byte order
+ private int loc; // current position
+ private int length; // current bytes being used
+
+ LogicalByteArray(int size, int startingLoc, boolean byteSwap) {
+ loc = startingLoc;
+ length = 0;
+ swap = byteSwap;
+
+ // TRANSPORT.IO_BUFFER_LENGTH is our minimum length so it is always safe
+ // to read with the buffer
+ resize((size > TRANSPORT.IO_BUFFER_LENGTH) ? size : TRANSPORT.IO_BUFFER_LENGTH);
+ }
+
+ void resize(long l) {
+ byte[] old = (byte[]) threadArray.get();
+
+ if (old == null || old.length < l) {
+ array = new byte[(int) l];
+ if (old != null)
+ System.arraycopy(old, 0, array, 0, old.length);
+
+ threadArray.set(array);
+ } else {
+ array = old;
+ }
+ }
+
+ void reset() {
+ length = 0;
+ loc = 0;
+ }
+
+ byte[] getBuffer() {
+ return array;
+ }
+
+ int getTotalAllocated() {
+ return array.length;
+ }
+
+ int getLength() {
+ if (length < loc) {
+ length = loc;
+ }
+
+ return length;
+ }
+
+ int getLocation() {
+ return loc;
+ }
+
+ public void setLocation(int newLoc) {
+ if (newLoc > length) {
+ length = newLoc;
+ }
+
+ loc = newLoc;
+ }
+
+ void insertByte(byte value) {
+ array[loc++] = value;
+ }
+
+ void insertByteArray(byte[] value, int len) {
+ System.arraycopy(value, 0, array, loc, len);
+
+ loc += len;
+ }
+
+ void insertChar(char value) {
+ array[loc++] = (byte) value;
+ }
+
+ void insertShort(short value) {
+ if (swap) {
+ array[loc + 1] = (byte) ((value >>> 8) & 0xff);
+ array[loc] = (byte) ((value) & 0xff);
+ } else {
+ array[loc] = (byte) ((value >>> 8) & 0xff);
+ array[loc + 1] = (byte) ((value) & 0xff);
+ }
+
+ loc += 2;
+ }
+
+ void insertInt(int value) {
+ if (swap) {
+ array[loc + 3] = (byte) ((value >>> 24) & 0xff);
+ array[loc + 2] = (byte) ((value >>> 16) & 0xff);
+ array[loc + 1] = (byte) ((value >>> 8) & 0xff);
+ array[loc] = (byte) ((value) & 0xff);
+ } else {
+ array[loc] = (byte) ((value >>> 24) & 0xff);
+ array[loc + 1] = (byte) ((value >>> 16) & 0xff);
+ array[loc + 2] = (byte) ((value >>> 8) & 0xff);
+ array[loc + 3] = (byte) ((value) & 0xff);
+ }
+
+ loc += 4;
+ }
+
+ void insertLong(long value) {
+ if (swap) {
+ array[loc + 7] = (byte) ((value >>> 56) & 0xff);
+ array[loc + 6] = (byte) ((value >>> 48) & 0xff);
+ array[loc + 5] = (byte) ((value >>> 40) & 0xff);
+ array[loc + 4] = (byte) ((value >>> 32) & 0xff);
+ array[loc + 3] = (byte) ((value >>> 24) & 0xff);
+ array[loc + 2] = (byte) ((value >>> 16) & 0xff);
+ array[loc + 1] = (byte) ((value >>> 8) & 0xff);
+ array[loc] = (byte) ((value) & 0xff);
+ } else {
+ array[loc] = (byte) ((value >>> 56) & 0xff);
+ array[loc + 1] = (byte) ((value >>> 48) & 0xff);
+ array[loc + 2] = (byte) ((value >>> 40) & 0xff);
+ array[loc + 3] = (byte) ((value >>> 32) & 0xff);
+ array[loc + 4] = (byte) ((value >>> 24) & 0xff);
+ array[loc + 5] = (byte) ((value >>> 16) & 0xff);
+ array[loc + 6] = (byte) ((value >>> 8) & 0xff);
+ array[loc + 7] = (byte) ((value) & 0xff);
+ }
+
+ loc += 8;
+ }
+
+ void insertStringWithCharset(byte[] str, int charset) {
+ if (str != null && str.length > 0) {
+ this.insertString(str);
+ this.insertInt(charset);
+ } else {
+ this.insertInt(0);
+ }
+ }
+
+ void insertFixedString(byte[] buf, int len) {
+ int dataLength;
+
+ if(buf != null) {
+ dataLength = (buf.length > len-1)?len-1:buf.length; //-1 for the null, max dataLength is (len-1)
+ this.insertByteArray(buf, dataLength);
+ } else {
+ dataLength = 0;
+ }
+
+ byte [] padding = new byte[len-dataLength]; //this will always be at least 1 for the null padding
+ this.insertByteArray(padding, padding.length);
+ }
+
+ void insertString(byte[] buf) {
+ if (buf != null && buf.length > 0) {
+ this.insertInt(buf.length + 1);
+ this.insertByteArray(buf, buf.length);
+ this.insertByte((byte) 0);
+ } else { // buffer is null or length 0
+ this.insertInt(0);
+ }
+ }
+
+ void insertString(byte[] str, boolean fixForServer) {
+ if (str != null && str.length > 0) {
+ this.insertInt(str.length + 1); // +1 null term
+ this.insertByteArray(str, str.length);
+ this.insertByte((byte) 0);
+ } else {
+ this.insertInt(1);
+ this.insertByte((byte) 0);
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////
+ // /////////////////////////////////////////////////////////////////
+
+ boolean extractBoolean() {
+ return (extractByte() == 0) ? false : true;
+ }
+
+ byte extractByte() {
+ return array[loc++];
+ }
+
+ byte[] extractByteArray(long bufferLength) {
+ byte[] a = new byte[(int) bufferLength];
+
+ System.arraycopy(array, loc, a, 0, (int) bufferLength);
+ loc += bufferLength;
+
+ return a;
+ }
+
+ byte[] extractByteArray() {
+ return extractByteArray(this.extractInt());
+ }
+
+ char extractChar() {
+ return (char) extractByte();
+ }
+
+ short extractShort() {
+ int value;
+
+ if (swap) {
+ value = ((array[loc]) & 0x00ff) | ((array[loc + 1] << 8) & 0xff00);
+ } else {
+ value = ((array[loc + 1]) & 0x00ff) | ((array[loc] << 8) & 0xff00);
+ }
+
+ loc += 2;
+
+ return (short) value;
+ }
+
+ int extractInt() {
+ int value;
+
+ if (swap) {
+ value = ((array[loc]) & 0x000000ff) | ((array[loc + 1] << 8) & 0x0000ff00)
+ | ((array[loc + 2] << 16) & 0x00ff0000) | ((array[loc + 3] << 24) & 0xff000000);
+ } else {
+ value = ((array[loc + 3]) & 0x000000ff) | ((array[loc + 2] << 8) & 0x0000ff00)
+ | ((array[loc + 1] << 16) & 0x00ff0000) | ((array[loc] << 24) & 0xff000000);
+ }
+
+ loc += 4;
+
+ return value;
+ }
+
+ long extractLong() {
+ long value;
+
+ if (swap) {
+ value = ((array[loc]) & 0x00000000000000ffL) | ((array[loc + 1] << 8) & 0x000000000000ff00L)
+ | ((array[loc + 2] << 16) & 0x0000000000ff0000L) | ((array[loc + 3] << 24) & 0x00000000ff000000L)
+ | ((array[loc + 4] << 32) & 0x000000ff00000000L) | ((array[loc + 5] << 40) & 0x0000ff0000000000L)
+ | ((array[loc + 6] << 48) & 0x00ff000000000000L) | ((array[loc + 7] << 56) & 0xff00000000000000L);
+ } else {
+ value = ((array[loc + 7]) & 0x00000000000000ffL) | ((array[loc + 6] << 8) & 0x000000000000ff00L)
+ | ((array[loc + 5] << 16) & 0x0000000000ff0000L) | ((array[loc + 4] << 24) & 0x00000000ff000000L)
+ | ((array[loc + 3] << 32) & 0x000000ff00000000L) | ((array[loc + 2] << 40) & 0x0000ff0000000000L)
+ | ((array[loc + 1] << 48) & 0x00ff000000000000L) | ((array[loc] << 56) & 0xff00000000000000L);
+ }
+
+ loc += 8;
+
+ return value;
+ }
+
+ long extractUnsignedInt() {
+ long value;
+
+ if(swap) {
+ value = ((array[loc]) & 0x000000ff) | ((array[loc + 1] << 8) & 0x0000ff00)
+ | ((array[loc + 2] << 16) & 0x00ff0000) | ((array[loc + 3] << 24) & 0xff000000);
+ } else {
+ value = ((array[loc + 3]) & 0x000000ff) | ((array[loc + 2] << 8) & 0x0000ff00)
+ | ((array[loc + 1] << 16) & 0x00ff0000) | ((array[loc] << 24) & 0xff000000);
+ }
+
+ loc += 4;
+
+ return value & 0xffffffffL;
+ }
+
+ byte[] extractString() {
+ int len = extractInt();
+ byte[] str = new byte[0];
+
+ if (len > 0) {
+ str = extractByteArray(len - 1);
+ extractByte(); // trailing null
+ }
+ return str;
+ }
+
+ byte[] extractByteString() {
+ int len = extractInt();
+ byte[] b = new byte[0];
+
+ if (len > 0) {
+ b = extractByteArray(len); // the packed length DOES NOT include
+ // the null character
+ extractByte(); // trailing null
+ }
+
+ return b;
+ }
+
+ void setDataBuffer(ByteBuffer buf) {
+ this.dataBuffer = buf;
+ }
+
+ void setTrailer(byte[] buf) {
+ this.trailer = buf;
+ }
+
+ ByteBuffer getDataBuffer() {
+ return this.dataBuffer;
+ }
+
+ byte[] getTrailer() {
+ return this.trailer;
+ }
+
+ void setByteSwap(boolean byteSwap) {
+ this.swap = byteSwap;
+ }
+
+ boolean getByteSwap() {
+ return this.swap;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/MessageDigest.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/MessageDigest.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/MessageDigest.java
new file mode 100644
index 0000000..4484076
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/MessageDigest.java
@@ -0,0 +1,84 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+//
+**********************************************************************/
+
+/**
+ * class MessageDigest - Computes the message authentication code using
+ * the SHA256 hash function
+ */
+
+package org.trafodion.jdbc.t4;
+
+public class MessageDigest
+{
+ private static class Holder
+ {
+ private static MessageDigest instance = new MessageDigest();
+ }
+
+ /**
+ *
+ * @return MessageDigest
+ */
+ public static MessageDigest getInstance()
+ {
+ return Holder.instance;
+ }
+
+ /**Digests message using HmacSHA256 algorithm.
+ * @param key - session key to use for create secret key used in HMAC digest
+ * @param data - The data used to create the digest
+ * @param md - returns the digested message
+ * @return the digested message's length or -1 in case of failure
+ * @throw SecurityException
+ */
+ public int digest(byte[] key, byte[] data, byte[] md) throws SecurityException
+ {
+ if (key == null)
+ throw new SecurityException(SecClientMsgKeys.INPUT_PARAMETER_IS_NULL,
+ new Object[]{"key"});
+ if (data == null)
+ throw new SecurityException(SecClientMsgKeys.INPUT_PARAMETER_IS_NULL,
+ new Object[]{"data"});
+ if (md == null)
+ throw new SecurityException(SecClientMsgKeys.INPUT_PARAMETER_IS_NULL,
+ new Object[]{"md"});
+ try {
+ javax.crypto.spec.SecretKeySpec keySpec =
+ new javax.crypto.spec.SecretKeySpec(key, "HmacSHA256");
+ javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA256");
+ byte[] tmpMd;
+ synchronized (mac) {
+ mac.init(keySpec);
+
+ tmpMd = mac.doFinal(data);
+ }
+ System.arraycopy(tmpMd, 0, md, 0, tmpMd.length);
+
+ return tmpMd.length;
+ }catch (Exception ex) {
+ throw new SecurityException(SecClientMsgKeys.HMAC_FAILED, null);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/NCSAddress.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/NCSAddress.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/NCSAddress.java
new file mode 100644
index 0000000..a23c7e6
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/NCSAddress.java
@@ -0,0 +1,220 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+/**********************************************************
+ * This class represents an address reference.
+ *
+ * @version 1.0
+ **********************************************************/
+
+import java.sql.SQLException;
+import java.util.Locale;
+
+final class NCSAddress extends Address {
+
+ private static final String ODBCServerPrefix = "TCP:";
+ private static final String ODBCServerSuffix = ":ODBC";
+ private static final int minODBCServerAddrLen = ODBCServerPrefix.length() + 7 + ODBCServerSuffix.length();
+
+ static final int OS_type = 2; // TCP:\<Machine Name>.<Process
+
+ // Name>/<port>:ODBC
+
+ /**
+ * The constructor.
+ *
+ * @param addr
+ * The addr has the format:
+ *
+ * ODBC server connect format returned by the ODBC Association Server.
+ *
+ * TCP:\<{IP Address|Machine Name}>.<Process Name>/<port>:ODBC
+ *
+ *
+ */
+ NCSAddress(T4Properties t4props, Locale locale, String addr) throws SQLException {
+ super(t4props, locale, addr);
+ int index0;
+ int index1;
+ int index2;
+ int index3;
+
+ m_locale = locale;
+
+ if (addr == null) {
+ SQLException se = HPT4Messages.createSQLException(m_t4props, m_locale, "address_null_error", null);
+ throw se;
+ }
+
+ if (acceptsURL(addr) == true) {
+ //
+ // We are dealing with an address of the form:
+ //
+ // TCP:\<{IP Address|Machine Name}>.<Process
+ // Name>/<port>:ODBC
+ //
+ m_type = OS_type;
+ if (addr.endsWith(ODBCServerSuffix) == false) {
+ SQLException se = HPT4Messages.createSQLException(m_t4props, m_locale, "address_parsing_error", addr);
+ SQLException se2 = HPT4Messages.createSQLException(m_t4props, m_locale, "odbc_server_suffix_error",
+ ODBCServerSuffix);
+
+ se.setNextException(se2);
+ throw se;
+ }
+ if (addr.length() < minODBCServerAddrLen) {
+ SQLException se = HPT4Messages.createSQLException(m_t4props, m_locale, "address_parsing_error", addr);
+ SQLException se2 = HPT4Messages.createSQLException(m_t4props, m_locale, "min_address_length_error",
+ null);
+
+ se.setNextException(se2);
+ throw se;
+ }
+
+ addr = addr.substring(ODBCServerPrefix.length());
+ addr = addr.substring(0, addr.length() - ODBCServerSuffix.length());
+
+ if (addr.indexOf(",") > 0)
+ interpretNEOAddress(t4props, locale, addr);
+ else
+ interpretAddress(t4props, locale, addr);
+
+ if ((m_machineName == null && m_ipAddress == null) || m_processName == null || m_portNumber == null) {
+ SQLException se = HPT4Messages.createSQLException(m_t4props, m_locale, "address_parsing_error", addr);
+ SQLException se2 = HPT4Messages.createSQLException(m_t4props, m_locale, "address_format_1_error", null);
+
+ se.setNextException(se2);
+ throw se;
+ }
+ }
+ } // end Address
+
+ // ----------------------------------------------------------
+ void interpretAddress(T4Properties t4props, Locale locale, String addr) throws SQLException {
+ //
+ // We are now expecting addr = "\<machine name>.<process name>/<port
+ // number>"
+ //
+
+ int index1 = addr.indexOf("\\");
+ int index3 = addr.indexOf("/");
+
+ //
+ // Find <{IP Address|Machine Name}>
+ //
+ int index2 = addr.lastIndexOf(".", index3);
+
+ if ((-1 < index1 && index1 < index2 && index2 < index3 && index3 < addr.length()) == false) {
+ SQLException se = HPT4Messages.createSQLException(m_t4props, m_locale, "address_parsing_error", addr);
+ SQLException se2 = HPT4Messages.createSQLException(m_t4props, m_locale, "address_format_1_error", null);
+
+ se.setNextException(se2);
+ throw se;
+ }
+
+ String temp4 = addr.substring((index1 + 1), index2);
+
+ if (Character.isDigit(temp4.charAt(0)) || temp4.substring(0, 1).equals("[")) {
+ //
+ // If first letter is a digit or "[" (i.e. IPv6), I'll assume it is
+ // an IP address
+ //
+ m_ipAddress = temp4;
+ } else {
+ m_machineName = temp4;
+ }
+
+ m_processName = addr.substring((index2 + 1), index3);
+ m_portNumber = new Integer(addr.substring((index3 + 1), addr.length()));
+ }
+
+ void interpretNEOAddress(T4Properties t4props, Locale locale, String addr) throws SQLException {
+ //
+ // We are now expecting addr = "\<machine name>.<process name>,<{IP
+ // Address|Machine Name}>/<port number>"
+ //
+ //int index1 = addr.indexOf("\\");
+ int index3 = addr.indexOf("/");
+ int index4 = addr.indexOf(",");
+ //
+ // Find <{IP Address|Machine Name}>
+ //
+ int index2 = addr.indexOf(".", 0);
+
+ if ((/*-1 < index1 && index1 < index2 &&*/ index2 < index4 && index4 < index3 && index3 < addr.length()) == false) {
+ SQLException se = HPT4Messages.createSQLException(m_t4props, m_locale, "address_parsing_error", addr);
+ SQLException se2 = HPT4Messages.createSQLException(m_t4props, m_locale, "address_format_1_error", null);
+
+ se.setNextException(se2);
+ throw se;
+ }
+
+ String temp4 = addr.substring((index4 + 1), index3);
+
+ if (Character.isDigit(temp4.charAt(0)) || temp4.substring(0, 1).equals("[")) {
+ //
+ // If first letter is a digit or "[" (i.e. IPv6), I'll assume it is
+ // an IP address
+ //
+ m_ipAddress = temp4;
+ } else {
+ m_machineName = temp4;
+ }
+
+ m_processName = addr.substring((index2 + 1), index4);
+ m_portNumber = new Integer(addr.substring((index3 + 1), addr.length()));
+ }
+
+ // ----------------------------------------------------------
+ String recreateAddress() {
+ String addr = ODBCServerPrefix + "\\";
+
+ if (m_machineName != null) {
+ addr = addr + m_machineName;
+ }
+ addr = addr + ".";
+
+ if (m_processName != null) {
+ addr = addr + m_processName;
+
+ }
+ addr = addr + "/";
+
+ if (m_portNumber != null) {
+ addr = addr + m_portNumber;
+
+ }
+ addr = addr + ODBCServerSuffix;
+
+ return addr;
+ } // end recreateAddress
+
+ static boolean acceptsURL(String url) throws SQLException {
+ try {
+ return (url.toUpperCase().startsWith(ODBCServerPrefix));
+ } catch (Exception ex) {
+ throw new SQLException(ex.toString());
+ }
+ }
+
+} // end class Address
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/OUT_CONNECTION_CONTEXT_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/OUT_CONNECTION_CONTEXT_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/OUT_CONNECTION_CONTEXT_def.java
new file mode 100644
index 0000000..b7b07dc
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/OUT_CONNECTION_CONTEXT_def.java
@@ -0,0 +1,97 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.sql.SQLException;
+
+class OUT_CONNECTION_CONTEXT_def {
+ static final long OUTCONTEXT_OPT1_ENFORCE_ISO88591 = 1; // (2^0)
+ static final long OUTCONTEXT_OPT1_IGNORE_SQLCANCEL = 1073741824; // (2^30)
+ static final long OUTCONTEXT_OPT1_EXTRA_OPTIONS = 2147483648L; // (2^31)
+ static final long OUTCONTEXT_OPT1_DOWNLOAD_CERTIFICATE = 536870912; //(2^29)
+
+ VERSION_LIST_def versionList;
+
+ short nodeId;
+ int processId;
+
+ String computerName;
+ String catalog;
+ String schema;
+
+ int optionFlags1;
+ int optionFlags2;
+
+ String _roleName;
+ boolean _enforceISO;
+ boolean _ignoreCancel;
+
+ byte [] certificate;
+
+ void extractFromByteArray(LogicalByteArray buf, InterfaceConnection ic) throws SQLException,
+ UnsupportedCharsetException, CharacterCodingException {
+ versionList = new VERSION_LIST_def();
+ versionList.extractFromByteArray(buf);
+
+ nodeId = buf.extractShort();
+ processId = buf.extractInt();
+ computerName = ic.decodeBytes(buf.extractString(), 1);
+
+ catalog = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ schema = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ optionFlags1 = buf.extractInt();
+ optionFlags2 = buf.extractInt();
+
+ this._enforceISO = (optionFlags1 & OUTCONTEXT_OPT1_ENFORCE_ISO88591) > 0;
+ this._ignoreCancel = (optionFlags1 & OUTCONTEXT_OPT1_IGNORE_SQLCANCEL) > 0;
+ if((optionFlags1 & OUTCONTEXT_OPT1_DOWNLOAD_CERTIFICATE) > 0) {
+ certificate = buf.extractByteArray();
+ }
+ else if ((optionFlags1 & OUTCONTEXT_OPT1_EXTRA_OPTIONS) > 0) {
+ try {
+ this.decodeExtraOptions(ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8));
+ } catch (Exception e) {
+ ic.t4props_.logger.warning("An error occurred parsing OutConnectionContext: " + e.getMessage());
+ }
+ }
+ }
+
+ public void decodeExtraOptions(String options) {
+ String[] opts = options.split(";");
+ String token;
+ String value;
+ int index;
+
+ for (int i = 0; i < opts.length; i++) {
+ index = opts[i].indexOf('=');
+ token = opts[i].substring(0, index).toUpperCase();
+ value = opts[i].substring(index + 1);
+
+ if (token.equals("RN")) {
+ this._roleName = value;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareMessage.java
new file mode 100644
index 0000000..2c7599a
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareMessage.java
@@ -0,0 +1,82 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+
+class PrepareMessage {
+ // ----------------------------------------------------------
+ static LogicalByteArray marshal(int dialogueId, int sqlAsyncEnable, int queryTimeout, short stmtType,
+ int sqlStmtType, String stmtLabel, int stmtLabelCharset, String cursorName, int cursorNameCharset,
+ String moduleName, int moduleNameCharset, long moduleTimestamp, String sqlString, int sqlStringCharset,
+ String stmtOptions, String stmtExplainLabel, int maxRowsetSize, byte[] txId, InterfaceConnection ic)
+ throws CharacterCodingException, UnsupportedCharsetException {
+ int wlength = Header.sizeOf();
+ LogicalByteArray buf;
+
+ byte[] stmtLabelBytes = ic.encodeString(stmtLabel, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] cursorNameBytes = ic.encodeString(cursorName, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] moduleNameBytes = ic.encodeString(moduleName, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] sqlStringBytes = ic.encodeString(sqlString, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] stmtOptionsBytes = ic.encodeString(stmtOptions, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] stmtExplainLabelBytes = ic.encodeString(stmtExplainLabel, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ wlength += TRANSPORT.size_int; // dialogueId
+ wlength += TRANSPORT.size_int; // sqlAsyncEnable
+ wlength += TRANSPORT.size_int; // queryTimeout
+ wlength += TRANSPORT.size_short; // stmtType
+ wlength += TRANSPORT.size_int; // sqlStmtType
+ wlength += TRANSPORT.size_bytesWithCharset(stmtLabelBytes); // +stmtCharset
+ wlength += TRANSPORT.size_bytesWithCharset(cursorNameBytes); // +cursorCharset
+ wlength += TRANSPORT.size_bytesWithCharset(moduleNameBytes);
+ if (moduleName != null && moduleName.length() > 0) {
+ wlength += TRANSPORT.size_long; // moduleTimestamp
+ }
+ wlength += TRANSPORT.size_bytesWithCharset(sqlStringBytes); // +sqlStringCharset
+ wlength += TRANSPORT.size_bytes(stmtOptionsBytes);
+ wlength += TRANSPORT.size_bytes(stmtExplainLabelBytes);
+ wlength += TRANSPORT.size_int; // maxRowsetSize
+ wlength += TRANSPORT.size_bytes(txId); // transId
+
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+
+ buf.insertInt(dialogueId);
+ buf.insertInt(sqlAsyncEnable);
+ buf.insertInt(queryTimeout);
+ buf.insertShort(stmtType);
+ buf.insertInt(sqlStmtType);
+ buf.insertStringWithCharset(stmtLabelBytes, stmtLabelCharset);
+ buf.insertStringWithCharset(cursorNameBytes, cursorNameCharset);
+ buf.insertStringWithCharset(moduleNameBytes, moduleNameCharset);
+ if (moduleName != null && moduleName.length() > 0) {
+ buf.insertLong(moduleTimestamp);
+ }
+ buf.insertStringWithCharset(sqlStringBytes, sqlStringCharset);
+ buf.insertString(stmtOptionsBytes);
+ buf.insertString(stmtExplainLabelBytes);
+ buf.insertInt(maxRowsetSize);
+ buf.insertString(txId);
+
+ return buf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareReply.java
new file mode 100644
index 0000000..82b0448
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PrepareReply.java
@@ -0,0 +1,103 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+
+class PrepareReply {
+ int returnCode;
+ int totalErrorLength;
+ SQLWarningOrError[] errorList;
+ int sqlQueryType;
+ int stmtHandle;
+ int estimatedCost;
+
+ int inputDescLength;
+ int inputParamLength;
+ int inputNumberParams;
+ Descriptor2[] inputDesc;
+
+ int outputDescLength;
+ int outputParamLength;
+ int outputNumberParams;
+ Descriptor2[] outputDesc;
+
+ // -------------------------------------------------------------
+ PrepareReply(LogicalByteArray buf, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException {
+ buf.setLocation(Header.sizeOf());
+
+ returnCode = buf.extractInt();
+
+ // should check SQL_SUCCESS or SQL_SUCCESS_WITH_INFO
+ // if(returnCode == TRANSPORT.SQL_SUCCESS)
+ if (returnCode == TRANSPORT.SQL_SUCCESS || returnCode == TRANSPORT.SQL_SUCCESS_WITH_INFO) {
+ if (returnCode == TRANSPORT.SQL_SUCCESS_WITH_INFO) {
+ totalErrorLength = buf.extractInt();
+
+ if (totalErrorLength > 0) {
+ errorList = new SQLWarningOrError[buf.extractInt()];
+ for (int i = 0; i < errorList.length; i++) {
+ errorList[i] = new SQLWarningOrError(buf, ic, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ }
+ }
+ }
+ sqlQueryType = buf.extractInt();
+ stmtHandle = buf.extractInt();
+ estimatedCost = buf.extractInt();
+
+ inputDescLength = buf.extractInt();
+ if (inputDescLength > 0) {
+ inputParamLength = buf.extractInt();
+ inputNumberParams = buf.extractInt();
+
+ inputDesc = new Descriptor2[inputNumberParams];
+ for (int i = 0; i < inputNumberParams; i++) {
+ inputDesc[i] = new Descriptor2(buf, ic);
+ inputDesc[i].setRowLength(inputParamLength);
+ }
+ }
+
+ outputDescLength = buf.extractInt();
+ if (outputDescLength > 0) {
+ outputParamLength = buf.extractInt();
+ outputNumberParams = buf.extractInt();
+
+ outputDesc = new Descriptor2[outputNumberParams];
+ for (int i = 0; i < outputNumberParams; i++) {
+ outputDesc[i] = new Descriptor2(buf, ic);
+ outputDesc[i].setRowLength(outputParamLength);
+ }
+ }
+ } else {
+ totalErrorLength = buf.extractInt();
+
+ if (totalErrorLength > 0) {
+ errorList = new SQLWarningOrError[buf.extractInt()];
+ for (int i = 0; i < errorList.length; i++) {
+ errorList[i] = new SQLWarningOrError(buf, ic, ic.getISOMapping());
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PreparedStatementManager.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PreparedStatementManager.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PreparedStatementManager.java
new file mode 100644
index 0000000..801a4b1
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/PreparedStatementManager.java
@@ -0,0 +1,242 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.io.PrintWriter;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.logging.Level;
+
+public abstract class PreparedStatementManager extends HPT4Handle {
+
+ boolean isStatementCachingEnabled() {
+ if (maxStatements_ < 1) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ boolean makeRoom() throws SQLException {
+ if (out_ != null) {
+ if (traceLevel_ != Level.OFF) {
+ out_.println(traceId_ + "makeRoom()");
+ }
+ }
+
+ Iterator i;
+ CachedPreparedStatement cs;
+ long oldest;
+ long stmtTime;
+ String key;
+
+ i = (prepStmtsInCache_.values()).iterator();
+ if (!i.hasNext()) {
+ return false;
+ }
+ cs = (CachedPreparedStatement) i.next();
+ stmtTime = cs.getLastUsedTime();
+ key = cs.getLookUpKey();
+ oldest = stmtTime;
+
+ for (; i.hasNext();) {
+ cs = (CachedPreparedStatement) i.next();
+ stmtTime = cs.getLastUsedTime();
+ if (oldest > stmtTime) {
+ oldest = stmtTime;
+ key = cs.getLookUpKey();
+ }
+ }
+ cs = (CachedPreparedStatement) prepStmtsInCache_.remove(key);
+ if (cs != null) {
+ if (cs.inUse_ == false) // if the user has already closed the
+ // statement, hard close it
+ cs.close(true);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ void closePreparedStatementsAll() throws SQLException {
+
+ if (out_ != null) {
+ if (traceLevel_ != Level.OFF) {
+ out_.println(traceId_ + "closePreparedStatementsAll()");
+ }
+ }
+
+ Object[] csArray;
+
+ CachedPreparedStatement cs;
+ int i = 0;
+
+ csArray = (prepStmtsInCache_.values()).toArray();
+ for (i = 0; i < csArray.length; i++) {
+ cs = (CachedPreparedStatement) csArray[i];
+ if (cs != null) {
+ cs.close(false);
+ }
+ }
+ }
+
+ private String createKey(TrafT4Connection connect, String sql, int resultSetHoldability) throws SQLException {
+ String lookupKey = sql + connect.getCatalog() + connect.getSchema() + connect.getTransactionIsolation()
+ + resultSetHoldability;
+
+ return lookupKey;
+ }
+
+ boolean closePreparedStatement(TrafT4Connection connect, String sql, int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ if (out_ != null) {
+ if (traceLevel_ != Level.OFF) {
+ out_.println(traceId_ + "closePreparedStatement(" + connect + ",\"" + sql + "\"," + resultSetType + ","
+ + resultSetConcurrency + "," + resultSetHoldability + ")");
+ }
+ }
+
+ CachedPreparedStatement cs;
+
+ String lookupKey = createKey(connect, sql, resultSetHoldability);
+
+ cs = (CachedPreparedStatement) prepStmtsInCache_.get(lookupKey);
+ if (cs != null) {
+ cs.inUse_ = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ void clearPreparedStatementsAll() {
+ if (out_ != null) {
+ if (traceLevel_ != Level.OFF) {
+ out_.println(traceId_ + "clearPreparedStatementsAll()");
+ }
+ }
+ if (prepStmtsInCache_ != null) {
+ prepStmtsInCache_.clear();
+ }
+ count_ = 0;
+ }
+
+ void addPreparedStatement(TrafT4Connection connect, String sql, PreparedStatement pStmt, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ if (out_ != null) {
+ if (traceLevel_ != Level.OFF) {
+ out_.println(traceId_ + "addPreparedStatement(" + connect + ",\"" + sql + "\"," + pStmt + ","
+ + resultSetType + "," + resultSetConcurrency + "," + resultSetHoldability + ")");
+ }
+ }
+
+ CachedPreparedStatement cachedStmt;
+
+ String lookupKey = createKey(connect, sql, resultSetHoldability);
+
+ cachedStmt = (CachedPreparedStatement) prepStmtsInCache_.get(lookupKey);
+ if (cachedStmt != null) {
+ // Update the last use time
+ cachedStmt.setLastUsedInfo();
+ } else {
+ if (count_ < maxStatements_) {
+ cachedStmt = new CachedPreparedStatement(pStmt, lookupKey);
+ prepStmtsInCache_.put(lookupKey, cachedStmt);
+ count_++;
+ } else {
+ if (makeRoom()) {
+ cachedStmt = new CachedPreparedStatement(pStmt, lookupKey);
+ prepStmtsInCache_.put(lookupKey, cachedStmt);
+ }
+ }
+ }
+ }
+
+ PreparedStatement getPreparedStatement(TrafT4Connection connect, String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ if (out_ != null) {
+ if (traceLevel_ != Level.OFF) {
+ out_.println(traceId_ + "getPreparedStatement(" + connect + ",\"" + sql + "\"," + resultSetType + ","
+ + resultSetConcurrency + "," + resultSetHoldability + ")");
+ }
+ }
+
+ PreparedStatement pStmt = null;
+ CachedPreparedStatement cachedStmt;
+
+ String lookupKey = createKey(connect, sql, resultSetHoldability);
+
+ if (prepStmtsInCache_ != null) {
+ cachedStmt = (CachedPreparedStatement) prepStmtsInCache_.get(lookupKey);
+ if (cachedStmt != null) {
+ if (!cachedStmt.inUse_) {
+ pStmt = cachedStmt.getPreparedStatement();
+ ((org.trafodion.jdbc.t4.TrafT4PreparedStatement) pStmt).reuse(connect, resultSetType, resultSetConcurrency,
+ resultSetHoldability);
+ } else {
+ pStmt = null;
+ }
+ }
+ }
+ return pStmt;
+ }
+
+ void setLogInfo(Level traceLevel, PrintWriter out) {
+ this.traceLevel_ = traceLevel;
+ this.out_ = out;
+
+ }
+
+ PreparedStatementManager() {
+ super();
+ String className = getClass().getName();
+ traceId_ = "jdbcTrace:[" + Thread.currentThread() + "]:[" + hashCode() + "]:" + className + ".";
+ }
+
+ PreparedStatementManager(T4Properties t4props) {
+ super();
+
+ String className = getClass().getName();
+
+ String tmp;
+
+ if (t4props != null) {
+ maxStatements_ = t4props.getMaxStatements();
+
+ }
+ if (maxStatements_ > 0) {
+ prepStmtsInCache_ = new Hashtable();
+ }
+ traceId_ = "jdbcTrace:[" + Thread.currentThread() + "]:[" + hashCode() + "]:" + className + ".";
+ }
+
+ private Hashtable prepStmtsInCache_;
+ private int maxStatements_;
+ private int count_;
+
+ Level traceLevel_;
+ PrintWriter out_;
+ String traceId_;
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Row.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Row.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Row.java
new file mode 100644
index 0000000..21ee6f3
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Row.java
@@ -0,0 +1,233 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.BitSet;
+import java.util.Locale;
+
+// Referenced classes of package sun.jdbc.rowset:
+// BaseRow
+
+class Row extends BaseRow implements Serializable, Cloneable {
+
+ private Object currentVals[];
+ private BitSet colsChanged;
+ private boolean deleted;
+ private boolean updated;
+ private boolean inserted;
+ private int numCols;
+
+ Row(int i) {
+ origVals = new Object[i];
+ currentVals = new Object[i];
+ colsChanged = new BitSet(i);
+ numCols = i;
+ }
+
+ Row(int i, Object aobj[]) {
+ origVals = new Object[i];
+ for (int j = 0; j < i; j++) {
+ origVals[j] = aobj[j];
+
+ }
+ currentVals = new Object[i];
+ colsChanged = new BitSet(i);
+ numCols = i;
+ }
+
+ protected void clearDeleted() {
+ deleted = false;
+ }
+
+ protected void clearInserted() {
+ inserted = false;
+ }
+
+ protected void clearUpdated() {
+ updated = false;
+ for (int i = 0; i < numCols; i++) {
+ currentVals[i] = null;
+ colsChanged.clear(i);
+ }
+
+ }
+
+ protected boolean getColUpdated(int i) {
+ return colsChanged.get(i);
+ }
+
+ protected Object getColumnObject(int i) throws SQLException {
+ if (getColUpdated(i - 1)) {
+ return currentVals[i - 1];
+ } else {
+ return origVals[i - 1];
+ }
+ }
+
+ protected boolean getDeleted() {
+ return deleted;
+ }
+
+ protected boolean getInserted() {
+ return inserted;
+ }
+
+ protected boolean getUpdated() {
+ return updated;
+ }
+
+ protected void initColumnObject(int i, Object obj) {
+ origVals[i - 1] = obj;
+ }
+
+ protected void moveCurrentToOrig() {
+ for (int i = 0; i < numCols; i++) {
+ if (getColUpdated(i)) {
+ origVals[i] = currentVals[i];
+ currentVals[i] = null;
+ colsChanged.clear(i);
+ }
+ }
+ }
+
+ private void setColUpdated(int i) {
+ colsChanged.set(i);
+ }
+
+ protected void setColumnObject(int i, Object obj) {
+ currentVals[i - 1] = obj;
+ setColUpdated(i - 1);
+ }
+
+ protected void setLobObject(int i, Object obj) {
+ currentVals[i - 1] = obj;
+ origVals[i - 1] = obj;
+ }
+
+ protected void setDeleted() {
+ deleted = true;
+ }
+
+ protected void setInserted() {
+ inserted = true;
+ }
+
+ protected void setUpdated() {
+ updated = true;
+ }
+
+ protected void deleteRow(Locale locale, PreparedStatement deleteStmt, BitSet paramCols) throws SQLException {
+ int i;
+ int j;
+ int count;
+
+ for (i = 0, j = 1; i < numCols; i++) {
+ if (paramCols.get(i)) {
+ deleteStmt.setObject(j++, origVals[i]);
+ }
+ }
+ count = deleteStmt.executeUpdate();
+ if (count == 0) {
+ throw HPT4Messages.createSQLException(null, locale, "row_modified", null);
+ }
+ }
+
+ protected void updateRow(Locale locale, PreparedStatement updateStmt, BitSet paramCols, BitSet keyCols)
+ throws SQLException {
+ int i;
+ int j;
+ int count;
+
+ for (i = 0, j = 1; i < numCols; i++) {
+ if (keyCols.get(i)) {
+ if (getColUpdated(i)) {
+ throw HPT4Messages.createSQLException(null, locale, "primary_key_not_updateable", null);
+ }
+ } else {
+ if (paramCols.get(i)) { // LOB Support SB 10/8/2004
+ Object obj = getColumnObject((i + 1));
+
+
+ updateStmt.setObject(j++, getColumnObject(i + 1));
+ }
+ }
+ }
+
+ for (i = 0; i < numCols; i++) {
+ // if (paramCols.get(i))
+ if (keyCols.get(i)) {
+ Object obj = origVals[i];
+
+
+ updateStmt.setObject(j++, origVals[i]);
+ }
+ }
+
+ count = updateStmt.executeUpdate();
+ if (count == 0) {
+ throw HPT4Messages.createSQLException(null, locale, "row_modified", null);
+ }
+ moveCurrentToOrig();
+ setUpdated();
+ }
+
+ protected void refreshRow(Locale locale, PreparedStatement selectStmt, BitSet selectCols, BitSet keyCols)
+ throws SQLException {
+ int i;
+ int j;
+ ResultSet rs;
+ ResultSetMetaData rsmd;
+ int columnCount;
+
+ clearUpdated();
+
+ for (i = 0, j = 1; i < numCols; i++) {
+ if (keyCols.get(i)) {
+ selectStmt.setObject(j++, origVals[i]);
+ }
+ }
+ rs = selectStmt.executeQuery();
+ if (rs != null) {
+ try {
+ rsmd = rs.getMetaData();
+ columnCount = rsmd.getColumnCount();
+ rs.next();
+ for (i = 0, j = 1; i < numCols; i++) {
+ if (selectCols.get(i)) {
+ origVals[i] = rs.getObject(j++);
+ }
+ }
+ } catch (SQLException ex) {
+ throw ex;
+ } finally {
+ rs.close();
+ }
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescList_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescList_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescList_def.java
new file mode 100644
index 0000000..042772b
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescList_def.java
@@ -0,0 +1,46 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+
+class SQLItemDescList_def {
+ SQLItemDesc_def[] list;
+
+ public SQLItemDescList_def(LogicalByteArray buf, boolean useOld, InterfaceConnection ic)
+ throws CharacterCodingException, UnsupportedCharsetException {
+ int length = buf.extractInt();
+
+ if (length > 0) {
+ if (!useOld) {
+ length = buf.extractInt();
+ }
+ list = new SQLItemDesc_def[length];
+
+ for (int i = 0; i < length; i++) {
+ list[i] = (useOld) ? new SQLItemDescOld_def() : new SQLItemDesc_def();
+ list[i].extractFromByteArray(buf, ic);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescOld_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescOld_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescOld_def.java
new file mode 100644
index 0000000..666f37c
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDescOld_def.java
@@ -0,0 +1,54 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+
+class SQLItemDescOld_def extends SQLItemDesc_def {
+ void extractFromByteArray(LogicalByteArray buf, InterfaceConnection ic) throws UnsupportedCharsetException,
+ CharacterCodingException {
+ version = buf.extractInt();
+ dataType = buf.extractInt();
+ datetimeCode = buf.extractInt();
+ maxLen = buf.extractInt();
+ precision = buf.extractShort();
+ scale = buf.extractShort();
+ nullInfo = buf.extractByte();
+
+ colHeadingNm = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ signType = buf.extractByte();
+ ODBCDataType = buf.extractInt();
+ ODBCPrecision = buf.extractShort();
+ SQLCharset = buf.extractInt();
+ ODBCCharset = buf.extractInt();
+
+ TableName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ CatalogName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ SchemaName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Heading = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ intLeadPrec = buf.extractInt();
+ paramMode = buf.extractInt();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDesc_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDesc_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDesc_def.java
new file mode 100644
index 0000000..24d0b04
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLItemDesc_def.java
@@ -0,0 +1,70 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+
+class SQLItemDesc_def {
+ int version;
+ int dataType;
+ int datetimeCode;
+ int maxLen;
+ short precision;
+ short scale;
+ byte nullInfo;
+ String colHeadingNm;
+ byte signType;
+ int ODBCDataType;
+ short ODBCPrecision;
+ int SQLCharset;
+ int ODBCCharset;
+ String TableName;
+ String CatalogName;
+ String SchemaName;
+ String Heading;
+ int intLeadPrec;
+ int paramMode;
+
+ void extractFromByteArray(LogicalByteArray buf, InterfaceConnection ic) throws UnsupportedCharsetException,
+ CharacterCodingException {
+ version = buf.extractInt();
+ dataType = buf.extractInt();
+ datetimeCode = buf.extractInt();
+ maxLen = buf.extractInt();
+ precision = buf.extractShort();
+ scale = buf.extractShort();
+ nullInfo = buf.extractByte();
+ signType = buf.extractByte();
+ ODBCDataType = buf.extractInt();
+ ODBCPrecision = buf.extractShort();
+ SQLCharset = buf.extractInt();
+ ODBCCharset = buf.extractInt();
+ colHeadingNm = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ TableName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ CatalogName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ SchemaName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Heading = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ intLeadPrec = buf.extractInt();
+ paramMode = buf.extractInt();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValueList_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValueList_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValueList_def.java
new file mode 100644
index 0000000..a56b1c5
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValueList_def.java
@@ -0,0 +1,64 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.sql.SQLException;
+
+class SQLValueList_def {
+ SQLValue_def[] buffer;
+
+ // ----------------------------------------------------------
+ int sizeof() {
+ int size = TRANSPORT.size_int;
+
+ if (buffer != null) {
+ for (int i = 0; i < buffer.length; i++) {
+ size += buffer[i].sizeof();
+ }
+ }
+ return size;
+ }
+
+ // ----------------------------------------------------------
+ void insertIntoByteArray(LogicalByteArray buf) {
+ if (buffer != null) {
+ buf.insertInt(buffer.length);
+ for (int i = 0; i < buffer.length; i++) {
+ buffer[i].insertIntoByteArray(buf);
+ }
+ } else {
+ buf.insertInt(0);
+ }
+ }
+
+ // ----------------------------------------------------------
+ void extractFromByteArray(LogicalByteArray buf) throws SQLException {
+ int len = buf.extractInt();
+
+ buffer = new SQLValue_def[len];
+
+ for (int i = 0; i < buffer.length; i++) {
+ buffer[i] = new SQLValue_def();
+ buffer[i].extractFromByteArray(buf);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValue_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValue_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValue_def.java
new file mode 100644
index 0000000..5795e7c
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLValue_def.java
@@ -0,0 +1,55 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.sql.SQLException;
+
+class SQLValue_def {
+ int dataType;
+ short dataInd;
+ SQL_DataValue_def dataValue;
+ int dataCharSet;
+
+ // ----------------------------------------------------------
+ int sizeof() {
+ return TRANSPORT.size_int * 2 + TRANSPORT.size_short + dataValue.sizeof();
+ }
+
+ // ----------------------------------------------------------
+ void insertIntoByteArray(LogicalByteArray buf) {
+ buf.insertInt(dataType);
+ buf.insertShort(dataInd);
+ dataValue.insertIntoByteArray(buf);
+ buf.insertInt(dataCharSet);
+ }
+
+ // ----------------------------------------------------------
+ void extractFromByteArray(LogicalByteArray buf) throws SQLException {
+ dataType = buf.extractInt();
+ dataInd = buf.extractShort();
+
+ dataValue = new SQL_DataValue_def();
+ dataValue.extractFromByteArray(buf);
+
+ dataCharSet = buf.extractInt();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLWarningOrError.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLWarningOrError.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLWarningOrError.java
new file mode 100644
index 0000000..a95697e
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQLWarningOrError.java
@@ -0,0 +1,47 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.jdbc.t4;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.UnsupportedCharsetException;
+
+public class SQLWarningOrError {
+ int rowId;
+ int sqlCode;
+ String text;
+ String sqlState;
+
+ public SQLWarningOrError(int rowId, int sqlCode, String text, String sqlState) {
+ this.rowId = rowId;
+ this.sqlCode = sqlCode;
+ this.text = text;
+ this.sqlState = sqlState;
+ }
+
+ public SQLWarningOrError(LogicalByteArray buf, InterfaceConnection ic, int charset)
+ throws CharacterCodingException, UnsupportedCharsetException {
+ rowId = buf.extractInt();
+ sqlCode = buf.extractInt();
+ text = ic.decodeBytes(buf.extractString(), charset);
+ sqlState = new String(buf.extractByteArray(5));
+ buf.extractByte(); // null terminator
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQL_DataValue_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQL_DataValue_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQL_DataValue_def.java
new file mode 100644
index 0000000..edaada8
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SQL_DataValue_def.java
@@ -0,0 +1,54 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.nio.ByteBuffer;
+
+class SQL_DataValue_def {
+ int length;
+ byte[] buffer;
+ ByteBuffer userBuffer;
+
+ // ----------------------------------------------------------
+ int sizeof() {
+ return (buffer != null) ? TRANSPORT.size_int + buffer.length + 1 : TRANSPORT.size_int;
+ }
+
+ // ----------------------------------------------------------
+ void insertIntoByteArray(LogicalByteArray buf) {
+ if (buffer != null) {
+ buf.insertInt(length);
+ buf.insertByteArray(buffer, length);
+ } else {
+ buf.insertInt(0);
+ }
+ }
+
+ // ----------------------------------------------------------
+ void extractFromByteArray(LogicalByteArray buf) {
+ length = buf.extractInt();
+
+ if (length > 0) {
+ buffer = buf.extractByteArray(length);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SecClientMsgKeys.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SecClientMsgKeys.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SecClientMsgKeys.java
new file mode 100644
index 0000000..a1e4d01
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/SecClientMsgKeys.java
@@ -0,0 +1,58 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+*
+/**********************************************************************/
+
+package org.trafodion.jdbc.t4;
+
+public class SecClientMsgKeys
+{
+ /**
+ * Literal constants of java Security Client error messages.
+ */
+
+ public static final String ERR_RETRIEVE_KEY_FROM_FILE = "ERR_RETRIEVE_KEY_FROM_FILE";
+ public static final String SESSION_KEY_GENERATION_FAILED = "SESSION_KEY_GENERATION_FAILED";
+ public static final String INPUT_PARAMETER_IS_NULL = "INPUT_PARAMETER_IS_NULL";
+ public static final String PWD_LENGTH_TOO_LONG = "PWD_LENGTH_TOO_LONG";
+ public static final String ENCRYPTION_FAILED = "ENCRYPTION_FAILED";
+ public static final String HMAC_FAILED = "HMAC_FAILED";
+ public static final String PUBKEY_LENGTH_IS_ZERO = "PUBKEY_LENGTH_IS_ZERO";
+ public static final String ERR_READ_CERT_FILE = "ERR_READ_CERT_FILE";
+ public static final String FAILED_GENERATE_RANDOM_NUM = "FAILED_GENERATE_RANDOM_NUM";
+ public static final String CIPHER_TEXT_LEN_NOT_EQUAL_KEY_LEN = "CIPHER_TEXT_LEN_NOT_EQUAL_KEY_LEN";
+ public static final String BAD_MESSAGE_DIGEST_LEN = "BAD_MESSAGE_DIGEST_LEN";
+ public static final String FILE_NOTFOUND = "FILE_NOTFOUND";
+ public static final String DATA_ENCRYPTION_FAILED = "DATA_ENCRYPTION_FAILED";
+ public static final String DECRYPTION_FAILED = "DECRYPTION_FAILED";
+ public static final String ERR_WRITE_CERT_FILE = "ERR_WRITE_CERT_FILE";
+ public static final String GET_LOCAL_HOST_NAME_FAILED = "GET_LOCAL_HOST_NAME_FAILED";
+ public static final String BAD_TOKEN_LEN = "BAD_TOKEN_LEN";
+ public static final String INCORRECT_TOKEN_FORMAT = "INCORRECT_TOKEN_FORMAT";
+ public static final String HOME_ENVIRONMENT_VAR_IS_NULL = "HOME_ENVIRONMENT_VAR_IS_NULL";
+ public static final String ERR_CREATE_SYMMETRIC_KEY = "ERR_CREATE_SYMMETRIC_KEY";
+ public static final String FAILED_BUILDING_PWDKEY = "FAILED_BUILDING_PWDKEY";
+ public static final String DIR_NOTFOUND = "DIR_NOTFOUND";
+ public static final String ERR_OPEN_INPUT_FILE = "ERR_OPEN_INPUT_FILE";
+ public static final String FILE_CORRUPTION = "FILE_CORRUPTION";
+}
+