MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AndPredicateImpl.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 com.mysql.clusterj.core.spi.QueryExecutionContext;
21 import com.mysql.clusterj.core.store.Operation;
22 import com.mysql.clusterj.core.store.ScanFilter;
23 import com.mysql.clusterj.core.store.ScanOperation;
24 import com.mysql.clusterj.ClusterJException;
25 import com.mysql.clusterj.ClusterJFatalInternalException;
26 import com.mysql.clusterj.query.Predicate;
27 import java.util.ArrayList;
28 import java.util.List;
29 
30 public class AndPredicateImpl extends PredicateImpl {
31 
32  List<PredicateImpl> predicates = new ArrayList<PredicateImpl>();
33 
34  public AndPredicateImpl(QueryDomainTypeImpl<?> dobj,
35  PredicateImpl left, PredicateImpl right) {
36  super(dobj);
37  predicates.add(left);
38  predicates.add(right);
39  }
40 
41  @Override
42  public Predicate and(Predicate predicate) {
43  if (predicate instanceof ComparativePredicateImpl) {
44  predicates.add((PredicateImpl)predicate);
45  return this;
46  } else if (predicate instanceof AndPredicateImpl) {
47  predicates.addAll(((AndPredicateImpl)predicate).predicates);
48  return this;
49  } else if (predicate instanceof OrPredicateImpl) {
50  predicates.add((PredicateImpl)predicate);
51  return this;
52  } else if (predicate instanceof InPredicateImpl) {
53  predicates.add((PredicateImpl)predicate);
54  return this;
55  } else if (predicate instanceof NotPredicateImpl) {
56  predicates.add((PredicateImpl)predicate);
57  return this;
58  } else {
59  throw new UnsupportedOperationException(
60  local.message("ERR_NotImplemented"));
61  }
62  }
63 
64  public Predicate or(Predicate predicate) {
65  throw new UnsupportedOperationException(
66  local.message("ERR_NotImplemented"));
67  }
68 
69  public Predicate not() {
70  throw new UnsupportedOperationException(
71  local.message("ERR_NotImplemented"));
72  }
73 
74  @Override
75  public void markParameters() {
76  for (PredicateImpl predicateImpl: predicates) {
77  predicateImpl.markParameters();
78  }
79  }
80 
81  @Override
82  public void unmarkParameters() {
83  for (PredicateImpl predicateImpl: predicates) {
84  predicateImpl.unmarkParameters();
85  }
86  }
87 
93  @Override
95  ScanOperation op) {
96  try {
97  ScanFilter filter = op.getScanFilter(context);
98  filter.begin(ScanFilter.Group.GROUP_AND);
99  for (PredicateImpl predicate: predicates) {
100  predicate.filterCmpValue(context, op, filter);
101  }
102  filter.end();
103  } catch (Exception ex) {
104  throw new ClusterJException(
105  local.message("ERR_Get_NdbFilter"), ex);
106  }
107  }
108 
113  Operation op) {
114  for (PredicateImpl predicate: predicates) {
115  if (!(predicate instanceof EqualPredicateImpl)) {
117  local.message("ERR_Implementation_Should_Not_Occur"));
118  }
119  predicate.operationEqual(context, op);
120  }
121  }
122 
128  @Override
130  return getBestCandidateIndexFor(context, predicates.toArray(
131  new PredicateImpl[predicates.size()]));
132  }
133 
143  @Override
145  return predicates.size();
146  }
147 }