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 java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
24 import com.mysql.clusterj.ClusterJException;
25 import com.mysql.clusterj.core.spi.QueryExecutionContext;
26 import com.mysql.clusterj.core.store.ScanFilter;
27 import com.mysql.clusterj.core.store.ScanOperation;
28 import com.mysql.clusterj.core.store.ScanFilter.Group;
29 import com.mysql.clusterj.query.Predicate;
31 public class OrPredicateImpl extends PredicateImpl {
33 /** The predicates being ORed */
34 List<PredicateImpl> predicates = new ArrayList<PredicateImpl>();
36 /** Create an OrPredicateImpl from two predicates.
38 * @param dobj the QueryDomainObject
39 * @param left one predicate
40 * @param right the other predicate
42 public OrPredicateImpl(QueryDomainTypeImpl<?> dobj,
43 PredicateImpl left, PredicateImpl right) {
46 predicates.add(right);
50 public Predicate or(Predicate predicate) {
51 if (predicate instanceof ComparativePredicateImpl) {
52 predicates.add((PredicateImpl)predicate);
54 } else if (predicate instanceof AndPredicateImpl) {
55 predicates.add((PredicateImpl)predicate);
57 } else if (predicate instanceof OrPredicateImpl) {
58 predicates.addAll(((OrPredicateImpl)predicate).predicates);
60 } else if (predicate instanceof InPredicateImpl) {
61 predicates.add((PredicateImpl)predicate);
64 throw new UnsupportedOperationException(
65 local.message("ERR_NotImplemented"));
70 public void markParameters() {
71 // Nothing to do because "or" can't use indexes
75 public void unmarkParameters() {
76 // Nothing to do because "or" can't use indexes
79 void markBoundsForCandidateIndices(QueryExecutionContext context,
80 CandidateIndexImpl[] candidateIndices) {
81 // Nothing to do because "or" can't use indexes
84 /** Create a filter for the operation. Call the ORed predicates to set
86 * @param context the query execution context with the parameter values
87 * @param op the operation
89 public void filterCmpValue(QueryExecutionContext context,
92 ScanFilter filter = op.getScanFilter(context);
93 filter.begin(Group.GROUP_OR);
94 for (PredicateImpl predicate: predicates) {
95 predicate.filterCmpValue(context, op, filter);
98 } catch (ClusterJException ex) {
100 } catch (Exception ex) {
101 throw new ClusterJException(
102 local.message("ERR_Get_NdbFilter"), ex);
106 /** Use an existing filter for the operation. Call the ORed predicates to set
108 * @param context the query execution context with the parameter values
109 * @param op the operation
110 * @param filter the existing filter
112 public void filterCmpValue(QueryExecutionContext context,
113 ScanOperation op, ScanFilter filter) {
115 filter.begin(Group.GROUP_OR);
116 for (PredicateImpl predicate: predicates) {
117 predicate.filterCmpValue(context, op, filter);
120 } catch (ClusterJException ex) {
122 } catch (Exception ex) {
123 throw new ClusterJException(
124 local.message("ERR_Get_NdbFilter"), ex);