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:14 UTC
[35/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/Compression.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Compression.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Compression.java
new file mode 100644
index 0000000..bb2bb8f
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Compression.java
@@ -0,0 +1,149 @@
+// @@@ 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 Compression {
+ private static int MAXCOUNT = 0xFF;
+ // private static int MAXUCOUNT = 0xFFFF;
+ private static int EOFCHAR = -1;
+
+
+
+ public static int compress(int alg, byte [][] sbuf, int [] sstart, int [] slen, byte[] dbuf, int dstart) {
+ int ret = 0;
+
+ switch(alg) {
+ case 1:
+ ret = compress_whitespace(sbuf, sstart, slen, dbuf, dstart);
+ break;
+ }
+
+ return ret;
+ }
+
+ public static int uncompress(int alg, byte [] sbuf, int sstart, int slen, byte [] dbuf, int dstart) {
+ int ret = 0;
+
+ switch(alg) {
+ case 1:
+ ret = uncompress_whitespace(sbuf, sstart, slen, dbuf, dstart);
+ break;
+ }
+
+ return ret;
+ }
+
+ // encodes repeated bytes in the byte form <b><b><#>
+ // b = byte which is repeated
+ // # = number of repetitions (max 255)
+ // source buffers, source lengths, destination buffer
+ private static int compress_whitespace(byte [][] param_sbuf, int [] param_sstart, int [] param_slen, byte[] dbuf, int dstart) {
+ int c = EOFCHAR, p = EOFCHAR;
+ int si = 0, di = dstart; // source, destination indexes
+ int cnt = 0; // count of repetition
+
+ byte []sbuf; //current source buffer
+ int slen; //current source length
+
+ for(int i=0;i<param_sbuf.length;i++) {
+ sbuf = param_sbuf[i];
+ slen = param_slen[i];
+ si = param_sstart[i];
+
+ while(si < slen) {
+ c = sbuf[si++]; // get the next byte from source
+ dbuf[di++] = (byte)c; // copy the byte to destination
+ cnt = 0;
+
+ if(c == p) { // check repetition
+ if(si == slen) {
+ c = EOFCHAR;
+ }
+ while(si < slen) {
+ if ((c = sbuf[si++]) == p) { // found repetition
+ cnt++;
+ if (cnt == MAXCOUNT) { // we can only store 255 in
+ // a byte
+ dbuf[di++] = (byte)cnt;
+
+ p = EOFCHAR; // move on
+ break;
+ }
+ }
+ else {
+ dbuf[di++] = (byte)cnt;
+ dbuf[di++] = (byte) c;
+
+ p = c;
+ break;
+ }
+
+ if (si == slen) {
+ c = EOFCHAR;
+ }
+ }
+ }
+ else {
+ p = c; // set our current as our previous
+ }
+
+ if (c == EOFCHAR) {
+ dbuf[di++] = (byte)cnt;
+ /*
+ * ADDED
+ */
+ p = EOFCHAR;
+ }
+ }
+ }
+
+ return di - dstart;
+ }
+
+ private static int uncompress_whitespace(byte [] sbuf, int sstart, int slen, byte [] dbuf, int dstart) {
+ int c = EOFCHAR, p = EOFCHAR;
+ int si = sstart, di = dstart, i = 0; // source, dest, and generic indexes
+ int cnt = 0;
+
+ while(si < slen ) {
+ c = sbuf[si++] & 0xFF;
+
+ /*if(di >= dbuf.length) {
+ System.out.println("%%%%%failed at " + di);
+ }*/
+ dbuf[di++] = (byte) c;
+
+ if(c == p) {
+ cnt = sbuf[si++] & 0xFF;
+
+ for(i=0;i<cnt;++i) {
+ dbuf[di++] = (byte)c;
+ }
+ p = EOFCHAR;
+ }
+ else {
+ p = c;
+ }
+ }
+
+ return di;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectMessage.java
new file mode 100644
index 0000000..fd594d5
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectMessage.java
@@ -0,0 +1,62 @@
+// @@@ 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 ConnectMessage {
+ static LogicalByteArray marshal(CONNECTION_CONTEXT_def inContext, USER_DESC_def userDesc, int srvrType,
+ short retryCount, int optionFlags1, int optionFlags2, String vproc, InterfaceConnection ic)
+ throws CharacterCodingException, UnsupportedCharsetException {
+ int wlength = Header.sizeOf();
+ LogicalByteArray buf = null;
+
+ byte[] vprocBytes = ic.encodeString(vproc, 1);
+ byte[] clientUserBytes = ic.encodeString(System.getProperty("user.name"), 1);
+
+ wlength += inContext.sizeOf(ic);
+ wlength += userDesc.sizeOf(ic);
+
+ wlength += TRANSPORT.size_int; // srvrType
+ wlength += TRANSPORT.size_short; // retryCount
+ wlength += TRANSPORT.size_int; // optionFlags1
+ wlength += TRANSPORT.size_int; // optionFlags2
+ wlength += TRANSPORT.size_bytes(vprocBytes);
+
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+
+ inContext.insertIntoByteArray(buf);
+ userDesc.insertIntoByteArray(buf);
+
+ buf.insertInt(srvrType);
+ buf.insertShort(retryCount);
+ buf.insertInt(optionFlags1);
+ buf.insertInt(optionFlags2);
+ buf.insertString(vprocBytes);
+
+ //TODO: restructure all the flags and this new param
+ buf.insertString(clientUserBytes);
+
+ return buf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectReply.java
new file mode 100644
index 0000000..f11b5d5
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ConnectReply.java
@@ -0,0 +1,148 @@
+// @@@ 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;
+import java.util.Locale;
+
+class ConnectReply {
+ odbc_Dcs_GetObjRefHdl_exc_ m_p1_exception;
+ String m_p2_srvrObjRef;
+ int m_p3_dialogueId;
+ String m_p4_dataSource;
+ byte[] m_p5_userSid;
+ VERSION_LIST_def m_p6_versionList;
+ int isoMapping;
+ boolean byteSwap;
+
+ boolean securityEnabled;
+ int serverNode;
+ int processId;
+ byte [] timestamp;
+ String clusterName;
+
+ String serverHostName="";
+ Integer serverNodeId=0;
+ Integer serverProcessId=0;
+ String serverProcessName="";
+ String serverIpAddress="";
+ Integer serverPort=0;
+
+ String remoteHost;
+ String remoteProcess;
+
+ private NCSAddress m_ncsAddr_;
+
+ // -------------------------------------------------------------
+ ConnectReply(LogicalByteArray buf, InterfaceConnection ic) throws SQLException, UnsupportedCharsetException,
+ CharacterCodingException {
+ buf.setLocation(Header.sizeOf());
+
+ m_p1_exception = new odbc_Dcs_GetObjRefHdl_exc_();
+ m_p1_exception.extractFromByteArray(buf, ic);
+
+ this.byteSwap = buf.getByteSwap();
+
+ if (m_p1_exception.exception_nr == TRANSPORT.CEE_SUCCESS) {
+ m_p3_dialogueId = buf.extractInt();
+ m_p4_dataSource = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ m_p5_userSid = buf.extractByteString(); // byteString -- only place
+ // used -- packed length
+ // does not include the null
+ // term
+ m_p6_versionList = new VERSION_LIST_def();
+
+ //buf.setByteSwap(false);
+ m_p6_versionList.extractFromByteArray(buf);
+ //buf.setByteSwap(this.byteSwap);
+
+ buf.extractInt(); //old iso mapping
+
+ /*if ((m_p6_versionList.list[0].buildId & InterfaceConnection.CHARSET) > 0) {
+ isoMapping =
+ } else {*/
+ isoMapping = 15;
+ //}
+ serverHostName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ serverNodeId = buf.extractInt();
+ serverProcessId = buf.extractInt();
+ serverProcessName = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ serverIpAddress = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ serverPort = buf.extractInt();
+
+ m_p2_srvrObjRef = String.format("TCP:%s:%d.%s,%s/%d:ODBC", serverHostName, serverNodeId, serverProcessName, serverIpAddress, serverPort);
+
+ if((m_p6_versionList.list[0].buildId & InterfaceConnection.PASSWORD_SECURITY) > 0) {
+ securityEnabled = true;
+ serverNode = serverNodeId;
+ processId = serverProcessId;
+ timestamp = buf.extractByteArray(8);
+ clusterName = ic.decodeBytes(buf.extractString(), 1);
+ }
+ else {
+ securityEnabled = false;
+ }
+ }
+ }
+
+ // -------------------------------------------------------------
+ void fixupSrvrObjRef(T4Properties t4props, Locale locale, String name) throws SQLException {
+ //
+ // This method will replace the domain name returned from the
+ // Association server, with a new name.
+ //
+ m_ncsAddr_ = null;
+
+ if (m_p2_srvrObjRef != null) {
+ remoteHost = m_p2_srvrObjRef.substring(4,m_p2_srvrObjRef.indexOf('$') - 1);
+ remoteProcess = m_p2_srvrObjRef.substring(m_p2_srvrObjRef.indexOf('$'), m_p2_srvrObjRef.indexOf(','));
+
+ try {
+ m_ncsAddr_ = new NCSAddress(t4props, locale, m_p2_srvrObjRef);
+ } catch (SQLException e) {
+ throw e;
+ }
+
+ // use your best guess if m_machineName was not found
+ if (m_ncsAddr_.m_machineName == null) {
+ if (m_ncsAddr_.m_ipAddress == null) {
+ m_ncsAddr_.m_machineName = name;
+ } else {
+ m_ncsAddr_.m_machineName = m_ncsAddr_.m_ipAddress;
+ }
+ }
+
+ m_p2_srvrObjRef = m_ncsAddr_.recreateAddress();
+ m_ncsAddr_.validateAddress();
+ m_ncsAddr_.setInputOutput();
+
+ return;
+ } // end if
+
+ } // end fixupSrvrObjRef
+
+ NCSAddress getNCSAddress() {
+ return m_ncsAddr_;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Descriptor2.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Descriptor2.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Descriptor2.java
new file mode 100644
index 0000000..fd25f51
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Descriptor2.java
@@ -0,0 +1,85 @@
+// @@@ 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 Descriptor2 {
+ int noNullValue_;
+ int nullValue_;
+ int version_;
+ int dataType_;
+ int datetimeCode_;
+ int maxLen_;
+ int precision_;
+ int scale_;
+ int nullInfo_;
+ int signed_;
+ int odbcDataType_;
+ int odbcPrecision_;
+ int sqlCharset_;
+ int odbcCharset_;
+ String colHeadingNm_;
+ String tableName_;
+ String catalogName_;
+ String schemaName_;
+ String headingName_;
+ int intLeadPrec_;
+ int paramMode_;
+
+ private int rowLength;
+
+ public void setRowLength(int len) {
+ rowLength = len;
+ }
+
+ public int getRowLength() {
+ return rowLength;
+ }
+
+ public Descriptor2(LogicalByteArray buf, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException {
+ noNullValue_ = buf.extractInt();
+ nullValue_ = buf.extractInt();
+ version_ = buf.extractInt();
+ dataType_ = buf.extractInt();
+ datetimeCode_ = buf.extractInt();
+ maxLen_ = buf.extractInt();
+ precision_ = buf.extractInt();
+ scale_ = buf.extractInt();
+ nullInfo_ = buf.extractInt();
+ signed_ = buf.extractInt();
+ odbcDataType_ = buf.extractInt();
+ odbcPrecision_ = buf.extractInt();
+ 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);
+ headingName_ = 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/ERROR_DESC_LIST_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ERROR_DESC_LIST_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ERROR_DESC_LIST_def.java
new file mode 100644
index 0000000..039fae3
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ERROR_DESC_LIST_def.java
@@ -0,0 +1,42 @@
+// @@@ 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 ERROR_DESC_LIST_def {
+ int length;
+ ERROR_DESC_def[] buffer;
+
+ // ----------------------------------------------------------
+ void extractFromByteArray(LogicalByteArray buf, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException {
+ length = buf.extractInt();
+ buffer = new ERROR_DESC_def[length];
+
+ for (int i = 0; i < length; i++) {
+ buffer[i] = new ERROR_DESC_def();
+ buffer[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/ERROR_DESC_def.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ERROR_DESC_def.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ERROR_DESC_def.java
new file mode 100644
index 0000000..48ebba2
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ERROR_DESC_def.java
@@ -0,0 +1,65 @@
+// @@@ 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 ERROR_DESC_def {
+ int rowId;
+ int errorDiagnosticId;
+ int sqlcode;
+ String sqlstate;
+ String errorText;
+ int operationAbortId;
+ int errorCodeType;
+ String Param1;
+ String Param2;
+ String Param3;
+ String Param4;
+ String Param5;
+ String Param6;
+ String Param7;
+
+ // ----------------------------------------------------------
+ void extractFromByteArray(LogicalByteArray buffer1, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException {
+ rowId = buffer1.extractInt();
+ errorDiagnosticId = buffer1.extractInt();
+ sqlcode = buffer1.extractInt();
+
+ // Note, SQLSTATE is logically 5 bytes, but ODBC uses 6 bytes for some
+ // reason.
+ sqlstate = ic.decodeBytes(buffer1.extractByteArray(6), 1);
+ errorText = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ operationAbortId = buffer1.extractInt();
+ errorCodeType = buffer1.extractInt();
+ Param1 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Param2 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Param3 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Param4 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Param5 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Param6 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ Param7 = ic.decodeBytes(buffer1.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionMessage.java
new file mode 100644
index 0000000..98a60d4
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionMessage.java
@@ -0,0 +1,49 @@
+// @@@ 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;
+
+class EndTransactionMessage {
+ int m_dialogueId;
+ short m_transactionOpt;
+
+ // ----------------------------------------------------------
+ EndTransactionMessage(int dialogueId, short transactionOpt) {
+ m_dialogueId = dialogueId;
+ m_transactionOpt = transactionOpt;
+ }
+
+ // ----------------------------------------------------------
+ static LogicalByteArray marshal(int dialogueId, short transactionOpt, InterfaceConnection ic) {
+ int wlength = Header.sizeOf();
+ LogicalByteArray buf;
+
+ wlength += TRANSPORT.size_int; // dialogueId
+ wlength += TRANSPORT.size_short; // transactionOpt
+
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+
+ buf.insertInt(dialogueId);
+ buf.insertShort(transactionOpt);
+
+ return buf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionReply.java
new file mode 100644
index 0000000..b85ce2f
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/EndTransactionReply.java
@@ -0,0 +1,49 @@
+// @@@ 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 EndTransactionReply {
+ odbc_SQLSvc_EndTransaction_exc_ m_p1;
+ ERROR_DESC_LIST_def m_p2;
+
+ // -------------------------------------------------------------
+ EndTransactionReply(LogicalByteArray buf, String addr, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException, SQLException {
+ buf.setLocation(Header.sizeOf());
+
+ m_p1 = new odbc_SQLSvc_EndTransaction_exc_();
+ m_p1.extractFromByteArray(buf, addr, ic);
+
+ if (m_p1.exception_nr != TRANSPORT.CEE_SUCCESS) {
+ int totalLen = buf.extractInt();
+
+ if(totalLen > 0) {
+ m_p2 = new ERROR_DESC_LIST_def();
+ m_p2.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/ExecuteMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExecuteMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExecuteMessage.java
new file mode 100644
index 0000000..2911bf9
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExecuteMessage.java
@@ -0,0 +1,107 @@
+// @@@ 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 ExecuteMessage {
+ // ----------------------------------------------------------
+ static LogicalByteArray marshal(int dialogueId, int sqlAsyncEnable, int queryTimeout, int inputRowCnt,
+ int maxRowsetSize, int sqlStmtType, int stmtHandle, int stmtType, String sqlString, int sqlStringCharset,
+ String cursorName, int cursorNameCharset, String stmtLabel, int stmtLabelCharset, String stmtExplainLabel,
+ SQL_DataValue_def inputDataValue, SQLValueList_def inputValueList, byte[] txId, boolean isUserBuffer,
+ InterfaceConnection ic
+
+ ) throws CharacterCodingException, UnsupportedCharsetException
+
+ {
+ int wlength = Header.sizeOf();
+ LogicalByteArray buf;
+
+ byte[] sqlStringBytes = ic.encodeString(sqlString, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] cursorNameBytes = ic.encodeString(cursorName, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] stmtLabelBytes = ic.encodeString(stmtLabel, 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_int; // inputRowCnt
+ wlength += TRANSPORT.size_int; // maxRowsetSize
+ wlength += TRANSPORT.size_int; // sqlStmtType
+ wlength += TRANSPORT.size_int; // stmtHandle
+ wlength += TRANSPORT.size_int; // stmtType
+ wlength += TRANSPORT.size_bytesWithCharset(sqlStringBytes); // +sqlStringCharset
+ wlength += TRANSPORT.size_bytesWithCharset(cursorNameBytes); // +cursorNameCharset
+ wlength += TRANSPORT.size_bytesWithCharset(stmtLabelBytes); // +stmtLabelCharset
+ wlength += TRANSPORT.size_bytes(stmtExplainLabelBytes);
+
+ if (!isUserBuffer) {
+ wlength += inputDataValue.sizeof();
+ wlength += TRANSPORT.size_bytes(txId); // transId
+ }
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+
+ buf.insertInt(dialogueId);
+ buf.insertInt(sqlAsyncEnable);
+ buf.insertInt(queryTimeout);
+ buf.insertInt(inputRowCnt);
+ buf.insertInt(maxRowsetSize);
+ buf.insertInt(sqlStmtType);
+ buf.insertInt(stmtHandle);
+ buf.insertInt(stmtType);
+ buf.insertStringWithCharset(sqlStringBytes, sqlStringCharset);
+ buf.insertStringWithCharset(cursorNameBytes, cursorNameCharset);
+ buf.insertStringWithCharset(stmtLabelBytes, stmtLabelCharset);
+ buf.insertString(stmtExplainLabelBytes);
+
+ if (isUserBuffer) {
+ buf.setDataBuffer(inputDataValue.userBuffer);
+
+ byte[] trailer = null;
+ if (txId == null || txId.length == 0) {
+ trailer = new byte[4];
+ for (int i = 0; i < 4; ++i) {
+ trailer[i] = (byte) 0;
+ }
+ } else {
+ int len = txId.length + 1;
+ trailer = new byte[4 + txId.length + 1];
+
+ trailer[0] = (byte) ((len >>> 24) & 0xff);
+ trailer[1] = (byte) ((len >>> 16) & 0xff);
+ trailer[2] = (byte) ((len >>> 8) & 0xff);
+ trailer[3] = (byte) ((len) & 0xff);
+ System.arraycopy(txId, 0, trailer, 4, txId.length);
+ trailer[len + 4 - 1] = '\0';
+ }
+
+ buf.setTrailer(trailer);
+ } else {
+ inputDataValue.insertIntoByteArray(buf);
+ 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/ExecuteReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExecuteReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExecuteReply.java
new file mode 100644
index 0000000..664c71f
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/ExecuteReply.java
@@ -0,0 +1,127 @@
+// @@@ 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 ExecuteReply {
+ int returnCode;
+ int totalErrorLength;
+ SQLWarningOrError[] errorList;
+ long rowsAffected;
+ int queryType;
+ int estimatedCost;
+ byte[] outValues;
+
+ int numResultSets;
+ Descriptor2[][] outputDesc;
+ String stmtLabels[];
+
+ int outputParamLength;
+ int outputNumberParams;
+
+ String[] proxySyntax;
+
+ // ----------------------------------------------------------
+ ExecuteReply(LogicalByteArray buf, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException {
+
+ buf.setLocation(Header.sizeOf());
+
+ returnCode = buf.extractInt();
+
+ 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);
+ }
+ }
+
+ int outputDescLength = buf.extractInt();
+ if (outputDescLength > 0) {
+ outputDesc = new Descriptor2[1][];
+
+ outputParamLength = buf.extractInt();
+ outputNumberParams = buf.extractInt();
+
+ outputDesc[0] = new Descriptor2[outputNumberParams];
+ for (int i = 0; i < outputNumberParams; i++) {
+ outputDesc[0][i] = new Descriptor2(buf, ic);
+ outputDesc[0][i].setRowLength(outputParamLength);
+ }
+ }
+ rowsAffected = buf.extractUnsignedInt();
+ queryType = buf.extractInt();
+ estimatedCost = buf.extractInt();
+
+ // 64 bit rowsAffected
+ // this is a horrible hack because we cannot change the protocol yet
+ // rowsAffected should be made a regular 64 bit value when possible
+ rowsAffected |= ((long) estimatedCost) << 32;
+
+ outValues = buf.extractByteArray();
+
+ numResultSets = buf.extractInt();
+
+ if (numResultSets > 0) {
+ outputDesc = new Descriptor2[numResultSets][];
+ stmtLabels = new String[numResultSets];
+ proxySyntax = new String[numResultSets];
+
+ for (int i = 0; i < numResultSets; i++) {
+ buf.extractInt(); // int stmt_handle
+
+ stmtLabels[i] = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ buf.extractInt(); // long stmt_label_charset
+ outputDescLength = buf.extractInt();
+
+ int outputParamsLength = 0;
+ int outputNumberParams = 0;
+ Descriptor2[] outputParams = null;
+
+ if (outputDescLength > 0) {
+ outputParamsLength = buf.extractInt();
+ outputNumberParams = buf.extractInt();
+
+ outputParams = new Descriptor2[outputNumberParams];
+ for (int j = 0; j < outputNumberParams; j++) {
+ outputParams[j] = new Descriptor2(buf, ic);
+ outputParams[j].setRowLength(outputParamsLength);
+ }
+ }
+ outputDesc[i] = outputParams;
+ proxySyntax[i] = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ }
+ }
+
+ String singleSyntax = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ if (proxySyntax == null) {
+ proxySyntax = new String[1];
+ proxySyntax[0] = singleSyntax;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchMessage.java
new file mode 100644
index 0000000..0f7d702
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchMessage.java
@@ -0,0 +1,63 @@
+// @@@ 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 FetchMessage {
+ // ----------------------------------------------------------
+ static LogicalByteArray marshal(int dialogueId, int sqlAsyncEnable, int queryTimeout, int stmtHandle,
+ String stmtLabel, int stmtCharset, int maxRowCnt, int maxRowLen, String cursorName, int cursorCharset,
+ String stmtOptions, 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[] stmtOptionsBytes = ic.encodeString(stmtOptions, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ wlength += TRANSPORT.size_int; // dialogueId
+ wlength += TRANSPORT.size_int; // sqlAsyncEnable
+ wlength += TRANSPORT.size_int; // queryTimeout
+ wlength += TRANSPORT.size_int; // stmtHandle
+ wlength += TRANSPORT.size_bytesWithCharset(stmtLabelBytes);
+ wlength += TRANSPORT.size_long; // maxRowCnt
+ wlength += TRANSPORT.size_long; // maxRowLen
+ wlength += TRANSPORT.size_bytesWithCharset(cursorNameBytes);
+ wlength += TRANSPORT.size_bytes(stmtOptionsBytes);
+
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+
+ buf.insertInt(dialogueId);
+ buf.insertInt(sqlAsyncEnable);
+ buf.insertInt(queryTimeout);
+ buf.insertInt(stmtHandle);
+ buf.insertStringWithCharset(stmtLabelBytes, stmtCharset);
+ buf.insertLong(maxRowCnt);
+ buf.insertLong(maxRowLen);
+ buf.insertStringWithCharset(cursorNameBytes, cursorCharset);
+ buf.insertString(stmtOptionsBytes);
+
+ return buf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchReply.java
new file mode 100644
index 0000000..5e82439
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/FetchReply.java
@@ -0,0 +1,63 @@
+// @@@ 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 FetchReply {
+ int returnCode;
+ int totalErrorLength;
+ SQLWarningOrError[] errorList;
+ int rowsAffected;
+ int outValuesFormat;
+ byte[] outValues;
+
+ // -------------------------------------------------------------
+ public FetchReply(LogicalByteArray buf, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException {
+ buf.setLocation(Header.sizeOf());
+
+ returnCode = buf.extractInt();
+
+ if (returnCode != TRANSPORT.SQL_SUCCESS && returnCode != TRANSPORT.NO_DATA_FOUND) {
+ 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);
+ }
+ }
+ }
+
+ if (errorList == null) {
+ errorList = new SQLWarningOrError[0];
+ }
+
+ rowsAffected = buf.extractInt();
+ outValuesFormat = buf.extractInt();
+
+ if (returnCode == TRANSPORT.SQL_SUCCESS || returnCode == TRANSPORT.SQL_SUCCESS_WITH_INFO) {
+ outValues = buf.extractByteArray();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericMessage.java
new file mode 100644
index 0000000..3558872
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericMessage.java
@@ -0,0 +1,45 @@
+// @@@ 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;
+import java.util.Locale;
+
+class GenericMessage {
+ // ----------------------------------------------------------
+ static LogicalByteArray marshal(Locale locale, byte[] messageBuffer, InterfaceConnection ic) throws SQLException
+
+ {
+ int wlength = Header.sizeOf();
+ LogicalByteArray buf;
+
+ if (messageBuffer != null)
+ wlength += messageBuffer.length;
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+ if (messageBuffer != null)
+ buf.insertByteArray(messageBuffer, messageBuffer.length);
+
+ return buf;
+ } // end marshal
+
+} // end class GenericMessage
+
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericReply.java
new file mode 100644
index 0000000..1aa2e8e
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GenericReply.java
@@ -0,0 +1,43 @@
+// @@@ 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;
+import java.util.Locale;
+
+class GenericReply {
+ byte[] replyBuffer;
+
+ // ----------------------------------------------------------
+ GenericReply(Locale locale, LogicalByteArray buf) throws SQLException {
+ Header header = new Header();
+ long bufferLength = 0;
+
+ buf.setLocation(0);
+ header.extractFromByteArray(buf);
+ buf.setLocation(Header.sizeOf());
+ bufferLength = header.total_length_;
+ replyBuffer = buf.extractByteArray(bufferLength);
+
+ } // end marshal
+
+} // end class GenericReply
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsMessage.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsMessage.java
new file mode 100644
index 0000000..17296f6
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsMessage.java
@@ -0,0 +1,88 @@
+// @@@ 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 GetSQLCatalogsMessage {
+ static LogicalByteArray marshal(int dialogueId, String stmtLabel, short APIType, String catalogNm, String schemaNm,
+ String tableNm, String tableTypeList, String columnNm, int columnType, int rowIdScope, int nullable,
+ int uniqueness, int accuracy, short sqlType, int metadataId, String fkCatalogNm, String fkSchemaNm,
+ String fkTableNm, InterfaceConnection ic) throws CharacterCodingException, UnsupportedCharsetException {
+ int wlength = Header.sizeOf();
+ LogicalByteArray buf;
+
+ byte[] stmtLabelBytes = ic.encodeString(stmtLabel, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] catalogNmBytes = ic.encodeString(catalogNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] schemaNmBytes = ic.encodeString(schemaNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] tableNmBytes = ic.encodeString(tableNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] tableTypeListBytes = ic.encodeString(tableTypeList, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] columnNmBytes = ic.encodeString(columnNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ byte[] fkCatalogNmBytes = ic.encodeString(fkCatalogNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] fkSchemaNmBytes = ic.encodeString(fkSchemaNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ byte[] fkTableNmBytes = ic.encodeString(fkTableNm, InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ wlength += TRANSPORT.size_int; // dialogueId
+ wlength += TRANSPORT.size_bytes(stmtLabelBytes);
+ wlength += TRANSPORT.size_short; // APIType
+ wlength += TRANSPORT.size_bytes(catalogNmBytes, true);
+ wlength += TRANSPORT.size_bytes(schemaNmBytes, true);
+ wlength += TRANSPORT.size_bytes(tableNmBytes, true);
+ wlength += TRANSPORT.size_bytes(tableTypeListBytes, true);
+ wlength += TRANSPORT.size_bytes(columnNmBytes, true);
+ wlength += TRANSPORT.size_int; // columnType
+ wlength += TRANSPORT.size_int; // rowIdScope
+ wlength += TRANSPORT.size_int; // nullable
+ wlength += TRANSPORT.size_int; // uniqueness
+ wlength += TRANSPORT.size_int; // accuracy
+ wlength += TRANSPORT.size_short; // sqlType
+ wlength += TRANSPORT.size_int; // metadataId
+ wlength += TRANSPORT.size_bytes(fkCatalogNmBytes, true);
+ wlength += TRANSPORT.size_bytes(fkSchemaNmBytes, true);
+ wlength += TRANSPORT.size_bytes(fkTableNmBytes, true);
+
+ buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
+
+ buf.insertInt(dialogueId);
+ buf.insertString(stmtLabelBytes);
+ buf.insertShort(APIType);
+ buf.insertString(catalogNmBytes, true);
+ buf.insertString(schemaNmBytes, true);
+ buf.insertString(tableNmBytes, true);
+ buf.insertString(tableTypeListBytes, true);
+ buf.insertString(columnNmBytes, true);
+ buf.insertInt(columnType);
+ buf.insertInt(rowIdScope);
+ buf.insertInt(nullable);
+ buf.insertInt(uniqueness);
+ buf.insertInt(accuracy);
+ buf.insertShort(sqlType);
+ buf.insertInt(metadataId);
+ buf.insertString(fkCatalogNmBytes, true);
+ buf.insertString(fkSchemaNmBytes, true);
+ buf.insertString(fkTableNmBytes, true);
+
+ return buf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsReply.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsReply.java
new file mode 100644
index 0000000..9736d47
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/GetSQLCatalogsReply.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;
+import java.sql.SQLException;
+
+class GetSQLCatalogsReply {
+ odbc_SQLSvc_GetSQLCatalogs_exc_ m_p1;
+ String m_p2;
+ SQLItemDescList_def m_p3;
+ ERROR_DESC_LIST_def m_p4;
+ String proxySyntax = "";
+
+ // -------------------------------------------------------------
+ GetSQLCatalogsReply(LogicalByteArray buf, String addr, InterfaceConnection ic) throws CharacterCodingException,
+ UnsupportedCharsetException, SQLException {
+ buf.setLocation(Header.sizeOf());
+
+ m_p1 = new odbc_SQLSvc_GetSQLCatalogs_exc_();
+ m_p1.extractFromByteArray(buf, addr, ic);
+
+ if (m_p1.exception_nr == TRANSPORT.CEE_SUCCESS) {
+ m_p2 = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+
+ m_p3 = new SQLItemDescList_def(buf, true, ic);
+
+ m_p4 = new ERROR_DESC_LIST_def();
+ m_p4.extractFromByteArray(buf, ic);
+
+ proxySyntax = ic.decodeBytes(buf.extractString(), InterfaceUtilities.SQLCHARSETCODE_UTF8);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSource.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSource.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSource.java
new file mode 100644
index 0000000..39e39dd
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSource.java
@@ -0,0 +1,346 @@
+// @@@ 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;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.FileHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+import javax.sql.PooledConnection;
+
+/**
+ *
+ * <p>
+ * JDBC Type 4 Driver <code>ConnectionPoolDataSource</code> class.
+ * </p>
+ * <p>
+ * Description: A <code>ConnectionPoolDataSource</code> object is a factory
+ * for <code>PooledConnection</code> objects. As the name indicates, this
+ * object provides a <code>PooledConnection</code> for data sources to be used
+ * by the application servers.
+ * </p>
+ *
+ * <p>
+ * The <code>HPT4ConnectionPoolDataSource</code> class should be used to
+ * provide JDBC3.0 connection pooling features. The
+ * <code>HPT4ConnectionPoolDataSource</code> is used by the application
+ * servers like WSAS to provide connection pooling features to the J2EE
+ * applications. <code>HPT4ConnectionPoolDataSource.getPooledConnection()</code>
+ * returns the <code>javax.sql.PooledConnection object</code>.
+ * </p>
+ *
+ *
+ * Setting connection properties such as catalog, schema, timeouts, and so on
+ * are done at the higher level objects such as DataSource or DriverManager.
+ *
+ * <p>
+ * Licensed to the Apache Software Foundation (ASF)
+ * </p>
+ *
+ * @see T4Properties
+ * @see HPT4DataSource
+ */
+
+public class HPT4ConnectionPoolDataSource extends T4DSProperties implements javax.sql.ConnectionPoolDataSource,
+ java.io.Serializable, Referenceable
+
+{
+
+ /**
+ * Attempts to establish a physical database connection that can be used as
+ * a pooled connection.
+ *
+ * @return A <code>PooledConnection</code> object that is a physical
+ * connection to the NDCS server that this
+ * <code>HPT4ConnectionPoolDataSource</code> object represents.
+ * @throws SQLException
+ * If any NDCS error occurs.
+ */
+ public PooledConnection getPooledConnection() throws SQLException {
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPooledConnection", "", p);
+ }
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("getPooledConnection");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ HPT4PooledConnection connect;
+
+ Properties l_props = super.getProperties();
+ T4Properties l_t4props = new T4Properties(l_props);
+ connect = new HPT4PooledConnection(this, l_t4props);
+
+ return connect;
+ }
+
+ /**
+ * Attempts to establish a physical database connection that can be used as
+ * a pooled connection.
+ *
+ * @param username
+ * Safeguard user name.
+ * @param password
+ * Safeguard user password.
+ * @return A <code>PooledConnection</code> object that is a physical
+ * connection to the NDCS server that this
+ * <code>HPT4ConnectionPoolDataSource</code> object represents.
+ * @throws SQLException
+ * If any NDCS error occurs.
+ */
+ public PooledConnection getPooledConnection(String username, String password) throws SQLException {
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null, username);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPooledConnection", "", p);
+ }
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null, username);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("getPooledConnection");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ HPT4PooledConnection connect;
+
+ setUser(username);
+ setPassword(password);
+ return getPooledConnection();
+
+ }
+
+ /**
+ * Returns all the properties associated with this
+ * <code>ConnectionPoolDataSource</code>.
+ *
+ * @return Reference Object containing all the Type 4 property references.
+ * @throws NamingException
+ */
+ public Reference getReference() throws NamingException {
+ if (t4Logger_ != null && t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getReference", "", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("getReference");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+
+ Reference ref = new Reference(this.getClass().getName(), "org.trafodion.jdbc.t4.HPT4ConnectionPoolDataSourceFactory",
+ null);
+ ref = addReferences(ref);
+ ref.add(new StringRefAddr("propertyCycle", Integer.toString(propertyCycle_)));
+ return ref;
+
+ }
+
+ /**
+ * Sets the Property cycle property. This property is not supprted by the
+ * Type 4 driver. This property is ignored by the Type 4 driver.
+ *
+ * @param propertyCycle
+ */
+ public void setPropertyCycle(int propertyCycle) {
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "setPropertyCycle", "", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null, propertyCycle);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("setPropertyCycle");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+ propertyCycle_ = propertyCycle;
+ }
+
+ /**
+ * Returns the Property cycle property. This property is not supprted by the
+ * Type 4 driver. This property is ignored by the Type 4 driver.
+ *
+ * @return propertyCycle
+ */
+ public int getPropertyCycle() {
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPropertyCycle", "", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("getPropertyCycle");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+ return propertyCycle_;
+ }
+
+ // --------------------------------------------------------
+ void setupLogFileHandler() {
+ try {
+ if (getT4LogFile() == null) {
+ setT4LogFile(getT4GlobalLogFile());
+ setT4LogFileHandler(getT4GlobalLogFileHandler());
+ } else {
+ if (getT4LogFileHandler() == null) {
+ String temp = getT4LogFile();
+ FileHandler fh1 = new FileHandler(temp);
+ Formatter ff1 = new T4LogFormatter();
+
+ fh1.setFormatter(ff1);
+ setT4LogFileHandler(fh1);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } // end setupLogFileHandler
+
+ // --------------------------------------------------------
+
+ /**
+ * Creates a pooled connection object.
+ *
+ * @see #HPT4ConnectionPoolDataSource(Properties)
+ * @see T4Properties
+ */
+ public HPT4ConnectionPoolDataSource() {
+ super();
+ if (getT4LogLevel() != Level.OFF)
+ setupLogFileHandler();
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "HPT4ConnectionPoolDataSource",
+ "Note, super called before this.", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+ }
+
+ /**
+ * Creates a pooled connection object with the properties specified.
+ *
+ * @param props
+ * properties for the Type 4 connection
+ * @see #HPT4ConnectionPoolDataSource()
+ * @link T4Properties
+ */
+ public HPT4ConnectionPoolDataSource(Properties props) {
+ super(props);
+ if (getT4LogLevel() != Level.OFF)
+ setupLogFileHandler();
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null, props);
+ t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "HPT4ConnectionPoolDataSource",
+ "Note, super called before this.", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null, props);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4ConnectionPoolDataSource");
+ lr.setSourceMethodName("");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ public void setNameType(String nameType) {
+ }
+
+ /**
+ * @deprecated
+ */
+ public String getNameType() {
+ return null;
+ }
+
+ // Standard ConnectionPoolDataSource Properties
+ int propertyCycle_;
+
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSourceFactory.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSourceFactory.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSourceFactory.java
new file mode 100644
index 0000000..3f87539
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4ConnectionPoolDataSourceFactory.java
@@ -0,0 +1,68 @@
+// @@@ 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.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+
+public class HPT4ConnectionPoolDataSourceFactory implements javax.naming.spi.ObjectFactory {
+ public HPT4ConnectionPoolDataSourceFactory() {
+ }
+
+ public Object getObjectInstance(Object refobj, Name name, Context nameCtx, Hashtable env) throws Exception {
+ Reference ref = (Reference) refobj;
+ HPT4ConnectionPoolDataSource ds;
+ RefAddr refAddr;
+ String tmp;
+
+ if (ref.getClassName().equals("org.trafodion.jdbc.t4.HPT4ConnectionPoolDataSource")) {
+ Properties props = new Properties();
+ for (Enumeration enum2 = ref.getAll(); enum2.hasMoreElements();) {
+ RefAddr tRefAddr = (RefAddr) enum2.nextElement();
+ String type = tRefAddr.getType();
+ String content = (String) tRefAddr.getContent();
+ props.setProperty(type, content);
+ }
+ ds = new HPT4ConnectionPoolDataSource(props);
+ /*
+ * tmp = props.getProperty("initialPoolSize"); if (tmp != null) {
+ * try { ds.setInitialPoolSize(Integer.parseInt(tmp)); } catch
+ * (NumberFormatException e1) { } } tmp =
+ * props.getProperty("maxIdleTime"); if (tmp != null) { try {
+ * ds.setMaxIdleTime(Integer.parseInt(tmp)); } catch
+ * (NumberFormatException e4) { } } tmp =
+ * props.getProperty("propertyCycle"); if (tmp != null) { try {
+ * ds.setPropertyCycle(Integer.parseInt(tmp)); } catch
+ * (NumberFormatException e5) { } }
+ */
+ return ds;
+ } else {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSource.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSource.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSource.java
new file mode 100644
index 0000000..f0e0c8f
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSource.java
@@ -0,0 +1,366 @@
+// @@@ 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.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.FileHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+
+/**
+ *
+ * <p>
+ * JDBC Type 4 Driver <code>DataSource</code> class.
+ * </p>
+ * <p>
+ * Description: A <code>DataSource</code> object is a factory for Connection
+ * objects. An object that implements the <code>DataSource</code> interface is
+ * typically registered with a JNDI service provider. A JDBC driver that is
+ * accessed through the <code>DataSource</code> API does not automatically
+ * register itself with the <code>DriverManager</code> object.
+ * </p>
+ *
+ * <p>
+ * The <code>HPT4DataSource</code> class can provide connection pooling and
+ * statement pooling features.
+ * </p>
+ *
+ * <pre>
+ * <b>Setting properties for the HPT4DataSource in the Type 4 driver</b>
+ * HPT4DataSource ds = new HPT4DataSource();
+ * ds.setUrl("jdbc:t4jdbc://<NDCS host>:<NDCS port>/:");
+ * ds.setCatalog("your catalog");
+ * ds.setSchema("your schema");
+ * ds.setUser("safeguard user name");
+ * ds.setPassword("safeguard password");
+ *
+ * // Following are optional properties
+ * ds.setConnectionTimeout("timeout in seconds");
+ * ds.setT4LogFile("your log file location");
+ * ds.setT4LogLevel("SEVERE");
+ * ds.setServerDataSource("NDCS datasource name");
+ *
+ * // Properties relevant for Type 4 connection pooling.
+ * // Set ds.setMaxPoolSize(-1) to turn OFF connection pooling
+ * ds.setMaxPoolSize("number of connections required");
+ * ds.setMinPoolSize("number of connections required");
+ *
+ * // Properties relevant for Type 4 statement pooling.
+ * // Set ds.setMaxStatement(0) to turn statement pooling OFF
+ * // Statement pooling is enabled only when connection pooling is enabled.
+ * ds.setMaxStatements("number of statements to be pooled");
+ * </pre>
+ *
+ * <pre>
+ * <b>Programmatically registering HPT4DataSource with JDNI</b>
+ * java.util.Hashtable env = new java.util.Hashtable();
+ * env.put(Context.INITIAL_CONTEXT_FACTORY, "Factory class name here");
+ * javax.naming.Context ctx = new javax.naming.InitialContext(env);
+ * ctx.rebind("DataSource name here", ds);
+ * </pre>
+ *
+ * <pre>
+ * <b>Application making Type4 connection using the DataSource from JDNI</b>
+ * java.util.Hashtable env = new java.util.Hashtable();
+ * env.put(Context.INITIAL_CONTEXT_FACTORY, "Factory class name here");
+ * javax.naming.Context ctx = new javax.naming.InitialContext(env);
+ * DataSource ds = (DataSource)ctx.lookup("DataSource name here");
+ * java.sql.Connection con = ds.getConnection();
+ * </pre>
+ *
+ * <p>
+ * Copyright: (C) Apache Software Foundation (ASF)
+ * </p>
+ *
+ * @see T4Properties
+ */
+public class HPT4DataSource extends T4DSProperties implements javax.sql.DataSource, java.io.Serializable, Referenceable
+
+{
+ /**
+ * Attempts to establish an NDCS connection.
+ *
+ * @return a connection to the NDCS server.
+ * @throws SQLException
+ * if a database access error or NDCS error occurs.
+ * @see #getConnection(String, String)
+ */
+ synchronized public Connection getConnection() throws SQLException {
+ if (logger.isLoggable(Level.FINER)) {
+ logger.entering("HPT4DataSource", "getConnection");
+ }
+
+ Connection conn;
+ TrafT4Connection t4Conn;
+ HPT4ConnectionPoolDataSource pds;
+
+ if (getSQLException() != null) {
+ throw HPT4Messages.createSQLException(null, getLocale(), "invalid_property", getSQLException());
+ }
+
+ if (getMaxPoolSize() == -1) {
+ t4Conn = new TrafT4Connection(this, getT4Properties());
+ } else {
+ if (poolManager != null) {
+ t4Conn = (TrafT4Connection) poolManager.getConnection();
+ } else {
+
+ pds = new HPT4ConnectionPoolDataSource(getProperties());
+ poolManager = new HPT4PooledConnectionManager(pds, getT4LogLevel());
+ t4Conn = (TrafT4Connection) poolManager.getConnection();
+ }
+ }
+
+ t4Conn.setLogInfo(getT4LogLevel(), getLogWriter());
+ conn = t4Conn;
+
+ if (logger.isLoggable(Level.FINER)) {
+ logger.exiting("HPT4DataSource", "getConnection", conn);
+ }
+
+ return conn;
+ }
+
+ /**
+ * Attempts to establish an NDCS connection.
+ *
+ * @return a connection to the NDCS server.
+ * @param username
+ * Safeguard user name
+ * @param password
+ * Safeguard user password
+ * @throws SQLException
+ * if a database access error or NDCS error occurs.
+ * @see #getConnection()
+ */
+ synchronized public Connection getConnection(String username, String password) throws SQLException {
+ if (logger.isLoggable(Level.FINER)) {
+ logger.entering("HPT4DataSource", "getConnection", new Object[] { this, username });
+ }
+
+ Connection conn;
+
+ setUser(username);
+ setPassword(password);
+
+ conn = getConnection();
+
+ if (logger.isLoggable(Level.FINER)) {
+ logger.exiting("HPT4DataSource", "getConnection", conn);
+ }
+
+ return conn;
+ }
+
+ /**
+ * @return Reference Object containing all the Type 4 property references.
+ * @throws NamingException
+ */
+ public Reference getReference() throws NamingException {
+
+ Reference ref = new Reference(this.getClass().getName(), "org.trafodion.jdbc.t4.HPT4DataSourceFactory", null);
+ return addReferences(ref);
+ }
+
+ /**
+ * Sets the print writer for the current Type 4 data source.
+ *
+ * @param out
+ * java.io.PrintWriter for the current T4 connection.
+ * @throws SQLException
+ * when error occurs.
+ * @see #getLogWriter()
+ * @see javax.sql.ConnectionPoolDataSource
+ */
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ super.setLogWriter(out);
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null, out);
+ t4Logger_.logp(Level.FINE, "HPT4DataSource", "setLogWriter",
+ "Note, this constructor was called before the previous constructor", p);
+ }
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null, out);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4DataSource");
+ lr.setSourceMethodName("setLogWriter");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ if (poolManager != null) {
+ poolManager.setLogWriter(getLogWriter());
+ }
+ }
+
+ // Local methods
+ void setPoolManager(Context nameCtx, String dataSourceName) throws Exception {
+ if (t4Logger_.isLoggable(Level.FINER) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null, nameCtx, dataSourceName);
+ t4Logger_.logp(Level.FINER, "HPT4DataSource", "setPoolManager", "", p);
+ }
+ Object pds;
+
+ try {
+ pds = nameCtx.lookup(dataSourceName);
+ if (pds instanceof HPT4ConnectionPoolDataSource) {
+ poolManager = new HPT4PooledConnectionManager((HPT4ConnectionPoolDataSource) pds, getT4LogLevel());
+ }
+ } catch (javax.naming.NameNotFoundException nnfe) {
+ }
+ }
+
+ // --------------------------------------------------------
+ void setupLogFileHandler() {
+ try {
+ if (getT4LogFile() == null) {
+ setT4LogFile(getT4GlobalLogFile());
+ setT4LogFileHandler(getT4GlobalLogFileHandler());
+ } else {
+ if (getT4LogFileHandler() == null) {
+ String temp = getT4LogFile();
+ FileHandler fh1 = new FileHandler(temp);
+
+ Formatter ff1 = new T4LogFormatter();
+
+ fh1.setFormatter(ff1);
+ setT4LogFileHandler(fh1);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } // end setupLogFileHandler
+
+ // --------------------------------------------------------
+
+ /**
+ * Contructor for the <code>HPT4DataSource</code> object.
+ *
+ * @see #HPT4DataSource(java.util.Properties)
+ */
+ public HPT4DataSource() {
+ super();
+ if (getT4LogLevel() != Level.OFF) {
+ setupLogFileHandler();
+ }
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4DataSource", "<init>",
+ "Note, this constructor was called before the previous constructor", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4DataSource");
+ lr.setSourceMethodName("<init>");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+
+ }
+
+ /**
+ * Contructor for the <code>HPT4DataSource</code> object.
+ *
+ * @param info
+ * Contains all the Type 4 properties in a <code>name,
+ * value</code>
+ * pair.
+ * @see #HPT4DataSource()
+ * @see java.util.Properties
+ */
+ public HPT4DataSource(Properties info) {
+ super(info);
+ if (getT4LogLevel() != Level.OFF) {
+ setupLogFileHandler();
+ }
+ if (t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ t4Logger_.logp(Level.FINE, "HPT4DataSource", "<init>",
+ "Note, this constructor was called before the previous constructor", p);
+ }
+ try {
+ if (getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(null);
+ lr.setParameters(p);
+ lr.setSourceClassName("HPT4DataSource");
+ lr.setSourceMethodName("<init>");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ getLogWriter().println(temp);
+ }
+ } catch (SQLException se) {
+ // ignore
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ public void setNameType(String nameType) {
+ }
+
+ /**
+ * @deprecated
+ */
+ public String getNameType() {
+ return null;
+ }
+
+ // fields
+ HPT4PooledConnectionManager poolManager;
+
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object unwrap(Class iface) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isWrapperFor(Class iface) throws SQLException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSourceFactory.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSourceFactory.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSourceFactory.java
new file mode 100644
index 0000000..1b7a8da
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/HPT4DataSourceFactory.java
@@ -0,0 +1,62 @@
+// @@@ 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.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+
+public class HPT4DataSourceFactory implements javax.naming.spi.ObjectFactory {
+ public HPT4DataSourceFactory() {
+ }
+
+ public Object getObjectInstance(Object refobj, Name name, Context nameCtx, Hashtable env) throws Exception {
+ Reference ref = (Reference) refobj;
+ HPT4DataSource ds;
+ String dataSourceName = null;
+
+ if (ref.getClassName().equals("org.trafodion.jdbc.t4.HPT4DataSource")) {
+ Properties props = new Properties();
+ for (Enumeration enum2 = ref.getAll(); enum2.hasMoreElements();) {
+ RefAddr tRefAddr = (RefAddr) enum2.nextElement();
+ String type = tRefAddr.getType();
+ String content = (String) tRefAddr.getContent();
+ props.setProperty(type, content);
+ }
+
+ ds = new HPT4DataSource(props);
+ dataSourceName = ds.getDataSourceName();
+
+ if (dataSourceName != null) {
+ ds.setPoolManager(nameCtx, dataSourceName);
+ }
+ return ds;
+ } else {
+ return null;
+ }
+ }
+}