diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java index 6c609d9c7e..4f484a0b49 100644 --- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java @@ -173,6 +173,8 @@ public class T4Properties { //TCP Nagle's algorithm private boolean _tcpNoDelay = true; + private boolean allowMultiQueries = false; + // ----------------------------------------------------------- // // The following static members and static block are ment to @@ -436,9 +438,10 @@ private void setProperties() { setLobChunkSize(getProperty("lobChunkSize")); setUseLobHandle(getProperty("useLobHandle")); + setAllowMultiQueries(getProperty("allowMultiQueries")); } - T4Properties getT4Properties() { + T4Properties getT4Properties() { return this; } @@ -532,6 +535,7 @@ public Properties getProperties() { props.setProperty("lobChunkSize", String.valueOf(lobChunkSize_)); props.setProperty("useLobHandle", String.valueOf(useLobHandle_)); + props.setProperty("allowMultiQueries", String.valueOf(allowMultiQueries)); return props; } @@ -1942,19 +1946,19 @@ public void setUseLobHandle(String val) { /** * Returns the rounding mode set for the driver as an Integer value with one - * of the following values. static int ROUND_CEILING Rounding mode to round - * towards positive infinity. static int ROUND_DOWN Rounding mode to round - * towards zero. static int ROUND_FLOOR Rounding mode to round towards - * negative infinity. static int ROUND_HALF_DOWN Rounding mode to round - * towards "nearest neighbor" unless both neighbors are equidistant, in - * which case round down. static int ROUND_HALF_EVEN Rounding mode to round - * towards the "nearest neighbor" unless both neighbors are equidistant, in - * which case, round towards the even neighbor. static int ROUND_HALF_UP - * Rounding mode to round towards "nearest neighbor" unless both neighbors - * are equidistant, in which case round up. static int ROUND_UNNECESSARY - * Rounding mode to assert that the requested operation has an exact result, - * hence no rounding is necessary. static int ROUND_UP Rounding mode to - * round away from zero. + * of the following values. + * static int ROUND_CEILING Rounding mode to round towards positive infinity. + * static int ROUND_DOWN Rounding mode to round towards zero. + * static int ROUND_FLOOR Rounding mode to round towards negative infinity. + * static int ROUND_HALF_DOWN Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round down. + * static int ROUND_HALF_EVEN Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, + * in which case, round towards the even neighbor. + * static int ROUND_HALF_UP Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round up. + * static int ROUND_UNNECESSARY Rounding mode to assert that the requested operation has an exact result, + * hence no rounding is necessary. + * static int ROUND_UP Rounding mode to round away from zero. */ int getRoundingMode() { return roundMode_; @@ -2571,6 +2575,20 @@ void setClientInfoProperties(Properties prop) { Properties getClientInfoProperties() { return this.clientInfoProp; } - - + + public boolean isAllowMultiQueries() { + return allowMultiQueries; + } + + public void setAllowMultiQueries(boolean allowMultiQueries) { + this.allowMultiQueries = allowMultiQueries; + } + + private void setAllowMultiQueries(String property) { + if (property != null && property.length()>0){ + setAllowMultiQueries(Boolean.valueOf(property)); + }else{ + setAllowMultiQueries(false); + } + } } diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Connection.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Connection.java index ce7c980c67..1320fdf15c 100644 --- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Connection.java +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Connection.java @@ -183,7 +183,11 @@ public Statement createStatement() throws SQLException { validateConnection(); try { - return new TrafT4Statement(this); + if (props_.isAllowMultiQueries()) { + return new TrafT4MultiQueriesStatement(this); + } else { + return new TrafT4Statement(this); + } } catch (SQLException se) { performConnectionErrorChecks(se); throw se; @@ -774,9 +778,12 @@ public PreparedStatement prepareStatement(String sql) throws SQLException { } } - stmt = new TrafT4PreparedStatement(this, sql); - - stmt.prepare(stmt.sql_, stmt.queryTimeout_, stmt.resultSetHoldability_); + if (props_.isAllowMultiQueries()) { + stmt = new TrafT4MultiQueriesPreparedStatement(this, sql); + } else { + stmt = new TrafT4PreparedStatement(this, sql); + stmt.prepare(stmt.sql_, stmt.queryTimeout_, stmt.resultSetHoldability_); + } if (isStatementCachingEnabled()) { addPreparedStatement(this, sql, stmt, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4MultiQueriesPreparedStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4MultiQueriesPreparedStatement.java new file mode 100644 index 0000000000..13027759b5 --- /dev/null +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4MultiQueriesPreparedStatement.java @@ -0,0 +1,393 @@ +// @@@ 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.sql.BatchUpdateException; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.logging.Level; + +public class TrafT4MultiQueriesPreparedStatement extends TrafT4PreparedStatement { + + private String[] sqlArr = null; + private TrafT4PreparedStatement[] pstmtArr = null; + private int[][] paramDescs = null; + + private int currentSqlIndex; + + TrafT4MultiQueriesPreparedStatement(TrafT4Connection connection, String sql) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, sql); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "", "", p); + } + } + + TrafT4MultiQueriesPreparedStatement(TrafT4Connection connection, String sql, String stmtLabel) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, stmtLabel); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, sql, stmtLabel); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "", "", p); + } + } + + TrafT4MultiQueriesPreparedStatement(TrafT4Connection connection, String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + this(connection, sql, resultSetType, resultSetConcurrency, connection.holdability_, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, sql, resultSetType, + resultSetConcurrency); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "", "", p); + } + } + + TrafT4MultiQueriesPreparedStatement(TrafT4Connection connection, String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) throws SQLException { + this(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "", "", p); + } + + } + + TrafT4MultiQueriesPreparedStatement(TrafT4Connection connection, String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability, String stmtLabel) throws SQLException { + super(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability, stmtLabel); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability, stmtLabel); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "", "", p); + } + + if (resultSetType != ResultSet.TYPE_FORWARD_ONLY && resultSetType != ResultSet.TYPE_SCROLL_INSENSITIVE + && resultSetType != ResultSet.TYPE_SCROLL_SENSITIVE) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_resultset_type", null); + } + if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY && resultSetConcurrency != ResultSet.CONCUR_UPDATABLE) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_resultset_concurrency", null); + } + if ((resultSetHoldability != 0) && (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) + && (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_holdability", + null); + } + + sqlArr = sql.split(";"); + pstmtArr = new TrafT4PreparedStatement[sqlArr.length]; + paramDescs = new int[sqlArr.length][3]; + int total = 0; + int currentParamsLen = 0; + for (int i = 0; i < sqlArr.length; i++) { + pstmtArr[i] = new TrafT4PreparedStatement(connection, sqlArr[i], resultSetType, resultSetConcurrency, + resultSetHoldability, stmtLabel); + pstmtArr[i].prepare(sqlArr[i], queryTimeout_, resultSetHoldability_); + + // this is to setup the paramDescs, each paramDesc has 3 column, + // 1: index of preparedStatement + // 2: num of params for current pstmt + // 3: accumulated params for current index + // this varible is used when there invoking setXXX api + if (pstmtArr[i].inputDesc_ != null) { + currentParamsLen = pstmtArr[i].inputDesc_.length; + total += currentParamsLen; + } + int[] paramDesc = { i, currentParamsLen, total }; + paramDescs[i] = paramDesc; + + } + } + + public boolean execute(String sql) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, sql); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "execute", "", p); + } + sqlArr = sql.split(";"); + pstmtArr = new TrafT4PreparedStatement[sqlArr.length]; + + boolean result = false; + + return result; + } + + // this method will return a 2 column array. + // first column means the index of preparedStatement + // second column means the real parameter index of the column one preparedStatement + // eg: + // insert into tbl values (?,?);insert into tbl values (?,?,?);insert into tbl values (?,?) + // the paramDescs is {0,2,2},{1,3,5},{2,2,7} , when use setXXX(6, x); + // there will return {2,1} , means set param for the 1st param of the 3rd sql. + private int[] getCurrentParamIndex(int paramIndex) { + if (paramIndex < 1 || paramIndex > paramDescs[paramDescs.length - 1][2]) { + return new int[] { 0, paramIndex }; + } + for (int i = 0; i < paramDescs.length; i++) { + if (paramIndex > paramDescs[i][2]) { + continue; + } else { + int index = paramIndex - (paramDescs[i][2] - paramDescs[i][1]); + return new int[] { i, index }; + } + } + + return new int[] { 0, paramIndex }; + + } + + public void setObject(int parameterIndex, Object x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setObject", "", p); + } + int[] paramIndex = getCurrentParamIndex(parameterIndex); + pstmtArr[paramIndex[0]].setObject(paramIndex[1], x); + } + + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setDate(int parameterIndex, Date x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setTime(int parameterIndex, Time x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + @Override + public void setFloat(int parameterIndex, float x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + @Override + public void setLong(int parameterIndex, long x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setInt(int parameterIndex, int x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setShort(int parameterIndex, short x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setByte(int parameterIndex, byte x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void setString(int parameterIndex, String x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setString", "", p); + } + setObject(parameterIndex, x); + } + + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "setInt", "", p); + } + setObject(parameterIndex, x); + } + + public void addBatch() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "addBatch", "", p); + } + for (int i = 0; i < pstmtArr.length; i++) { + pstmtArr[i].addBatch(); + } + } + + public int[] executeBatch() throws SQLException, BatchUpdateException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "executeBatch", "", p); + } + currentSqlIndex = 0; + + int[] results = null; + for (int i = 0; i < pstmtArr.length; i++) { + int[] result = pstmtArr[i].executeBatch(); + if (results == null) { + results = result; + } else { + int[] tmp = new int[results.length + result.length]; + System.arraycopy(results, 0, tmp, 0, results.length); + System.arraycopy(result, 0, tmp, results.length, result.length); + results = tmp; + } + } + + return results; + } + + // TODO here may add some logic in TrafT4ResultSet + public ResultSet executeQuery() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "executeQuery", "", p); + } + ResultSet[] results = new ResultSet[pstmtArr.length]; + currentSqlIndex = 0; + + for (int i = 0; i < pstmtArr.length; i++) { + results[i] = pstmtArr[i].executeQuery(); + } + return results[currentSqlIndex++]; + } + + public boolean execute() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "execute", "", p); + } + boolean result = false; + currentSqlIndex = 0; + + for (int i = 0; i < pstmtArr.length; i++) { + result |= pstmtArr[i].execute(); + } + return result; + } + + public int getUpdateCount() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "getUpdateCount", "", + p); + } + long result = 0; + currentSqlIndex = 0; + + for (int i = 0; i < pstmtArr.length; i++) { + result += pstmtArr[i].getUpdateCount(); + } + return (int) result; + } + + public int executeUpdate() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_ + .logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "executeUpdate", "", p); + } + long result = 0; + currentSqlIndex = 0; + + for (int i = 0; i < pstmtArr.length; i++) { + result += pstmtArr[i].executeUpdate(); + } + return (int) result; + } + + public void close() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "close", "", p); + } + for (int i = 0; i < pstmtArr.length; i++) { + pstmtArr[i].close(); + } + } + + public void cancel() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesPreparedStatement", "cancel", "", p); + } + for (int i = 0; i < pstmtArr.length; i++) { + pstmtArr[i].cancel(); + } + } +} diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4MultiQueriesStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4MultiQueriesStatement.java new file mode 100644 index 0000000000..ce2160b068 --- /dev/null +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4MultiQueriesStatement.java @@ -0,0 +1,176 @@ +// @@@ 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.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; + +public class TrafT4MultiQueriesStatement extends TrafT4Statement { + + private String[] sqlArr = null; + private Statement[] stmtArr = null; + private TrafT4Connection conn = null; + private int resultSetType; + private int resultSetConcurrency; + private int resultSetHoldability; + private String stmtLabel = null; + private int currentSqlIndex; + + TrafT4MultiQueriesStatement(TrafT4Connection connection) throws SQLException { + this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "", "", p); + } + } + + TrafT4MultiQueriesStatement(TrafT4Connection connection, String stmtLabel) throws SQLException { + this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, stmtLabel); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, stmtLabel); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "", "", p); + } + } + + TrafT4MultiQueriesStatement(TrafT4Connection connection, int resultSetType, int resultSetConcurrency) + throws SQLException { + this(connection, resultSetType, resultSetConcurrency, TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, resultSetType, + resultSetConcurrency); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "", "", p); + } + } + + TrafT4MultiQueriesStatement(TrafT4Connection connection, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + this(connection, resultSetType, resultSetConcurrency, resultSetHoldability, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, resultSetType, + resultSetConcurrency, resultSetHoldability); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "", "", p); + } + + } + + TrafT4MultiQueriesStatement(TrafT4Connection connection, int resultSetType, int resultSetConcurrency, + int resultSetHoldability, String stmtLabel) throws SQLException { + super(connection, resultSetType, resultSetConcurrency, resultSetHoldability, stmtLabel); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, resultSetType, + resultSetConcurrency, resultSetHoldability, stmtLabel); + connection.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "", "", p); + } + + if (resultSetType != ResultSet.TYPE_FORWARD_ONLY && resultSetType != ResultSet.TYPE_SCROLL_INSENSITIVE + && resultSetType != ResultSet.TYPE_SCROLL_SENSITIVE) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_resultset_type", null); + } + if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY && resultSetConcurrency != ResultSet.CONCUR_UPDATABLE) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_resultset_concurrency", null); + } + if ((resultSetHoldability != 0) && (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) + && (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_holdability", + null); + } + + this.conn = connection; + this.resultSetType = resultSetType; + this.resultSetConcurrency = resultSetConcurrency; + this.resultSetHoldability = resultSetHoldability; + this.stmtLabel = stmtLabel; + } + + public ResultSet executeQuery(String sql) throws SQLException { + return super.executeQuery(sql); + } + + public int executeUpdate(String sql) throws SQLException { + return super.executeUpdate(sql); + } + + public boolean execute(String sql) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, sql); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "execute", "", p); + } + sqlArr = sql.split(";"); + stmtArr = new Statement[sqlArr.length]; + + boolean result = false; + for (int i = 0; i < sqlArr.length; i++) { + stmtArr[i] = new TrafT4Statement(conn, resultSetType, resultSetConcurrency, resultSetHoldability, stmtLabel); + result |= stmtArr[i].execute(sqlArr[i]); + } + return result; + } + + public ResultSet getResultSet() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "getResultSet", "", p); + } + return stmtArr[currentSqlIndex].getResultSet(); + } + + public boolean getMoreResults() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "getMoreResults", "", p); + } + if (currentSqlIndex++ >= (sqlArr.length - 1)) { + return false; + } + return true; + } + + public void close() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "close", "", p); + } + if (stmtArr != null) { + for (int i = 0; i < stmtArr.length; i++) { + stmtArr[i].close(); + } + } + } + + public void cancel() throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4MultiQueriesStatement", "cancel", "", p); + } + if (stmtArr != null) { + for (int i = 0; i < stmtArr.length; i++) { + stmtArr[i].cancel(); + } + } + } +} diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java index 0016510c43..5e3530f8a1 100644 --- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java @@ -2067,150 +2067,134 @@ public void close(boolean hardClose) throws SQLException { } + public TrafT4PreparedStatement() { + if (T4Properties.t4GlobalLogger.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(null); + T4Properties.t4GlobalLogger.logp(Level.FINE, "TrafT4PreparedStatement", "", "", p); + } + } + + TrafT4PreparedStatement(TrafT4Connection connection, String sql, String stmtLabel) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.holdability_, + stmtLabel); + connection.ic_.t4props_.setUseArrayBinding(false); + connection.ic_.t4props_.setBatchRecovery(false); + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, stmtLabel); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", + "Note, this call is before previous constructor call.", p); + } + if (connection_.props_.getLogWriter() != null) { + LogRecord lr = new LogRecord(Level.FINE, ""); + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); + lr.setParameters(p); + lr.setSourceClassName("TrafT4PreparedStatement"); + lr.setSourceMethodName(""); + T4LogFormatter lf = new T4LogFormatter(); + String temp = lf.format(lr); + connection_.props_.getLogWriter().println(temp); + } + } + + // Constructors with access specifier as "default" + TrafT4PreparedStatement(TrafT4Connection connection, String sql) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.holdability_, null); + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", + "Note, this call is before previous constructor call.", p); + } + if (connection_.props_.getLogWriter() != null) { + LogRecord lr = new LogRecord(Level.FINE, ""); + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); + lr.setParameters(p); + lr.setSourceClassName("TrafT4PreparedStatement"); + lr.setSourceMethodName(""); + T4LogFormatter lf = new T4LogFormatter(); + String temp = lf.format(lr); + connection_.props_.getLogWriter().println(temp); + } + } + + TrafT4PreparedStatement(TrafT4Connection connection, String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + this(connection, sql, resultSetType, resultSetConcurrency, connection.holdability_, null); + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, + resultSetConcurrency); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", + "Note, this call is before previous constructor call.", p); + } + if (connection_.props_.getLogWriter() != null) { + LogRecord lr = new LogRecord(Level.FINE, ""); + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, + resultSetConcurrency); + lr.setParameters(p); + lr.setSourceClassName("TrafT4PreparedStatement"); + lr.setSourceMethodName(""); + T4LogFormatter lf = new T4LogFormatter(); + String temp = lf.format(lr); + connection_.props_.getLogWriter().println(temp); + } + } + + TrafT4PreparedStatement(TrafT4Connection connection, String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + this(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability, null); + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", + "Note, this call is before previous constructor call.", p); + } + if (connection_.props_.getLogWriter() != null) { + LogRecord lr = new LogRecord(Level.FINE, ""); + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability); + lr.setParameters(p); + lr.setSourceClassName("TrafT4PreparedStatement"); + lr.setSourceMethodName(""); + T4LogFormatter lf = new T4LogFormatter(); + String temp = lf.format(lr); + connection_.props_.getLogWriter().println(temp); + } + } + + TrafT4PreparedStatement(TrafT4Connection connection, String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability, String stmtLabel) throws SQLException { + super(connection, resultSetType, resultSetConcurrency, resultSetHoldability, stmtLabel); + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability, stmtLabel); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", + "Note, this call is before previous constructor call.", p); + } + if (connection_.props_.getLogWriter() != null) { + LogRecord lr = new LogRecord(Level.FINE, ""); + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability); + lr.setParameters(p); + lr.setSourceClassName("TrafT4PreparedStatement"); + lr.setSourceMethodName(""); + T4LogFormatter lf = new T4LogFormatter(); + String temp = lf.format(lr); + connection_.props_.getLogWriter().println(temp); + } + // connection_.getServerHandle().isConnectionOpen(); + connection_.isConnectionOpen(); + sqlStmtType_ = ist_.getSqlStmtType(sql); + if (sqlStmtType_ == TRANSPORT.TYPE_STATS) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "infostats_invalid_error", null); + } else if (sqlStmtType_ == TRANSPORT.TYPE_CONFIG) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "config_cmd_invalid_error", null); + } + ist_.setTransactionStatus(connection_, sql); + sql_ = sql; - TrafT4PreparedStatement(TrafT4Connection connection, String sql, String stmtLabel) throws SQLException { - this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.holdability_, - stmtLabel); - connection.ic_.t4props_.setUseArrayBinding(false); - connection.ic_.t4props_.setBatchRecovery(false); - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", - "Note, this call is before previous constructor call.", p); - } - if (connection_.props_.getLogWriter() != null) { - LogRecord lr = new LogRecord(Level.FINE, ""); - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); - lr.setParameters(p); - lr.setSourceClassName("TrafT4PreparedStatement"); - lr.setSourceMethodName(""); - T4LogFormatter lf = new T4LogFormatter(); - String temp = lf.format(lr); - connection_.props_.getLogWriter().println(temp); - } - } - - // Constructors with access specifier as "default" - TrafT4PreparedStatement(TrafT4Connection connection, String sql) throws SQLException { - this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.holdability_); - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", - "Note, this call is before previous constructor call.", p); - } - if (connection_.props_.getLogWriter() != null) { - LogRecord lr = new LogRecord(Level.FINE, ""); - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql); - lr.setParameters(p); - lr.setSourceClassName("TrafT4PreparedStatement"); - lr.setSourceMethodName(""); - T4LogFormatter lf = new T4LogFormatter(); - String temp = lf.format(lr); - connection_.props_.getLogWriter().println(temp); - } - } - - TrafT4PreparedStatement(TrafT4Connection connection, String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - this(connection, sql, resultSetType, resultSetConcurrency, connection.holdability_); - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, - resultSetConcurrency); - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", - "Note, this call is before previous constructor call.", p); - } - if (connection_.props_.getLogWriter() != null) { - LogRecord lr = new LogRecord(Level.FINE, ""); - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, - resultSetConcurrency); - lr.setParameters(p); - lr.setSourceClassName("TrafT4PreparedStatement"); - lr.setSourceMethodName(""); - T4LogFormatter lf = new T4LogFormatter(); - String temp = lf.format(lr); - connection_.props_.getLogWriter().println(temp); - } - - } - TrafT4PreparedStatement(TrafT4Connection connection, String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability, String stmtLabel) throws SQLException { - super(connection, resultSetType, resultSetConcurrency, resultSetHoldability, stmtLabel); - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, - resultSetConcurrency, resultSetHoldability); - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", - "Note, this call is before previous constructor call.", p); - } - if (connection_.props_.getLogWriter() != null) { - LogRecord lr = new LogRecord(Level.FINE, ""); - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, - resultSetConcurrency, resultSetHoldability); - lr.setParameters(p); - lr.setSourceClassName("TrafT4PreparedStatement"); - lr.setSourceMethodName(""); - T4LogFormatter lf = new T4LogFormatter(); - String temp = lf.format(lr); - connection_.props_.getLogWriter().println(temp); - } - // connection_.getServerHandle().isConnectionOpen(); - connection_.isConnectionOpen(); - sqlStmtType_ = ist_.getSqlStmtType(sql); - if (sqlStmtType_ == TRANSPORT.TYPE_STATS) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "infostats_invalid_error", null); - } else if (sqlStmtType_ == TRANSPORT.TYPE_CONFIG) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "config_cmd_invalid_error", null); - } - ist_.setTransactionStatus(connection_, sql); - sql_ = sql; - - - // stmtLabel_ = generateStmtLabel(); - stmtLabel_ = stmtLabel; - // System.out.println("TrafT4PreparedStatement stmtLabel_ " + stmtLabel_); - - usingRawRowset_ = false; - } - - TrafT4PreparedStatement(TrafT4Connection connection, String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - super(connection, resultSetType, resultSetConcurrency, resultSetHoldability); - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, - resultSetConcurrency, resultSetHoldability); - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "", - "Note, this call is before previous constructor call.", p); - } - if (connection_.props_.getLogWriter() != null) { - LogRecord lr = new LogRecord(Level.FINE, ""); - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, connection, sql, resultSetType, - resultSetConcurrency, resultSetHoldability); - lr.setParameters(p); - lr.setSourceClassName("TrafT4PreparedStatement"); - lr.setSourceMethodName(""); - T4LogFormatter lf = new T4LogFormatter(); - String temp = lf.format(lr); - connection_.props_.getLogWriter().println(temp); - } - // connection_.getServerHandle().isConnectionOpen(); - connection_.isConnectionOpen(); - sqlStmtType_ = ist_.getSqlStmtType(sql); - if (sqlStmtType_ == TRANSPORT.TYPE_STATS) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "infostats_invalid_error", null); - } else if (sqlStmtType_ == TRANSPORT.TYPE_CONFIG) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "config_cmd_invalid_error", null); - } - ist_.setTransactionStatus(connection_, sql); - sql_ = sql; - - - //stmtLabel_ = generateStmtLabel(); - - usingRawRowset_ = false; - } + usingRawRowset_ = false; + } TrafT4PreparedStatement(TrafT4Connection connection, String moduleName, int moduleVersion, long moduleTimestamp, String stmtName, boolean isSelect, int holdability) { @@ -2249,7 +2233,6 @@ public void close(boolean hardClose) throws SQLException { queryTimeout_ = connection_.getServerHandle().getQueryTimeout(); resultSetType_ = ResultSet.TYPE_FORWARD_ONLY; resultSetHoldability_ = holdability; - usingRawRowset_ = false; } // Interface methods diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Statement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Statement.java index cda76d68bb..8405f19e08 100644 --- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Statement.java +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Statement.java @@ -349,9 +349,7 @@ public int[] executeBatch() throws SQLException, BatchUpdateException { validateExecDirectInvocation(); if ((batchCommands_ == null) || (batchCommands_.isEmpty())) { - return new int[] - - {}; + return new int[] {}; } for (i = 0; i < batchCommands_.size(); i++) { @@ -1299,7 +1297,9 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St * * For closing statements using label. */ TrafT4Statement(TrafT4Connection connection, String stmtLabel) throws SQLException { - if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, stmtLabel); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, stmtLabel); connection.props_.t4Logger_.logp(Level.FINE, "TrafT4Statement", "", "", p); } @@ -1313,31 +1313,12 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St String temp = lf.format(lr); connection.props_.getLogWriter().println(temp); } - int hashcode; - - connection_ = connection; - operationID_ = -1; - - resultSetType_ = ResultSet.TYPE_FORWARD_ONLY; - resultSetConcurrency_ = ResultSet.CONCUR_READ_ONLY; - resultSetHoldability_ = TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT; - queryTimeout_ = connection_.getServerHandle().getQueryTimeout(); - - stmtLabel_ = stmtLabel; - fetchSize_ = TrafT4ResultSet.DEFAULT_FETCH_SIZE; - maxRows_ = 0; - fetchDirection_ = ResultSet.FETCH_FORWARD; - pRef_ = new WeakReference(this, connection_.refStmtQ_); - ist_ = new InterfaceStatement(this); - connection_.addElement(pRef_, stmtLabel_); - - resultSet_ = new TrafT4ResultSet[1]; - initResultSets(); } TrafT4Statement(TrafT4Connection connection) throws SQLException { - this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT); - if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection); connection.props_.t4Logger_.logp(Level.FINE, "TrafT4Statement", "", "Note, this constructor was called before the previous constructor", p); @@ -1352,13 +1333,10 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St String temp = lf.format(lr); connection.props_.getLogWriter().println(temp); } - resultSet_ = new TrafT4ResultSet[1]; - roundingMode_ = connection_.props_.getRoundingMode(); - initResultSets(); } TrafT4Statement(TrafT4Connection connection, int resultSetType, int resultSetConcurrency) throws SQLException { - this(connection, resultSetType, resultSetConcurrency, TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT); + this(connection, resultSetType, resultSetConcurrency, TrafT4ResultSet.CLOSE_CURSORS_AT_COMMIT, null); if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, resultSetType, resultSetConcurrency); @@ -1376,9 +1354,6 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St String temp = lf.format(lr); connection.props_.getLogWriter().println(temp); } - resultSet_ = new TrafT4ResultSet[1]; - roundingMode_ = connection_.props_.getRoundingMode(); - initResultSets(); } TrafT4Statement(TrafT4Connection connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability, String stmtLabel) throws SQLException { @@ -1398,40 +1373,40 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St String temp = lf.format(lr); connection.props_.getLogWriter().println(temp); } - int hashcode; - - connection_ = connection; - operationID_ = -1; - if (resultSetType != ResultSet.TYPE_FORWARD_ONLY && resultSetType != ResultSet.TYPE_SCROLL_INSENSITIVE - && resultSetType != ResultSet.TYPE_SCROLL_SENSITIVE) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "invalid_resultset_type", null); - } - - if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) { - resultSetType_ = ResultSet.TYPE_SCROLL_INSENSITIVE; - connection_.setSQLWarning(null, "scrollResultSetChanged", null); - //setSQLWarning(null, "scrollResultSetChanged", null); - } else { - resultSetType_ = resultSetType; + && resultSetType != ResultSet.TYPE_SCROLL_SENSITIVE) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_resultset_type", null); } if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY && resultSetConcurrency != ResultSet.CONCUR_UPDATABLE) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "invalid_resultset_concurrency", null); + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_resultset_concurrency", null); } - if ((resultSetHoldability != 0) && (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) - && (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_holdability", - null); + && (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_holdability", + null); + } + + if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) { + resultSetType_ = ResultSet.TYPE_SCROLL_INSENSITIVE; + connection_.setSQLWarning(null, "scrollResultSetChanged", null); + //setSQLWarning(null, "scrollResultSetChanged", null); + } else { + resultSetType_ = resultSetType; } + connection_ = connection; + operationID_ = -1; resultSetConcurrency_ = resultSetConcurrency; resultSetHoldability_ = resultSetHoldability; queryTimeout_ = connection_.getServerHandle().getQueryTimeout(); - stmtLabel_ = stmtLabel; + if (stmtLabel == null || stmtLabel.length() == 0) { + stmtLabel_ = generateStmtLabel(); + } else { + stmtLabel_ = stmtLabel; + } fetchSize_ = TrafT4ResultSet.DEFAULT_FETCH_SIZE; maxRows_ = 0; fetchDirection_ = ResultSet.FETCH_FORWARD; @@ -1443,11 +1418,15 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St roundingMode_ = connection_.props_.getRoundingMode(); resultSet_ = new TrafT4ResultSet[1]; + if (stmtLabel == null || stmtLabel.length() == 0) { + initResultSets(); + } } TrafT4Statement(TrafT4Connection connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { + this(connection, resultSetType, resultSetConcurrency, resultSetHoldability, null); + if (connection.props_.t4Logger_.isLoggable(Level.FINE) == true) { Object p[] = T4LoggingUtilities.makeParams(connection.props_, connection, resultSetType, resultSetConcurrency, resultSetHoldability); connection.props_.t4Logger_.logp(Level.FINE, "TrafT4Statement", "", "", p); @@ -1463,52 +1442,6 @@ void setExecute2Outputs(byte[] values, short rowsAffected, boolean endOfData, St String temp = lf.format(lr); connection.props_.getLogWriter().println(temp); } - int hashcode; - - connection_ = connection; - operationID_ = -1; - - if (resultSetType != ResultSet.TYPE_FORWARD_ONLY && resultSetType != ResultSet.TYPE_SCROLL_INSENSITIVE - && resultSetType != ResultSet.TYPE_SCROLL_SENSITIVE) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "invalid_resultset_type", null); - } - - if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) { - resultSetType_ = ResultSet.TYPE_SCROLL_INSENSITIVE; - connection_.setSQLWarning(null, "scrollResultSetChanged", null); - //setSQLWarning(null, "scrollResultSetChanged", null); - } else { - resultSetType_ = resultSetType; - } - if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY && resultSetConcurrency != ResultSet.CONCUR_UPDATABLE) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), - "invalid_resultset_concurrency", null); - } - - if ((resultSetHoldability != 0) && (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) - && (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_holdability", - null); - } - - resultSetConcurrency_ = resultSetConcurrency; - resultSetHoldability_ = resultSetHoldability; - queryTimeout_ = connection_.getServerHandle().getQueryTimeout(); - - stmtLabel_ = generateStmtLabel(); - fetchSize_ = TrafT4ResultSet.DEFAULT_FETCH_SIZE; - maxRows_ = 0; - fetchDirection_ = ResultSet.FETCH_FORWARD; - - connection_.gcStmts(); - pRef_ = new WeakReference(this, connection_.refStmtQ_); - ist_ = new InterfaceStatement(this); - connection_.addElement(pRef_, stmtLabel_); - - resultSet_ = new TrafT4ResultSet[1]; - roundingMode_ = connection_.props_.getRoundingMode(); - initResultSets(); } //max length for a label is 32 characters.