From 57200426df368af9ce98f9d269cac7cdd15a6b93 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 10 Aug 2007 17:54:49 +0000 Subject: Support configuring the result set fetch size for queries. --- .../amazon/carbonado/repo/jdbc/JDBCRepository.java | 7 +++++++ .../carbonado/repo/jdbc/JDBCRepositoryBuilder.java | 22 ++++++++++++++++++++++ .../amazon/carbonado/repo/jdbc/JDBCStorage.java | 4 ++++ .../carbonado/repo/jdbc/LiteralStatement.java | 2 ++ 4 files changed, 35 insertions(+) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java index 105de87..9e54694 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java @@ -171,6 +171,7 @@ public class JDBCRepository extends AbstractRepository private final boolean mDataSourceClose; private final String mCatalog; private final String mSchema; + private final Integer mFetchSize; // Maps Storable types which should have automatic version management. private Map mAutoVersioningMap; @@ -214,6 +215,7 @@ public class JDBCRepository extends AbstractRepository Iterable triggerFactories, DataSource dataSource, boolean dataSourceClose, String catalog, String schema, + Integer fetchSize, Map autoVersioningMap, String sequenceSelectStatement, boolean forceStoredSequence) throws RepositoryException @@ -229,6 +231,7 @@ public class JDBCRepository extends AbstractRepository mDataSourceClose = dataSourceClose; mCatalog = catalog; mSchema = schema; + mFetchSize = fetchSize; mAutoVersioningMap = autoVersioningMap; @@ -582,6 +585,10 @@ public class JDBCRepository extends AbstractRepository return mRootRef.get(); } + Integer getFetchSize() { + return mFetchSize; + } + /** * Transforms the given throwable into an appropriate fetch exception. If * it already is a fetch exception, it is simply casted. diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java index 2329206..12e21cc 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java @@ -70,6 +70,7 @@ public class JDBCRepositoryBuilder extends AbstractRepositoryBuilder { private String mURL; private String mUsername; private String mPassword; + private Integer mFetchSize; private Map mAutoVersioningMap; private String mSequenceSelectStatement; private boolean mForceStoredSequence; @@ -83,6 +84,7 @@ public class JDBCRepositoryBuilder extends AbstractRepositoryBuilder { (rootRef, getName(), isMaster(), getTriggerFactories(), getDataSource(), getDataSourceCloseOnShutdown(), mCatalog, mSchema, + mFetchSize, getAutoVersioningMap(), mSequenceSelectStatement, mForceStoredSequence); rootRef.set(repo); @@ -272,6 +274,26 @@ public class JDBCRepositoryBuilder extends AbstractRepositoryBuilder { return mPassword; } + /** + * Set the default fetch size when running queries. Pass null to let driver + * use its own default. + * + * @since 1.2 + */ + public void setDefaultFetchSize(Integer size) { + mFetchSize = size; + } + + /** + * Returns the default fetch size when running queries, or null if driver + * default is used instead. + * + * @since 1.2 + */ + public Integer getDefaultFetchSize() { + return mFetchSize; + } + /** * By default, JDBCRepository assumes that {@link * com.amazon.carbonado.Version version numbers} are initialized and 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 2421be7..fd36c6e 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -489,6 +489,10 @@ class JDBCStorage extends StandardQueryFactory Connection con = mRepository.getConnection(); try { PreparedStatement ps = con.prepareStatement(prepareSelect(values, forUpdate)); + Integer fetchSize = mRepository.getFetchSize(); + if (fetchSize != null) { + ps.setFetchSize(fetchSize); + } try { setParameters(ps, values); diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java b/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java index 8fa0933..ceedd94 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java @@ -38,6 +38,7 @@ class LiteralStatement extends SQLStatement { return mStr.length(); } + @Override public String buildStatement(int initialCapacity, FilterValues filterValues) { return mStr; } @@ -49,6 +50,7 @@ class LiteralStatement extends SQLStatement { /** * Returns the literal value. */ + @Override public String toString() { return mStr; } -- cgit v1.2.3