View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.xdbm.search;
21  
22  
23  import org.apache.directory.shared.ldap.filter.ExprNode;
24  import org.apache.directory.server.xdbm.IndexEntry;
25  
26  
27  /**
28   * Evaluates candidate entries to see if they match a filter expression.
29   *
30   * Evaluators contain various overloads to the evaluate method.  Often a
31   * developer working in this region of the code may wonder when to use one
32   * override verses another.  The overload taking an IndexEntry argument is
33   * specifically suited for use when there is the possibility of multiple entry
34   * lookups from the master table.  If the same candidate in the form of an
35   * IndexEntry is evaluated more then this overload is more efficient since it
36   * stores the looked up entry in the IndexEntry preventing multiple lookups.
37   *
38   * If the index entry is already populated with an entry object, and some
39   * evaluation is required then it is preferrable to use the overload that
40   * takes a Long id instead.  Likewise if it is known in advance that the
41   * expression is a leaf node built on an indexed attribute then the overload
42   * with the Long id argument is also preferrable unless an IndexEntry already
43   * exists in which case it makes no difference.
44   *
45   * The overload taking the ServerEntry itself is a last resort option and ok
46   * to use when it is known that no index exists for the attributes of
47   * Evaluators based on leaf expressions.
48   * 
49   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
50   * @version $Rev: 656489 $
51   */
52  public interface Evaluator<N extends ExprNode,E>
53  {
54      /**
55       * Evaluates a candidate to determine if a filter expression selects it.
56       * If an IndexEntry does has a null reference to the entry object, this
57       * Evaluator may set it if it has to access the full entry within the
58       * master table of the store.  Subsequent evaluations on the IndexEntry
59       * then need not access the store to retreive the entry if they need to
60       * access it's attributes.
61       * 
62       * @param entry the index record of the entry to evaluate
63       * @return true if filter selects the candidate false otherwise
64       * @throws Exception if there are faults during evaluation
65       */
66      boolean evaluate( IndexEntry<?, E> entry ) throws Exception;
67  
68  
69      /**
70       * Evaluates whether or not a candidate, specified by an id, satisfies the
71       * expression associated with this Evaluator .
72       *
73       * @param id the identifier for the candidate entry
74       * @return true if filter selects the candidate false otherwise
75       * @throws Exception if there are faults during evaluation
76       */
77      boolean evaluate( Long id ) throws Exception;
78  
79  
80      /**
81       * Evaluates whether or not a candidate, satisfies the expression
82       * associated with this Evaluator .
83       *
84       * @param entry the candidate entry
85       * @return true if filter selects the candidate false otherwise
86       * @throws Exception if there are faults during evaluation
87       */
88      boolean evaluate( E entry ) throws Exception;
89  
90  
91      /**
92       * Gets the expression used by this expression Evaluator.
93       *
94       * @return the AST for the expression
95       */
96      N getExpression();
97  }