]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
2126ef0459299017837a31746042fea83abd0b7c
[packages/trusty/mysql-wsrep-5.6.git] /
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
27 /** Implement the between operator with a property and two parameters.
28  *
29  * 
30  */
31 public class BetweenPredicateImpl extends PredicateImpl {
32
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;
38
39     public BetweenPredicateImpl(QueryDomainTypeImpl<?> dobj,
40             PropertyImpl property, ParameterImpl lower, ParameterImpl upper) {
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
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
74      */
75     @Override
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);
82     }
83
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
89      */
90     @Override
91     public void operationSetUpperBound(QueryExecutionContext context,
92             IndexScanOperation op, boolean lastColumn) {
93         property.operationSetBounds(upper.getParameterValue(context),
94                 IndexScanOperation.BoundType.BoundGE, op);
95     }
96
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
102      */
103     @Override
104     public void operationSetLowerBound(QueryExecutionContext context,
105             IndexScanOperation op, boolean lastColumn) {
106         property.operationSetBounds(lower.getParameterValue(context),
107                 IndexScanOperation.BoundType.BoundLE, op);
108     }
109
110     /** Create a filter for the operation. Set the condition into the
111      * new filter.
112      * @param context the query execution context with the parameter values
113      * @param op the operation
114      */
115     @Override
116     public void filterCmpValue(QueryExecutionContext context,
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
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
133      */
134     @Override
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);
141     }
142
143 }