MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PropertyImpl.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.ClusterJUserException;
21 
22 import com.mysql.clusterj.core.spi.DomainFieldHandler;
23 import com.mysql.clusterj.core.spi.QueryExecutionContext;
24 import com.mysql.clusterj.core.store.IndexScanOperation;
25 import com.mysql.clusterj.core.store.Operation;
26 import com.mysql.clusterj.core.store.ScanFilter;
27 
28 import com.mysql.clusterj.core.util.I18NHelper;
29 import com.mysql.clusterj.core.util.Logger;
30 import com.mysql.clusterj.core.util.LoggerFactoryService;
31 
32 import com.mysql.clusterj.query.Predicate;
33 import com.mysql.clusterj.query.PredicateOperand;
34 
35 public class PropertyImpl implements PredicateOperand {
36 
38  static final I18NHelper local = I18NHelper.getInstance(PropertyImpl.class);
39 
41  static final Logger logger = LoggerFactoryService.getFactory().getInstance(PropertyImpl.class);
42 
44  protected QueryDomainTypeImpl<?> dobj;
45 
48 
50  private boolean complexParameter = false;
51 
52  public PropertyImpl(QueryDomainTypeImpl<?> dobj, DomainFieldHandler fmd) {
53  this.dobj = dobj;
54  this.fmd = fmd;
55  }
56 
57  public void setComplexParameter() {
58  complexParameter = true;
59  }
60 
61  public void operationSetBounds(Object value, IndexScanOperation.BoundType type, IndexScanOperation op) {
62  fmd.operationSetBounds(value, type, op);
63  }
64 
65  public void operationEqual(Object value, Operation op) {
66  fmd.operationEqual(value, op);
67  }
68 
69  void objectSetValuesFor(Object value, Object row, String indexName) {
70  fmd.objectSetValueFor(value, row, indexName);
71  }
72 
73  void operationEqualFor(Object parameterValue, Operation op, String indexName) {
74  fmd.operationEqualForIndex(parameterValue, op, indexName);
75  }
76 
77  public void filterCmpValue(Object value, ScanFilter.BinaryCondition condition, ScanFilter filter) {
78  fmd.filterCompareValue(value, condition, filter);
79  }
80 
82  if (!(other instanceof ParameterImpl)) {
83  throw new ClusterJUserException(
84  local.message("ERR_Only_Parameters", "equal"));
85  }
86  return (Predicate) new EqualPredicateImpl(dobj, this, (ParameterImpl)other);
87  }
88 
90  if (!((lower instanceof ParameterImpl) && (upper instanceof ParameterImpl))) {
91  throw new ClusterJUserException(
92  local.message("ERR_Only_Parameters", "between"));
93  }
94  return (Predicate) new BetweenPredicateImpl(dobj, this, (ParameterImpl)lower, (ParameterImpl)upper);
95  }
96 
98  if (!(other instanceof ParameterImpl)) {
99  throw new ClusterJUserException(
100  local.message("ERR_Only_Parameters", "greaterThan"));
101  }
102  return (Predicate) new GreaterThanPredicateImpl(dobj, this, (ParameterImpl)other);
103  }
104 
106  if (!(other instanceof ParameterImpl)) {
107  throw new ClusterJUserException(
108  local.message("ERR_Only_Parameters", "greaterEqual"));
109  }
110  return (Predicate) new GreaterEqualPredicateImpl(dobj, this, (ParameterImpl)other);
111  }
112 
114  if (!(other instanceof ParameterImpl)) {
115  throw new ClusterJUserException(
116  local.message("ERR_Only_Parameters", "lessThan"));
117  }
118  return (Predicate) new LessThanPredicateImpl(dobj, this, (ParameterImpl)other);
119  }
120 
122  if (!(other instanceof ParameterImpl)) {
123  throw new ClusterJUserException(
124  local.message("ERR_Only_Parameters", "lessEqual"));
125  }
126  return (Predicate) new LessEqualPredicateImpl(dobj, this, (ParameterImpl)other);
127  }
128 
129  public Predicate in(PredicateOperand other) {
130  if (!(other instanceof ParameterImpl)) {
131  throw new ClusterJUserException(
132  local.message("ERR_Only_Parameters", "in"));
133  }
134  return (Predicate) new InPredicateImpl(dobj, this, (ParameterImpl)other);
135  }
136 
138  if (!(other instanceof ParameterImpl)) {
139  throw new ClusterJUserException(
140  local.message("ERR_Only_Parameters", "like"));
141  }
142  return (Predicate) new LikePredicateImpl(dobj, this, (ParameterImpl)other);
143  }
144 
145  void markLowerBound(CandidateIndexImpl[] candidateIndices, PredicateImpl predicate, boolean strict) {
146  fmd.markLowerBounds(candidateIndices, predicate, strict);
147  }
148 
149  void markUpperBound(CandidateIndexImpl[] candidateIndices, PredicateImpl predicate, boolean strict) {
150  fmd.markUpperBounds(candidateIndices, predicate, strict);
151  }
152 
153  void markEqualBound(CandidateIndexImpl[] candidateIndices, PredicateImpl predicate) {
154  fmd.markEqualBounds(candidateIndices, predicate);
155  }
156 
157  public void markInBound(CandidateIndexImpl[] candidateIndices, InPredicateImpl predicate) {
158  fmd.markInBounds(candidateIndices, predicate);
159  }
160 
161  public Object getParameterValue(QueryExecutionContext context, String parameterName) {
162  if (complexParameter) {
163  // the parameter is just an object at this point -- to be checked elsewhere
164  return context.getParameterValue(parameterName);
165  } else {
166  return fmd.getValue(context, parameterName);
167  }
168  }
169 
170 }