From d803c7dca98da1a487e2549dd0038801eb346b72 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 9 Aug 2007 17:57:59 +0000 Subject: Yanked out support for fast skipping of JDBC results. JDBC drivers leak memory when this option is used. --- .../com/amazon/carbonado/repo/jdbc/JDBCCursor.java | 52 +++------------------- .../amazon/carbonado/repo/jdbc/JDBCStorage.java | 17 +------ 2 files changed, 7 insertions(+), 62 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java index 28b73c7..985232c 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java @@ -37,27 +37,22 @@ class JDBCCursor extends AbstractCursor { private final JDBCStorage mStorage; private final Connection mConnection; private final PreparedStatement mStatement; - private final boolean mScrollInsensitiveReadOnly; private ResultSet mResultSet; private boolean mHasNext; /** - * @param scrollInsensitiveReadOnly when true, statement is - * TYPE_SCROLL_INSENSITIVE and CONCUR_READ_ONLY. * @throws SQLException from executeQuery on statement. Caller must clean * up when this happens by closing statement and connection. */ JDBCCursor(JDBCStorage storage, Connection con, - PreparedStatement statement, - boolean scrollInsensitiveReadOnly) + PreparedStatement statement) throws SQLException { mStorage = storage; mConnection = con; mStatement = statement; - mScrollInsensitiveReadOnly = scrollInsensitiveReadOnly; mResultSet = statement.executeQuery(); } @@ -127,48 +122,11 @@ class JDBCCursor extends AbstractCursor { int actual = 0; - if (amount > 1 && mScrollInsensitiveReadOnly) { - // Skip a relative amount, which is preferred. + while (amount > 0) { if (hasNext()) { - ResultSet rs = mResultSet; - try { - int rowStart = rs.getRow(); - mHasNext = rs.relative(amount); - int rowEnd = rs.getRow(); - if (rowEnd == 0) { - // Skipped past the end. Move back to find the last row number. - if (rs.previous() && (rowEnd = rs.getRow()) != 0) { - rowEnd++; - } else if (rs.last() && (rowEnd = rs.getRow()) != 0) { - rowEnd++; - } else { - // No clue how many were skipped. It's at least one. - rowEnd = rowStart + 1; - } - // Make sure ResultSet is closed below. - mHasNext = false; - } - actual += rowEnd - rowStart; - } catch (SQLException e) { - try { - close(); - } catch (FetchException e2) { - // Don't care. - } - throw mStorage.getJDBCRepository().toFetchException(e); - } - if (!mHasNext) { - close(); - } - } - } else { - // Call next a bunch, which is likely slower than relative skipping. - while (amount > 0) { - if (hasNext()) { - actual++; - amount--; - mHasNext = false; - } + actual++; + amount--; + mHasNext = false; } } diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java index 384f1bc..2421be7 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -488,24 +488,11 @@ class JDBCStorage extends StandardQueryFactory boolean forUpdate = mRepository.localTxnManager().isForUpdate(); Connection con = mRepository.getConnection(); try { - boolean scrollInsensitiveReadOnly = - mRepository.supportsScrollInsensitiveReadOnly(); - - PreparedStatement ps; - - if (scrollInsensitiveReadOnly) { - // Can support fast skipping. - ps = con.prepareStatement - (prepareSelect(values, forUpdate), - ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - } else { - // Can't support fast skipping. - ps = con.prepareStatement(prepareSelect(values, forUpdate)); - } + PreparedStatement ps = con.prepareStatement(prepareSelect(values, forUpdate)); try { setParameters(ps, values); - return new JDBCCursor(JDBCStorage.this, con, ps, scrollInsensitiveReadOnly); + return new JDBCCursor(JDBCStorage.this, con, ps); } catch (Exception e) { // in case of exception, close statement try { -- cgit v1.2.3