2 Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 package com.mysql.clusterj.core.query;
20 import com.mysql.clusterj.ClusterJException;
22 import com.mysql.clusterj.core.spi.QueryExecutionContext;
23 import com.mysql.clusterj.core.store.IndexScanOperation;
24 import com.mysql.clusterj.core.store.ScanFilter;
25 import com.mysql.clusterj.core.store.ScanOperation;
27 /** Implement the between operator with a property and two parameters.
31 public class BetweenPredicateImpl extends PredicateImpl {
33 /** The lower and upper bound parameters */
34 protected ParameterImpl lower;
35 protected ParameterImpl upper;
36 /** The property to compare with */
37 protected PropertyImpl property;
39 public BetweenPredicateImpl(QueryDomainTypeImpl<?> dobj,
40 PropertyImpl property, ParameterImpl lower, ParameterImpl upper) {
44 this.property = property;
45 lower.setProperty(property);
46 upper.setProperty(property);
49 public void markParameters() {
54 public void unmarkParameters() {
60 public void markBoundsForCandidateIndices(QueryExecutionContext context, CandidateIndexImpl[] candidateIndices) {
61 if (lower.getParameterValue(context) == null || upper.getParameterValue(context) == null) {
62 // null parameters cannot be used with index scans
65 property.markLowerBound(candidateIndices, this, false);
66 property.markUpperBound(candidateIndices, this, false);
69 /** Set the upper and lower bounds for the operation.
70 * Delegate to the property to actually call the setBounds for each
71 * of upper and lower bound.
72 * @param context the query context that contains the parameter values
73 * @param op the index scan operation on which to set bounds
76 public void operationSetBounds(QueryExecutionContext context,
77 IndexScanOperation op, boolean lastColumn) {
78 property.operationSetBounds(lower.getParameterValue(context),
79 IndexScanOperation.BoundType.BoundLE, op);
80 property.operationSetBounds(upper.getParameterValue(context),
81 IndexScanOperation.BoundType.BoundGE, op);
84 /** Set the upper bound for the operation.
85 * Delegate to the property to actually call the setBounds
86 * for the upper bound.
87 * @param context the query context that contains the parameter values
88 * @param op the index scan operation on which to set bounds
91 public void operationSetUpperBound(QueryExecutionContext context,
92 IndexScanOperation op, boolean lastColumn) {
93 property.operationSetBounds(upper.getParameterValue(context),
94 IndexScanOperation.BoundType.BoundGE, op);
97 /** Set the lower bound for the operation.
98 * Delegate to the property to actually call the setBounds
99 * for the lower bound.
100 * @param context the query context that contains the parameter values
101 * @param op the index scan operation on which to set bounds
104 public void operationSetLowerBound(QueryExecutionContext context,
105 IndexScanOperation op, boolean lastColumn) {
106 property.operationSetBounds(lower.getParameterValue(context),
107 IndexScanOperation.BoundType.BoundLE, op);
110 /** Create a filter for the operation. Set the condition into the
112 * @param context the query execution context with the parameter values
113 * @param op the operation
116 public void filterCmpValue(QueryExecutionContext context,
119 ScanFilter filter = op.getScanFilter(context);
121 filterCmpValue(context, op, filter);
123 } catch (Exception ex) {
124 throw new ClusterJException(
125 local.message("ERR_Get_NdbFilter"), ex);
129 /** Set the condition into the filter.
130 * @param context the query execution context with the parameter values
131 * @param op the operation
132 * @param filter the filter
135 public void filterCmpValue(QueryExecutionContext context,
136 ScanOperation op, ScanFilter filter) {
137 property.filterCmpValue(lower.getParameterValue(context),
138 ScanFilter.BinaryCondition.COND_GE, filter);
139 property.filterCmpValue(upper.getParameterValue(context),
140 ScanFilter.BinaryCondition.COND_LE, filter);