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:54 UTC
[15/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/HPT4PooledConnectionManager.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4PooledConnectionManager.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4PooledConnectionManager.java
deleted file mode 100644
index 0657b92..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4PooledConnectionManager.java
+++ /dev/null
@@ -1,385 +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.PrintWriter;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.Vector;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-import javax.sql.ConnectionEvent;
-import javax.sql.ConnectionPoolDataSource;
-import javax.sql.PooledConnection;
-
-public class HPT4PooledConnectionManager implements javax.sql.ConnectionEventListener {
-
- public void connectionClosed(ConnectionEvent event) {
- if (T4Properties.t4GlobalLogger.isLoggable(Level.FINE) == true) {
- Object p[] = T4LoggingUtilities.makeParams(null, event);
- T4Properties.t4GlobalLogger.logp(Level.FINE, "HPT4PooledConnectionManager", "connectionClosed", "", p);
- }
- if (out_ != null) {
- LogRecord lr = new LogRecord(Level.FINE, "");
- Object p[] = T4LoggingUtilities.makeParams(null, event);
- lr.setParameters(p);
- lr.setSourceClassName("HPT4PooledConnectionManager");
- lr.setSourceMethodName("connectionClosed");
- T4LogFormatter lf = new T4LogFormatter();
- String temp = lf.format(lr);
- out_.println(temp);
- }
- if (out_ != null) {
- if (traceLevel_ != Level.OFF) {
- out_.println(traceId_ + "connectionClosed(" + event + ")");
- }
- }
- PooledConnection pc;
-
- pc = (PooledConnection) event.getSource();
-
- boolean addToFreePool = true;
- if (minPoolSize_ > 0 && free_.size() >= minPoolSize_) {
- addToFreePool = false;
- }
- // If an initial pool is being created, then ensure that the connection
- // is
- // added to the free pool irrespective of minPoolSize being reached
- if (initialPoolCreationFlag_) {
- addToFreePool = true;
- }
- boolean wasPresent = removeInUseConnection(pc, addToFreePool);
-
- if (wasPresent && (!addToFreePool)) {
- try {
- pc.close();
- } catch (SQLException e) {
- // ignore any close error
- }
- }
- }
-
- public void connectionErrorOccurred(ConnectionEvent event) {
- if (out_ != null) {
- if (traceLevel_ != Level.OFF) {
- out_.println(traceId_ + "connectionErrorOccurred(" + event + ")");
- }
- }
-
- PooledConnection pc;
-
- pc = (PooledConnection) event.getSource();
- try {
- pc.close();
- } catch (SQLException e) {
- // ignore any close error
- }
- removeInUseConnection(pc, false);
- }
-
- public Connection getConnection() throws SQLException {
- if (out_ != null) {
- if (traceLevel_ != Level.OFF) {
- out_.println(traceId_ + "getConnection()");
- }
- }
-
- PooledConnection pc;
- boolean validConnection = false;
-
- do {
- if (free_.size() == 0) {
- if (maxPoolSize_ == 0 || count_ < maxPoolSize_) {
- pc = pds_.getPooledConnection();
- count_++;
- pc.addConnectionEventListener(this);
- inUse_.add(pc);
-
- TrafT4Connection c = (TrafT4Connection) pc.getConnection();
- try {
- c.ic_.enforceT4ConnectionTimeout(c);
- validConnection = true;
- } catch (SQLException sqlEx) {
- try {
- pc.close();
- } catch (Exception e) {
- } // cleanup, ignore any errors
- }
- } else {
- throw HPT4Messages.createSQLException(null, null, "max_pool_size_reached", null);
- }
- } else {
- pc = (PooledConnection) free_.get(0);
- if (removeFreeConnection(pc, true)) {
- TrafT4Connection c = (TrafT4Connection) pc.getConnection();
- try {
- c.ic_.enforceT4ConnectionTimeout(c);
- validConnection = true;
- } catch (SQLException sqlEx) {
- try {
- pc.close();
- } catch (Exception e) {
- } // cleanup, ignore any errors
- }
- }
- }
- } while (!validConnection);
-
- return pc.getConnection();
- }
-
- private synchronized boolean removeFreeConnection(PooledConnection pc, boolean addToUsePool) {
- boolean wasPresent = free_.remove(pc);
- hashTab_.remove(pc);
- if (wasPresent) {
- if (addToUsePool) {
- inUse_.add(pc);
- } else {
- count_--;
- }
- }
- return wasPresent;
- }
-
- private synchronized boolean removeInUseConnection(PooledConnection pc, boolean addToFreePool) {
- boolean wasPresent = inUse_.remove(pc);
- hashTab_.remove(pc);
- if (wasPresent) {
- if (addToFreePool) {
- hashTab_.put(pc, new Long(System.currentTimeMillis() + (1000 * maxIdleTime_)));
- free_.add(pc);
- } else {
- count_--;
- }
- }
- return wasPresent;
- }
-
- private void createInitialPool(int initialPoolSize) throws SQLException {
- if (initialPoolSize <= 0) {
- return;
- }
-
- int limit = initialPoolSize > maxPoolSize_ ? maxPoolSize_ : initialPoolSize;
- Connection initPool_[] = new Connection[limit];
- int created = 0;
- try {
- // Set initialPoolInCreation to indicate that an initial pool is in
- // the
- // process of being created.
- initialPoolCreationFlag_ = true;
-
- for (int i = 0; i < limit; i++) {
- initPool_[i] = getConnection();
- created++;
- }
- } catch (SQLException se) {
- SQLException head = HPT4Messages.createSQLException(null, null, "initial_pool_creation_error", "" + limit);
- head.setNextException(se);
- throw head;
- } finally {
- for (int i = 0; i < created; i++) {
- try {
- if (initPool_[i] != null)
- initPool_[i].close();
- } catch (SQLException se) {
- // ignore
- }
- }
- // Ensuring that the initialPoolInCreation has been set to false to
- // indicate
- // that the initial pool creation process has occured.
- initialPoolCreationFlag_ = false;
- }
- }
-
- void setLogWriter(PrintWriter out) {
- out_ = out;
- }
-
- HPT4PooledConnectionManager(HPT4ConnectionPoolDataSource pds, Level traceLevel) throws SQLException {
- String className = getClass().getName();
- pds_ = pds;
- inUse_ = Collections.synchronizedList(new LinkedList());
- free_ = Collections.synchronizedList(new LinkedList());
- maxPoolSize_ = pds.getMaxPoolSize();
- minPoolSize_ = pds.getMinPoolSize();
- maxIdleTime_ = pds.getMaxIdleTime();
- connectionTimeout_ = pds.getConnectionTimeout();
- traceLevel_ = traceLevel;
- timer_ = null;
- if (maxIdleTime_ > 0 && maxPoolSize_ > 0) {
- IdleConnectionCleanupTask timerTask_ = new IdleConnectionCleanupTask();
- timer_ = new Timer(true);
- timer_.schedule(timerTask_, (maxIdleTime_ * 1000), (maxIdleTime_ * 500));
- }
- if (connectionTimeout_ > 0 && maxPoolSize_ > 0) {
- ConnectionTimeoutCleanupTask timerTask_ = new ConnectionTimeoutCleanupTask();
- if (timer_ == null) {
- timer_ = new Timer(true);
- }
- timer_.schedule(timerTask_, (connectionTimeout_ * 1000), (connectionTimeout_ * 500));
- }
- createInitialPool(pds.getInitialPoolSize());
- traceId_ = "jdbcTrace:[" + Thread.currentThread() + "]:[" + hashCode() + "]:" + className + ".";
- }
-
- ConnectionPoolDataSource pds_;
- // LinkedList inUse_;
- // LinkedList free_;
- List inUse_;
- List free_;
- int count_;
-
- int maxPoolSize_;
- int minPoolSize_;
- long maxIdleTime_;
- int connectionTimeout_;
- Level traceLevel_;
- PrintWriter out_;
- String traceId_;
- Timer timer_;
- Hashtable hashTab_ = new java.util.Hashtable(); // synchronized
- // We keep a flag to indicate to this class that an initial pool is in the
- // process
- // of being created
- boolean initialPoolCreationFlag_ = false;
-
- /*
- * Private class used to clean up the connections that have surpassed
- * maxIdleTime
- */
- /* Start TimerTask definition */
- private class IdleConnectionCleanupTask extends TimerTask {
- Vector toRemove = null;
-
- IdleConnectionCleanupTask() {
- toRemove = new Vector();
- }
-
- public void run() {
- cleanUp();
- }
-
- private void cleanUp() {
- toRemove.clear();
- synchronized (free_) {
- try {
- Iterator it_ = free_.iterator();
- while (it_.hasNext()) {
- PooledConnection tempPC = (PooledConnection) it_.next();
- Long timeOutVal = (Long) hashTab_.get(tempPC);
- if (System.currentTimeMillis() > timeOutVal.longValue()) {
- toRemove.add(tempPC);
- }
- }
- } catch (Throwable t) {
- if (T4Properties.t4GlobalLogger.isLoggable(Level.WARNING) == true) {
- T4Properties.t4GlobalLogger.logp(Level.WARNING, "IdleConnectionCleanupTask", "cleanUp", t
- .getMessage());
- }
- }
- } // synchronized block
- for (int i = 0; i < toRemove.size(); i++) {
- PooledConnection pc = (PooledConnection) toRemove.get(i);
- boolean wasPresent = removeFreeConnection(pc, false);
- if (wasPresent) {
- // close it to cleanup
- try {
- /*
- * System.out.println("Closing connection : " + (
- * (HPT4Connection) ( (HPT4PooledConnection)
- * pc).getConnection()).getDialogueId());
- */
- pc.close();
- } catch (SQLException se) {
- // Ignore
- }
- }
- }
- }
- }
-
- /* End TimerTask definition */
- /*
- * Private class used to clean up the connections that have surpassed
- * connectionTimeout
- */
- /* Start TimerTask definition */
- private class ConnectionTimeoutCleanupTask extends TimerTask {
- Vector toRemove = null;
-
- ConnectionTimeoutCleanupTask() {
- toRemove = new Vector();
- }
-
- public void run() {
- cleanUp();
- }
-
- private void cleanUp() {
- toRemove.clear();
- synchronized (inUse_) {
- Iterator it_ = inUse_.iterator();
- while (it_.hasNext()) {
- try {
- PooledConnection tempPC = (PooledConnection) it_.next();
- InterfaceConnection ic = ((HPT4PooledConnection) tempPC).getTrafT4ConnectionReference().ic_;
- if (ic != null) {
- T4Connection tconn = ic.getT4Connection();
- if (tconn != null) {
- if (tconn.connectionIdleTimeoutOccured()) {
- // System.out.println("********* Found a
- // timed out connection **********");
- toRemove.add(tempPC);
- }
- }
- }
- } catch (Throwable t) {
- if (T4Properties.t4GlobalLogger.isLoggable(Level.WARNING) == true) {
- T4Properties.t4GlobalLogger.logp(Level.WARNING, "ConnectionTimeoutCleanupTask", "cleanUp",
- t.getMessage());
- }
- }
- }
- } // synchronized block
- for (int i = 0; i < toRemove.size(); i++) {
- PooledConnection pc = (PooledConnection) toRemove.get(i);
- removeInUseConnection(pc, false);
- // do not close the connections because:
- // 1.> Corresponding NCS server is already gone
- // 2.> We need to give a timeout error when user uses this
- // connection
- }
- }
- }
- /* End TimerTask definition */
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4ResultSetMetaData.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4ResultSetMetaData.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4ResultSetMetaData.java
deleted file mode 100644
index d1f1f7e..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/HPT4ResultSetMetaData.java
+++ /dev/null
@@ -1,309 +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.sql.SQLException;
-import java.util.logging.Level;
-
-public class HPT4ResultSetMetaData implements java.sql.ResultSetMetaData {
-
- // begin required methods
- public String getCatalogName(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].catalogName_;
- }
-
- public String getColumnClassName(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].getColumnClassName();
- }
-
- public int getColumnCount() throws SQLException {
- return outputDesc_.length;
- }
-
- public int getColumnDisplaySize(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].displaySize_;
- }
-
- public String getColumnLabel(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
-
- return (outputDesc_[column - 1].columnLabel_ == null) ? outputDesc_[column - 1].name_
- : outputDesc_[column - 1].columnLabel_;
- }
-
- public String getColumnName(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].name_;
- }
-
- public int getColumnType(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].dataType_;
- }
-
- public String getColumnTypeName(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].getColumnTypeName(connection_.getLocale());
- }
-
- public int getPrecision(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].precision_;
- }
-
- public int getScale(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].scale_;
- }
-
- public String getSchemaName(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].schemaName_;
- }
-
- public String getTableName(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].tableName_;
- }
-
- public boolean isAutoIncrement(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].isAutoIncrement_;
- }
-
- public boolean isCaseSensitive(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].isCaseSensitive_;
- }
-
- public boolean isCurrency(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].isCurrency_;
- }
-
- public boolean isDefinitelyWritable(int column) throws SQLException {
- return true;
- }
-
- public int isNullable(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].isNullable_;
- }
-
- public boolean isReadOnly(int column) throws SQLException {
- return false;
- }
-
- public boolean isSearchable(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].isSearchable_;
- }
-
- public boolean isSigned(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].isSigned_;
- }
-
- public boolean isWritable(int column) throws SQLException {
- return true;
- }
-
- // ////////////////////////
- // begin custom accessors//
- // ////////////////////////
-
- public int getFSDataType(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].fsDataType_;
- }
-
- public int getMaxLength(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].maxLen_;
- }
-
- public int getOdbcCharset(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].odbcCharset_;
- }
-
- public int getRowLength() throws SQLException {
- // this is the same for all params
- // only if we have no input params will we throw an error
- if (outputDesc_.length == 0) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.props_.getLocale(),
- "invalid_desc_index", null);
- }
-
- return outputDesc_[0].rowLength_;
- }
-
- public int getSqlCharset(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].sqlCharset_;
- }
-
- public int getSqlPrecision(int column) throws SQLException {
- if (column > outputDesc_.length) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].sqlPrecision_;
- }
-
- public int getSqlDatetimeCode(int param) throws SQLException {
- return stmt_.ist_.pr_.outputDesc[param - 1].datetimeCode_;
- }
-
- // /////////////////////////////////
- // these are legacy names...do not remove these yet even though they are
- // duplicate
- // ///////////////////////////////
-
- /**
- * @deprecated
- */
- public String cpqGetCharacterSet(int column) throws SQLException {
- if ((column > outputDesc_.length) || (column <= 0)) {
- throw HPT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_desc_index",
- null);
- }
- return outputDesc_[column - 1].getCharacterSetName();
- }
-
- /**
- * @deprecated
- */
- public int getSqlTypeCode(int param) throws SQLException {
- return stmt_.ist_.pr_.outputDesc[param - 1].dataType_;
- } // end getSqlTypeCode
-
- /**
- * @deprecated
- */
- public int getSqlLength(int param) throws SQLException {
- return stmt_.ist_.pr_.outputDesc[param - 1].maxLen_;
- } // end getSqlTypeCode
-
- HPT4ResultSetMetaData(TrafT4Statement stmt, HPT4Desc[] outputDesc) {
- if (stmt.connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
- Object p[] = T4LoggingUtilities.makeParams(stmt.connection_.props_, stmt, outputDesc);
- stmt.connection_.props_.t4Logger_.logp(Level.FINE, "HPT4ResultSetMetaData", "", "", p);
- }
-
- connection_ = stmt.connection_;
- outputDesc_ = outputDesc;
- stmt_ = stmt;
- }
-
- HPT4ResultSetMetaData(TrafT4ResultSet resultSet, HPT4Desc[] outputDesc) {
- if (resultSet.connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
- Object p[] = T4LoggingUtilities.makeParams(resultSet.connection_.props_, resultSet, outputDesc);
- resultSet.connection_.props_.t4Logger_.logp(Level.FINE, "HPT4ResultSetMetaData", "", "", p);
- }
-
- resultSet_ = resultSet;
- connection_ = resultSet_.connection_;
- outputDesc_ = outputDesc;
- stmt_ = resultSet.stmt_;
- }
-
- TrafT4ResultSet resultSet_;
- TrafT4Connection connection_;
- HPT4Desc[] outputDesc_;
- TrafT4Statement stmt_;
- 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/jdbc_type4/src/org/trafodion/jdbc/t4/Header.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/Header.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/Header.java
deleted file mode 100644
index 41a35a3..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/Header.java
+++ /dev/null
@@ -1,157 +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.sql.SQLException;
-import java.util.Locale;
-
-/**
- * This class corresponds to the ODBC HEADER structure as taken from
- * TransportBase.h
- * @version 1.0
- */
-
-class Header {
-
- //
- // Fixed values taken from TransportBase.h
- //
- static final short WRITE_REQUEST_FIRST = 1;
- static final short WRITE_REQUEST_NEXT = (short) (WRITE_REQUEST_FIRST + 1);
- static final short READ_RESPONSE_FIRST = (short) (WRITE_REQUEST_NEXT + 1);
- static final short READ_RESPONSE_NEXT = (short) (READ_RESPONSE_FIRST + 1);
- static final short CLEANUP = (short) (READ_RESPONSE_NEXT + 1);
- static final short SRVR_TRANSPORT_ERROR = (short) (CLEANUP + 1);
- static final short CLOSE_TCPIP_SESSION = (short) (SRVR_TRANSPORT_ERROR + 1);
-
- static final int SIGNATURE = 12345; // 0x3039
-
- //static final int OLD_VERSION = 100; //pre 2.5 server
- static final int CLIENT_HEADER_VERSION_BE = 101;
- //static final int CLIENT_HEADER_VERSION_LE = 102 //not used in JDBC
- static final int SERVER_HEADER_VERSION_BE = 201;
- static final int SERVER_HEADER_VERSION_LE = 202;
-
- static final char TCPIP = 'T';
-
- static final char NSK = 'N';
- static final char PC = 'P';
-
- static final char YES = 'Y';
- static final char NO = 'N';
-
- static final char COMP_0 = 0x0;
- static final char COMP_12 = 0x12;
- static final char COMP_14 = 0x14;
-
- //
- // The Java version of the HEADER structure taken from TransportBase.h
- //
- short operation_id_;
- // + 2 filler
- int dialogueId_;
- int total_length_;
- int cmp_length_;
- char compress_ind_;
- char compress_type_;
- // + 2 filler
- int hdr_type_;
- int signature_;
- int version_;
- char platform_;
- char transport_;
- char swap_;
- // + 1 filler
- short error_;
- short error_detail_;
-
- Header() {
- // Do nothing constructor
- }
-
- Header(short operation_id, int dialogueId, int total_length, int cmp_length, char compress_ind, char compress_type,
- int hdr_type, int signature, int version, char platform, char transport, char swap) {
- operation_id_ = operation_id;
- dialogueId_ = dialogueId;
- total_length_ = total_length;
- cmp_length_ = cmp_length;
- compress_ind_ = compress_ind;
- compress_type_ = compress_type;
- hdr_type_ = hdr_type;
- signature_ = signature;
- version_ = version;
- platform_ = platform;
- transport_ = transport;
- swap_ = swap;
- }
-
- void reuseHeader(short operation_id, int dialogueId) {
- operation_id_ = operation_id;
- dialogueId_ = dialogueId;
- }
-
- static int sizeOf() {
- return 40;
- }
-
- void insertIntoByteArray(LogicalByteArray buffer1, Locale locale) throws SQLException {
-
- buffer1.insertShort(operation_id_);
- buffer1.insertShort((short) 0); // + 2 filler
- buffer1.insertInt(dialogueId_);
- buffer1.insertInt(total_length_);
- buffer1.insertInt(cmp_length_);
- buffer1.insertChar(compress_ind_);
-
- buffer1.insertChar(compress_type_);
- buffer1.insertShort((short) 0); // + 2 filler
- buffer1.insertInt(hdr_type_);
- buffer1.insertInt(signature_);
- buffer1.insertInt(version_);
- buffer1.insertChar(platform_);
- buffer1.insertChar(transport_);
- buffer1.insertChar(swap_);
- buffer1.insertByte((byte) 0); // + 2 filler
- buffer1.insertShort(error_);
- buffer1.insertShort(error_detail_);
- }
-
- void extractFromByteArray(LogicalByteArray buffer1) {
- operation_id_ = buffer1.extractShort();
- buffer1.extractShort(); // + 2 filler
- dialogueId_ = buffer1.extractInt();
- total_length_ = buffer1.extractInt();
- cmp_length_ = buffer1.extractInt();
- compress_ind_ = buffer1.extractChar();
- compress_type_ = buffer1.extractChar();
- buffer1.extractShort(); // + 2 filler
- hdr_type_ = buffer1.extractInt();
- signature_ = buffer1.extractInt();
- version_ = buffer1.extractInt();
- platform_ = buffer1.extractChar();
- transport_ = buffer1.extractChar();
- swap_ = buffer1.extractChar();
- buffer1.extractByte(); // + 1 filler
- error_ = buffer1.extractShort();
- error_detail_ = buffer1.extractShort();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueMessage.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueMessage.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueMessage.java
deleted file mode 100644
index 39ba2b8..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueMessage.java
+++ /dev/null
@@ -1,66 +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.nio.charset.CharacterCodingException;
-import java.nio.charset.UnsupportedCharsetException;
-
-class InitializeDialogueMessage {
- static LogicalByteArray marshal(USER_DESC_def userDesc, CONNECTION_CONTEXT_def inContext, int dialogueId,
- int optionFlags1, int optionFlags2, String sessionID, InterfaceConnection ic)
- throws CharacterCodingException, UnsupportedCharsetException {
- int wlength = Header.sizeOf();
- LogicalByteArray buf;
-
- byte[] sessionBytes = ic.encodeString(sessionID, InterfaceUtilities.SQLCHARSETCODE_UTF8);
- byte[] clientUserBytes = ic.encodeString(System.getProperty("user.name"), InterfaceUtilities.SQLCHARSETCODE_UTF8);
-
- wlength += userDesc.sizeOf(ic);
- wlength += inContext.sizeOf(ic);
-
- wlength += TRANSPORT.size_int; // dialogueId
- wlength += TRANSPORT.size_int; // optionFlags1
- wlength += TRANSPORT.size_int; // optionFlags2
- wlength += sessionBytes.length;
- wlength += clientUserBytes.length;
-
- buf = new LogicalByteArray(wlength, Header.sizeOf(), ic.getByteSwap());
-
- userDesc.insertIntoByteArray(buf);
- inContext.insertIntoByteArray(buf);
-
- buf.insertInt(dialogueId);
- buf.insertInt(optionFlags1);
- buf.insertInt(optionFlags2);
-
- if((optionFlags1 & T4Connection.INCONTEXT_OPT1_SESSIONNAME) != 0)
- {
- buf.insertString(sessionBytes);
- }
- if((optionFlags1 & T4Connection.INCONTEXT_OPT1_CLIENT_USERNAME) != 0)
- {
- buf.insertString(clientUserBytes);
- }
-
- return buf;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueReply.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueReply.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueReply.java
deleted file mode 100644
index 5deb159..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InitializeDialogueReply.java
+++ /dev/null
@@ -1,90 +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.nio.charset.CharacterCodingException;
-import java.nio.charset.UnsupportedCharsetException;
-import java.sql.SQLException;
-
-class InitializeDialogueReply {
- static final int odbc_SQLSvc_InitializeDialogue_ParamError_exn_ = 1;
- static final int odbc_SQLSvc_InitializeDialogue_InvalidConnection_exn_ = 2;
- static final int odbc_SQLSvc_InitializeDialogue_SQLError_exn_ = 3;
- static final int odbc_SQLSvc_InitializeDialogue_SQLInvalidHandle_exn_ = 4;
- static final int odbc_SQLSvc_InitializeDialogue_SQLNeedData_exn_ = 5;
- static final int odbc_SQLSvc_InitializeDialogue_InvalidUser_exn_ = 6;
-
- static final int SQL_PASSWORD_EXPIRING = 8857;
- static final int SQL_PASSWORD_GRACEPERIOD = 8837;
-
- Header m_hdr;
-
- int exception_nr;
- int exception_detail;
- String ParamError;
- ERROR_DESC_LIST_def SQLError;
- ERROR_DESC_LIST_def InvalidUser;
- String clientErrorText;
-
- OUT_CONNECTION_CONTEXT_def outContext;
-
- // -------------------------------------------------------------
- InitializeDialogueReply(LogicalByteArray buf, String addr, InterfaceConnection ic, boolean downloadCert) throws CharacterCodingException,
- UnsupportedCharsetException, SQLException {
- buf.setLocation(Header.sizeOf());
-
- exception_nr = buf.extractInt();
- exception_detail = buf.extractInt();
-
- switch (exception_nr) {
- case TRANSPORT.CEE_SUCCESS:
- outContext = new OUT_CONNECTION_CONTEXT_def();
- outContext.extractFromByteArray(buf, ic);
- break;
- case odbc_SQLSvc_InitializeDialogue_SQLError_exn_:
- SQLError = new ERROR_DESC_LIST_def();
- SQLError.extractFromByteArray(buf, ic);
-
- if (exception_detail == SQL_PASSWORD_EXPIRING || exception_detail == SQL_PASSWORD_GRACEPERIOD) {
- outContext = new OUT_CONNECTION_CONTEXT_def();
- outContext.extractFromByteArray(buf, ic);
- }
- break;
- case odbc_SQLSvc_InitializeDialogue_InvalidUser_exn_:
- SQLError = new ERROR_DESC_LIST_def();
- SQLError.extractFromByteArray(buf, ic);
-
- ic.outContext = new OUT_CONNECTION_CONTEXT_def();
- ic.outContext.extractFromByteArray(buf, ic);
- break;
- //throw HPT4Messages.createSQLException(null, ic.getLocale(), "ids_28_000", null);
- case odbc_SQLSvc_InitializeDialogue_ParamError_exn_:
- ParamError = ic.decodeBytes(buf.extractString(), 1);
- throw HPT4Messages.createSQLException(null, ic.getLocale(), "ids_program_error", ParamError, addr);
- case odbc_SQLSvc_InitializeDialogue_InvalidConnection_exn_:
- throw HPT4Messages.createSQLException(null, ic.getLocale(), "ids_08_s01", null);
- default:
- clientErrorText = "unknown_initialize_dialogue_reply_error";
- break;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InputOutput.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InputOutput.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InputOutput.java
deleted file mode 100644
index 7062778..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InputOutput.java
+++ /dev/null
@@ -1,682 +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.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.net.SocketTimeoutException;
-import java.nio.ByteBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.WritableByteChannel;
-import java.sql.SQLException;
-import java.util.Locale;
-import java.util.Vector;
-import java.util.logging.Level;
-
-import javax.net.SocketFactory;
-
-class InputOutput {
- private Address m_addr;
- private Socket m_socket;
- private Locale m_locale;
- private int readHdrLength = Header.sizeOf();
- private int m_dialogueId;
- private int m_timeout;
- private int m_connectionIdleTimeout;
- private Header m_rheader;
- private OutputStream m_os;
- private InputStream m_is;
- private WritableByteChannel m_wbc;
- private T4Connection m_t4conn; // trace_connection
- //private int m_sendBufSize;
-
- private char compress = Header.NO; //Header.NO means no compression is used.
- private char compType = Header.COMP_0; //the used compression type. COMP_0 which means no compression
-
- private static SocketFactory m_factory = SocketFactory.getDefault(); // NRV
- // -
- // socket
- // factory
-
- static {
- try {
- String factStr = System.getProperty("t4jdbc.socketFactoryClass");
- if (factStr != null) {
- Class z = Class.forName(factStr);
- if (SocketFactory.class.isAssignableFrom(z)) {
- m_factory = (SocketFactory) z.newInstance();
- } else {
- m_factory = SocketFactory.getDefault();
- }
- }
- } catch (Throwable t) {
- m_factory = SocketFactory.getDefault();
- }
- }
-
- public static SocketFactory getSocketFactory() {
- return m_factory;
- }
-
- public static void setSocketFactory(SocketFactory factory) {
- m_factory = factory;
- }
-
- // ----------------------------------------------------------
- InputOutput(Locale locale, Address addr1) {
- m_locale = locale;
- m_addr = addr1;
- m_dialogueId = 0;
- m_timeout = 0;
- m_connectionIdleTimeout = 0;
-
- if(m_addr.m_t4props.getCompression()) {
- compress = Header.YES;
- }
-
- m_rheader = new Header((short) 0, m_dialogueId, 0, 0, compress, compType, Header.READ_RESPONSE_FIRST,
- Header.SIGNATURE, Header.CLIENT_HEADER_VERSION_BE, Header.PC, Header.TCPIP, Header.NO);
-
- } // end InputOutput
-
- // trace_connection - AM
- void setT4Connection(T4Connection t4conn) {
- m_t4conn = t4conn;
- }
-
- void setDialogueId(int dialogueId) {
- m_dialogueId = dialogueId;
- }
-
- void setTimeout(int timeout) {
- m_timeout = timeout;
- }
-
- void setConnectionIdleTimeout(int timeout) {
- m_connectionIdleTimeout = timeout;
- }
-
- String getRemoteHost() {
- return this.m_addr.getIPorName();
- }
-
- // ----------------------------------------------------------
- synchronized void openIO() throws SQLException {
- // trace_connection - AM
- if (m_t4conn != null && m_t4conn.m_ic.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(m_t4conn.m_ic.t4props_);
- String temp = "m_socket=" + m_socket;
- m_t4conn.m_ic.t4props_.t4Logger_.logp(Level.FINEST, "InputOutput", "openIO", temp, p);
- }
- if (m_socket == null) {
- int numTry = 0;
- boolean found = false;
- int i = 0;
- Vector eList = new Vector();
-
- //
- // Sometimes the server isn't ready to be contacted, so we will try
- // 3 times
- // before giving up.
- //
- while (found == false && numTry < 3) {
- //
- // Because each machine name can have multiple IP addresses
- // associated with it,
- // we need to go through the entire list of IP addresses until
- // we can find
- // one we can connect too, or all address fail.
- //
- i = 0;
- while (found == false && i < m_addr.m_inetAddrs.length) {
- try {
- //System.out.println(m_addr.m_inetAddrs[i] + ":" + m_addr.m_portNumber.intValue());
- m_socket = m_factory.createSocket(m_addr.m_inetAddrs[i], m_addr.m_portNumber.intValue());
-// m_socket = new Socket(InetAddress.getByName("a.b.c.d"),5358);
- m_socket.setKeepAlive(this.m_addr.m_t4props.getKeepAlive());
- m_socket.setSoLinger(false, 0); // Make sure the socket
- m_socket.setKeepAlive(true);
- // can immediately
- // reused if connection
- // is lost.
- m_socket.setSoTimeout(0);
- // disable/enable Nagle's algorithm
- m_socket.setTcpNoDelay(this.m_addr.m_t4props.getTcpNoDelay());
- //
- // Note, I have not set a timeout here for either the
- // conneciton or for
- // read operations on the socket. I need to figure out
- // what the
- // semantics should be, and add this logic.
- //
- // Although the user can set a
- // connection timeout, we
- // do not set the timeout on the open/connect of the
- // socket. Instead
- // we use the default system TCP/IP timeout. In theory,
- // this may be
- // longer than the user login timeout. Also, we keep
- // trying to create/connect
- // the socket a minimun of 3 times. In theory, this
- // could really mess up the
- // user's use of login timeout. For example, if the user
- // login timeout is
- // small (e.g. 5 sec.), and the TCP/IP default socket
- // create/connect timeout
- // is large (e.g. 10 sec.), and the number of inetAddrs
- // is large (e.g. 5),
- // and the correct inetAddr is the last one on the list,
- // and the AS server
- // isn't ready until the last try, we could end up
- // taking way more than
- // the user specified login time to connect (3 * 10 * 5
- // = 150 seconds vs.
- // 5 sec. the user specified!).
- //
- //
- m_os = m_socket.getOutputStream();
- m_wbc = Channels.newChannel(m_os);
- m_is = m_socket.getInputStream();
- //m_sendBufSize = m_socket.getSendBufferSize();
- found = true;
- // Swastik: added code to start connection idle timers
- startConnectionIdleTimeout();
- // trace_connection - AM
- if (m_t4conn != null && m_t4conn.m_ic.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(m_t4conn.m_ic.t4props_);
- String temp = "found=" + found + ",numTry=" + numTry + ",i=" + i
- + ",m_addr.m_inetAddrs.length=" + m_addr.m_inetAddrs.length;
- m_t4conn.m_ic.t4props_.t4Logger_.logp(Level.FINEST, "InputOutput", "openIO", temp, p);
- }
- } catch (Exception e) {
- //
- // Make note of the exception, and keep trying all the
- // possible addresses.
- //
- // If no address works, we will chain all the exceptions
- // together,
- // and let the user figure out what went wrong.
- //
- eList.addElement(e);
- found = false;
- }
- i = i + 1;
- } // end while
- if (found == false) {
- try {
- Thread.sleep(100); // wait for 0.1 second before trying
- // again
- } catch (Exception e) {
- // Do nothing.
- }
- }
- numTry = numTry + 1;
- } // end while
- if (found == false) {
- // trace_connection - AM
- if (m_t4conn != null && m_t4conn.m_ic.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(m_t4conn.m_ic.t4props_);
- String temp = "found=" + found + ",numTry=" + numTry + ",i=" + i + ",m_addr.m_inetAddrs.length="
- + m_addr.m_inetAddrs.length;
- m_t4conn.m_ic.t4props_.t4Logger_.logp(Level.FINEST, "InputOutput", "openIO", temp, p);
- }
- //
- // Couldn't open the socket
- //
- Exception eFirst = (Exception) eList.firstElement();
-
- //
- // Just add the first exception for now. I'd like to add the
- // entire list, but
- // it will take some thought to figure out the best way to put
- // each exception,
- // and it's associated exception cause (i.e. chained list)
- // together.
- // If there is more than one address, then we must be dealing
- // with a machine name.
- // Hopefully, the problem with the first address is
- // representitive of the problem
- // with all addresses.
- //
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_open_error", eFirst
- .getMessage());
-
- se.initCause(eFirst);
- throw se;
- }
- } // end if (p1.m_hSocket == null)
-
- //
- // If m_socket is not null, then we will assume it is already open.
- //
-
- } // end openIO
-
- // ----------------------------------------------------------
- synchronized LogicalByteArray doIO(short odbcAPI, LogicalByteArray buffer) throws SQLException {
- int cmpLength = 0;
- int totalLength = buffer.getLength();
- ByteBuffer dataBuffer = buffer.getDataBuffer();
- byte[] trailer = buffer.getTrailer();
- if (dataBuffer != null)
- totalLength += dataBuffer.limit();
- if (trailer != null)
- totalLength += trailer.length;
-
- if(totalLength > 10000 && compress == Header.YES) //maybe totalLength - readHdrLength > 10000
- {
- compType = Header.COMP_14;
-
- //dont set the databuffer
- dataBuffer = null;
- trailer = null;
- }
- else
- {
- cmpLength = 0;//totalLength - readHdrLength;
- compType = Header.COMP_0;
- }
-
- // trace_connection - AM
- if (m_t4conn != null && m_t4conn.m_ic.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(m_t4conn.m_ic.t4props_);
- String temp = "MessageBuffer";
- m_t4conn.m_ic.t4props_.t4Logger_.logp(Level.FINEST, "InputOutput", "doIO", temp, p);
- }
- Header wheader = new Header(odbcAPI, m_dialogueId, totalLength - readHdrLength// minus
- // the
- // size
- // of
- // the
- // Header
- , cmpLength, compress, compType, Header.WRITE_REQUEST_FIRST, Header.SIGNATURE, Header.CLIENT_HEADER_VERSION_BE, Header.PC, Header.TCPIP,
- Header.NO);
-
- m_rheader.reuseHeader(odbcAPI, m_dialogueId);
-
- // Send to the server
- int buffer_index = 0;
-
- int wCount = buffer.getLength();
- /*int tcount;
- while (wCount > 0) {
- if (wCount > m_sendBufSize) {
- tcount = m_sendBufSize;
- } else {
- tcount = wCount;
- }*/
- TCPIPDoWrite(wheader, buffer, buffer_index, wCount);
-/*
- wheader.hdr_type_ = Header.WRITE_REQUEST_NEXT;
- wCount = wCount - tcount;
- buffer_index = buffer_index + tcount;
- }*/
-
- if (dataBuffer != null && trailer != null) {
- TCPIPWriteByteBuffer(dataBuffer);
- TCPIPWriteByteBuffer(ByteBuffer.wrap(trailer));
- }
-
- // Receive from the server
- buffer.reset();
-
- // Read for READ_RESPONSE_FIRST
- int numRead = 0;
- int totalNumRead = 0;
- int whileCount1 = 0;
- long totalAvailable = 0;
-
- // Read the first part
- m_rheader.hdr_type_ = Header.READ_RESPONSE_FIRST;
- m_rheader.total_length_ = readHdrLength;
-
- // Keep reading until we have a header, but give up after 3 attempts.
- while (totalNumRead < readHdrLength && whileCount1 < 3) {
- numRead = TCPIPDoRead(m_rheader, buffer, totalNumRead);
- totalNumRead = totalNumRead + numRead;
- whileCount1 = whileCount1 + 1;
- // trace_connection - AM
- if (m_t4conn != null && m_t4conn.m_ic.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
- Object p[] = T4LoggingUtilities.makeParams(m_t4conn.m_ic.t4props_);
- String temp = "MessageBuffer whileCount1=" + whileCount1 + ",numRead=" + numRead + ",totalNumRead="
- + totalNumRead;
- m_t4conn.m_ic.t4props_.t4Logger_.logp(Level.FINEST, "InputOutput", "doIO", temp, p);
- }
- } // end while
-
- // trace_connection - AM
- // if (totalNumRead < readHdrLength)
- if (numRead < readHdrLength) {
- //
- // We didn't even get the header back, so something is seriously
- // wrong.
- //
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "problem_with_server_read", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "header_not_long_enough", null);
-
- se.setNextException(se2);
- throw se;
- }
-
- buffer.setLocation(0);
- m_rheader.extractFromByteArray(buffer);
-
- if(odbcAPI == TRANSPORT.AS_API_GETOBJREF) {
- switch(m_rheader.version_) {
- case Header.CLIENT_HEADER_VERSION_BE:
- case Header.SERVER_HEADER_VERSION_BE:
- buffer.setByteSwap(false);
- break;
- case Header.SERVER_HEADER_VERSION_LE:
- buffer.setByteSwap(true);
- break;
- default:
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "problem_with_server_read", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "wrong_header_version", String.valueOf(m_rheader.version_));
-
- se.setNextException(se2);
- throw se;
- }
- }
-
- if (m_rheader.signature_ != Header.SIGNATURE) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "problem_with_server_read", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "wrong_header_signature", String
- .valueOf(Header.SIGNATURE), String.valueOf(m_rheader.signature_));
-
- se.setNextException(se2);
- throw se;
- }
-
- if (m_rheader.error_ != 0) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "driver_err_error_from_server", String
- .valueOf(m_rheader.error_), String.valueOf(m_rheader.error_detail_));
-
- throw se;
- }
-
- if(m_rheader.compress_ind_ == Header.YES && m_rheader.compress_type_ == Header.COMP_14) {
- totalAvailable = m_rheader.cmp_length_;
- }
- else {
- totalAvailable = m_rheader.total_length_;
- }
-
- numRead = 0;
- buffer.resize(m_rheader.total_length_ + readHdrLength); // make sure the
- // buffer is big
- // enough
-
- while (totalNumRead < (totalAvailable + readHdrLength)) {
- m_rheader.hdr_type_ = Header.READ_RESPONSE_NEXT;
-
- numRead = TCPIPDoRead(m_rheader, buffer, totalNumRead);
- totalNumRead = totalNumRead + numRead;
- }
- buffer.setLocation(totalNumRead);
-
- return buffer;
- } // end doIO
-
- // ----------------------------------------------------------
- synchronized void CloseIO(LogicalByteArray buffer) throws SQLException {
- /*Header hdr = new Header(Header.CLOSE_TCPIP_SESSION, m_dialogueId, 0, 0, Header.NO, Header.COMP_0,
- Header.CLOSE_TCPIP_SESSION, Header.SIGNATURE, Header.VERSION, Header.PC, Header.TCPIP, Header.NO);
-
- TCPIPDoWrite(hdr, buffer, 0, hdr.sizeOf());*/
- try {
- m_socket.close();
- m_socket = null;
- } catch (Exception e) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "session_close_error", e.getMessage());
- se.initCause(e);
- throw se;
- } finally {
- closeTimers();
- }
- } // end CloseIO
-
- void TCPIPWriteByteBuffer(ByteBuffer buffer) throws SQLException {
-
- if (m_socket == null) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_write_error", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "socket_is_closed_error", null);
-
- se.setNextException(se2);
- throw se;
- }
-
- try {
- m_wbc.write(buffer);
- m_os.flush();
- } catch (Exception e) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_write_error", e.getMessage());
-
- se.initCause(e);
- throw se;
- } finally {
- resetTimedOutConnection();
- }
-
- } // end TCPIPWriteByteBuffer
-
- // ----------------------------------------------------------
- void TCPIPDoWrite(Header hdr, LogicalByteArray buffer, int buffer_index, int bufcount) throws SQLException {
-// int error = 0;
-// short error_detail = 0;
-// int wcount = 0;
- int data_length = 0;
-
- if (m_socket == null) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_write_error", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "socket_is_closed_error", null);
-
- se.setNextException(se2);
- throw se;
- }
-
- switch (hdr.hdr_type_) {
- case Header.WRITE_REQUEST_FIRST:
- case Header.CLOSE_TCPIP_SESSION:
- buffer.setLocation(0);
- hdr.insertIntoByteArray(buffer, m_locale);
- case Header.WRITE_REQUEST_NEXT:
- data_length = data_length + bufcount;
-
- send_nblk(buffer.getBuffer(), buffer_index, data_length);
- break;
- default:
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "unknown_message_type_error", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "internal_error", null);
- SQLException se3 = HPT4Messages.createSQLException(null, m_locale, "cntact_hp_error", null);
-
- se.setNextException(se2);
- se2.setNextException(se3);
- throw se;
- // break;
- } // end switch (hdr.hdr_type)
-
- } // end TCPIPDoWrite
-
- // ----------------------------------------------------------
- int TCPIPDoRead(Header hdr, LogicalByteArray buffer, int buffer_index) throws SQLException {
- int numRead = 0;
-
- if (m_socket == null) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_read_error", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "socket_is_closed_error", null);
-
- se.setNextException(se2);
- throw se;
- }
-
- switch (hdr.hdr_type_) {
- case Header.READ_RESPONSE_FIRST:
- case Header.READ_RESPONSE_NEXT:
- numRead = recv_nblk(buffer.getBuffer(), buffer_index);
-// buffer.setLocation(numRead);
- break;
- default:
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "unknown_message_type_error", null);
- SQLException se2 = HPT4Messages.createSQLException(null, m_locale, "internal_error", null);
- SQLException se3 = HPT4Messages.createSQLException(null, m_locale, "cntact_hp_error", null);
-
- se.setNextException(se2);
- se2.setNextException(se3);
- throw se;
- } // end switch (hdr.hdr_type)
-
- return numRead;
-
- } // end TCPIPDoRead
-
- // ----------------------------------------------------------
- void send_nblk(byte[] buf, int offset, int len) throws SQLException {
- try {
- m_os.write(buf, offset, len);
- m_os.flush();
- } catch (Exception e) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_write_error", e.getMessage());
-
- se.initCause(e);
- throw se;
- } finally {
- resetTimedOutConnection();
- }
- } // end send_nblk
-
- // ----------------------------------------------------------
- int recv_nblk(byte[] buf, int offset) throws SQLException {
- int num_read = 0;
-
- boolean retry = false;
-
- do {
- try {
- m_socket.setSoTimeout(m_timeout * 1000);
-
- num_read = m_is.read(buf, offset, buf.length - offset);
-
- // if the socket.read returns -1 then return 0 instead of -1
- if (num_read < 0) {
- num_read = 0;
- }
- m_socket.setSoTimeout(0); // set timeout back to infinite
- retry = false;
-
- } catch (SocketTimeoutException ste) {
- // the first exception should try to cancel and wait for the cancel message from the server
- if(retry == false) {
- this.m_t4conn.m_ic.cancel();
- retry = true;
- continue;
- }
-
- // if cancel didnt work the first time, clean everything up
- try {
- m_socket.close();
- this.m_t4conn.m_ic.setIsClosed(true);
- this.m_t4conn.m_ic.cancel();
-
- throw ste;
- } catch (Exception e) {
- SQLException se = HPT4Messages
- .createSQLException(null, m_locale, "session_close_error", e.getMessage());
- se.initCause(e);
- throw se;
- }
- } catch (Exception e) {
- SQLException se = HPT4Messages.createSQLException(null, m_locale, "socket_read_error", e.getMessage());
-
- se.initCause(e);
- throw se;
- } finally {
- resetTimedOutConnection();
- }
- }while(retry);
-
- return num_read;
- } // recv_nblk
-
- /** ***************************************** */
- // Start of connectino timeout related code //
- /** ***************************************** */
- void closeTimers() {
- if (m_connectionIdleTimeout > 0) {
- T4TimerThread t = T4TimerThread.getThread(m_dialogueId);
- if (t != null) {
- // t.interrupt(); //SB:2/24/05
- T4TimerThread.removeThread(this.m_dialogueId);
- }
- }
- }
-
- void resetConnectionIdleTimeout() {
- if (m_connectionIdleTimeout > 0) {
- T4TimerThread t = T4TimerThread.getThread(m_dialogueId);
- if (t != null) {
- t.reset(m_connectionIdleTimeout * 1000);
- } else { // first time
- startConnectionIdleTimeout();
- }
- }
- }
-
- private void resetTimedOutConnection() {
- if (m_connectionIdleTimeout > 0) {
- // check connection idle timeout
- boolean timedOut = checkConnectionIdleTimeout();
- if (timedOut) {
- startConnectionIdleTimeout(); // this closes existing timers
- // and starts a new one
- // required for long runnign queries
- } else {
- resetConnectionIdleTimeout();
- }
- }
- }
-
- boolean checkConnectionIdleTimeout() {
- if (m_connectionIdleTimeout > 0) {
- T4TimerThread t = T4TimerThread.getThread(m_dialogueId);
- if (t != null && t.getTimedOut()) {
- return true;
- }
- }
- return false;
- }
-
- void startConnectionIdleTimeout() {
- if (m_connectionIdleTimeout > 0 && m_dialogueId > 0) {
- closeTimers();
- T4TimerThread m_t4TimerThread = new T4TimerThread(m_dialogueId, m_connectionIdleTimeout * 1000);
- // m_t4TimerThread.start(); ==> // SB:2/24/05 this class is no
- // longer
- // inheriting the thread package
- // However it can be modified if
- // need be - see class comments.
- }
- }
-} // end class InputOutput
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InsertRow.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InsertRow.java b/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InsertRow.java
deleted file mode 100644
index e569d20..0000000
--- a/core/conn/jdbc_type4/src/org/trafodion/jdbc/t4/InsertRow.java
+++ /dev/null
@@ -1,82 +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.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.BitSet;
-
-class InsertRow extends BaseRow implements Serializable, Cloneable {
-
- private BitSet colsInserted;
- private int cols;
-
- InsertRow(int i) {
- origVals = new Object[i];
- colsInserted = new BitSet(i);
- cols = i;
- }
-
- protected Object getColumnObject(int i) throws SQLException {
- if (!colsInserted.get(i - 1)) {
- throw HPT4Messages.createSQLException(null, null, "no_column_value_specified", null);
- } else {
- return origVals[i - 1];
- }
- }
-
- protected void initInsertRow() {
- for (int i = 0; i < cols; i++) {
- colsInserted.clear(i);
-
- }
- }
-
- /*
- * protected boolean isCompleteRow(RowSetMetaData rowsetmetadata) throws
- * SQLException { for(int i = 0; i < cols; i++) if(!colsInserted.get(i) &&
- * rowsetmetadata.isNullable(i + 1) == 0) return false; return true; }
- */
-
- protected void markColInserted(int i) {
- colsInserted.set(i);
- }
-
- protected void setColumnObject(int i, Object obj) {
- origVals[i - 1] = obj;
- markColInserted(i - 1);
- }
-
- protected void insertRow(PreparedStatement insertStmt, BitSet paramCols) throws SQLException {
- int i;
- int j;
-
- for (i = 0, j = 1; i < cols; i++) {
- if (paramCols.get(i)) {
- insertStmt.setObject(j++, origVals[i]);
- }
- }
- insertStmt.execute();
- initInsertRow();
- }
-}