diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-09-27 23:51:49 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-09-27 23:51:49 +0000 |
commit | bddf5aea31f3ed34b43d26133de1671b2acbcc46 (patch) | |
tree | e8d3f9f92dc66e395550e0158cec8208c05c6cf0 /src/main/java/com/amazon/carbonado | |
parent | 3d1c317bf2d063bbff597f2c05e3a9749e448dd4 (diff) |
Add support for faster full count.
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
-rw-r--r-- | src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java | 15 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java index dbf5690..b8035f0 100644 --- a/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java @@ -51,6 +51,15 @@ public class FullScanQueryExecutor<S extends Storable> extends AbstractQueryExec mSupport = support;
}
+ @Override
+ public long count(FilterValues<S> values) throws FetchException {
+ long count = mSupport.countAll();
+ if (count == -1) {
+ count = super.count(values);
+ }
+ return count;
+ }
+
/**
* Returns an open filter.
*/
@@ -83,6 +92,12 @@ public class FullScanQueryExecutor<S extends Storable> extends AbstractQueryExec Class<S> getStorableType();
/**
+ * Counts all Storables. Implementation may return -1 to indicate that
+ * default count algorithm should be used.
+ */
+ long countAll() throws FetchException;
+
+ /**
* Perform a full scan of all Storables.
*/
Cursor<S> fetchAll() throws FetchException;
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java index 1fa1244..2901ea0 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java @@ -297,6 +297,10 @@ class IndexedStorage<S extends Storable> implements Storage<S>, StorageAccess<S> return new MergeSortBuffer<S>(mRootStorage);
}
+ public long countAll() throws FetchException {
+ return mMasterStorage.query().count();
+ }
+
public Cursor<S> fetchAll() throws FetchException {
return mMasterStorage.query().fetch();
}
|