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 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/qe') 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(); + } + } } -- cgit v1.2.3