1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.xdbm.search.evaluator;
21
22
23 import java.util.Iterator;
24
25 import org.apache.directory.api.ldap.model.entry.Attribute;
26 import org.apache.directory.api.ldap.model.entry.Entry;
27 import org.apache.directory.api.ldap.model.entry.Value;
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29 import org.apache.directory.api.ldap.model.exception.LdapOtherException;
30 import org.apache.directory.api.ldap.model.filter.GreaterEqNode;
31 import org.apache.directory.api.ldap.model.schema.AttributeType;
32 import org.apache.directory.api.ldap.model.schema.MatchingRule;
33 import org.apache.directory.api.ldap.model.schema.SchemaManager;
34 import org.apache.directory.server.core.api.partition.PartitionTxn;
35 import org.apache.directory.server.i18n.I18n;
36 import org.apache.directory.server.xdbm.Index;
37 import org.apache.directory.server.xdbm.IndexEntry;
38 import org.apache.directory.server.xdbm.IndexNotFoundException;
39 import org.apache.directory.server.xdbm.Store;
40
41
42
43
44
45
46
47
48 public class GreaterEqEvaluator<T> extends LeafEvaluator<T>
49 {
50
51
52
53
54
55
56
57
58 @SuppressWarnings("unchecked")
59 public GreaterEqEvaluator( GreaterEqNode<T> node, Store db, SchemaManager schemaManager )
60 throws LdapException
61 {
62 super( node, db, schemaManager );
63
64 if ( db.hasIndexOn( node.getAttributeType() ) )
65 {
66 try
67 {
68 idx = ( Index<T, String> ) db.getIndex( attributeType );
69 }
70 catch ( IndexNotFoundException infe )
71 {
72 throw new LdapOtherException( infe.getMessage(), infe );
73 }
74 }
75 else
76 {
77 idx = null;
78 }
79
80
81
82
83
84
85
86 MatchingRule mr = attributeType.getOrdering();
87
88 if ( mr == null )
89 {
90 mr = attributeType.getEquality();
91 }
92
93 if ( mr == null )
94 {
95 throw new IllegalStateException( I18n.err( I18n.ERR_715, node ) );
96 }
97
98 normalizer = mr.getNormalizer();
99 ldapComparator = mr.getLdapComparator();
100 }
101
102
103
104
105
106 @Override
107 public GreaterEqNode getExpression()
108 {
109 return ( GreaterEqNode ) node;
110 }
111
112
113
114
115
116 @Override
117 public boolean evaluate( PartitionTxn partitionTxn, IndexEntry<?, String> indexEntry ) throws LdapException
118 {
119 Entry entry = indexEntry.getEntry();
120
121
122 if ( null == entry )
123 {
124 entry = db.fetch( partitionTxn, indexEntry.getId() );
125
126 if ( null == entry )
127 {
128
129 return false;
130 }
131
132 indexEntry.setEntry( entry );
133 }
134
135
136
137
138
139
140
141
142
143
144 Attribute attr = entry.get( attributeType );
145
146
147
148 if ( attr != null && evaluate( ( IndexEntry<Object, String> ) indexEntry, attr ) )
149 {
150 return true;
151 }
152
153
154
155
156 if ( schemaManager.getAttributeTypeRegistry().hasDescendants( attributeType ) )
157 {
158
159
160
161 Iterator<AttributeType> descendants = schemaManager.getAttributeTypeRegistry().descendants( attributeType );
162
163 while ( descendants.hasNext() )
164 {
165 AttributeType descendant = descendants.next();
166
167 attr = entry.get( descendant );
168
169
170 if ( attr != null && evaluate( ( IndexEntry<Object, String> ) indexEntry, attr ) )
171 {
172 return true;
173 }
174 }
175 }
176
177
178 return false;
179 }
180
181
182
183
184
185 @Override
186 public boolean evaluate( Entry entry ) throws LdapException
187 {
188
189 Attribute attr = entry.get( attributeType );
190
191
192 if ( ( attr != null ) && evaluate( null, attr ) )
193 {
194 return true;
195 }
196
197
198
199
200 if ( schemaManager.getAttributeTypeRegistry().hasDescendants( attributeType ) )
201 {
202
203
204
205 Iterator<AttributeType> descendants = schemaManager.getAttributeTypeRegistry().descendants( attributeType );
206
207 while ( descendants.hasNext() )
208 {
209 AttributeType descendant = descendants.next();
210
211 attr = entry.get( descendant );
212
213 if ( ( attr != null ) && evaluate( null, attr ) )
214 {
215 return true;
216 }
217 }
218 }
219
220
221 return false;
222 }
223
224
225
226
227 private boolean evaluate( IndexEntry<Object, String> indexEntry, Attribute attribute )
228 throws LdapException
229 {
230
231
232
233
234
235
236 for ( Value value : attribute )
237 {
238 if ( ldapComparator.compare( value.getNormalized(), node.getValue().getNormalized() ) >= 0 )
239 {
240 if ( indexEntry != null )
241 {
242 indexEntry.setKey( value.getString() );
243 }
244
245 return true;
246 }
247 }
248
249 return false;
250 }
251
252
253
254
255
256 @Override
257 public String toString( String tabs )
258 {
259 StringBuilder sb = new StringBuilder();
260
261 sb.append( tabs ).append( "GreaterEqEvaluator : " ).append( super.toString() ).append( "\n" );
262
263 return sb.toString();
264 }
265
266
267
268
269
270 @Override
271 public String toString()
272 {
273 return toString( "" );
274 }
275 }