diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-08-10 17:54:49 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-08-10 17:54:49 +0000 |
commit | 57200426df368af9ce98f9d269cac7cdd15a6b93 (patch) | |
tree | 1b77b161c658588a391873117b9eef7278b46fe2 /src/main/java/com/amazon/carbonado | |
parent | 3ea47b49a69e0a1abd52ed7252c3df5bc02e12d4 (diff) |
Support configuring the result set fetch size for queries.
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
4 files changed, 35 insertions, 0 deletions
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<JDBCTransaction> 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<String, Boolean> mAutoVersioningMap;
@@ -214,6 +215,7 @@ public class JDBCRepository extends AbstractRepository<JDBCTransaction> Iterable<TriggerFactory> triggerFactories,
DataSource dataSource, boolean dataSourceClose,
String catalog, String schema,
+ Integer fetchSize,
Map<String, Boolean> autoVersioningMap,
String sequenceSelectStatement, boolean forceStoredSequence)
throws RepositoryException
@@ -229,6 +231,7 @@ public class JDBCRepository extends AbstractRepository<JDBCTransaction> mDataSourceClose = dataSourceClose;
mCatalog = catalog;
mSchema = schema;
+ mFetchSize = fetchSize;
mAutoVersioningMap = autoVersioningMap;
@@ -582,6 +585,10 @@ public class JDBCRepository extends AbstractRepository<JDBCTransaction> 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<String, Boolean> 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);
@@ -273,6 +275,26 @@ public class JDBCRepositoryBuilder extends AbstractRepositoryBuilder { }
/**
+ * 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
* incremented by triggers installed on the database. Enabling automatic
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<S extends Storable> extends StandardQueryFactory<S> 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<S extends Storable> extends SQLStatement<S> { return mStr.length();
}
+ @Override
public String buildStatement(int initialCapacity, FilterValues<S> filterValues) {
return mStr;
}
@@ -49,6 +50,7 @@ class LiteralStatement<S extends Storable> extends SQLStatement<S> { /**
* Returns the literal value.
*/
+ @Override
public String toString() {
return mStr;
}
|