From 0ffae97e0938b0c9fe2d264b8f5e26be9f6f6f0e Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 8 Sep 2006 17:00:16 +0000 Subject: Make better use of OrderingList class. --- .../carbonado/qe/ArraySortedQueryExecutor.java | 8 +- .../carbonado/qe/DelegatedQueryExecutor.java | 60 +++--- .../java/com/amazon/carbonado/qe/EmptyQuery.java | 46 +++-- .../amazon/carbonado/qe/FilteredQueryExecutor.java | 2 +- .../carbonado/qe/FullScanIndexedQueryExecutor.java | 4 +- .../amazon/carbonado/qe/FullScanQueryExecutor.java | 4 +- .../amazon/carbonado/qe/IndexedQueryExecutor.java | 4 +- .../amazon/carbonado/qe/JoinedQueryExecutor.java | 14 +- .../com/amazon/carbonado/qe/KeyQueryExecutor.java | 4 +- .../java/com/amazon/carbonado/qe/OrderingList.java | 216 ++++++++++++--------- .../com/amazon/carbonado/qe/QueryExecutor.java | 2 +- .../amazon/carbonado/qe/SortedQueryExecutor.java | 58 +++--- .../amazon/carbonado/qe/UnionQueryExecutor.java | 14 +- .../carbonado/qe/TestJoinedQueryExecutor.java | 12 +- .../com/amazon/carbonado/qe/TestQueryExecutor.java | 13 +- .../carbonado/qe/TestSortedQueryExecutor.java | 6 +- 16 files changed, 247 insertions(+), 220 deletions(-) diff --git a/src/main/java/com/amazon/carbonado/qe/ArraySortedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/ArraySortedQueryExecutor.java index 1ca2965..85b6c2e 100644 --- a/src/main/java/com/amazon/carbonado/qe/ArraySortedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/ArraySortedQueryExecutor.java @@ -37,13 +37,13 @@ public class ArraySortedQueryExecutor extends SortedQueryExe /** * @param executor executor to wrap * @throws IllegalArgumentException if executor is null or if remainder - * orderings is empty + * ordering is empty */ public ArraySortedQueryExecutor(QueryExecutor executor, - List> handledOrderings, - List> remainderOrderings) + OrderingList handledOrdering, + OrderingList remainderOrdering) { - super(executor, handledOrderings, remainderOrderings); + super(executor, handledOrdering, remainderOrdering); } protected SortBuffer createSortBuffer() { diff --git a/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java index 9c950e0..7b1c27b 100644 --- a/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java @@ -39,48 +39,60 @@ import com.amazon.carbonado.info.OrderedProperty; * @author Brian S O'Neill */ public class DelegatedQueryExecutor implements QueryExecutor { - private final QueryExecutor mExecutor; - private final Storage mStorage; + private static final T check(T object) { + if (object == null) { + throw new IllegalArgumentException(); + } + return object; + } + + private final Filter mFilter; + private final OrderingList mOrdering; private final Query mQuery; /** + * @param rootStorage root storage to query * @param executor executor to emulate - * @param storage storage to query * @throws IllegalArgumentException if any parameter is null */ - public DelegatedQueryExecutor(QueryExecutor executor, Storage storage) + public DelegatedQueryExecutor(Storage rootStorage, QueryExecutor executor) throws FetchException { - if (executor == null || storage == null) { - throw new IllegalStateException(); - } - - mExecutor = executor; - mStorage = storage; + this(rootStorage, (executor = check(executor)).getFilter(), executor.getOrdering()); + } - Filter filter = executor.getFilter(); + /** + * @param rootStorage root storage to query + * @param filter optional query filter + * @param ordering optional ordering + * @throws IllegalArgumentException if rootStorage is null + */ + public DelegatedQueryExecutor(Storage rootStorage, + Filter filter, OrderingList ordering) + throws FetchException + { + check(rootStorage); Query query; if (filter == null) { - query = storage.query(); + query = rootStorage.query(); } else { - query = storage.query(filter); + query = rootStorage.query(filter); } - List> ordering = executor.getOrdering(); - if (ordering.size() > 0) { - String[] orderBy = new String[ordering.size()]; - for (int i=0; i 0) { + query = query.orderBy(ordering.asStringArray()); } + mFilter = filter; + mOrdering = ordering; mQuery = query; } public Class getStorableType() { - return mStorage.getStorableType(); + return mFilter.getStorableType(); } public Cursor fetch(FilterValues values) throws FetchException { @@ -92,11 +104,11 @@ public class DelegatedQueryExecutor implements QueryExecutor } public Filter getFilter() { - return mExecutor.getFilter(); + return mFilter; } - public List> getOrdering() { - return mExecutor.getOrdering(); + public OrderingList getOrdering() { + return mOrdering; } public boolean printNative(Appendable app, int indentLevel, FilterValues values) diff --git a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java index 4918f08..16a8f26 100644 --- a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java @@ -41,20 +41,20 @@ import com.amazon.carbonado.info.OrderedProperty; * @author Brian S O'Neill */ public final class EmptyQuery extends AbstractQuery { - private final Storage mStorage; + private final Storage mRootStorage; // Properties that this query is ordered by. private final OrderingList mOrderings; /** - * @param storage required storage object + * @param rootStorage required root storage object, used by 'or' and 'not' methods * @param orderings optional order-by properties */ - public EmptyQuery(Storage storage, OrderingList orderings) { - if (storage == null) { + public EmptyQuery(Storage rootStorage, OrderingList orderings) { + if (rootStorage == null) { throw new IllegalArgumentException(); } - mStorage = storage; + mRootStorage = rootStorage; if (orderings == null) { orderings = OrderingList.emptyList(); } @@ -62,22 +62,30 @@ public final class EmptyQuery extends AbstractQuery { } /** - * @param storage required storage object + * @param rootStorage required root storage object, used by 'or' and 'not' methods + * @param ordering optional order-by property + */ + public EmptyQuery(Storage rootStorage, String ordering) { + this(rootStorage, OrderingList.get(rootStorage.getStorableType(), ordering)); + } + + /** + * @param rootStorage required root storage object, used by 'or' and 'not' methods * @param orderings optional order-by properties */ - public EmptyQuery(Storage storage, String... orderings) { - this(storage, OrderingList.get(storage.getStorableType(), orderings)); + public EmptyQuery(Storage rootStorage, String... orderings) { + this(rootStorage, OrderingList.get(rootStorage.getStorableType(), orderings)); } public Class getStorableType() { - return mStorage.getStorableType(); + return mRootStorage.getStorableType(); } /** * Always returns a {@link com.amazon.carbonado.filter.ClosedFilter ClosedFilter}. */ public Filter getFilter() { - return Filter.getClosedFilter(mStorage.getStorableType()); + return Filter.getClosedFilter(getStorableType()); } /** @@ -174,12 +182,18 @@ public final class EmptyQuery extends AbstractQuery { throw new IllegalStateException("Query is already guaranteed to fetch nothing"); } + /** + * Returns a query that fetches only what's specified by the given filter. + */ public Query or(Filter filter) throws FetchException { - return mStorage.query(filter); + return mRootStorage.query(filter); } + /** + * Returns a query that fetches everything, possibly in a specified order. + */ public Query not() throws FetchException { - Query query = mStorage.query(); + Query query = mRootStorage.query(); if (mOrderings.size() > 0) { query = query.orderBy(mOrderings.asStringArray()); } @@ -187,13 +201,11 @@ public final class EmptyQuery extends AbstractQuery { } public Query orderBy(String property) throws FetchException { - // This allows property to be checked for validity. - return mStorage.query().orderBy(property).not(); + return new EmptyQuery(mRootStorage, property); } public Query orderBy(String... properties) throws FetchException { - // This allows properties to be checked for validity. - return mStorage.query().orderBy(properties).not(); + return new EmptyQuery(mRootStorage, properties); } /** @@ -239,7 +251,7 @@ public final class EmptyQuery extends AbstractQuery { public void appendTo(Appendable app) throws IOException { app.append("Query {type="); - app.append(mStorage.getStorableType().getName()); + app.append(getStorableType().getName()); app.append(", filter="); getFilter().appendTo(app); diff --git a/src/main/java/com/amazon/carbonado/qe/FilteredQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/FilteredQueryExecutor.java index d2c45aa..edf51cd 100644 --- a/src/main/java/com/amazon/carbonado/qe/FilteredQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/FilteredQueryExecutor.java @@ -73,7 +73,7 @@ public class FilteredQueryExecutor extends AbstractQueryExec return mExecutor.getFilter().and(mFilter); } - public List> getOrdering() { + public OrderingList getOrdering() { return mExecutor.getOrdering(); } diff --git a/src/main/java/com/amazon/carbonado/qe/FullScanIndexedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/FullScanIndexedQueryExecutor.java index 3ac0169..e7c6f2b 100644 --- a/src/main/java/com/amazon/carbonado/qe/FullScanIndexedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/FullScanIndexedQueryExecutor.java @@ -70,8 +70,8 @@ public abstract class FullScanIndexedQueryExecutor * Returns the natural order of the index. */ @Override - public List> getOrdering() { - return Collections.unmodifiableList(Arrays.asList(mIndex.getOrderedProperties())); + public OrderingList getOrdering() { + return OrderingList.get(mIndex.getOrderedProperties()); } protected Cursor fetch() throws FetchException { diff --git a/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java index 1e2ad16..fc29983 100644 --- a/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/FullScanQueryExecutor.java @@ -65,8 +65,8 @@ public abstract class FullScanQueryExecutor extends Abstract /** * Returns an empty list. */ - public List> getOrdering() { - return Collections.emptyList(); + public OrderingList getOrdering() { + return OrderingList.emptyList(); } public boolean printPlan(Appendable app, int indentLevel, FilterValues values) diff --git a/src/main/java/com/amazon/carbonado/qe/IndexedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/IndexedQueryExecutor.java index 28bd7e4..a306db1 100644 --- a/src/main/java/com/amazon/carbonado/qe/IndexedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/IndexedQueryExecutor.java @@ -173,8 +173,8 @@ public abstract class IndexedQueryExecutor extends AbstractQ return filter; } - public List> getOrdering() { - return Collections.unmodifiableList(Arrays.asList(mIndex.getOrderedProperties())); + public OrderingList getOrdering() { + return OrderingList.get(mIndex.getOrderedProperties()); } public boolean printPlan(Appendable app, int indentLevel, FilterValues values) diff --git a/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java index ef10657..9557b31 100644 --- a/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java @@ -57,26 +57,26 @@ import com.amazon.carbonado.info.StorableIntrospector; public class JoinedQueryExecutor extends AbstractQueryExecutor { - private static List> + private static OrderingList transformOrdering(Class bType, String bToAProperty, QueryExecutor aExecutor) { StorableInfo bInfo = StorableIntrospector.examine(bType); - List> aOrdering = aExecutor.getOrdering(); + OrderingList aOrdering = aExecutor.getOrdering(); int size = aOrdering.size(); - List> bOrdering = new ArrayList>(size); + OrderedProperty[] bOrdering = new OrderedProperty[size]; for (int i=0; i aProp = aOrdering.get(i); String bName = bToAProperty + '.' + aProp.getChainedProperty(); OrderedProperty bProp = OrderedProperty .get(ChainedProperty.parse(bInfo, bName), aProp.getDirection()); - bOrdering.add(bProp); + bOrdering[i] = bProp; } - return Collections.unmodifiableList(bOrdering); + return OrderingList.get(bOrdering); } private final JoinedCursorFactory mFactory; @@ -84,7 +84,7 @@ public class JoinedQueryExecutor private final FilterValues mAFilterValues; private final Filter mBFilter; - private final List> mBOrdering; + private final OrderingList mBOrdering; /** * @param repo access to storage instances for properties @@ -145,7 +145,7 @@ public class JoinedQueryExecutor return mFactory.join(mAExecutor.fetch(transferValues(values))); } - public List> getOrdering() { + public OrderingList getOrdering() { return mBOrdering; } diff --git a/src/main/java/com/amazon/carbonado/qe/KeyQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/KeyQueryExecutor.java index fe07ed6..8209be7 100644 --- a/src/main/java/com/amazon/carbonado/qe/KeyQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/KeyQueryExecutor.java @@ -78,8 +78,8 @@ public abstract class KeyQueryExecutor extends AbstractQuery /** * Returns an empty list. */ - public List> getOrdering() { - return Collections.emptyList(); + public OrderingList getOrdering() { + return OrderingList.emptyList(); } public boolean printPlan(Appendable app, int indentLevel, FilterValues values) diff --git a/src/main/java/com/amazon/carbonado/qe/OrderingList.java b/src/main/java/com/amazon/carbonado/qe/OrderingList.java index 907453d..0cb1fc4 100644 --- a/src/main/java/com/amazon/carbonado/qe/OrderingList.java +++ b/src/main/java/com/amazon/carbonado/qe/OrderingList.java @@ -43,14 +43,14 @@ public class OrderingList extends AbstractList cCache; static { - cCache = new SoftValuedHashMap(); + cCache = new SoftValuedHashMap(); } /** * Returns a canonical empty instance. */ public static OrderingList emptyList() { - return EMPTY_LIST; + return EMPTY_LIST; } /** @@ -59,10 +59,10 @@ public class OrderingList extends AbstractList OrderingList get(Class type, String property) { - if (property == null) { - return EMPTY_LIST; - } - return getListNode(type).nextNode(type, property); + if (property == null) { + return EMPTY_LIST; + } + return getListNode(type).nextNode(type, property); } /** @@ -71,14 +71,14 @@ public class OrderingList extends AbstractList OrderingList get(Class type, String... orderings) { - if (orderings == null || orderings.length == 0) { - return EMPTY_LIST; - } + if (orderings == null || orderings.length == 0) { + return EMPTY_LIST; + } - OrderingList node = getListNode(type); - for (String property : orderings) { - node = node.nextNode(type, property); - } + OrderingList node = getListNode(type); + for (String property : orderings) { + node = node.nextNode(type, property); + } return node; } @@ -87,30 +87,30 @@ public class OrderingList extends AbstractList OrderingList get(OrderedProperty... orderings) { - if (orderings == null || orderings.length == 0) { - return EMPTY_LIST; - } + if (orderings == null || orderings.length == 0) { + return EMPTY_LIST; + } - Class type = orderings[0].getChainedProperty().getPrimeProperty().getEnclosingType(); + Class type = orderings[0].getChainedProperty().getPrimeProperty().getEnclosingType(); - OrderingList node = getListNode(type); - for (OrderedProperty property : orderings) { - node = node.nextNode(property); - } + OrderingList node = getListNode(type); + for (OrderedProperty property : orderings) { + node = node.nextNode(property); + } return node; } private static OrderingList getListNode(Class type) { - OrderingList node; - synchronized (cCache) { - node = (OrderingList) cCache.get(type); - if (node == null) { - node = new OrderingList(); - cCache.put(type, node); - } - } - return node; + OrderingList node; + synchronized (cCache) { + node = (OrderingList) cCache.get(type); + if (node == null) { + node = new OrderingList(); + cCache.put(type, node); + } + } + return node; } private final OrderingList mParent; @@ -123,105 +123,129 @@ public class OrderingList extends AbstractList parent, OrderedProperty property) { - if (property == null) { - throw new IllegalArgumentException("Ordering property is null"); - } - mParent = parent; - mProperty = property; - mSize = parent.mSize + 1; + if (property == null) { + throw new IllegalArgumentException("Ordering property is null"); + } + mParent = parent; + mProperty = property; + mSize = parent.mSize + 1; } public int size() { - return mSize; + return mSize; } public OrderedProperty get(int index) { - return asArray()[index]; + return asArray()[index]; + } + + /** + * Returns a list which concatenates this one with the other one. + */ + public OrderingList concat(OrderingList other) { + if (size() == 0) { + return other; + } + + OrderingList node = this; + + if (other.size() > 0) { + for (OrderedProperty property : other) { + node = node.nextNode(property); + } + } + + return node; } + /** + * This method is not public because the array is not a clone. + */ private OrderedProperty[] asArray() { - if (mOrderings == null) { - OrderedProperty[] orderings = new OrderedProperty[mSize]; - OrderingList node = this; - for (int i=mSize; --i>=0; ) { - orderings[i] = node.mProperty; - node = node.mParent; - } - mOrderings = orderings; - } - return mOrderings; + if (mOrderings == null) { + OrderedProperty[] orderings = new OrderedProperty[mSize]; + OrderingList node = this; + for (int i=mSize; --i>=0; ) { + orderings[i] = node.mProperty; + node = node.mParent; + } + mOrderings = orderings; + } + return mOrderings; } /** * Returns the orderings as qualified string property names. Each is * prefixed with a '+' or '-'. + * + *

This method is not public because the array is not a clone. */ String[] asStringArray() { - if (mOrderingStrings == null) { - String[] orderings = new String[mSize]; - OrderingList node = this; - for (int i=mSize; --i>=0; ) { - orderings[i] = node.mProperty.toString(); - node = node.mParent; - } - mOrderingStrings = orderings; - } - return mOrderingStrings; + if (mOrderingStrings == null) { + String[] orderings = new String[mSize]; + OrderingList node = this; + for (int i=mSize; --i>=0; ) { + orderings[i] = node.mProperty.toString(); + node = node.mParent; + } + mOrderingStrings = orderings; + } + return mOrderingStrings; } @Override public int hashCode() { - return System.identityHashCode(this); + return System.identityHashCode(this); } @Override public boolean equals(Object other) { - if (this == other) { - return true; - } - return super.equals(other); + if (this == other) { + return true; + } + return super.equals(other); } private synchronized OrderingList nextNode(Class type, String property) { - OrderingList node; - if (mNextNode == null) { - mNextNode = new HashMap>(); - node = null; - } else { - node = mNextNode.get(property); - } - - if (node == null) { - OrderedProperty op = OrderedProperty - .parse(StorableIntrospector.examine(type), property); + OrderingList node; + if (mNextNode == null) { + mNextNode = new HashMap>(); + node = null; + } else { + node = mNextNode.get(property); + } + + if (node == null) { + OrderedProperty op = OrderedProperty + .parse(StorableIntrospector.examine(type), property); + + node = nextNode(op); + mNextNode.put(property, node); + } - node = nextNode(op); - mNextNode.put(property, node); - } - - return node; + return node; } private synchronized OrderingList nextNode(OrderedProperty property) { - OrderingList node; - if (mNextNode == null) { - mNextNode = new HashMap>(); - node = null; - } else { - node = mNextNode.get(property); - } - - if (node == null) { - node = new OrderingList(this, property); - mNextNode.put(property, node); - } - - return node; + OrderingList node; + if (mNextNode == null) { + mNextNode = new HashMap>(); + node = null; + } else { + node = mNextNode.get(property); + } + + if (node == null) { + node = new OrderingList(this, property); + mNextNode.put(property, node); + } + + return node; } } diff --git a/src/main/java/com/amazon/carbonado/qe/QueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/QueryExecutor.java index 024c31c..c81077f 100644 --- a/src/main/java/com/amazon/carbonado/qe/QueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/QueryExecutor.java @@ -65,7 +65,7 @@ public interface QueryExecutor { * * @return query ordering in an unmodifiable list */ - List> getOrdering(); + OrderingList getOrdering(); /** * Prints the native query to any appendable, if applicable. diff --git a/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java index 48defa7..b5fdcb9 100644 --- a/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java @@ -49,46 +49,46 @@ public abstract class SortedQueryExecutor extends AbstractQu private final Comparator mHandledComparator; private final Comparator mFinisherComparator; - private final List> mHandledOrderings; - private final List> mRemainderOrderings; + private final OrderingList mHandledOrdering; + private final OrderingList mRemainderOrdering; /** * @param executor executor to wrap - * @param handledOrderings optional handled orderings - * @param remainderOrderings required remainder orderings + * @param handledOrdering optional handled ordering + * @param remainderOrdering required remainder ordering * @throws IllegalArgumentException if executor is null or if remainder - * orderings is empty + * ordering is empty */ public SortedQueryExecutor(QueryExecutor executor, - List> handledOrderings, - List> remainderOrderings) + OrderingList handledOrdering, + OrderingList remainderOrdering) { if (executor == null) { throw new IllegalArgumentException(); } mExecutor = executor; - if (handledOrderings != null && handledOrderings.size() == 0) { - handledOrderings = null; + if (handledOrdering != null && handledOrdering.size() == 0) { + handledOrdering = null; } - if (remainderOrderings != null && remainderOrderings.size() == 0) { - remainderOrderings = null; + if (remainderOrdering != null && remainderOrdering.size() == 0) { + remainderOrdering = null; } - if (remainderOrderings == null) { + if (remainderOrdering == null) { throw new IllegalArgumentException(); } - if (handledOrderings == null) { + if (handledOrdering == null) { mHandledComparator = null; - mHandledOrderings = Collections.emptyList(); + mHandledOrdering = OrderingList.emptyList(); } else { - mHandledComparator = SortedCursor.createComparator(handledOrderings); - mHandledOrderings = handledOrderings; + mHandledComparator = SortedCursor.createComparator(handledOrdering); + mHandledOrdering = handledOrdering; } - mFinisherComparator = SortedCursor.createComparator(remainderOrderings); - mRemainderOrderings = remainderOrderings; + mFinisherComparator = SortedCursor.createComparator(remainderOrdering); + mRemainderOrdering = remainderOrdering; } public Cursor fetch(FilterValues values) throws FetchException { @@ -106,32 +106,26 @@ public abstract class SortedQueryExecutor extends AbstractQu return mExecutor.getFilter(); } - public List> getOrdering() { - if (mHandledOrderings.size() == 0) { - return mRemainderOrderings; + public OrderingList getOrdering() { + if (mHandledOrdering.size() == 0) { + return mRemainderOrdering; } - if (mRemainderOrderings.size() == 0) { - return mHandledOrderings; + if (mRemainderOrdering.size() == 0) { + return mHandledOrdering; } - List> ordering = new ArrayList> - (mHandledOrderings.size() + mRemainderOrderings.size()); - - ordering.addAll(mHandledOrderings); - ordering.addAll(mRemainderOrderings); - - return ordering; + return mHandledOrdering.concat(mRemainderOrdering); } public boolean printPlan(Appendable app, int indentLevel, FilterValues values) throws IOException { indent(app, indentLevel); - if (mHandledOrderings.size() == 0) { + if (mHandledOrdering.size() == 0) { app.append("full sort: "); } else { app.append("finish sort: "); } - app.append(mRemainderOrderings.toString()); + app.append(mRemainderOrdering.toString()); newline(app); mExecutor.printPlan(app, increaseIndent(indentLevel), values); return true; diff --git a/src/main/java/com/amazon/carbonado/qe/UnionQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/UnionQueryExecutor.java index 39e6157..5d2a5c6 100644 --- a/src/main/java/com/amazon/carbonado/qe/UnionQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/UnionQueryExecutor.java @@ -51,7 +51,7 @@ public class UnionQueryExecutor extends AbstractQueryExecuto } private final QueryExecutor[] mExecutors; - private final List> mTotalOrderings; + private final OrderingList mTotalOrdering; private final Comparator mOrderComparator; /** @@ -70,17 +70,17 @@ public class UnionQueryExecutor extends AbstractQueryExecuto if (executors == null || executors.size() == 0) { throw new IllegalArgumentException(); } - List> totalOrderings = executors.get(0).getOrdering(); + OrderingList totalOrdering = executors.get(0).getOrdering(); // Compare for consistency. for (int i=1; i fetch(FilterValues values) throws FetchException { @@ -105,8 +105,8 @@ public class UnionQueryExecutor extends AbstractQueryExecuto return filter; } - public List> getOrdering() { - return mTotalOrderings; + public OrderingList getOrdering() { + return mTotalOrdering; } public boolean printPlan(Appendable app, int indentLevel, FilterValues values) diff --git a/src/test/java/com/amazon/carbonado/qe/TestJoinedQueryExecutor.java b/src/test/java/com/amazon/carbonado/qe/TestJoinedQueryExecutor.java index e2c9f5e..7d352ed 100644 --- a/src/test/java/com/amazon/carbonado/qe/TestJoinedQueryExecutor.java +++ b/src/test/java/com/amazon/carbonado/qe/TestJoinedQueryExecutor.java @@ -175,16 +175,10 @@ public class TestJoinedQueryExecutor extends TestQueryExecutor { addressExecutor = new FilteredQueryExecutor (addressExecutor, Filter.filterFor(UserAddress.class, "state = ?")); - StorableProperty prop = StorableIntrospector - .examine(UserAddress.class).getAllProperties().get("country"); + OrderingList ordering = OrderingList.get(UserAddress.class, "+country"); - List> orderings = - new ArrayList>(); - - orderings.add(OrderedProperty.get(prop, Direction.ASCENDING)); - - addressExecutor = new ArraySortedQueryExecutor - (addressExecutor, null, orderings); + addressExecutor = + new ArraySortedQueryExecutor(addressExecutor, null, ordering); return addressExecutor; } diff --git a/src/test/java/com/amazon/carbonado/qe/TestQueryExecutor.java b/src/test/java/com/amazon/carbonado/qe/TestQueryExecutor.java index 4727a56..07558f1 100644 --- a/src/test/java/com/amazon/carbonado/qe/TestQueryExecutor.java +++ b/src/test/java/com/amazon/carbonado/qe/TestQueryExecutor.java @@ -83,17 +83,8 @@ public abstract class TestQueryExecutor extends TestCase { } } - protected List> createOrdering(String... properties) { - StorableInfo

info = StorableIntrospector.examine(Address.class); - Map> props = info.getAllProperties(); - - List> ordered = new ArrayList>(); - - for (String prop : properties) { - ordered.add(OrderedProperty.get(props.get(prop), Direction.ASCENDING)); - } - - return ordered; + protected OrderingList
createOrdering(String... properties) { + return OrderingList.get(Address.class, properties); } static void printPlan(QueryExecutor executor) { diff --git a/src/test/java/com/amazon/carbonado/qe/TestSortedQueryExecutor.java b/src/test/java/com/amazon/carbonado/qe/TestSortedQueryExecutor.java index 9e9906f..8e1eda2 100644 --- a/src/test/java/com/amazon/carbonado/qe/TestSortedQueryExecutor.java +++ b/src/test/java/com/amazon/carbonado/qe/TestSortedQueryExecutor.java @@ -47,7 +47,7 @@ public class TestSortedQueryExecutor extends TestQueryExecutor { QueryExecutor
unsorted = createExecutor(4, 2, 3, 1); Filter
filter = Filter.getOpenFilter(Address.class); FilterValues
values = filter.initialFilterValues(); - List> ordered = createOrdering("addressCountry"); + OrderingList
ordered = createOrdering("addressCountry"); QueryExecutor
executor = new ArraySortedQueryExecutor
(unsorted, null, ordered); @@ -65,8 +65,8 @@ public class TestSortedQueryExecutor extends TestQueryExecutor { QueryExecutor
unsorted = createExecutor(1, 2, 3, 4); Filter
filter = Filter.getOpenFilter(Address.class); FilterValues
values = filter.initialFilterValues(); - List> handled = createOrdering("addressCountry"); - List> finisher = createOrdering("addressState"); + OrderingList
handled = createOrdering("addressCountry"); + OrderingList
finisher = createOrdering("addressState"); QueryExecutor
executor = new ArraySortedQueryExecutor
(unsorted, handled, finisher); -- cgit v1.2.3