View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.ldap.server.partition.impl.btree;
18  
19  
20  import java.math.BigInteger;
21  
22  import javax.naming.NamingException;
23  import javax.naming.directory.Attribute;
24  import javax.naming.directory.Attributes;
25  
26  import org.apache.ldap.common.schema.AttributeType;
27  import org.apache.regexp.RE;
28  
29  
30  /***
31   * Required interfaces for an index.
32   *
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   * @version $Rev: 264732 $
35   */
36  public interface Index
37  {
38      /***
39       * Gets the attribute this Index is built upon.
40       *
41       * @return the id of the Index's attribute
42       */
43      AttributeType getAttribute();
44  
45      /***
46       * Gets the normalized value for an attribute.
47       *
48       * @param attrVal the user provided value to normalize
49       * @return the normalized value.
50       * @throws NamingException if something goes wrong.
51       */
52      Object getNormalized( Object attrVal ) throws NamingException;
53  
54      /***
55       * Gets the total scan count for this index.
56       *
57       * @return the number of key/value pairs in this index
58       * @throws NamingException if their is a failure accessing the index
59       */
60      int count() throws NamingException;
61  
62      /***
63       * Gets the scan count for the occurance of a specific attribute value 
64       * within the index.
65       *
66       * @param attrVal the value of the attribute to get a scan count for
67       * @return the number of key/value pairs in this index with the value value
68       * @throws NamingException if their is a failure accessing the index
69       */
70      int count( Object attrVal ) throws NamingException;
71  
72      int count( Object attrVal, boolean isGreaterThan ) throws NamingException;
73  
74      BigInteger forwardLookup( Object attrVal )  throws NamingException;
75  
76      Object reverseLookup( BigInteger id ) throws NamingException;
77  
78      void add( Object attrVal, BigInteger id ) throws NamingException;
79  
80      void add( Attribute attr, BigInteger id ) throws NamingException;
81  
82      void add( Attributes attrs, BigInteger id ) throws NamingException;
83  
84      void drop( BigInteger entryId ) throws NamingException;
85  
86      void drop( Object attrVal, BigInteger id ) throws NamingException;
87          
88      /***
89       * If the Attribute does not have any values then this reduces to a 
90       * drop(BigInteger) call.
91       */
92      void drop( Attribute attr, BigInteger id ) throws NamingException;
93          
94      /***
95       * If the Attribute for this index within the Attributes does not have any 
96       * values then this reduces to a drop(BigInteger) call.
97       */
98      void drop( Attributes attrs, BigInteger id ) throws NamingException;
99          
100     IndexEnumeration listReverseIndices( BigInteger id ) throws NamingException;
101 
102     IndexEnumeration listIndices() throws NamingException;
103 
104     IndexEnumeration listIndices( Object attrVal ) throws NamingException;
105 
106     IndexEnumeration listIndices( Object attrVal, boolean isGreaterThan )
107         throws NamingException;
108 
109     IndexEnumeration listIndices( RE regex ) throws NamingException;
110 
111     IndexEnumeration listIndices( RE regex, String prefix )
112         throws NamingException;
113 
114     boolean hasValue( Object attrVal, BigInteger id ) 
115         throws NamingException;
116 
117     boolean hasValue( Object attrVal, BigInteger id, boolean isGreaterThan )
118         throws NamingException;
119 
120     boolean hasValue( RE regex, BigInteger id ) throws NamingException;
121 
122     void close() throws NamingException;
123 
124     void sync() throws NamingException;
125 }