From b1ba29c24f6c48c9b028bc8c4c5e9c729092f5ac Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 11 Sep 2006 01:33:12 +0000 Subject: Completed new query engine implementation. --- .../com/amazon/carbonado/repo/toy/ToyStorage.java | 62 +++++++++++++--------- 1 file changed, 37 insertions(+), 25 deletions(-) (limited to 'src/test/java/com/amazon/carbonado/repo/toy') diff --git a/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java b/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java index 84792ad..bafa244 100644 --- a/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java +++ b/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java @@ -48,7 +48,9 @@ import com.amazon.carbonado.filter.FilterValues; import com.amazon.carbonado.info.OrderedProperty; import com.amazon.carbonado.info.StorableIntrospector; -import com.amazon.carbonado.qe.ArraySortedQueryExecutor; +import com.amazon.carbonado.qe.QueryExecutorFactory; +import com.amazon.carbonado.qe.QueryFactory; +import com.amazon.carbonado.qe.SortedQueryExecutor; import com.amazon.carbonado.qe.FilteredQueryExecutor; import com.amazon.carbonado.qe.IterableQueryExecutor; import com.amazon.carbonado.qe.OrderingList; @@ -59,7 +61,9 @@ import com.amazon.carbonado.qe.StandardQuery; * * @author Brian S O'Neill */ -public class ToyStorage implements Storage, MasterSupport { +public class ToyStorage + implements Storage, MasterSupport, QueryFactory, QueryExecutorFactory +{ final ToyRepository mRepo; final Class mType; @@ -89,18 +93,36 @@ public class ToyStorage implements Storage, MasterSupport return (S) mInstanceFactory.instantiate(this); } - public Query query() throws FetchException { + public Query query() { return new ToyQuery(null, null); } - public Query query(String filter) throws FetchException { + public Query query(String filter) { return query(Filter.filterFor(mType, filter)); } - public Query query(Filter filter) throws FetchException { + public Query query(Filter filter) { return new ToyQuery(filter.initialFilterValues(), null); } + public Query query(FilterValues values, OrderingList ordering) { + return new ToyQuery(values, ordering); + } + + public QueryExecutor executor(Filter filter, OrderingList ordering) { + QueryExecutor executor = new IterableQueryExecutor(mType, mData, mDataLock); + + if (filter != null) { + executor = new FilteredQueryExecutor(executor, filter); + } + + if (ordering.size() > 0) { + executor = new SortedQueryExecutor(null, executor, null, ordering); + } + + return executor; + } + public boolean addTrigger(Trigger trigger) { return false; } @@ -217,34 +239,24 @@ public class ToyStorage implements Storage, MasterSupport } private class ToyQuery extends StandardQuery { - ToyQuery(FilterValues values, OrderingList orderings) { - super(values, orderings); + ToyQuery(FilterValues values, OrderingList ordering) { + super(values, ordering); } - protected Storage getStorage() { - return ToyStorage.this; - } - - protected Transaction enterTransactionForDelete(IsolationLevel level) { + protected Transaction enterTransaction(IsolationLevel level) { return mRepo.enterTransaction(level); } - protected QueryExecutor getExecutor(FilterValues values, OrderingList orderings) { - QueryExecutor executor = new IterableQueryExecutor(mType, mData, mDataLock); - - if (values != null) { - executor = new FilteredQueryExecutor(executor, values.getFilter()); - } - - if (orderings.size() > 0) { - executor = new ArraySortedQueryExecutor(executor, null, orderings); - } + protected QueryFactory queryFactory() { + return ToyStorage.this; + } - return executor; + protected QueryExecutorFactory executorFactory() { + return ToyStorage.this; } - protected StandardQuery newInstance(FilterValues values, OrderingList orderings) { - return new ToyQuery(values, orderings); + protected StandardQuery newInstance(FilterValues values, OrderingList ordering) { + return new ToyQuery(values, ordering); } } } -- cgit v1.2.3