001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.server.xdbm.search; 021 022 023import org.apache.directory.api.ldap.model.entry.Entry; 024import org.apache.directory.api.ldap.model.exception.LdapException; 025import org.apache.directory.api.ldap.model.filter.ExprNode; 026import org.apache.directory.server.core.api.partition.PartitionTxn; 027import org.apache.directory.server.xdbm.IndexEntry; 028 029 030/** 031 * Evaluates candidate entries to see if they match a filter expression. 032 * 033 * Evaluators contain various overloads to the evaluate method. Often a 034 * developer working in this region of the code may wonder when to use one 035 * override verses another. The overload taking an IndexEntry argument is 036 * specifically suited for use when there is the possibility of multiple entry 037 * lookups from the master table. If the same candidate in the form of an 038 * IndexEntry is evaluated more then this overload is more efficient since it 039 * stores the looked up entry in the IndexEntry preventing multiple lookups. 040 * 041 * If the index entry is already populated with an entry object, and some 042 * evaluation is required then it is preferrable to use the overload that 043 * takes a Long id instead. Likewise if it is known in advance that the 044 * expression is a leaf node built on an indexed attribute then the overload 045 * with the Long id argument is also preferrable unless an IndexEntry already 046 * exists in which case it makes no difference. 047 * 048 * The overload taking the ServerEntry itself is a last resort option and ok 049 * to use when it is known that no index exists for the attributes of 050 * Evaluators based on leaf expressions. 051 * 052 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 053 */ 054public interface Evaluator<N extends ExprNode> 055{ 056 /** 057 * Evaluates a candidate to determine if a filter expression selects it. 058 * If an IndexEntry does has a null reference to the entry object, this 059 * Evaluator may set it if it has to access the full entry within the 060 * master table of the store. Subsequent evaluations on the IndexEntry 061 * then need not access the store to retreive the entry if they need to 062 * access it's attributes. 063 * 064 * @param partitionTxn The transaction to use 065 * @param entry the index record of the entry to evaluate 066 * @return true if filter selects the candidate false otherwise 067 * @throws LdapException if there are faults during evaluation 068 */ 069 boolean evaluate( PartitionTxn partitionTxn, IndexEntry<?, String> entry ) throws LdapException; 070 071 072 /** 073 * Evaluates whether or not a candidate, satisfies the expression 074 * associated with this Evaluator . 075 * 076 * @param entry the candidate entry 077 * @return true if filter selects the candidate false otherwise 078 * @throws LdapException if there are faults during evaluation 079 */ 080 boolean evaluate( Entry entry ) throws LdapException; 081 082 083 /** 084 * Gets the expression used by this expression Evaluator. 085 * 086 * @return the AST for the expression 087 */ 088 N getExpression(); 089 090 091 /** 092 * Pretty-print an Evaluator 093 * @param tabs The tabs to add before the evaluator 094 * @return The pretty-printed evaluator and its descendants 095 */ 096 String toString( String tabs ); 097}