From 36c23fee82392014557ff06d4cf7ca42db39f2d3 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 7 Apr 2008 01:16:19 +0000 Subject: Clean up use of MergeSortBuffer. --- .../amazon/carbonado/qe/SortedQueryExecutor.java | 36 +++++++++++++++++++--- .../carbonado/repo/indexed/IndexedStorage.java | 16 +--------- .../amazon/carbonado/repo/jdbc/JDBCStorage.java | 4 +-- .../carbonado/repo/sleepycat/BDBStorage.java | 16 +--------- 4 files changed, 36 insertions(+), 36 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') 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 extends AbstractQueryExecut OrderingList handledOrdering, OrderingList remainderOrdering) { - if (support == null && this instanceof Support) { - support = (Support) this; + if (support == null) { + if (this instanceof Support) { + support = (Support) this; + } else { + support = new ArraySortSupport(); + } } if (executor == null) { throw new IllegalArgumentException(); @@ -97,8 +102,7 @@ public class SortedQueryExecutor extends AbstractQueryExecut public Cursor fetch(FilterValues values) throws FetchException { Cursor cursor = mExecutor.fetch(values); - SortBuffer buffer = - mSupport == null ? new ArraySortBuffer() : mSupport.createSortBuffer(); + SortBuffer buffer = mSupport.createSortBuffer(); return new SortedCursor(cursor, buffer, mHandledComparator, mFinisherComparator); } @@ -149,4 +153,28 @@ public class SortedQueryExecutor extends AbstractQueryExecut */ SortBuffer createSortBuffer(); } + + /** + * @since 1.2 + */ + public static class ArraySortSupport implements Support { + /** + * Returns a new ArraySortBuffer. + */ + public SortBuffer createSortBuffer() { + return new ArraySortBuffer(); + } + } + + /** + * @since 1.2 + */ + public static class MergeSortSupport implements Support { + /** + * Returns a new MergeSortBuffer. + */ + public SortBuffer createSortBuffer() { + return new MergeSortBuffer(); + } + } } 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 implements Storage, StorageAccess private final QueryEngine mQueryEngine; - private Storage mRootStorage; - @SuppressWarnings("unchecked") IndexedStorage(IndexedRepository repository, Storage masterStorage) throws RepositoryException @@ -404,18 +401,7 @@ class IndexedStorage implements Storage, StorageAccess } public SortBuffer 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(); - } - } - - return new MergeSortBuffer(mRootStorage); + return new MergeSortBuffer(); } 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 extends StandardQueryFactory } if (remainderOrdering != null && remainderOrdering.size() > 0) { - // FIXME: use MergeSortBuffer executor = new SortedQueryExecutor - (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 implements Storage, Storag /** Reference to query engine, defined later in this class */ private QueryEngine mQueryEngine; - private Storage mRootStorage; - final TriggerManager mTriggerManager; /** @@ -260,18 +257,7 @@ abstract class BDBStorage implements Storage, Storag } public SortBuffer 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(); - } - } - - return new MergeSortBuffer(mRootStorage); + return new MergeSortBuffer(); } public long countAll() throws FetchException { -- cgit v1.2.3