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.impl;
21  
22  
23  import org.apache.directory.server.core.entry.ServerEntry;
24  import org.apache.directory.server.xdbm.AbstractIndexCursor;
25  import org.apache.directory.server.xdbm.ForwardIndexEntry;
26  import org.apache.directory.server.xdbm.IndexCursor;
27  import org.apache.directory.server.xdbm.IndexEntry;
28  import org.apache.directory.server.xdbm.Store;
29  
30  
31  /**
32   * A Cursor over all entries in a partition which returns IndexEntries.
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev$, $Date$
36   */
37  public class AllEntriesCursor extends AbstractIndexCursor<Long,ServerEntry>
38  {
39      private IndexEntry<Long, ServerEntry> indexEntry = new ForwardIndexEntry<Long, ServerEntry>();
40      private final IndexCursor<String,ServerEntry> wrapped;
41  
42      
43      public AllEntriesCursor( Store<ServerEntry> db ) throws Exception
44      {
45          // Get a reverse cursor because we want to sort by ID
46          wrapped = db.getNdnIndex().reverseCursor();
47      }
48      
49      
50      /* 
51       * @see org.apache.directory.server.xdbm.IndexCursor#afterValue(Long, Object)
52       */
53      public void afterValue( Long key, Long value ) throws Exception
54      {
55          checkNotClosed( "afterValue()" );
56          wrapped.afterValue( key, null );
57      }
58  
59  
60      /* 
61       * @see org.apache.directory.server.xdbm.IndexCursor#beforeValue(java.lang.Long, java.lang.Object)
62       */
63      public void beforeValue( Long id, Long value ) throws Exception
64      {
65          checkNotClosed( "beforeValue()" );
66          wrapped.beforeValue( id, null );
67      }
68  
69  
70      /* 
71       * @see org.apache.directory.server.core.cursor.Cursor#after(java.lang.Object)
72       */
73      public void after( IndexEntry<Long,ServerEntry> indexEntry ) throws Exception
74      {
75          checkNotClosed( "after()" );
76          wrapped.afterValue( indexEntry.getId(), null );
77      }
78  
79  
80      /* 
81       * @see org.apache.directory.server.core.cursor.Cursor#afterLast()
82       */
83      public void afterLast() throws Exception
84      {
85          checkNotClosed( "afterLast()" );
86          wrapped.afterLast();
87      }
88  
89  
90      /* 
91       * @see org.apache.directory.server.core.cursor.Cursor#available()
92       */
93      public boolean available()
94      {
95          return wrapped.available();
96      }
97  
98  
99      /* 
100      * @see org.apache.directory.server.core.cursor.Cursor#before(java.lang.Object)
101      */
102     public void before( IndexEntry<Long,ServerEntry> indexEntry ) throws Exception
103     {
104         checkNotClosed( "before()" );
105         wrapped.beforeValue( indexEntry.getId(), null );
106     }
107 
108 
109     /* 
110      * @see org.apache.directory.server.core.cursor.Cursor#beforeFirst()
111      */
112     public void beforeFirst() throws Exception
113     {
114         checkNotClosed( "beforeFirst()" );
115         wrapped.beforeFirst();
116     }
117 
118 
119     /* 
120      * @see org.apache.directory.server.core.cursor.Cursor#first()
121      */
122     public boolean first() throws Exception
123     {
124         checkNotClosed( "first()" );
125         return wrapped.first();
126     }
127 
128 
129     /* 
130      * @see org.apache.directory.server.core.cursor.Cursor#get()
131      */
132     public IndexEntry<Long,ServerEntry> get() throws Exception
133     {
134         checkNotClosed( "get()" );
135         IndexEntry<String,ServerEntry> wrappedEntry = wrapped.get();
136         indexEntry.setId( wrappedEntry.getId() );
137         indexEntry.setValue( wrappedEntry.getId() );
138         indexEntry.setObject( wrappedEntry.getObject() );
139         return indexEntry;
140     }
141 
142 
143     /* 
144      * @see org.apache.directory.server.core.cursor.Cursor#isElementReused()
145      */
146     public boolean isElementReused()
147     {
148         return true;
149     }
150 
151 
152     /* 
153      * @see org.apache.directory.server.core.cursor.Cursor#last()
154      */
155     public boolean last() throws Exception
156     {
157         checkNotClosed( "last()" );
158         return wrapped.last();
159     }
160 
161 
162     /* 
163      * @see org.apache.directory.server.core.cursor.Cursor#next()
164      */
165     public boolean next() throws Exception
166     {
167         checkNotClosed( "next()" );
168         return wrapped.next();
169     }
170 
171 
172     /* 
173      * @see org.apache.directory.server.core.cursor.Cursor#previous()
174      */
175     public boolean previous() throws Exception
176     {
177         checkNotClosed( "previous()" );
178         return wrapped.previous();
179     }
180 }