|
55 | 55 | import java.util.Map; |
56 | 56 | import java.util.logging.Level; |
57 | 57 | import java.util.logging.LogRecord; |
| 58 | +import org.slf4j.Logger; |
| 59 | +import org.slf4j.LoggerFactory; |
58 | 60 |
|
59 | 61 | // ---------------------------------------------------------------------------- |
60 | 62 | // This class partially implements the result set class as defined in |
61 | 63 | // java.sql.ResultSet. |
62 | 64 | // ---------------------------------------------------------------------------- |
63 | 65 | public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet { |
64 | | - |
| 66 | + private static final Logger LOG = LoggerFactory.getLogger(TrafT4ResultSet.class); |
| 67 | + private static final long FETCH_BYTES_LIMIT = 1024 * 1024 * 1024; |
65 | 68 | // java.sql.ResultSet interface methods |
66 | 69 | public boolean absolute(int row) throws SQLException { |
67 | 70 | if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { |
@@ -2772,7 +2775,7 @@ public boolean next() throws SQLException { |
2772 | 2775 | maxRows = 0; |
2773 | 2776 | queryTimeout = 0; |
2774 | 2777 | } |
2775 | | - |
| 2778 | + setFetchSizeIfExceedLimit(); |
2776 | 2779 | if (maxRows == 0 || maxRows > totalRowsFetched_ + fetchSize_) { |
2777 | 2780 | maxRowCnt = fetchSize_; |
2778 | 2781 | } else { |
@@ -2973,34 +2976,52 @@ public void setFetchDirection(int direction) throws SQLException { |
2973 | 2976 | } |
2974 | 2977 | } |
2975 | 2978 |
|
2976 | | - public void setFetchSize(int rows) throws SQLException { |
2977 | | - if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { |
2978 | | - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); |
2979 | | - connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p); |
2980 | | - } |
2981 | | - if (connection_.props_.getLogWriter() != null) { |
2982 | | - LogRecord lr = new LogRecord(Level.FINE, ""); |
2983 | | - Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); |
2984 | | - lr.setParameters(p); |
2985 | | - lr.setSourceClassName("TrafT4ResultSet"); |
2986 | | - lr.setSourceMethodName("setFetchSize"); |
2987 | | - T4LogFormatter lf = new T4LogFormatter(); |
2988 | | - String temp = lf.format(lr); |
2989 | | - connection_.props_.getLogWriter().println(temp); |
2990 | | - } |
2991 | | - if (isClosed_) { |
2992 | | - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_cursor_state", |
2993 | | - null); |
2994 | | - } |
2995 | | - if (rows < 0) { |
2996 | | - throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "invalid_fetch_size", |
2997 | | - null); |
2998 | | - } else if (rows == 0) { |
2999 | | - fetchSize_ = DEFAULT_FETCH_SIZE; |
3000 | | - } else { |
3001 | | - fetchSize_ = rows; |
3002 | | - } |
3003 | | - } |
| 2979 | + public void setFetchSize(int rows) throws SQLException { |
| 2980 | + if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { |
| 2981 | + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); |
| 2982 | + connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4ResultSet", "setFetchSize", "", p); |
| 2983 | + } |
| 2984 | + if (connection_.props_.getLogWriter() != null) { |
| 2985 | + LogRecord lr = new LogRecord(Level.FINE, ""); |
| 2986 | + Object p[] = T4LoggingUtilities.makeParams(connection_.props_, rows); |
| 2987 | + lr.setParameters(p); |
| 2988 | + lr.setSourceClassName("TrafT4ResultSet"); |
| 2989 | + lr.setSourceMethodName("setFetchSize"); |
| 2990 | + T4LogFormatter lf = new T4LogFormatter(); |
| 2991 | + String temp = lf.format(lr); |
| 2992 | + connection_.props_.getLogWriter().println(temp); |
| 2993 | + } |
| 2994 | + if (isClosed_) { |
| 2995 | + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), |
| 2996 | + "invalid_cursor_state", null); |
| 2997 | + } |
| 2998 | + if (rows < 0) { |
| 2999 | + throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), |
| 3000 | + "invalid_fetch_size", null); |
| 3001 | + } else if (rows == 0) { |
| 3002 | + fetchSize_ = DEFAULT_FETCH_SIZE; |
| 3003 | + } else { |
| 3004 | + fetchSize_ = rows; |
| 3005 | + } |
| 3006 | + |
| 3007 | + setFetchSizeIfExceedLimit(); |
| 3008 | + } |
| 3009 | + |
| 3010 | + /** |
| 3011 | + * if (row width) * (fetch rows) too large, there will have core in server side. once fetch |
| 3012 | + * bytes bigger than 1GB, divide it into several times to fetch, each time fetch bytes less than |
| 3013 | + * 1GB. |
| 3014 | + */ |
| 3015 | + private void setFetchSizeIfExceedLimit() { |
| 3016 | + if (outputDesc_ != null && outputDesc_[0] != null) { |
| 3017 | + long rowLength = outputDesc_[0].rowLength_; |
| 3018 | + long fetchBytes = rowLength * fetchSize_; |
| 3019 | + if (fetchBytes >= FETCH_BYTES_LIMIT) { |
| 3020 | + fetchSize_ = (int) Math.ceil(FETCH_BYTES_LIMIT / (double) rowLength); |
| 3021 | + LOG.trace("Fetch size exceed limit, change it to <{}>.", fetchSize_); |
| 3022 | + } |
| 3023 | + } |
| 3024 | + } |
3004 | 3025 |
|
3005 | 3026 | public void updateArray(int columnIndex, Array x) throws SQLException { |
3006 | 3027 | if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) { |
|
0 commit comments