MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OrPredicateImpl.java
1 /*
2  Copyright (c) 2010, 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 java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 
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;
30 
31 public class OrPredicateImpl extends PredicateImpl {
32 
34  List<PredicateImpl> predicates = new ArrayList<PredicateImpl>();
35 
42  public OrPredicateImpl(QueryDomainTypeImpl<?> dobj,
43  PredicateImpl left, PredicateImpl right) {
44  super(dobj);
45  predicates.add(left);
46  predicates.add(right);
47  }
48 
49  @Override
50  public Predicate or(Predicate predicate) {
51  if (predicate instanceof ComparativePredicateImpl) {
52  predicates.add((PredicateImpl)predicate);
53  return this;
54  } else if (predicate instanceof AndPredicateImpl) {
55  predicates.add((PredicateImpl)predicate);
56  return this;
57  } else if (predicate instanceof OrPredicateImpl) {
58  predicates.addAll(((OrPredicateImpl)predicate).predicates);
59  return this;
60  } else if (predicate instanceof InPredicateImpl) {
61  predicates.add((PredicateImpl)predicate);
62  return this;
63  } else {
64  throw new UnsupportedOperationException(
65  local.message("ERR_NotImplemented"));
66  }
67  }
68 
69  @Override
70  public void markParameters() {
71  // Nothing to do because "or" can't use indexes
72  }
73 
74  @Override
75  public void unmarkParameters() {
76  // Nothing to do because "or" can't use indexes
77  }
78 
79  void markBoundsForCandidateIndices(QueryExecutionContext context,
80  CandidateIndexImpl[] candidateIndices) {
81  // Nothing to do because "or" can't use indexes
82  }
83 
90  ScanOperation op) {
91  try {
92  ScanFilter filter = op.getScanFilter(context);
93  filter.begin(Group.GROUP_OR);
94  for (PredicateImpl predicate: predicates) {
95  predicate.filterCmpValue(context, op, filter);
96  }
97  filter.end();
98  } catch (ClusterJException ex) {
99  throw ex;
100  } catch (Exception ex) {
101  throw new ClusterJException(
102  local.message("ERR_Get_NdbFilter"), ex);
103  }
104  }
105 
113  ScanOperation op, ScanFilter filter) {
114  try {
115  filter.begin(Group.GROUP_OR);
116  for (PredicateImpl predicate: predicates) {
117  predicate.filterCmpValue(context, op, filter);
118  }
119  filter.end();
120  } catch (ClusterJException ex) {
121  throw ex;
122  } catch (Exception ex) {
123  throw new ClusterJException(
124  local.message("ERR_Get_NdbFilter"), ex);
125  }
126  }
127 
128 }