diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-08-09 17:57:59 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-08-09 17:57:59 +0000 |
commit | d803c7dca98da1a487e2549dd0038801eb346b72 (patch) | |
tree | c666129e1737ffa4eb33abbe747e5fcda72a2915 /src/main | |
parent | a28709aabca96f19023370dd072cb3dc131e0e99 (diff) |
Yanked out support for fast skipping of JDBC results. JDBC drivers leak memory when this option is used.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java | 52 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java | 17 |
2 files changed, 7 insertions, 62 deletions
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<S extends Storable> extends AbstractCursor<S> { private final JDBCStorage<S> 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<S> 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<S extends Storable> extends AbstractCursor<S> { 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<S extends Storable> extends StandardQueryFactory<S> 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<S>(JDBCStorage.this, con, ps, scrollInsensitiveReadOnly);
+ return new JDBCCursor<S>(JDBCStorage.this, con, ps);
} catch (Exception e) {
// in case of exception, close statement
try {
|