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:11:53 UTC
[14/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/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceConnection.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceConnection.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceConnection.java
deleted file mode 100644
index 4c1877f..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceConnection.java
+++ /dev/null
@@ -1,1420 +0,0 @@
-// @@@ 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.File;
-import java.io.UnsupportedEncodingException;
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.UnsupportedCharsetException;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.util.Hashtable;
-import java.util.Locale;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-
-
-class InterfaceConnection {
- static final int MODE_SQL = 0;
- static final int MODE_WMS = 1;
- static final int MODE_CMD = 2;
-
- static final short SQL_COMMIT = 0;
- static final short SQL_ROLLBACK = 1;
- private int txnIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
- private boolean autoCommit = true;
- private boolean isReadOnly = false;
- private boolean isClosed_;
- private long txid;
- private Locale locale;
- private USER_DESC_def userDesc;
- private CONNECTION_CONTEXT_def inContext;
- OUT_CONNECTION_CONTEXT_def outContext;
- private boolean useArrayBinding_;
- private short transportBufferSize_;
- Handler t4FileHandler;
- private NCSAddress ncsAddr_;
- private T4Connection t4connection_;
- private String m_ncsSrvr_ref;
- private int dialogueId_;
- private String m_sessionName;
-
- // character set information
- private int isoMapping_ = 15;
- private int termCharset_ = 15;
- private boolean enforceISO = false;
- private boolean byteSwap = false;
- private String _serverDataSource;
-
- private int _mode = MODE_SQL;
-
- T4Properties t4props_;
- SQLWarning sqlwarning_;
-
- Hashtable encoders = new Hashtable(11);
- Hashtable decoders = new Hashtable(11);
-
- // static fields from odbc_common.h and sql.h
- static final int SQL_TXN_READ_UNCOMMITTED = 1;
- static final int SQL_TXN_READ_COMMITTED = 2;
- static final int SQL_TXN_REPEATABLE_READ = 4;
- static final int SQL_TXN_SERIALIZABLE = 8;
- static final short SQL_ATTR_CURRENT_CATALOG = 109;
- static final short SQL_ATTR_ACCESS_MODE = 101;
- static final short SQL_ATTR_AUTOCOMMIT = 102;
- static final short SQL_TXN_ISOLATION = 108;
-
- // spj proxy syntax support
- static final short SPJ_ENABLE_PROXY = 1040;
-
- static final int PASSWORD_SECURITY = 0x4000000; //(2^26)
- static final int ROWWISE_ROWSET = 0x8000000; // (2^27);
- static final int CHARSET = 0x10000000; // (2^28)
- static final int STREAMING_DELAYEDERROR_MODE = 0x20000000; // 2^29
- // Zbig added new attribute on 4/18/2005
- static final short JDBC_ATTR_CONN_IDLE_TIMEOUT = 3000;
- static final short RESET_IDLE_TIMER = 1070;
-
- // for handling WeakReferences
- static ReferenceQueue refQ_ = new ReferenceQueue();
- static Hashtable refTosrvrCtxHandle_ = new Hashtable();
-
- //3196 - NDCS transaction for SPJ
- static final short SQL_ATTR_JOIN_UDR_TRANSACTION = 1041;
- static final short SQL_ATTR_SUSPEND_UDR_TRANSACTION = 1042;
- long transId_ = 0;
- boolean suspendRequest_ = false;
-
- private String _roleName = "";
- private boolean _ignoreCancel;
-
- private long _seqNum = 0;
- private SecPwd _security;
- long currentTime;
-
- private TrafT4Connection _t4Conn;
- private String _remoteProcess;
- private String _connStringHost = "";
-
- InterfaceConnection(TrafT4Connection conn, T4Properties t4props) throws SQLException {
- _t4Conn = conn;
- t4props_ = t4props;
- _remoteProcess = "";
-
- // close any weak connections that need to be closed.
- gcConnections();
-
- if (t4props.getSQLException() != null) {
- throw HPT4Messages.createSQLException(t4props_, t4props.getLocale(), "invalid_property", t4props
- .getSQLException());
- }
-
- m_sessionName = t4props_.getSessionName();
-
- if (m_sessionName != null && m_sessionName.length() > 0) {
- if (m_sessionName.length() > 24)
- m_sessionName = m_sessionName.substring(0, 24);
-
- if (!m_sessionName.matches("\\w+"))
- throw new SQLException("Invalid sessionName. Session names can only contain alphnumeric characters.");
- }
-
- locale = t4props.getLocale();
- txid = 0;
- isClosed_ = false;
- useArrayBinding_ = t4props.getUseArrayBinding();
- // transportBufferSize_ = t4props.getTransportBufferSize();
- transportBufferSize_ = 32000;
-
- userDesc = getUserDescription(t4props.getUser());
-
- // Connection context details
- inContext = getInContext(t4props);
- m_ncsSrvr_ref = t4props.getUrl();
- _ignoreCancel = false;
-
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, t4props);
- String temp = "url is = " + t4props.getUrl();
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "", temp, p);
- p = T4LoggingUtilities.makeParams(t4props_, t4props);
- temp = "user is = " + userDesc.userName;
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "", temp, p);
- }
- sqlwarning_ = null;
- connect();
- }
-
- public void setConnStrHost(String host) {
- this._connStringHost = host;
- }
-
- public int getMode() {
- return this._mode;
- }
-
- public void setMode(int mode) {
- this._mode = mode;
- }
-
- public long getSequenceNumber() {
- if(++_seqNum < 0) {
- _seqNum = 1;
- }
-
- return _seqNum;
- }
-
- public String getRemoteProcess() throws SQLException {
- return _remoteProcess;
- }
-
- public boolean isClosed() {
- return this.isClosed_;
- }
-
- String getRoleName() {
- return this._roleName;
- }
-
- CONNECTION_CONTEXT_def getInContext() {
- return inContext;
- }
-
- private CONNECTION_CONTEXT_def getInContext(T4Properties t4props) {
- inContext = new CONNECTION_CONTEXT_def();
- inContext.catalog = t4props.getCatalog();
- inContext.schema = t4props.getSchema();
- inContext.datasource = t4props.getServerDataSource();
- inContext.userRole = t4props.getRoleName();
- inContext.cpuToUse = t4props.getCpuToUse();
- inContext.cpuToUseEnd = -1; // for future use by DBTransporter
-
- inContext.accessMode = (short) (isReadOnly ? 1 : 0);
- inContext.autoCommit = (short) (autoCommit ? 1 : 0);
-
- inContext.queryTimeoutSec = t4props.getQueryTimeout();
- inContext.idleTimeoutSec = (short) t4props.getConnectionTimeout();
- inContext.loginTimeoutSec = (short) t4props.getLoginTimeout();
- inContext.txnIsolationLevel = (short) SQL_TXN_READ_COMMITTED;
- inContext.rowSetSize = t4props.getFetchBufferSize();
- inContext.diagnosticFlag = 0;
- inContext.processId = (int) System.currentTimeMillis() & 0xFFF;
-
- try {
- inContext.computerName = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException uex) {
- inContext.computerName = "Unknown Client Host";
- }
- inContext.windowText = t4props.getApplicationName();
-
- inContext.ctxDataLang = 15;
- inContext.ctxErrorLang = 15;
-
- inContext.ctxACP = 1252;
- inContext.ctxCtrlInferNXHAR = -1;
- inContext.clientVersionList.list = getVersion(inContext.processId);
- return inContext;
- }
-
- private VERSION_def[] getVersion(int pid) {
- short majorVersion = 3;
- short minorVersion = 0;
- int buildId = 0;
-
- VERSION_def version[] = new VERSION_def[2];
-
- // Entry [0] is the Driver Version information
- version[0] = new VERSION_def();
- version[0].componentId = 20;
- version[0].majorVersion = majorVersion;
- version[0].minorVersion = minorVersion;
- version[0].buildId = buildId | ROWWISE_ROWSET | CHARSET | PASSWORD_SECURITY;
-
- if (this.t4props_.getDelayedErrorMode())
- {
- version[0].buildId |= STREAMING_DELAYEDERROR_MODE;
- }
-
- // Entry [1] is the Application Version information
- version[1] = new VERSION_def();
- version[1].componentId = 8;
- version[1].majorVersion = 3;
- version[1].minorVersion = 0;
- version[1].buildId = 0;
-
- return version;
- }
-
- USER_DESC_def getUserDescription() {
- return userDesc;
- }
-
- private void setISOMapping(int isoMapping) {
-// if (InterfaceUtilities.getCharsetName(isoMapping) == InterfaceUtilities.SQLCHARSET_UNKNOWN)
-// isoMapping = InterfaceUtilities.getCharsetValue("ISO8859_1");
-
- isoMapping_ = InterfaceUtilities.getCharsetValue("UTF-8");;
- }
-
- String getServerDataSource() {
- return this._serverDataSource;
- }
-
- boolean getEnforceISO() {
- return enforceISO;
- }
-
- int getISOMapping() {
- return isoMapping_;
- }
-
- public String getSessionName() {
- return m_sessionName;
- }
-
- private void setTerminalCharset(int termCharset) {
-// if (InterfaceUtilities.getCharsetName(termCharset) == InterfaceUtilities.SQLCHARSET_UNKNOWN)
-// termCharset = InterfaceUtilities.getCharsetValue("ISO8859_1");
-
- termCharset_ = InterfaceUtilities.getCharsetValue("UTF-8");;
- }
-
- int getTerminalCharset() {
- return termCharset_;
- }
-
- private USER_DESC_def getUserDescription(String user) throws SQLException {
- userDesc = new USER_DESC_def();
- userDesc.userDescType = (this.t4props_.getSessionToken()) ? TRANSPORT.PASSWORD_ENCRYPTED_USER_TYPE
- : TRANSPORT.UNAUTHENTICATED_USER_TYPE;
- userDesc.userName = (user.length() > 128) ? user.substring(0, 128) : user;
- userDesc.domainName = "";
-
- userDesc.userSid = null;
- userDesc.password = null; //we no longer want to send the password to the MXOAS
-
- return userDesc;
- }
-
- void writeToOutFile(byte[] input, String file)
- {
- java.io.DataOutputStream os = null;
- try {
- os = new java.io.DataOutputStream
- (new java.io.FileOutputStream(file));
- os.write(input, 0, input.length);
- }catch (java.io.IOException io) {
- System.out.println("IO exception");
- }finally {
- if (os != null)
- try {
- os.close();
- }catch (java.io.IOException io) {
- System.out.println("IO exception");
- }
- }
- }
-
- private void oldEncryptPassword() throws SQLException {
- String pwd = this.t4props_.getPassword();
-
- if (pwd.length() > 386)
- pwd = pwd.substring(0, 386);
-
- byte [] authentication;
- try {
- authentication = pwd.getBytes("US-ASCII");
- } catch (UnsupportedEncodingException uex) {
- throw HPT4Messages.createSQLException(t4props_, locale, uex.getMessage(), null);
- }
-
- if (authentication.length > 0) {
- Utility.Encryption(authentication, authentication, authentication.length);
- }
-
- userDesc.password = authentication;
- }
-
- T4Connection getT4Connection() {
- return t4connection_;
- }
-
- int getDialogueId() {
- return dialogueId_;
- }
-
- int getQueryTimeout() {
- return inContext.queryTimeoutSec;
- }
-
- int getLoginTimeout() {
- return inContext.loginTimeoutSec;
- }
-
- int getConnectionTimeout() {
- return inContext.idleTimeoutSec;
- }
-
- String getCatalog() {
- if (outContext != null) {
- return outContext.catalog;
- } else {
- return inContext.catalog;
- }
- }
-
- boolean getDateConversion() {
- return ((outContext.versionList.list[0].buildId & 512) > 0);
- }
-
- int getServerMajorVersion() {
- return outContext.versionList.list[1].majorVersion;
- }
-
- int getServerMinorVersion() {
- return outContext.versionList.list[1].minorVersion;
- }
-
- String getUid() {
- return userDesc.userName;
- }
-
- String getSchema() {
- if (outContext != null) {
- return outContext.schema;
- } else {
- return inContext.schema;
- }
- }
-
- void setLocale(Locale locale) {
- this.locale = locale;
- }
-
- Locale getLocale() {
- return locale;
- }
-
- boolean getByteSwap() {
- return this.byteSwap;
- }
-
- NCSAddress getNCSAddress() {
- return ncsAddr_;
- }
-
- void commit() throws SQLException {
- endTransaction(SQL_COMMIT);
- }
-
- void rollback() throws SQLException {
- endTransaction(SQL_ROLLBACK);
- }
-
- void cancel() throws SQLException {
- if(!this._ignoreCancel) {
- String srvrObjRef = "" + ncsAddr_.getPort();
- // String srvrObjRef = t4props_.getServerID();
- int srvrType = 2; // AS server
- CancelReply cr_ = null;
-
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_);
- String temp = "cancel request received for " + srvrObjRef;
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "connect", temp, p);
- }
-
- //
- // Send the cancel to the ODBC association server.
- //
- String errorText = null;
- int tryNum = 0;
- String errorMsg = null;
- String errorMsg_detail = null;
- long currentTime = (new java.util.Date()).getTime();
- long endTime;
-
- if (inContext.loginTimeoutSec > 0) {
- endTime = currentTime + inContext.loginTimeoutSec * 1000;
- } else {
-
- // less than or equal to 0 implies infinit time out
- endTime = Long.MAX_VALUE;
-
- //
- // Keep trying to contact the Association Server until we run out of
- // time, or make a connection or we exceed the retry count.
- //
- }
- cr_ = T4_Dcs_Cancel.cancel(t4props_, this, dialogueId_, srvrType, srvrObjRef, 0);
-
- switch (cr_.m_p1_exception.exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_);
- String temp = "Cancel successful";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "connect", temp, p);
- }
- break;
- default:
-
- //
- // Some unknown error
- //
- if (cr_.m_p1_exception.clientErrorText != null) {
- errorText = "Client Error text = " + cr_.m_p1_exception.clientErrorText;
- }
- errorText = errorText + " :Exception = " + cr_.m_p1_exception.exception_nr;
- errorText = errorText + " :" + "Exception detail = " + cr_.m_p1_exception.exception_detail;
- errorText = errorText + " :" + "Error code = " + cr_.m_p1_exception.errorCode;
-
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_);
- String temp = errorText;
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "cancel", temp, p);
- }
- throw HPT4Messages.createSQLException(t4props_, locale, "as_cancel_message_error", errorText);
- } // end switch
-
- currentTime = (new java.util.Date()).getTime();
- }
- }
-
- private void initDiag(boolean setTimestamp, boolean downloadCert) throws SQLException {
- short retryCount = 3;
- InitializeDialogueReply idr = null;
- long endTime = (inContext.loginTimeoutSec > 0) ? currentTime + inContext.loginTimeoutSec * 1000 : Long.MAX_VALUE;
- int tryNum = 0;
- boolean done = false;
-
- boolean socketException = false;
- SQLException seSave = null;
-
- do {
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "Attempting initDiag. Try " + (tryNum + 1) + " of " + retryCount;
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
-
- socketException = false;
- try {
- t4connection_ = new T4Connection(this);
- idr = t4connection_.InitializeDialogue(setTimestamp, downloadCert);
- } catch (SQLException se) {
- //
- // We will retry socket exceptions, but will fail on all other
- // exceptions.
- //
- int sc = se.getErrorCode();
- int s1 = HPT4Messages.createSQLException(t4props_, locale, "socket_open_error", null).getErrorCode();
- int s2 = HPT4Messages.createSQLException(t4props_, locale, "socket_write_error", null).getErrorCode();
- int s3 = HPT4Messages.createSQLException(t4props_, locale, "socket_read_error", null).getErrorCode();
-
- if (sc == s1 || sc == s2 || sc == s3) {
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "A socket exception occurred: " + se.getMessage();
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
-
- socketException = true;
- seSave = se;
- } else {
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "A non-socket fatal exception occurred: " + se.getMessage();
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
-
- try {
- t4connection_.getInputOutput().CloseIO(new LogicalByteArray(1, 0, false));
- } catch (Exception e) {
- // ignore error
- }
-
- throw se;
- }
- }
-
- if (socketException == false) {
- if (idr.exception_nr == TRANSPORT.CEE_SUCCESS) {
- done = true;
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "initDiag Successful.";
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
- } else if (idr.exception_nr == odbc_SQLSvc_InitializeDialogue_exc_.odbc_SQLSvc_InitializeDialogue_SQLError_exn_ ||
- idr.exception_nr == odbc_SQLSvc_InitializeDialogue_exc_.odbc_SQLSvc_InitializeDialogue_InvalidUser_exn_) {
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "A SQL Warning or Error occurred during initDiag: " + idr.SQLError;
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
-
- int ex_nr = idr.exception_nr;
- int ex_nr_d = idr.exception_detail;
-
- if (ex_nr_d == odbc_SQLSvc_InitializeDialogue_exc_.SQL_PASSWORD_EXPIRING ||
- ex_nr_d == odbc_SQLSvc_InitializeDialogue_exc_.SQL_PASSWORD_GRACEPERIOD) {
- HPT4Messages.setSQLWarning(this.t4props_, this._t4Conn, idr.SQLError);
- done = true;
- } else {
- HPT4Messages.throwSQLException(t4props_, idr.SQLError);
- }
- }
- }
-
- currentTime = System.currentTimeMillis();
- tryNum = tryNum + 1;
- } while (done == false && endTime > currentTime && tryNum < retryCount);
-
- if (done == false) {
- SQLException se1;
- SQLException se2;
-
- if (socketException == true) {
- throw seSave;
- }
-
- if (currentTime >= endTime) {
- se1 = HPT4Messages.createSQLException(t4props_, locale, "ids_s1_t00", null);
- } else if (tryNum >= retryCount) {
- se1 = HPT4Messages.createSQLException(t4props_, locale, "as_connect_message_error",
- "exceeded retry count");
- } else {
- se1 = HPT4Messages.createSQLException(t4props_, locale, "as_connect_message_error", null);
- }
- throw se1;
- }
-
- //
- // Set the outcontext value returned by the ODBC MX server in the
- // serverContext
- //
- outContext = idr.outContext;
- enforceISO = outContext._enforceISO;
- this._roleName = outContext._roleName;
- this._ignoreCancel = outContext._ignoreCancel;
-
- t4props_.setDialogueID(Integer.toString(dialogueId_));
- t4props_.setServerID(m_ncsSrvr_ref);
-
- t4props_.setNcsMajorVersion(idr.outContext.versionList.list[0].majorVersion);
- t4props_.setNcsMinorVersion(idr.outContext.versionList.list[0].minorVersion);
- t4props_.setSqlmxMajorVersion(idr.outContext.versionList.list[1].majorVersion);
- t4props_.setSqlmxMinorVersion(idr.outContext.versionList.list[1].minorVersion);
-
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "Connection process successful";
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
- }
-
- private void encryptPassword() throws SecurityException, SQLException {
- byte [] pwBytes;
- byte [] roleBytes;
-
- String roleName = t4props_.getRoleName();
-
- try {
- pwBytes = t4props_.getPassword().getBytes("US-ASCII");
- roleBytes = (roleName != null && roleName.length() > 0)?roleName.getBytes("US-ASCII"):null;
- }
- catch (UnsupportedEncodingException uex) {
- //ERROR MESSAGE
- throw new SQLException("failed to find encoding");
- }
-
- userDesc.password = new byte[_security.getPwdEBufferLen()];
-
- _security.encryptPwd(pwBytes, roleBytes, userDesc.password);
- }
-
- private byte [] createProcInfo(int pid, int nid, byte [] timestamp) throws SQLException {
- byte [] procInfo;
-
- procInfo = new byte[16];
-
- ByteBuffer bb = ByteBuffer.allocate(16);
- bb.order(ByteOrder.LITTLE_ENDIAN);
- bb.putInt(pid);
- bb.putInt(nid);
- bb.put(timestamp);
- bb.rewind();
- bb.get(procInfo, 0, 16);
-
- return procInfo;
- }
-
- private void secureLogin(ConnectReply cr) throws SQLException {
- try {
- byte [] procInfo = createProcInfo(cr.processId, cr.serverNode, cr.timestamp);
- boolean tokenAuth = this.t4props_.getSPJEnv() && this.t4props_.getTokenAuth();
-
- _security = SecPwd.getInstance(
- this._t4Conn,
- this.t4props_.getCertificateDir(),
- this.t4props_.getCertificateFile(),
- cr.clusterName,
- tokenAuth,
- procInfo
- );
- }
- catch(SecurityException se) {
- CleanupServer(); //MXOSRVR is expecting InitDiag, clean it up since we failed
- throw se;
- }
-
- try {
- _security.openCertificate();
- this.encryptPassword();
- }catch(SecurityException se) {
- if(se.getErrorCode() != 29713) {
- throw se; //we have a fatal error
- }
-
- DownloadCertificate(); //otherwise, download and continue
- }
-
- try {
- inContext.connectOptions = new String(_security.getCertExpDate());
- initDiag(true,false);
- }catch(SQLException e) {
- if(outContext != null && outContext.certificate != null) { //we got a certificate back, switch to it, continue
- _security.switchCertificate(outContext.certificate);
- }
- else {
- throw e;
- }
-
- inContext.connectOptions = new String(_security.getCertExpDate());
- this.encryptPassword(); //re-encrypt
- this.initDiag(true,false); //re-initdiag
- }
- }
-
- private void CleanupServer() throws SQLException {
- this.userDesc.userName = null;
- this.userDesc.password = null;
-
- try {
- initDiag(false,false); //send dummy init diag to clean up server
- }catch(SQLException e) {
-
- }
-
- }
-
- private void DownloadCertificate() throws SQLException {
- //attempt download
- this.userDesc.userName = null;
- this.userDesc.password = null;
- inContext.connectOptions = null;
-
- try {
- initDiag(true,true);
- }catch(SQLException e) {
- if(outContext == null || outContext.certificate == null) {
- SQLException he = HPT4Messages.createSQLException(t4props_, this.locale, "certificate_download_error", e.getMessage());
- he.setNextException(e);
- throw he;
- }
- }
-
- this.userDesc.userName = this.t4props_.getUser();
-
- try {
- _security.switchCertificate(outContext.certificate);
- this.encryptPassword();
- }catch(SecurityException se1) {
- throw se1;
- }
- }
-
- private void connect() throws SQLException {
- short retryCount = 3;
- int srvrType = 2; // AS server
- ConnectReply cr = null;
-
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String msg = "Association Server URL: " + m_ncsSrvr_ref;
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", msg, t4props_);
- }
-
- //
- // Connect to the association server.
- //
- String errorText = null;
- boolean done = false;
- int tryNum = 0;
- String errorMsg = null;
- String errorMsg_detail = null;
- currentTime = System.currentTimeMillis();
- long endTime = (inContext.loginTimeoutSec > 0) ? currentTime + inContext.loginTimeoutSec * 1000
- : Long.MAX_VALUE;
-
- do {
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String temp = "Attempting getObjRef. Try " + (tryNum + 1) + " of " + retryCount;
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", temp, t4props_);
- }
-
- cr = T4_Dcs_Connect.getConnection(t4props_, this, inContext, userDesc, srvrType,
- retryCount);
-
- switch (cr.m_p1_exception.exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
- done = true;
- if (t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String msg = "getObjRef Successful. Server URL: " + cr.m_p2_srvrObjRef;
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", msg, t4props_);
- }
- if (!cr.m_p4_dataSource.equals(t4props_.getServerDataSource())) {
- Object[] messageArguments = new Object[1];
- messageArguments[0] = cr.m_p4_dataSource;
- sqlwarning_ = HPT4Messages.createSQLWarning(t4props_, "connected_to_Default_DS", messageArguments);
- }
- break;
- case odbc_Dcs_GetObjRefHdl_exc_.odbc_Dcs_GetObjRefHdl_ASTryAgain_exn_:
- done = false;
- tryNum = tryNum + 1;
- errorMsg = "as_connect_message_error";
- errorMsg_detail = "try again request";
- if(tryNum < retryCount) {
- try {
- Thread.sleep(5000);
- }catch(Exception e) {}
- }
- break;
- case odbc_Dcs_GetObjRefHdl_exc_.odbc_Dcs_GetObjRefHdl_ASNotAvailable_exn_:
- done = false;
- tryNum = tryNum + 1;
- errorMsg = "as_connect_message_error";
- errorMsg_detail = "association server not available";
- break;
- case odbc_Dcs_GetObjRefHdl_exc_.odbc_Dcs_GetObjRefHdl_DSNotAvailable_exn_:
- done = false;
- tryNum = tryNum + 1;
- errorMsg = "as_connect_message_error";
- errorMsg_detail = "data source not available";
- break;
- case odbc_Dcs_GetObjRefHdl_exc_.odbc_Dcs_GetObjRefHdl_PortNotAvailable_exn_:
- done = false;
- tryNum = tryNum + 1;
- errorMsg = "as_connect_message_error";
- errorMsg_detail = "port not available";
- break;
- case odbc_Dcs_GetObjRefHdl_exc_.odbc_Dcs_GetObjRefHdl_ASNoSrvrHdl_exn_:
- done = false;
- tryNum = tryNum + 1;
- errorMsg = "as_connect_message_error";
- errorMsg_detail = "server handle not available";
- break;
- default:
-
- //
- // Some unknown error
- //
- if (cr.m_p1_exception.clientErrorText != null) {
- errorText = "Client Error text = " + cr.m_p1_exception.clientErrorText;
-
- }
- errorText = errorText + " :Exception = " + cr.m_p1_exception.exception_nr;
- errorText = errorText + " :" + "Exception detail = " + cr.m_p1_exception.exception_detail;
- errorText = errorText + " :" + "Error code = " + cr.m_p1_exception.errorCode;
-
- if (cr.m_p1_exception.ErrorText != null) {
- errorText = errorText + " :" + "Error text = " + cr.m_p1_exception.ErrorText;
-
- }
- throw HPT4Messages.createSQLException(t4props_, locale, "as_connect_message_error", errorText);
- }
-
- if (done == false && t4props_.t4Logger_.isLoggable(Level.INFO)) {
- String msg = "getObjRef Failed. Message from Association Server: " + errorMsg_detail;
- t4props_.t4Logger_.logp(Level.INFO, "InterfaceConnection", "connect", msg, t4props_);
- }
-
- currentTime = System.currentTimeMillis();
- } while (done == false && endTime > currentTime && tryNum < retryCount);
-
- if (done == false) {
- SQLException se1;
- SQLException se2;
-
- if (currentTime >= endTime) {
- se1 = HPT4Messages.createSQLException(t4props_, locale, "ids_s1_t00", null);
- se2 = HPT4Messages.createSQLException(t4props_, locale, errorMsg, errorMsg_detail);
- se1.setNextException(se2);
- } else {
- se1 = HPT4Messages.createSQLException(t4props_, locale, errorMsg, errorMsg_detail);
- }
-
- throw se1;
- }
-
- dialogueId_ = cr.m_p3_dialogueId;
- m_ncsSrvr_ref = cr.m_p2_srvrObjRef;
- _remoteProcess = "\\" + cr.remoteHost + "." + cr.remoteProcess;
-
- ncsAddr_ = cr.getNCSAddress();
- this.byteSwap = cr.byteSwap;
- this._serverDataSource = cr.m_p4_dataSource;
-
- setISOMapping(cr.isoMapping);
-
- if (cr.isoMapping == InterfaceUtilities.getCharsetValue("ISO8859_1")) {
- setTerminalCharset(InterfaceUtilities.getCharsetValue("ISO8859_1"));
- this.inContext.ctxDataLang = 0;
- this.inContext.ctxErrorLang = 0;
- } else {
- setTerminalCharset(InterfaceUtilities.getCharsetValue("UTF-8"));
- }
-
- if(cr.securityEnabled) {
- this.secureLogin(cr);
- }
- else {
- this.oldEncryptPassword();
- this.initDiag(false,false);
- }
- }
-
- // @deprecated
- void isConnectionClosed() throws SQLException {
- if (isClosed_ == false) {
- throw HPT4Messages.createSQLException(t4props_, locale, "invalid_connection", null);
- }
- }
-
- // @deprecated
- void isConnectionOpen() throws SQLException {
- if (isClosed_) {
- throw HPT4Messages.createSQLException(t4props_, locale, "invalid_connection", null);
- }
- }
-
- // @deprecated
- boolean getIsClosed() {
- return isClosed_;
- }
-
- void setIsClosed(boolean isClosed) {
- this.isClosed_ = isClosed;
- }
-
- String getUrl() {
- return m_ncsSrvr_ref;
- }
-
- void setCatalog(TrafT4Connection conn, String catalog) throws SQLException {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, catalog);
- String temp = "Setting connection catalog = " + catalog;
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setCatalog", temp, p);
- }
- if (catalog != null && catalog.length() == 0) {
- catalog = T4Properties.DEFAULT_CATALOG;
- }
- setConnectionAttr(conn, SQL_ATTR_CURRENT_CATALOG, 0, catalog);
- outContext.catalog = catalog;
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, catalog);
- String temp = "Setting connection catalog = " + catalog + " is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setCatalog", temp, p);
- }
- };
-
- // enforces the connection timeout set by the user
- // to be called by the connection pooling mechanism whenever a connection is
- // given to the user from the pool
- void enforceT4ConnectionTimeout(TrafT4Connection conn) throws SQLException {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, (short) t4props_.getConnectionTimeout());
- String temp = "Enforcing connection timeout = " + (short) t4props_.getConnectionTimeout();
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "enforceT4ConnectionTimeout", temp, p);
- }
- inContext.idleTimeoutSec = (short) t4props_.getConnectionTimeout();
- setConnectionAttr(conn, JDBC_ATTR_CONN_IDLE_TIMEOUT, inContext.idleTimeoutSec, String
- .valueOf(inContext.idleTimeoutSec));
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, (short) t4props_.getConnectionTimeout());
- String temp = "Enforcing connection timeout = " + (short) t4props_.getConnectionTimeout() + " is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "enforceT4ConnectionTimeout", temp, p);
- }
- };
-
- // disregards the T4's connectionTimeout value (set during initialize
- // dialog) and
- // enforces the connection timeout set by the NCS datasource settings
- // to be called by the connection pooling mechanism whenever a connection is
- // put into the pool (after a user has called connection.close())
- void disregardT4ConnectionTimeout(TrafT4Connection conn) throws SQLException {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, "-1");
- String temp = "Setting connection timeout = -1";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "disregardT4ConnectionTimeout", temp, p);
- }
- setConnectionAttr(conn, JDBC_ATTR_CONN_IDLE_TIMEOUT, -1, "-1");
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, "-1");
- String temp = "Setting connection timeout = -1 is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "disregardT4ConnectionTimeout", temp, p);
- }
- };
-
- void setConnectionAttr(TrafT4Connection conn, short attr, int valueNum, String valueString) throws SQLException {
- SetConnectionOptionReply scr_;
- isConnectionOpen();
-
- try {
- scr_ = t4connection_.SetConnectionOption(attr, valueNum, valueString);
- //3196 - NDCS transaction for SPJ
- if (attr == SQL_ATTR_JOIN_UDR_TRANSACTION) {
- transId_ = Long.valueOf(valueString);
- suspendRequest_ = true;
- }
- else if (attr == SQL_ATTR_SUSPEND_UDR_TRANSACTION) {
- transId_ = Long.valueOf(valueString);
- suspendRequest_ = false;
- }
- } catch (SQLException tex) {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, attr, valueNum, valueString);
- String temp = "NDCS or SQLException occurred.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setConnectionAttr", temp, p);
- }
- throw tex;
- }
-
- switch (scr_.m_p1.exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
-
- // do the warning processing
- if (scr_.m_p2.length != 0) {
- HPT4Messages.setSQLWarning(conn.props_, conn, scr_.m_p2);
- }
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, attr, valueNum, valueString);
- String temp = "Setting connection attribute is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setConnectionAttr", temp, p);
- }
- break;
- case odbc_SQLSvc_SetConnectionOption_exc_.odbc_SQLSvc_SetConnectionOption_SQLError_exn_:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, attr, valueNum, valueString);
- String temp = "odbc_SQLSvc_SetConnectionOption_SQLError_exn_ occurred.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setConnectionAttr", temp, p);
- }
- HPT4Messages.throwSQLException(t4props_, scr_.m_p1.errorList);
- default:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, attr, valueNum, valueString);
- String temp = "UnknownException occurred.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setConnectionAttr", temp, p);
- }
- throw HPT4Messages.createSQLException(conn.props_, locale, "ids_unknown_reply_error", null);
- }
- };
-
- void setTransactionIsolation(TrafT4Connection conn, int level) throws SQLException {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, level);
- String temp = "Setting transaction isolation = " + level;
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setTransactionIsolation", temp, p);
- }
- isConnectionOpen();
-
- if (level != Connection.TRANSACTION_NONE && level != Connection.TRANSACTION_READ_COMMITTED
- && level != Connection.TRANSACTION_READ_UNCOMMITTED && level != Connection.TRANSACTION_REPEATABLE_READ
- && level != Connection.TRANSACTION_SERIALIZABLE) {
- throw HPT4Messages.createSQLException(conn.props_, locale, "invalid_transaction_isolation", null);
- }
-
- txnIsolationLevel = level;
-
- switch (txnIsolationLevel) {
- case Connection.TRANSACTION_NONE:
- inContext.txnIsolationLevel = (short) SQL_TXN_READ_COMMITTED;
- break;
- case Connection.TRANSACTION_READ_COMMITTED:
- inContext.txnIsolationLevel = (short) SQL_TXN_READ_COMMITTED;
- break;
- case Connection.TRANSACTION_READ_UNCOMMITTED:
- inContext.txnIsolationLevel = (short) SQL_TXN_READ_UNCOMMITTED;
- break;
- case Connection.TRANSACTION_REPEATABLE_READ:
- inContext.txnIsolationLevel = (short) SQL_TXN_REPEATABLE_READ;
- break;
- case Connection.TRANSACTION_SERIALIZABLE:
- inContext.txnIsolationLevel = (short) SQL_TXN_SERIALIZABLE;
- break;
- default:
- inContext.txnIsolationLevel = (short) SQL_TXN_READ_COMMITTED;
- break;
- }
-
- setConnectionAttr(conn, SQL_TXN_ISOLATION, inContext.txnIsolationLevel, String
- .valueOf(inContext.txnIsolationLevel));
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, level);
- String temp = "Setting transaction isolation = " + level + " is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setTransactionIsolation", temp, p);
- }
- };
-
- int getTransactionIsolation() throws SQLException {
- return txnIsolationLevel;
- }
-
- long getTxid() {
- return txid;
- }
-
- void setTxid(long txid) {
- this.txid = txid;
- }
-
- boolean getAutoCommit() {
- return autoCommit;
- }
-
- void setAutoCommit(TrafT4Connection conn, boolean autoCommit) throws SQLException {
- isConnectionOpen();
- boolean commit = this.autoCommit;
-
- this.autoCommit = autoCommit;
-
- if (autoCommit == false) {
- inContext.autoCommit = 0;
- } else {
- inContext.autoCommit = 1;
-
- }
- try {
- setConnectionAttr(conn, SQL_ATTR_AUTOCOMMIT, inContext.autoCommit, String.valueOf(inContext.autoCommit));
- } catch (SQLException sqle) {
- this.autoCommit = commit;
- throw sqle;
- }
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, autoCommit);
- String temp = "Setting autoCommit = " + autoCommit + " is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "setAutoCommit", temp, p);
- }
- }
-
- void enableNARSupport(TrafT4Connection conn, boolean NARSupport) throws SQLException {
- int val = NARSupport ? 1 : 0;
- setConnectionAttr(conn, TRANSPORT.SQL_ATTR_ROWSET_RECOVERY, val, String.valueOf(val));
- }
-
- void enableProxySyntax(TrafT4Connection conn) throws SQLException {
- setConnectionAttr(conn, InterfaceConnection.SPJ_ENABLE_PROXY, 1, "1");
- }
-
- boolean isReadOnly() {
- return isReadOnly;
- }
-
- void setReadOnly(boolean readOnly) throws SQLException {
- isConnectionOpen();
- this.isReadOnly = readOnly;
- }
- void setReadOnly(TrafT4Connection conn, boolean readOnly) throws SQLException {
- isConnectionOpen();
- this.isReadOnly = readOnly;
- if (readOnly == false) {
- inContext.accessMode = 0;
- } else {
- inContext.accessMode = 1;
-
- }
- setConnectionAttr(conn, SQL_ATTR_ACCESS_MODE, inContext.accessMode, String.valueOf(inContext.accessMode));
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, readOnly);
- String temp = "Setting readOnly = " + readOnly + " is done.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "readOnly", temp, p);
- }
-
- }
-
- void close() throws SQLException {
- TerminateDialogueReply tdr_ = null;
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_);
- String temp = "Terminate Dialogue.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "close", temp, p);
- }
-
- //3196 - NDCS transaction for SPJ
- if (suspendRequest_) {
- _t4Conn.suspendUDRTransaction();
- }
-
- SecPwd.removeInstance(this._t4Conn);
-
- try {
- tdr_ = t4connection_.TerminateDialogue();
- } catch (SQLException tex) {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_);
- String temp = "SQLException during TerminateDialogue.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "close", temp, p);
- }
- throw tex;
- }
-
- switch (tdr_.m_p1.exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
- break;
- case odbc_SQLSvc_TerminateDialogue_exc_.odbc_SQLSvc_TerminateDialogue_SQLError_exn_:
- //ignore errors
- }
-
- // needs work here. This should be proxy destroy. close the logfiles
- try {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_);
- String temp = "Terminate Dialogue successful.";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "close", temp, p);
- }
- } catch (java.lang.SecurityException sex) {
- }
- };
-
- void endTransaction(short commitOption) throws SQLException {
- EndTransactionReply etr_ = null;
- if (autoCommit && !_t4Conn.isBeginTransaction()) {
- throw HPT4Messages.createSQLException(t4props_, locale, "invalid_commit_mode", null);
- }
-
- isConnectionOpen();
- // XA_RESUMETRANSACTION();
-
- try {
- etr_ = t4connection_.EndTransaction(commitOption);
- _t4Conn.setBeginTransaction(false);
- } catch (SQLException tex) {
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "SQLException during EndTransaction." + tex.toString();
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- throw tex;
- }
-
- switch (etr_.m_p1.exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
- break;
- case odbc_SQLSvc_EndTransaction_exc_.odbc_SQLSvc_EndTransaction_ParamError_exn_:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "odbc_SQLSvc_EndTransaction_ParamError_exn_ :";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- throw HPT4Messages.createSQLException(t4props_, locale, "ParamError:" + etr_.m_p1.ParamError, null);
- case odbc_SQLSvc_EndTransaction_exc_.odbc_SQLSvc_EndTransaction_InvalidConnection_exn_:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "odbc_SQLSvc_EndTransaction_InvalidConnection_exn_:";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- throw new SQLException("odbc_SQLSvc_EndTransaction_InvalidConnection_exn", "HY100002", 10001);
- case odbc_SQLSvc_EndTransaction_exc_.odbc_SQLSvc_EndTransaction_SQLError_exn_:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "odbc_SQLSvc_EndTransaction_SQLError_exn_:" + etr_.m_p1.SQLError;
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- HPT4Messages.throwSQLException(t4props_, etr_.m_p1.SQLError);
- case odbc_SQLSvc_EndTransaction_exc_.odbc_SQLSvc_EndTransaction_SQLInvalidHandle_exn_:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "odbc_SQLSvc_EndTransaction_SQLInvalidHandle_exn_:";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- throw new SQLException("odbc_SQLSvc_EndTransaction_SQLInvalidHandle_exn", "HY100004", 10001);
- case odbc_SQLSvc_EndTransaction_exc_.odbc_SQLSvc_EndTransaction_TransactionError_exn_:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "odbc_SQLSvc_EndTransaction_TransactionError_exn_:";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- throw new SQLException("odbc_SQLSvc_EndTransaction_TransactionError_exn", "HY100005", 10001);
- default:
- if (t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(t4props_, commitOption);
- String temp = "UnknownError:";
- t4props_.t4Logger_.logp(Level.FINEST, "InterfaceConnection", "endTransaction", temp, p);
- }
- throw new SQLException("Unknown Error during EndTransaction", "HY100001", 10001);
- }
-
- };
-
- long beginTransaction() throws SQLException {
- isConnectionOpen();
-
- return txid;
- };
-
- void reuse() {
- txnIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
- autoCommit = true;
- isReadOnly = false;
- isClosed_ = false;
- txid = 0;
- t4connection_.reuse();
- };
-
- boolean useArrayBinding() {
- return useArrayBinding_;
- }
-
- short getTransportBufferSize() {
- return transportBufferSize_;
- }
-
- // methods for handling weak connections
- void removeElement(TrafT4Connection conn) {
- refTosrvrCtxHandle_.remove(conn.pRef_);
- conn.pRef_.clear();
- }
-
- void gcConnections() {
- Reference pRef;
- InterfaceConnection ic;
- while ((pRef = refQ_.poll()) != null) {
- ic = (InterfaceConnection) refTosrvrCtxHandle_.get(pRef);
- // All PreparedStatement objects are added to Hashtable
- // Only Statement objects that produces ResultSet are added to
- // Hashtable
- // Hence stmtLabel could be null
- if (ic != null) {
- try {
- ic.close();
- } catch (SQLException e) {
- } finally {
- refTosrvrCtxHandle_.remove(pRef);
- }
- }
- }
- }
-
- public byte[] encodeString(String str, int charset) throws CharacterCodingException, UnsupportedCharsetException {
- Integer key = new Integer(charset);
- CharsetEncoder ce;
- byte[] ret = null;
-
- if (str != null) {
- if (this.isoMapping_ == InterfaceUtilities.SQLCHARSETCODE_ISO88591 && !this.enforceISO) {
- ret = str.getBytes(); //convert the old way
- } else {
- if ((ce = (CharsetEncoder) encoders.get(key)) == null) { //only create a new encoder if its the first time
- String charsetName = InterfaceUtilities.getCharsetName(charset);
-
- //encoder needs to be based on our current swap flag for UTF-16 data
- //this should be redesigned when we fixup character set issues for SQ
- if(key == InterfaceUtilities.SQLCHARSETCODE_UNICODE && this.byteSwap == true) {
- charsetName = "UTF-16LE";
- }
-
- Charset c = Charset.forName(charsetName);
- ce = c.newEncoder();
- ce.onUnmappableCharacter(CodingErrorAction.REPORT);
- encoders.put(key, ce);
- }
-
- synchronized(ce) { //since one connection shares encoders
- ce.reset();
- ByteBuffer buf = ce.encode(CharBuffer.wrap(str));
- ret = new byte[buf.remaining()];
- buf.get(ret, 0, ret.length);
- }
- }
- }
-
- return ret;
- }
-
- public String decodeBytes(byte[] data, int charset) throws CharacterCodingException, UnsupportedCharsetException {
- Integer key = new Integer(charset);
- CharsetDecoder cd;
- String str = null;
-
- // we use this function for USC2 columns as well and we do NOT want to
- // apply full pass-thru mode for them
- if (this.isoMapping_ == InterfaceUtilities.SQLCHARSETCODE_ISO88591 && !this.enforceISO
- && charset != InterfaceUtilities.SQLCHARSETCODE_UNICODE) {
- str = new String(data);
- } else {
- // the following is a fix for JDK 1.4.2 and MS932. For some reason
- // it does not handle single byte entries properly
- boolean fix = false;
- if (charset == 10 && data.length == 1) {
- data = new byte[] { 0, data[0] };
- fix = true;
- }
-
- if ((cd = (CharsetDecoder) decoders.get(key)) == null) { //only create a decoder if its the first time
- String charsetName = InterfaceUtilities.getCharsetName(charset);
-
- //encoder needs to be based on our current swap flag for UTF-16 data
- //this should be redesigned when we fixup character set issues for SQ
- if(key == InterfaceUtilities.SQLCHARSETCODE_UNICODE && this.byteSwap == true) {
- charsetName = "UTF-16LE";
- }
-
- Charset c = Charset.forName(charsetName);
- cd = c.newDecoder();
- cd.replaceWith(this.t4props_.getReplacementString());
- cd.onUnmappableCharacter(CodingErrorAction.REPLACE);
- decoders.put(key, cd);
- }
-
- synchronized(cd) { //one decoder for the entire connection
- cd.reset();
- str = cd.decode(ByteBuffer.wrap(data)).toString();
- }
-
- if (fix)
- str = str.substring(1);
- }
-
- return str;
- }
-
- public String getApplicationName() {
- return this.t4props_.getApplicationName();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceResultSet.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceResultSet.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceResultSet.java
deleted file mode 100644
index 0d7c0b4..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InterfaceResultSet.java
+++ /dev/null
@@ -1,927 +0,0 @@
-// @@@ 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.sql.Date;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.text.DecimalFormat;
-import java.text.FieldPosition;
-import java.util.Properties;
-import java.util.logging.Level;
-
-class InterfaceResultSet {
- InterfaceConnection ic_;
- String stmtLabel_;
-
- /* CHAR/CHARACTER */
- static final int SQLTYPECODE_CHAR = 1;
-
- /* NUMERIC */
- static final int SQLTYPECODE_NUMERIC = 2;
- static final int SQLTYPECODE_NUMERIC_UNSIGNED = -201;
-
- /* DECIMAL */
- static final int SQLTYPECODE_DECIMAL = 3;
-
- static final int SQLTYPECODE_DECIMAL_UNSIGNED = -301;
- static final int SQLTYPECODE_DECIMAL_LARGE = -302;
- static final int SQLTYPECODE_DECIMAL_LARGE_UNSIGNED = -303;
-
- /* INTEGER/INT */
- static final int SQLTYPECODE_INTEGER = 4;
-
- static final int SQLTYPECODE_INTEGER_UNSIGNED = -401;
- static final int SQLTYPECODE_LARGEINT = -402;
-
- /* SMALLINT */
- static final int SQLTYPECODE_SMALLINT = 5;
-
- static final int SQLTYPECODE_SMALLINT_UNSIGNED = -502;
-
- static final int SQLTYPECODE_BPINT_UNSIGNED = -503;
-
- /*
- * DOUBLE depending on precision
- */
- static final int SQLTYPECODE_FLOAT = 6;
-
- /*
- */
- static final int SQLTYPECODE_REAL = 7;
-
- /*
- */
- static final int SQLTYPECODE_DOUBLE = 8;
-
- /* DATE,TIME,TIMESTAMP */
- static final int SQLTYPECODE_DATETIME = 9;
-
- /* TIMESTAMP */
- static final int SQLTYPECODE_INTERVAL = 10;
-
- /* no ANSI value 11 */
-
- /* VARCHAR/CHARACTER VARYING */
- static final int SQLTYPECODE_VARCHAR = 12;
-
- /* SQL/MP stype VARCHAR with length prefix:
- * */
- static final int SQLTYPECODE_VARCHAR_WITH_LENGTH = -601;
- static final int SQLTYPECODE_BLOB = -602;
- static final int SQLTYPECODE_CLOB = -603;
-
- /* LONG VARCHAR/ODBC CHARACTER VARYING */
- static final int SQLTYPECODE_VARCHAR_LONG = -1; /* ## NEGATIVE??? */
-
- /* no ANSI value 13 */
-
- /* BIT */
- static final int SQLTYPECODE_BIT = 14; /* not supported */
-
- /* BIT VARYING */
- static final int SQLTYPECODE_BITVAR = 15; /* not supported */
-
- /* NCHAR -- CHAR(n) CHARACTER SET s -- where s uses two bytes per char */
- static final int SQLTYPECODE_CHAR_DBLBYTE = 16;
-
- /* NCHAR VARYING -- VARCHAR(n) CHARACTER SET s -- s uses 2 bytes per char */
- static final int SQLTYPECODE_VARCHAR_DBLBYTE = 17;
-
- /* Date/Time/TimeStamp related constants */
- static final int SQLDTCODE_DATE = 1;
- static final int SQLDTCODE_TIME = 2;
- static final int SQLDTCODE_TIMESTAMP = 3;
- static final int SQLDTCODE_MPDATETIME = 4;
- static final int dateLength = 10;
- static final int timeLength = 8;
- static final int timestampLength = 26;
-
- T4ResultSet t4resultSet_;
-
- static Properties javaLangToJavaNio = null;
-
- TrafT4ResultSet rs_;
-
- InterfaceResultSet(TrafT4ResultSet rs) throws SQLException {
- this.ic_ = ((TrafT4Connection) rs.connection_).getServerHandle();
- stmtLabel_ = rs.stmtLabel_;
- t4resultSet_ = new T4ResultSet(this);
- rs_ = rs;
- };
-
- // -------------------------------------------------------------------
- // from nskieee.cpp -- find the length for the data based on datatype
- //
- static int dataLengthFetchPerf(int SQLDataType, int SQLDateTimeCode, int SQLOctetLength, int maxRowLen,
- int bufferLen, int ODBCDataType, int ODBCPrecision) {
- int allocLength = 0;
- switch (SQLDataType) {
- case SQLTYPECODE_INTERVAL:
- allocLength = SQLOctetLength;
- break;
- case SQLTYPECODE_VARCHAR_WITH_LENGTH:
- case SQLTYPECODE_VARCHAR_LONG:
- case SQLTYPECODE_VARCHAR_DBLBYTE:
- case SQLTYPECODE_BITVAR:
- case SQLTYPECODE_BLOB:
- case SQLTYPECODE_CLOB:
- allocLength = bufferLen + 2;
- break;
- case SQLTYPECODE_CHAR:
-
- // allocLength = SQLOctetLength - 1; // no null at the end
- allocLength = SQLOctetLength;
- if (maxRowLen > 0) {
- allocLength = (allocLength > maxRowLen) ? (maxRowLen + 1) : (allocLength);
- }
- break;
- case SQLTYPECODE_BIT:
- case SQLTYPECODE_CHAR_DBLBYTE:
- case SQLTYPECODE_VARCHAR:
- allocLength = SQLOctetLength - 1; // no null at the end
- if (maxRowLen > 0) {
- allocLength = (allocLength > maxRowLen) ? (maxRowLen + 1) : (allocLength);
- }
- break;
- case SQLTYPECODE_DATETIME:
- switch (SQLDateTimeCode) {
- case SQLDTCODE_DATE:
- allocLength = dateLength;
- break;
- case SQLDTCODE_TIME:
- if (ODBCDataType == java.sql.Types.OTHER) // For
- // HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
- {
- allocLength = SQLOctetLength;
- } else {
- allocLength = timeLength;
- }
- break;
- case SQLDTCODE_TIMESTAMP:
-
- /*
- * allocLength = timestampLength; if (SQLOctetLength <
- * timestampLength) { allocLength = 19; // timestamp without
- * fraction }
- */
- allocLength = ODBCPrecision;
- break;
- default:
- allocLength = SQLOctetLength;
- break;
- }
-
- break;
- default:
- allocLength = SQLOctetLength; // exclude nullable
- break;
- }
- return allocLength;
- }
-
- // -------------------------------------------------------------------
- // get the column value data in String format
- Object getFetchString(TrafT4Connection conn, int scale, int SQLDataType, int SQLDatetimeCode, int FSDataType,
- byte[] ibuffer, int byteIndex, int byteLen, int SQLcharset, int ODBCDataType) throws SQLException {
- Object retObj;
- String tmpStr;
- byte[] tbuffer;
- BigDecimal tmpbd;
-
- switch (SQLDataType) {
-
- case SQLTYPECODE_CHAR:
- tbuffer = new byte[byteLen];
- System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
- retObj = tbuffer;
- break;
- case SQLTYPECODE_VARCHAR:
- tbuffer = new byte[byteLen];
- System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
- retObj = tbuffer;
- break;
- case SQLTYPECODE_INTERVAL:
- tbuffer = new byte[byteLen];
- System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
- retObj = tbuffer;
- break;
- case SQLTYPECODE_VARCHAR_WITH_LENGTH:
- case SQLTYPECODE_VARCHAR_LONG:
- case SQLTYPECODE_BLOB:
- case SQLTYPECODE_CLOB:
- tbuffer = new byte[byteLen - 2];
- System.arraycopy(ibuffer, byteIndex + 2, tbuffer, 0, byteLen - 2);
-
- // retObj = new String(tbuffer); Swastik for LOB Support 10/29/2004
- retObj = tbuffer;
- break;
- case SQLTYPECODE_DATETIME:
- tmpStr = new String(Bytes.read_chars(ibuffer, byteIndex, byteLen));
- switch (SQLDatetimeCode) {
- case SQLDTCODE_DATE:
- retObj = Date.valueOf(tmpStr);
- break;
- case SQLDTCODE_TIMESTAMP:
- retObj = Timestamp.valueOf(tmpStr);
- break;
- case SQLDTCODE_TIME:
-
- // Need to add code here to check if it's
- // HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
- if (ODBCDataType != java.sql.Types.OTHER) {
- retObj = Time.valueOf(tmpStr);
- break;
- } else {
- // Do default processing as it is
- // HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
- }
- default:
- retObj = tmpStr;
- break;
- }
- break;
- case SQLTYPECODE_SMALLINT:
- short sValue = Bytes.extractShort(ibuffer, byteIndex, this.ic_.getByteSwap());
- retObj = new Short(sValue);
- if (scale > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
- }
- break;
- case SQLTYPECODE_SMALLINT_UNSIGNED:
- retObj = new Integer(Bytes.extractUShort(ibuffer, byteIndex, this.ic_.getByteSwap()));
- if (scale > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
- }
- break;
- case SQLTYPECODE_INTEGER:
- retObj = new Integer(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
- if (scale > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
- }
- break;
- case SQLTYPECODE_INTEGER_UNSIGNED:
- retObj = new Long(Bytes.extractUInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
- if (scale > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
- }
- break;
- case SQLTYPECODE_LARGEINT:
- tbuffer = new byte[byteLen];
- System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
- retObj = new BigInteger(tbuffer);
- if (scale > 0) {
- retObj = new BigDecimal((BigInteger) retObj, scale);
- }
- break;
- case SQLTYPECODE_NUMERIC:
- case SQLTYPECODE_NUMERIC_UNSIGNED:
- switch (FSDataType) {
- case 130:
- case 131:
- tmpStr = String.valueOf(Bytes.extractShort(ibuffer, byteIndex, this.ic_.getByteSwap()));
- break;
- case 132:
- case 133:
- tmpStr = String.valueOf(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
- break;
- case 134:
- tmpStr = String.valueOf(Bytes.extractLong(ibuffer, byteIndex, this.ic_.getByteSwap()));
- break;
- default:
- throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "restricted_data_type", null);
- }
- retObj = new BigDecimal((new BigInteger(tmpStr)), scale);
- break;
- case SQLTYPECODE_DECIMAL:
- case SQLTYPECODE_DECIMAL_UNSIGNED:
- case SQLTYPECODE_DECIMAL_LARGE:
- case SQLTYPECODE_DECIMAL_LARGE_UNSIGNED:
- String retStr;
-
- // check if the sign is minus (-80)
- byte sign = (byte) (ibuffer[byteIndex] & (byte) (-80));
-
- // first byte = inbyte - (-80)
- if (sign == (byte) (-80)) {
- byte firstByte = (byte) (ibuffer[byteIndex] - (byte) (-80));
- retStr = "-" + firstByte + String.valueOf(Bytes.read_chars(ibuffer, byteIndex + 1, byteLen - 1));
- } else {
- retStr = String.valueOf(Bytes.read_chars(ibuffer, byteIndex, byteLen));
- }
- retObj = new BigDecimal(new BigInteger(retStr), scale);
- break;
- case SQLTYPECODE_REAL:
- retObj = new Float(Float.intBitsToFloat(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap())));
- break;
- case SQLTYPECODE_DOUBLE:
- case SQLTYPECODE_FLOAT:
- retObj = new Double(Double.longBitsToDouble(Bytes.extractLong(ibuffer, byteIndex, this.ic_.getByteSwap())));
- break;
- case SQLTYPECODE_BIT:
- case SQLTYPECODE_BITVAR:
- case SQLTYPECODE_BPINT_UNSIGNED:
- default:
- throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "restricted_data_type", null);
- }
- return retObj;
- } // end getFetchString
-
- private static String padZero(long i, int len) {
- String s = String.valueOf(i);
-
- while (s.length() < len)
- s = '0' + s;
-
- return s;
- }
-
- // -------------------------------------------------------------------
- // get the column value data from Execute2 in String format
- static Object getExecute2FetchString(TrafT4Connection conn, HPT4Desc desc, byte[] values, int noNullValue,
- int ODBCDataType, boolean useOldDateFormat, boolean swap) throws SQLException {
- Object retObj;
- String tmpStr;
- byte[] tbuffer;
- BigDecimal tmpbd;
- int length;
- int year, month, day, hour, minute, second;
- long nanoSeconds;
-
- switch (desc.sqlDataType_) {
- case SQLTYPECODE_CHAR:
- length = desc.sqlOctetLength_;
- tbuffer = new byte[length];
- System.arraycopy(values, noNullValue, tbuffer, 0, length);
- retObj = tbuffer;
- break;
- case SQLTYPECODE_VARCHAR:
- case SQLTYPECODE_VARCHAR_WITH_LENGTH:
- case SQLTYPECODE_VARCHAR_LONG:
- case SQLTYPECODE_BLOB:
- case SQLTYPECODE_CLOB:
- boolean shortLength = desc.precision_ < Math.pow(2, 15);
- int dataOffset = noNullValue + ((shortLength) ? 2 : 4);
-
- length = (shortLength) ? Bytes.extractShort(values, noNullValue, swap) : Bytes.extractInt(values, noNullValue, swap);
-
- tbuffer = new byte[length];
- int len = values.length - (dataOffset);
- System.arraycopy(values, (dataOffset), tbuffer, 0, (length > len) ? len : length);
- retObj = tbuffer;
- break;
- case SQLTYPECODE_INTERVAL:
- length = desc.sqlOctetLength_;
- tbuffer = new byte[length];
- System.arraycopy(values, noNullValue, tbuffer, 0, length);
- retObj = tbuffer;
- break;
- case SQLTYPECODE_DATETIME:
- switch (desc.sqlDatetimeCode_) {
- case SQLDTCODE_DATE:
- if (!useOldDateFormat) // new date format, only for bulk move
- {
- // "yyyy-mm-dd"
- year = Bytes.extractUShort(values, noNullValue, swap);
- month = values[noNullValue + 2];
- day = values[noNullValue + 3];
- String t = padZero(year,4) + "-" + padZero(month,2) + "-" + padZero(day,2);
- retObj = Date.valueOf(t);
- } else {// do the old way
- length = dateLength;
- retObj = Date.valueOf(new String(Bytes.read_chars(values, noNullValue, length)));
- }
- break;
- case SQLDTCODE_TIMESTAMP:
- if (!useOldDateFormat) // new date format, if not SQLCatalogs
- {
- // yyyy-mm-dd hh:mm:ss.fffffffff
- year = Bytes.extractUShort(values, noNullValue, swap);
- month = values[noNullValue + 2];
- day = values[noNullValue + 3];
- hour = values[noNullValue + 4];
- minute = values[noNullValue + 5];
- second = values[noNullValue + 6];
-
- if (desc.sqlPrecision_ > 0) {
- nanoSeconds = Bytes.extractUInt(values, noNullValue + 7, swap);
-
- if (nanoSeconds > 999999) // returned in microseconds
- nanoSeconds = 0;
-
- // apply leading 0's for string conversion
- tmpStr = "" + nanoSeconds;
- length = tmpStr.length();
- for (int i = 0; i < desc.sqlPrecision_ - length; i++) {
- tmpStr = "0" + tmpStr;
- }
- } else {
- tmpStr = "0";
- }
-
- retObj = Timestamp.valueOf(padZero((int) year, 4) + "-" + padZero(month, 2) + "-" + padZero(day, 2)
- + " " + padZero(hour, 2) + ":" + padZero(minute, 2) + ":" + padZero(second, 2) + "."
- + tmpStr);
- } else { // do the old way
- length = desc.precision_;
- retObj = Timestamp.valueOf(new String(Bytes.read_chars(values, noNullValue, length)));
- }
- break;
-
- case SQLDTCODE_TIME:
- if (ODBCDataType == java.sql.Types.OTHER) // For
- // HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
- {
- length = desc.sqlOctetLength_;
- retObj = new String(Bytes.read_chars(values, noNullValue, length));
- } else {
- length = timeLength;
- if (!useOldDateFormat) // new date format, only for bulk
- // move
- {
- // "hh:mm:ss"
- hour = values[noNullValue];
- minute = values[noNullValue + 1];
- second = values[noNullValue + 2];
-
- if (desc.sqlPrecision_ > 0) {
- nanoSeconds = Bytes.extractUInt(values, noNullValue + 3, swap);
-
- if (nanoSeconds > 999999) // returned in microseconds
- nanoSeconds = 0;
-
- String formatStr = "";
- for(int i=0;i<desc.sqlPrecision_;i++)
- formatStr += "0";
-
- StringBuffer sb = new StringBuffer();
- DecimalFormat format = new DecimalFormat("00");
- format.format(hour, sb, new FieldPosition(0));
- sb.append(':');
- format.format(minute, sb, new FieldPosition(0));
- sb.append(':');
- format.format(second, sb, new FieldPosition(0));
- sb.append('.');
- format = new DecimalFormat(formatStr);
- format.format(nanoSeconds, sb, new FieldPosition(0));
-
- retObj = sb.toString();
- } else {
- retObj = Time.valueOf(String.valueOf(hour) + ":" + String.valueOf(minute) + ":"
- + String.valueOf(second));
- }
- } else
- // do the old way
- retObj = Time.valueOf(new String(Bytes.read_chars(values, noNullValue, length)));
- }
- break;
- default:
- length = desc.sqlOctetLength_;
- retObj = new String(Bytes.read_chars(values, noNullValue, length));
- break;
- }
- break;
- case SQLTYPECODE_SMALLINT:
- short sValue = Bytes.extractShort(values, noNullValue, swap);
- retObj = new Short(sValue);
- if (desc.scale_ > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
- }
- break;
- case SQLTYPECODE_SMALLINT_UNSIGNED:
- int signedSValue = Bytes.extractUShort(values, noNullValue, swap);
- if (desc.scale_ > 0) {
- tmpbd = new BigDecimal(new BigInteger(String.valueOf(signedSValue)), (int) desc.scale_);
- } else {
- tmpbd = new BigDecimal(String.valueOf(signedSValue));
- }
- retObj = tmpbd;
- break;
- case SQLTYPECODE_INTEGER:
- retObj = new Integer(Bytes.extractInt(values, noNullValue,swap));
- if (desc.scale_ > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
- }
- break;
- case SQLTYPECODE_INTEGER_UNSIGNED:
- retObj = new Long(Bytes.extractUInt(values, noNullValue, swap));
- if (desc.scale_ > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
- }
- break;
- case SQLTYPECODE_LARGEINT:
- retObj = new Long(Bytes.extractLong(values, noNullValue, swap));
- if (desc.scale_ > 0) {
- retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
- }
- break;
- case SQLTYPECODE_NUMERIC:
- case SQLTYPECODE_NUMERIC_UNSIGNED:
- tbuffer = new byte[desc.sqlOctetLength_];
- System.arraycopy(values, noNullValue, tbuffer, 0, desc.sqlOctetLength_);
- retObj = InterfaceUtilities.convertSQLBigNumToBigDecimal(tbuffer, desc.scale_, swap);
- break;
- case SQLTYPECODE_DECIMAL:
- case SQLTYPECODE_DECIMAL_UNSIGNED:
- case SQLTYPECODE_DECIMAL_LARGE:
- case SQLTYPECODE_DECIMAL_LARGE_UNSIGNED:
- String retStr;
-
- // check if the sign is minus (-80)
- byte sign = (byte) (values[noNullValue] & (byte) (-80));
-
- // first byte = inbyte - (-80)
- if (sign == (byte) (-80)) {
- byte firstByte = (byte) (values[noNullValue] - (byte) (-80));
- retStr = "-" + firstByte
- + String.valueOf(Bytes.read_chars(values, noNullValue + 1, desc.sqlOctetLength_ - 1));
- } else {
- retStr = String.valueOf(Bytes.read_chars(values, noNullValue, desc.sqlOctetLength_));
- }
- retObj = new BigDecimal(new BigInteger(retStr), desc.scale_);
- break;
- case SQLTYPECODE_REAL:
- retObj = new Float(Float.intBitsToFloat(Bytes.extractInt(values, noNullValue, swap)));
- break;
- case SQLTYPECODE_DOUBLE:
- case SQLTYPECODE_FLOAT:
- retObj = new Double(Double.longBitsToDouble(Bytes.extractLong(values, noNullValue, swap)));
- break;
- case SQLTYPECODE_BIT:
- case SQLTYPECODE_BITVAR:
- case SQLTYPECODE_BPINT_UNSIGNED:
- default:
- throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "restricted_data_type", null);
- }
- return retObj;
- } // end getExecute2FetchString
-
- // -------------------------------------------------------------------
- void setFetchOutputs(TrafT4ResultSet rs, int rowsAffected, boolean endOfData, byte[] outputDataValue)
- throws SQLException
-
- {
- Row[] rowArray;
- Object[] objectArray;
- Object columnValue;
-
- int columnCount;
- int rowIndex;
- int columnIndex;
- int byteIndex = 0;
- short SQLDataInd = 0;
- int byteLen = 0;
- int maxRowLen = rs.connection_.ic_.getTransportBufferSize(); // maxRowLen
-
- rowArray = new Row[rowsAffected];
-
- // get the number of colums
- columnCount = rs.getNoOfColumns();
-
- for (rowIndex = 0; rowIndex < rowsAffected; rowIndex++) {
- if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, outputDataValue, rowsAffected,
- endOfData, 0);
- String temp = "Reading row = " + rowIndex;
- rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "setFetchOutputs", temp, p);
- }
- objectArray = new Object[columnCount];
-
- for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
- if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, outputDataValue,
- rowsAffected, endOfData, 0);
- String temp = "Reading column = " + columnIndex;
- rs.connection_.props_.t4Logger_
- .logp(Level.FINEST, "InterfaceResultSet", "setFetchOutputs", temp, p);
- }
- SQLDataInd = new Byte(outputDataValue[byteIndex++]).shortValue();
- if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, outputDataValue,
- rowsAffected, endOfData, 0);
- String temp = "Row = " + rowIndex + "," + "Column = " + columnIndex + " SQLDataInd is = "
- + SQLDataInd;
- rs.connection_.props_.t4Logger_
- .logp(Level.FINEST, "InterfaceResultSet", "setFetchOutputs", temp, p);
- }
- if (SQLDataInd == 0) {
- short varDataLen;
- if (outputDataValue.length > (byteIndex + 2)) {
- varDataLen = Bytes.extractShort(outputDataValue, byteIndex, this.ic_.getByteSwap());
- } else {
- varDataLen = 0;
-
- }
- byteLen = dataLengthFetchPerf(rs.outputDesc_[columnIndex].sqlDataType_,
- rs.outputDesc_[columnIndex].sqlDatetimeCode_, rs.outputDesc_[columnIndex].sqlOctetLength_,
- maxRowLen, // maxLength
- varDataLen, rs.outputDesc_[columnIndex].dataType_, rs.outputDesc_[columnIndex].precision_);
-
- columnValue = getFetchString(rs.connection_, rs.outputDesc_[columnIndex].scale_,
- rs.outputDesc_[columnIndex].sqlDataType_, rs.outputDesc_[columnIndex].sqlDatetimeCode_,
- rs.outputDesc_[columnIndex].fsDataType_, outputDataValue, byteIndex, byteLen,
- rs.outputDesc_[columnIndex].sqlCharset_, rs.outputDesc_[columnIndex].dataType_);
-
- byteIndex = byteIndex + byteLen;
-
- switch (rs.outputDesc_[columnIndex].sqlDataType_) {
- case SQLTYPECODE_VARCHAR_WITH_LENGTH:
- case SQLTYPECODE_VARCHAR_LONG:
- case SQLTYPECODE_VARCHAR_DBLBYTE:
- case SQLTYPECODE_BITVAR:
- case SQLTYPECODE_CHAR:
- case SQLTYPECODE_CHAR_DBLBYTE:
- case SQLTYPECODE_VARCHAR:
- case SQLTYPECODE_BLOB:
- case SQLTYPECODE_CLOB:
- byteIndex++;
- break;
- }
-
- if (columnValue == null) {
- throw HPT4Messages
- .createSQLException(rs.connection_.props_, ic_.getLocale(), "null_data", null);
- }
- } else {
- columnValue = null;
-
- }
- objectArray[columnIndex] = columnValue;
- }
- rowArray[rowIndex] = new Row(columnCount, objectArray);
- }
- rs.setFetchOutputs(rowArray, rowsAffected, endOfData);
- }
-
- // ----------------------------------------------------------------------------
- void setExecute2FetchOutputs(TrafT4ResultSet rs, int rowsAffected, boolean endOfData, byte[] values)
- throws SQLException {
- if (rs.useOldDateFormat()) {
- setFetchOutputs(rs, rowsAffected, endOfData, values);
- return;
- }
- Object[] objectArray;
- Object columnValue;
- Row[] rowArray = new Row[rowsAffected];
-
- int columnCount = rs.getNoOfColumns();
- int rowIndex;
- int columnIndex;
- int byteIndex = 0;
- int SQLDataInd = 0;
- int byteLen = 0;
- int maxRowLen = rs.connection_.ic_.getTransportBufferSize(); // maxRowLen
-
- objectArray = new Object[columnCount];
-
- int dataLength = 0;
-
- if (rs.outputDesc_ != null && rs.outputDesc_.length > 0) {
- dataLength = rs.outputDesc_[0].rowLength_;
- }
-
- int rowOffset = 0;
- for (rowIndex = 0; rowIndex < rowsAffected; rowIndex++) {
- rowOffset = rowIndex * dataLength;
-
- for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
- int noNullValueOffset = rs.outputDesc_[columnIndex].noNullValue_;
- int nullValueOffset = rs.outputDesc_[columnIndex].nullValue_;
-
- if (nullValueOffset != -1)
- nullValueOffset += rowOffset;
- if (noNullValueOffset != -1)
- noNullValueOffset += rowOffset;
-
- if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, endOfData, values);
- String temp = "Processing column = " + columnIndex + ": noNullValueOffset = " + noNullValueOffset
- + ": nullValueOffset = " + nullValueOffset;
- rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "setExecute2FetchOutputs",
- temp, p);
- }
-
- if (nullValueOffset != -1 && Bytes.extractShort(values, nullValueOffset, this.ic_.getByteSwap()) == -1) {
- columnValue = null;
- } else {
- columnValue = getExecute2FetchString(rs.connection_, rs.outputDesc_[columnIndex], values,
- noNullValueOffset, rs.outputDesc_[columnIndex].dataType_, rs.useOldDateFormat(), this.ic_.getByteSwap());
- if (columnValue == null) {
- throw HPT4Messages
- .createSQLException(rs.connection_.props_, ic_.getLocale(), "null_data", null);
- }
- } // end if else
-
- objectArray[columnIndex] = columnValue;
- } // end for
-
- rowArray[rowIndex] = new Row(columnCount, objectArray);
- }
- rs.setFetchOutputs(rowArray, rowsAffected, endOfData);
-
- } // end setExectue2FetchOutputs
-
- // ----------------------------------------------------------------------------
- // Interface methods
- boolean fetch(String stmtLabel, int maxRowCnt, int queryTimeout, int holdability, TrafT4ResultSet rs)
- throws SQLException {
- int sqlAsyncEnable = 0;
- int stmtHandle = 0;
- int stmtCharset = 1;
- String cursorName = "";
- int cursorCharset = 1;
- String stmtOptions = "";
-
- boolean endOfData = false;
- boolean dataFound = false;
- String sqlStmt = ""; // qs_interface
-
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt, queryTimeout,
- holdability);
- String temp = "Entering Fetch";
- rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
- }
-
- if (rs_.stmt_ != null && rs_.stmt_.sql_ != null) {
- sqlStmt = rs_.stmt_.sql_.toUpperCase();
- }
-
- FetchReply fr;
-
- try {
- fr = t4resultSet_.Fetch(sqlAsyncEnable, queryTimeout, stmtHandle, stmtCharset, maxRowCnt, cursorName,
- cursorCharset, stmtOptions);
-
- } catch (SQLException tex) {
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt, queryTimeout,
- holdability);
- String temp = "SQLException while fetching.";
- rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
- }
- throw tex;
- }
-
- switch (fr.returnCode) {
- case TRANSPORT.CEE_SUCCESS:
- case TRANSPORT.SQL_SUCCESS_WITH_INFO:
-
- // do warning processing
- if (fr.errorList.length != 0) {
- HPT4Messages.setSQLWarning(rs.connection_.props_, rs, fr.errorList);
- }
- //endOfData = (fr.rowsAffected < maxRowCnt) ? true : false;
-
- if (fr.rowsAffected > 0) {
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt,
- queryTimeout, holdability);
- String temp = "Data Found. Setting fetch outputs";
- rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
- }
- if (rs.keepRawBuffer_ == true) {
- rs.rawBuffer_ = fr.outValues;
- }
-
- setExecute2FetchOutputs(rs, fr.rowsAffected, endOfData, fr.outValues);
-
- dataFound = true;
- }
- break;
- case 100: // fix this
- case odbc_SQLSvc_Fetch_exc_.odbc_SQLSvc_Fetch_SQLNoDataFound_exn_:
- dataFound = false;
- endOfData = true;
- break;
-
- default:
- HPT4Messages.throwSQLException(rs.connection_.props_, fr.errorList);
-
- }
-
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt, queryTimeout,
- holdability);
- String temp = "Exiting Fetch.";
- rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
- }
-
- // see if the rows fetched is valid
- return dataFound;
- };
-
- void close() throws SQLException {
- ic_.isConnectionOpen();
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
- String temp = "Closing resultset.";
- rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
- }
-
- int rval = 0;
- CloseReply cry_ = null;
-
- //
- // If the query is non-unique, then close the result set (cursor).
- // If the query was a unique select, then the result set was implicitly
- // closed by NCS.
- //
- if (rs_ != null && rs_.stmt_ != null && rs_.stmt_.ist_ != null
- && rs_.stmt_.ist_.sqlQueryType_ != TRANSPORT.SQL_SELECT_UNIQUE) {
- cry_ = t4resultSet_.Close();
-
- switch (cry_.m_p1.exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
-
- // ignore the SQLWarning for the static close
- break;
- case odbc_SQLSvc_Close_exc_.odbc_SQLSvc_Close_SQLError_exn_:
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
- String temp = "odbc_SQLSvc_Close_SQLError_exn_";
- rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
- }
-
- HPT4Messages.throwSQLException(rs_.connection_.props_, cry_.m_p1.SQLError);
- default:
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
- String temp = "UnknownException occurred during close.";
- rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
- }
- throw HPT4Messages.createSQLException(rs_.connection_.props_, ic_.getLocale(),
- "ids_unknown_reply_error", null);
- } // end switch
- } // end if
-
- if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
- String temp = "Closed resultset.";
- rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
- }
- };
-
- // ----------------------------------------------------------------------------
- static Object[] getExecute2Outputs(TrafT4Connection conn, HPT4Desc[] desc, byte[] values, boolean swap) throws SQLException
-
- {
- Object[] objectArray;
- Object columnValue;
- int columnIndex;
- int columnCount = (desc == null) ? 0 : desc.length;
-
- objectArray = new Object[columnCount];
-
- for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
- int noNullValueOffset = desc[columnIndex].noNullValue_;
- int nullValueOffset = desc[columnIndex].nullValue_;
-
- if (conn.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(conn.props_, conn, desc, values);
- String temp = "Processing column = " + columnIndex + ": noNullValueOffset = " + noNullValueOffset
- + ": nullValueOffset = " + nullValueOffset;
- conn.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "getExecute2Outputs", temp, p);
- }
-
- if ((nullValueOffset != -1 && Bytes.extractShort(values, nullValueOffset, swap) == -1)
- || (desc[columnIndex].paramMode_ == HPT4ParameterMetaData.parameterModeIn)) {
- columnValue = null;
- } else {
- columnValue = getExecute2FetchString(conn, desc[columnIndex], values, noNullValueOffset,
- desc[columnIndex].dataType_, false, swap);
- if (columnValue == null) {
- throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "null_data", null);
- }
- } // end if else
-
- objectArray[columnIndex] = columnValue;
- } // end for
-
- return objectArray;
-
- } // end getExectue2Outputs
-
-}