summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon')
-rw-r--r--src/main/java/com/amazon/carbonado/filter/FilterValues.java91
-rw-r--r--src/main/java/com/amazon/carbonado/qe/DelegatedQueryExecutor.java6
-rw-r--r--src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java4
-rw-r--r--src/main/java/com/amazon/carbonado/qe/StandardQuery.java2
-rw-r--r--src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java2
5 files changed, 94 insertions, 11 deletions
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<S extends Storable> 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<S extends Storable> 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<S> 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<S> list = filter.getTailPropertyFilterList();
+ if (list == null) {
+ return NO_VALUES;
+ }
+
+ FilterValues<S> 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<S> 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<S> 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<S extends Storable> implements QueryExecutor
}
private Query<S> applyFilterValues(FilterValues<S> values) {
- // FIXME: figure out how to transfer values directly to query.
-
Query<S> query = mQuery;
Filter<S> 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<S extends Storable, T extends Storable>
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<S extends Storable> extends AbstractQuery<S>
if (mValues == null) {
return new EmptyQuery<S>(queryFactory(), mOrdering);
}
- // FIXME: Just like with DelegatedQueryExecutor, need a better way of
- // transfering values.
FilterValues<S> 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<S extends Storable> 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;