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.ClusterJUserException;
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;
28 import com.mysql.clusterj.core.util.I18NHelper;
29 import com.mysql.clusterj.core.util.Logger;
30 import com.mysql.clusterj.core.util.LoggerFactoryService;
32 import com.mysql.clusterj.query.Predicate;
33 import com.mysql.clusterj.query.PredicateOperand;
35 public class PropertyImpl implements PredicateOperand {
37 /** My message translator */
38 static final I18NHelper local = I18NHelper.getInstance(PropertyImpl.class);
41 static final Logger logger = LoggerFactoryService.getFactory().getInstance(PropertyImpl.class);
43 /** My domain object. */
44 protected QueryDomainTypeImpl<?> dobj;
47 protected DomainFieldHandler fmd;
49 /** Is this property used with a complex parameter? */
50 private boolean complexParameter = false;
52 public PropertyImpl(QueryDomainTypeImpl<?> dobj, DomainFieldHandler fmd) {
57 public void setComplexParameter() {
58 complexParameter = true;
61 public void operationSetBounds(Object value, IndexScanOperation.BoundType type, IndexScanOperation op) {
62 fmd.operationSetBounds(value, type, op);
65 public void operationEqual(Object value, Operation op) {
66 fmd.operationEqual(value, op);
69 void objectSetValuesFor(Object value, Object row, String indexName) {
70 fmd.objectSetValueFor(value, row, indexName);
73 void operationEqualFor(Object parameterValue, Operation op, String indexName) {
74 fmd.operationEqualForIndex(parameterValue, op, indexName);
77 public void filterCmpValue(Object value, ScanFilter.BinaryCondition condition, ScanFilter filter) {
78 fmd.filterCompareValue(value, condition, filter);
81 public Predicate equal(PredicateOperand other) {
82 if (!(other instanceof ParameterImpl)) {
83 throw new ClusterJUserException(
84 local.message("ERR_Only_Parameters", "equal"));
86 return (Predicate) new EqualPredicateImpl(dobj, this, (ParameterImpl)other);
89 public Predicate between(PredicateOperand lower, PredicateOperand upper) {
90 if (!((lower instanceof ParameterImpl) && (upper instanceof ParameterImpl))) {
91 throw new ClusterJUserException(
92 local.message("ERR_Only_Parameters", "between"));
94 return (Predicate) new BetweenPredicateImpl(dobj, this, (ParameterImpl)lower, (ParameterImpl)upper);
97 public Predicate greaterThan(PredicateOperand other) {
98 if (!(other instanceof ParameterImpl)) {
99 throw new ClusterJUserException(
100 local.message("ERR_Only_Parameters", "greaterThan"));
102 return (Predicate) new GreaterThanPredicateImpl(dobj, this, (ParameterImpl)other);
105 public Predicate greaterEqual(PredicateOperand other) {
106 if (!(other instanceof ParameterImpl)) {
107 throw new ClusterJUserException(
108 local.message("ERR_Only_Parameters", "greaterEqual"));
110 return (Predicate) new GreaterEqualPredicateImpl(dobj, this, (ParameterImpl)other);
113 public Predicate lessThan(PredicateOperand other) {
114 if (!(other instanceof ParameterImpl)) {
115 throw new ClusterJUserException(
116 local.message("ERR_Only_Parameters", "lessThan"));
118 return (Predicate) new LessThanPredicateImpl(dobj, this, (ParameterImpl)other);
121 public Predicate lessEqual(PredicateOperand other) {
122 if (!(other instanceof ParameterImpl)) {
123 throw new ClusterJUserException(
124 local.message("ERR_Only_Parameters", "lessEqual"));
126 return (Predicate) new LessEqualPredicateImpl(dobj, this, (ParameterImpl)other);
129 public Predicate in(PredicateOperand other) {
130 if (!(other instanceof ParameterImpl)) {
131 throw new ClusterJUserException(
132 local.message("ERR_Only_Parameters", "in"));
134 return (Predicate) new InPredicateImpl(dobj, this, (ParameterImpl)other);
137 public Predicate like(PredicateOperand other) {
138 if (!(other instanceof ParameterImpl)) {
139 throw new ClusterJUserException(
140 local.message("ERR_Only_Parameters", "like"));
142 return (Predicate) new LikePredicateImpl(dobj, this, (ParameterImpl)other);
145 void markLowerBound(CandidateIndexImpl[] candidateIndices, PredicateImpl predicate, boolean strict) {
146 fmd.markLowerBounds(candidateIndices, predicate, strict);
149 void markUpperBound(CandidateIndexImpl[] candidateIndices, PredicateImpl predicate, boolean strict) {
150 fmd.markUpperBounds(candidateIndices, predicate, strict);
153 void markEqualBound(CandidateIndexImpl[] candidateIndices, PredicateImpl predicate) {
154 fmd.markEqualBounds(candidateIndices, predicate);
157 public void markInBound(CandidateIndexImpl[] candidateIndices, InPredicateImpl predicate) {
158 fmd.markInBounds(candidateIndices, predicate);
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);
166 return fmd.getValue(context, parameterName);