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.api.ldap.model.entry.Entry; 24 import org.apache.directory.api.ldap.model.exception.LdapException; 25 import org.apache.directory.api.ldap.model.filter.ExprNode; 26 import org.apache.directory.server.core.api.partition.PartitionTxn; 27 import org.apache.directory.server.xdbm.IndexEntry; 28 29 30 /** 31 * Evaluates candidate entries to see if they match a filter expression. 32 * 33 * Evaluators contain various overloads to the evaluate method. Often a 34 * developer working in this region of the code may wonder when to use one 35 * override verses another. The overload taking an IndexEntry argument is 36 * specifically suited for use when there is the possibility of multiple entry 37 * lookups from the master table. If the same candidate in the form of an 38 * IndexEntry is evaluated more then this overload is more efficient since it 39 * stores the looked up entry in the IndexEntry preventing multiple lookups. 40 * 41 * If the index entry is already populated with an entry object, and some 42 * evaluation is required then it is preferrable to use the overload that 43 * takes a Long id instead. Likewise if it is known in advance that the 44 * expression is a leaf node built on an indexed attribute then the overload 45 * with the Long id argument is also preferrable unless an IndexEntry already 46 * exists in which case it makes no difference. 47 * 48 * The overload taking the ServerEntry itself is a last resort option and ok 49 * to use when it is known that no index exists for the attributes of 50 * Evaluators based on leaf expressions. 51 * 52 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 53 */ 54 public interface Evaluator<N extends ExprNode> 55 { 56 /** 57 * Evaluates a candidate to determine if a filter expression selects it. 58 * If an IndexEntry does has a null reference to the entry object, this 59 * Evaluator may set it if it has to access the full entry within the 60 * master table of the store. Subsequent evaluations on the IndexEntry 61 * then need not access the store to retreive the entry if they need to 62 * access it's attributes. 63 * 64 * @param partitionTxn The transaction to use 65 * @param entry the index record of the entry to evaluate 66 * @return true if filter selects the candidate false otherwise 67 * @throws LdapException if there are faults during evaluation 68 */ 69 boolean evaluate( PartitionTxn partitionTxn, IndexEntry<?, String> entry ) throws LdapException; 70 71 72 /** 73 * Evaluates whether or not a candidate, satisfies the expression 74 * associated with this Evaluator . 75 * 76 * @param entry the candidate entry 77 * @return true if filter selects the candidate false otherwise 78 * @throws LdapException if there are faults during evaluation 79 */ 80 boolean evaluate( Entry entry ) throws LdapException; 81 82 83 /** 84 * Gets the expression used by this expression Evaluator. 85 * 86 * @return the AST for the expression 87 */ 88 N getExpression(); 89 90 91 /** 92 * Pretty-print an Evaluator 93 * @param tabs The tabs to add before the evaluator 94 * @return The pretty-printed evaluator and its descendants 95 */ 96 String toString( String tabs ); 97 }