MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BetweenPredicateImpl.java
1 /*
2  Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3 
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.
7 
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.
12 
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
16 */
17 
18 package com.mysql.clusterj.core.query;
19 
20 import com.mysql.clusterj.ClusterJException;
21 
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;
26 
31 public class BetweenPredicateImpl extends PredicateImpl {
32 
34  protected ParameterImpl lower;
35  protected ParameterImpl upper;
38 
39  public BetweenPredicateImpl(QueryDomainTypeImpl<?> dobj,
41  super(dobj);
42  this.lower = lower;
43  this.upper = upper;
44  this.property = property;
45  lower.setProperty(property);
46  upper.setProperty(property);
47  }
48 
49  public void markParameters() {
50  lower.mark();
51  upper.mark();
52  }
53 
54  public void unmarkParameters() {
55  lower.unmark();
56  upper.unmark();
57  }
58 
59  @Override
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
63  return;
64  }
65  property.markLowerBound(candidateIndices, this, false);
66  property.markUpperBound(candidateIndices, this, false);
67  }
68 
75  @Override
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);
82  }
83 
90  @Override
92  IndexScanOperation op, boolean lastColumn) {
93  property.operationSetBounds(upper.getParameterValue(context),
94  IndexScanOperation.BoundType.BoundGE, op);
95  }
96 
103  @Override
105  IndexScanOperation op, boolean lastColumn) {
106  property.operationSetBounds(lower.getParameterValue(context),
107  IndexScanOperation.BoundType.BoundLE, op);
108  }
109 
115  @Override
117  ScanOperation op) {
118  try {
119  ScanFilter filter = op.getScanFilter(context);
120  filter.begin();
121  filterCmpValue(context, op, filter);
122  filter.end();
123  } catch (Exception ex) {
124  throw new ClusterJException(
125  local.message("ERR_Get_NdbFilter"), ex);
126  }
127  }
128 
134  @Override
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);
141  }
142 
143 }