diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java index ac876384df..bc4e9a984b 100644 --- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java +++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java @@ -55,13 +55,16 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.LogRecord; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; // ---------------------------------------------------------------------------- // This class partially implements the result set class as defined in // java.sql.ResultSet. // ---------------------------------------------------------------------------- public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet { - + private static final Logger LOG = LoggerFactory.getLogger(TrafT4ResultSet.class); + private static final long FETCH_BYTES_LIMIT = 1024 * 1024 * 1024; // java.sql.ResultSet interface methods public boolean absolute(int row) throws SQLException { if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { @@ -2772,7 +2775,7 @@ public boolean next() throws SQLException { maxRows = 0; queryTimeout = 0; } - + setFetchSizeIfExceedLimit(); if (maxRows == 0 || maxRows > totalRowsFetched_ + fetchSize_) { maxRowCnt = fetchSize_; } else { @@ -2973,34 +2976,52 @@ public void setFetchDirection(int direction) throws SQLException { } } - public void setFetchSize(int rows) throws SQLException { - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p); - } - if (connection_.props_.getLogWriter() != null) { - LogRecord lr = new LogRecord(Level.FINE, ""); - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); - lr.setParameters(p); - lr.setSourceClassName("TrafT4ResultSet"); - lr.setSourceMethodName("setFetchSize"); - T4LogFormatter lf = new T4LogFormatter(); - String temp = lf.format(lr); - connection_.props_.getLogWriter().println(temp); - } - if (isClosed_) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_cursor_state", - null); - } - if (rows < 0) { - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_fetch_size", - null); - } else if (rows == 0) { - fetchSize_ = DEFAULT_FETCH_SIZE; - } else { - fetchSize_ = rows; - } - } + public void setFetchSize(int rows) throws SQLException { + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p); + } + if (connection_.props_.getLogWriter() != null) { + LogRecord lr = new LogRecord(Level.FINE, ""); + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); + lr.setParameters(p); + lr.setSourceClassName("TrafT4ResultSet"); + lr.setSourceMethodName("setFetchSize"); + T4LogFormatter lf = new T4LogFormatter(); + String temp = lf.format(lr); + connection_.props_.getLogWriter().println(temp); + } + if (isClosed_) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_cursor_state", null); + } + if (rows < 0) { + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), + "invalid_fetch_size", null); + } else if (rows == 0) { + fetchSize_ = DEFAULT_FETCH_SIZE; + } else { + fetchSize_ = rows; + } + + setFetchSizeIfExceedLimit(); + } + + /** + * if (row width) * (fetch rows) too large, there will have core in server side. once fetch + * bytes bigger than 1GB, divide it into several times to fetch, each time fetch bytes less than + * 1GB. + */ + private void setFetchSizeIfExceedLimit() { + if (outputDesc_ != null && outputDesc_[0] != null) { + long rowLength = outputDesc_[0].rowLength_; + long fetchBytes = rowLength * fetchSize_; + if (fetchBytes >= FETCH_BYTES_LIMIT) { + fetchSize_ = (int) Math.ceil(FETCH_BYTES_LIMIT / (double) rowLength); + LOG.trace("Fetch size exceed limit, change it to <{}>.", fetchSize_); + } + } + } public void updateArray(int columnIndex, Array x) throws SQLException { if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { diff --git a/dcs/src/test/jdbc_test/pom.xml.template b/dcs/src/test/jdbc_test/pom.xml.template index ec754395a3..5fdf34281c 100644 --- a/dcs/src/test/jdbc_test/pom.xml.template +++ b/dcs/src/test/jdbc_test/pom.xml.template @@ -64,5 +64,23 @@ system MY_JDBC_SYS_PATH + + org.slf4j + slf4j-api + 1.7.5 + test + + + * + * + + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + test + diff --git a/tests/phx/pom.xml.template b/tests/phx/pom.xml.template index af79023e73..8977082a3e 100644 --- a/tests/phx/pom.xml.template +++ b/tests/phx/pom.xml.template @@ -174,24 +174,6 @@ - - org.slf4j - slf4j-api - 1.7.5 - test - - - * - * - - - - - org.slf4j - slf4j-log4j12 - 1.7.5 - test - @@ -247,7 +229,24 @@ 2.6 test - + + org.slf4j + slf4j-api + 1.7.5 + test + + + * + * + + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + test +