summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-04-07 01:16:19 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-04-07 01:16:19 +0000
commit36c23fee82392014557ff06d4cf7ca42db39f2d3 (patch)
treeb2ce2206630031e0d489146b12d425ba2b783a13 /src/main/java
parent96c1a940cf1c91b389ee39872ec3ab0444252b2d (diff)
Clean up use of MergeSortBuffer.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java36
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java16
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java4
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java16
4 files changed, 36 insertions, 36 deletions
diff --git a/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java
index 5419fe6..8202301 100644
--- a/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java
+++ b/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java
@@ -27,6 +27,7 @@ import com.amazon.carbonado.FetchException;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.cursor.ArraySortBuffer;
+import com.amazon.carbonado.cursor.MergeSortBuffer;
import com.amazon.carbonado.cursor.SortBuffer;
import com.amazon.carbonado.cursor.SortedCursor;
@@ -62,8 +63,12 @@ public class SortedQueryExecutor<S extends Storable> extends AbstractQueryExecut
OrderingList<S> handledOrdering,
OrderingList<S> remainderOrdering)
{
- if (support == null && this instanceof Support) {
- support = (Support<S>) this;
+ if (support == null) {
+ if (this instanceof Support) {
+ support = (Support<S>) this;
+ } else {
+ support = new ArraySortSupport<S>();
+ }
}
if (executor == null) {
throw new IllegalArgumentException();
@@ -97,8 +102,7 @@ public class SortedQueryExecutor<S extends Storable> extends AbstractQueryExecut
public Cursor<S> fetch(FilterValues<S> values) throws FetchException {
Cursor<S> cursor = mExecutor.fetch(values);
- SortBuffer<S> buffer =
- mSupport == null ? new ArraySortBuffer<S>() : mSupport.createSortBuffer();
+ SortBuffer<S> buffer = mSupport.createSortBuffer();
return new SortedCursor<S>(cursor, buffer, mHandledComparator, mFinisherComparator);
}
@@ -149,4 +153,28 @@ public class SortedQueryExecutor<S extends Storable> extends AbstractQueryExecut
*/
SortBuffer<S> createSortBuffer();
}
+
+ /**
+ * @since 1.2
+ */
+ public static class ArraySortSupport<S extends Storable> implements Support<S> {
+ /**
+ * Returns a new ArraySortBuffer.
+ */
+ public SortBuffer<S> createSortBuffer() {
+ return new ArraySortBuffer<S>();
+ }
+ }
+
+ /**
+ * @since 1.2
+ */
+ public static class MergeSortSupport<S extends Storable> implements Support<S> {
+ /**
+ * Returns a new MergeSortBuffer.
+ */
+ public SortBuffer<S> createSortBuffer() {
+ return new MergeSortBuffer<S>();
+ }
+ }
}
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 246a433..dbd6e4f 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java
@@ -41,7 +41,6 @@ import com.amazon.carbonado.Trigger;
import com.amazon.carbonado.capability.IndexInfo;
import com.amazon.carbonado.capability.IndexInfoCapability;
-import com.amazon.carbonado.cursor.ArraySortBuffer;
import com.amazon.carbonado.cursor.MergeSortBuffer;
import com.amazon.carbonado.filter.Filter;
@@ -81,8 +80,6 @@ class IndexedStorage<S extends Storable> implements Storage<S>, StorageAccess<S>
private final QueryEngine<S> mQueryEngine;
- private Storage<S> mRootStorage;
-
@SuppressWarnings("unchecked")
IndexedStorage(IndexedRepository repository, Storage<S> masterStorage)
throws RepositoryException
@@ -404,18 +401,7 @@ class IndexedStorage<S extends Storable> implements Storage<S>, StorageAccess<S>
}
public SortBuffer<S> createSortBuffer() {
- // FIXME: This is messy. If Storables had built-in serialization
- // support, then MergeSortBuffer would not need a root storage.
- if (mRootStorage == null) {
- try {
- mRootStorage = mRepository.getRootRepository().storageFor(getStorableType());
- } catch (RepositoryException e) {
- LogFactory.getLog(IndexedStorage.class).warn(null, e);
- return new ArraySortBuffer<S>();
- }
- }
-
- return new MergeSortBuffer<S>(mRootStorage);
+ return new MergeSortBuffer<S>();
}
public long countAll() throws FetchException {
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 598f9f6..54ff24a 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
@@ -472,9 +472,9 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
}
if (remainderOrdering != null && remainderOrdering.size() > 0) {
- // FIXME: use MergeSortBuffer
executor = new SortedQueryExecutor<S>
- (null, executor, sqlOrdering, remainderOrdering);
+ (new SortedQueryExecutor.MergeSortSupport(),
+ executor, sqlOrdering, remainderOrdering);
}
return executor;
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
index 126e40f..6c4d4e0 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
@@ -42,7 +42,6 @@ import com.amazon.carbonado.UniqueConstraintException;
import com.amazon.carbonado.capability.IndexInfo;
-import com.amazon.carbonado.cursor.ArraySortBuffer;
import com.amazon.carbonado.cursor.EmptyCursor;
import com.amazon.carbonado.cursor.MergeSortBuffer;
import com.amazon.carbonado.cursor.SingletonCursor;
@@ -119,8 +118,6 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
/** Reference to query engine, defined later in this class */
private QueryEngine<S> mQueryEngine;
- private Storage<S> mRootStorage;
-
final TriggerManager<S> mTriggerManager;
/**
@@ -260,18 +257,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
}
public SortBuffer<S> createSortBuffer() {
- // FIXME: This is messy. If Storables had built-in serialization
- // support, then MergeSortBuffer would not need a root storage.
- if (mRootStorage == null) {
- try {
- mRootStorage = mRepository.getRootRepository().storageFor(getStorableType());
- } catch (RepositoryException e) {
- LogFactory.getLog(BDBStorage.class).warn(null, e);
- return new ArraySortBuffer<S>();
- }
- }
-
- return new MergeSortBuffer<S>(mRootStorage);
+ return new MergeSortBuffer<S>();
}
public long countAll() throws FetchException {