From 9e4cd7e3af4ff5326fcb7a1dde3861f64badab41 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 4 Nov 2006 00:27:28 +0000 Subject: Fixed exception when printing join plan with blank parameters. --- .../com/amazon/carbonado/filter/FilterValues.java | 91 ++++++++++++++++++++++ .../carbonado/qe/DelegatedQueryExecutor.java | 6 +- .../amazon/carbonado/qe/JoinedQueryExecutor.java | 4 +- .../com/amazon/carbonado/qe/StandardQuery.java | 2 - .../amazon/carbonado/qe/StandardQueryFactory.java | 2 - 5 files changed, 94 insertions(+), 11 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/filter/FilterValues.java b/src/main/java/com/amazon/carbonado/filter/FilterValues.java index 162194c..b9d3f5a 100644 --- a/src/main/java/com/amazon/carbonado/filter/FilterValues.java +++ b/src/main/java/com/amazon/carbonado/filter/FilterValues.java @@ -443,6 +443,7 @@ public class FilterValues implements Appender { * as used to construct this object. An IllegalStateException will result * otherwise. * + * @param filter filter must be bound * @return new object array * @throws IllegalStateException if any values are blank */ @@ -505,6 +506,96 @@ public class FilterValues implements Appender { return values; } + /** + * Returns all supplied values in this object, as required by the given + * Filter. Constant filter values are not included. The given Filter must + * be composed only of the same PropertyFilter instances as used to + * construct this object. An IllegalStateException will result otherwise. + * + * @param filter filter must be bound + * @return new object array + */ + public Object[] getSuppliedValuesFor(Filter filter) throws IllegalStateException { + // Traverse filter properties in reverse, since the filter likely was + // used to create this FilterValues instance. If so, then no value map + // needs to be constructed. + PropertyFilterList list = filter.getTailPropertyFilterList(); + if (list == null) { + return NO_VALUES; + } + + FilterValues prevValues = mPrevValues; + int blankCount; + if (prevValues == null || (blankCount= prevValues.mCurrentProperty.getBlankCount()) == 0) { + return NO_VALUES; + } + + int i = list.getPreviousRemaining() + 1; + + int valuesPos = Math.min(i, blankCount); + Object[] values = new Object[valuesPos]; + + FilterValues filterValues = this; + + for (; --i >= 0; list = list.getPrevious()) { + PropertyFilter propFilter = list.getPropertyFilter(); + + Object value; + + if (prevValues != null + && propFilter == prevValues.mCurrentProperty.getPropertyFilter()) { + + value = filterValues.mPrevValue; + + filterValues = prevValues; + prevValues = prevValues.mPrevValues; + + if (propFilter.isConstant()) { + continue; + } + } else { + if (propFilter.isConstant()) { + continue; + } + + if (i > 0 || mValueMap != null) { + if (isAssigned(propFilter)) { + value = getAssignedValue(propFilter); + } else { + continue; + } + } else { + // No need to force value map to be created since this is + // the last property to be processed. Do the same scan operation + // as performed by buildValueMap, except don't save the results. + + filterValues = this; + prevValues = mPrevValues; + + findValue: { + while (prevValues != null) { + if (propFilter == prevValues.mCurrentProperty.getPropertyFilter()) { + value = filterValues.mPrevValue; + break findValue; + } + filterValues = prevValues; + prevValues = prevValues.mPrevValues; + } + + continue; + } + } + } + + values[--valuesPos] = value; + if (valuesPos <= 0) { + break; + } + } + + return values; + } + private IllegalStateException valueNotFound(PropertyFilter propFilter) { return new IllegalStateException ("Property value not found for: \"" + propFilter + "\" in filter \"" + this + '"'); diff --git a/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java index 1fe3ba8..b4bc0a3 100644 --- a/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java @@ -126,14 +126,10 @@ public class DelegatedQueryExecutor implements QueryExecutor } private Query applyFilterValues(FilterValues values) { - // FIXME: figure out how to transfer values directly to query. - Query query = mQuery; Filter filter = query.getFilter(); - // FIXME: this code can get confused if filter has constants. if (values != null && filter != null && query.getBlankParameterCount() != 0) { - // FIXME: throws exception if not all values supplied - query = query.withValues(values.getValuesFor(filter)); + query = query.withValues(values.getSuppliedValuesFor(filter)); } return query; } diff --git a/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java index f3399a5..00ffda3 100644 --- a/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java @@ -595,8 +595,8 @@ public class JoinedQueryExecutor if (values == null) { return null; } - // FIXME: throws exception if not all values supplied - return mOuterLoopFilterValues.withValues(values.getValuesFor(mSourceFilterAsFromTarget)); + return mOuterLoopFilterValues + .withValues(values.getSuppliedValuesFor(mSourceFilterAsFromTarget)); } @SuppressWarnings("unused") diff --git a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java index d7f5263..c1038c7 100644 --- a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java @@ -162,8 +162,6 @@ public abstract class StandardQuery extends AbstractQuery if (mValues == null) { return new EmptyQuery(queryFactory(), mOrdering); } - // FIXME: Just like with DelegatedQueryExecutor, need a better way of - // transfering values. FilterValues newValues = mValues.getFilter().not() .initialFilterValues().withValues(mValues.getSuppliedValues()); return createQuery(newValues, mOrdering); diff --git a/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java b/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java index c7ac720..06767c5 100644 --- a/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java +++ b/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java @@ -157,8 +157,6 @@ public abstract class StandardQueryFactory implements QueryF if (values == null) { query = query(Filter.getOpenFilter(mType), ordering); } else { - // FIXME: Just like with DelegatedQueryExecutor, need a better way - // of transfering values. query = query(values.getFilter(), ordering).withValues(values.getSuppliedValues()); } return query; -- cgit v1.2.3