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  package org.apache.directory.server.xdbm;
20  
21  
22  import java.io.IOException;
23  
24  import org.apache.directory.api.ldap.model.constants.Loggers;
25  import org.apache.directory.api.ldap.model.cursor.CursorException;
26  import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException;
27  import org.apache.directory.api.ldap.model.exception.LdapException;
28  import org.apache.directory.server.core.api.partition.PartitionTxn;
29  import org.apache.directory.server.i18n.I18n;
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  
34  /**
35   * An empty Cursor implementation.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class EmptyIndexCursor<K> extends AbstractIndexCursor<K>
40  {
41      /** A dedicated log for cursors */
42      private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() );
43  
44      /** Speedup for logs */
45      private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled();
46  
47  
48      public EmptyIndexCursor( PartitionTxn partitionTxn )
49      {
50          if ( IS_DEBUG )
51          {
52              LOG_CURSOR.debug( "Creating EmptyIndexCursor {}", this );
53          }
54          
55          this.partitionTxn = partitionTxn;
56      }
57  
58  
59      /**
60       * {@inheritDoc}
61       */
62      @Override
63      public void before( IndexEntry<K, String> element ) throws LdapException, CursorException
64      {
65          checkNotClosed();
66      }
67  
68  
69      /**
70       * {@inheritDoc}
71       */
72      protected String getUnsupportedMessage()
73      {
74          return UNSUPPORTED_MSG;
75      }
76  
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public void after( IndexEntry<K, String> element ) throws LdapException, CursorException
83      {
84          checkNotClosed();
85      }
86  
87  
88      /**
89       * {@inheritDoc}
90       */
91      public void beforeFirst() throws LdapException, CursorException
92      {
93          checkNotClosed();
94      }
95  
96  
97      /**
98       * {@inheritDoc}
99       */
100     public void afterLast() throws LdapException, CursorException
101     {
102         checkNotClosed();
103     }
104 
105 
106     /**
107      * {@inheritDoc}
108      */
109     public boolean first() throws LdapException, CursorException
110     {
111         checkNotClosed();
112         return false;
113     }
114 
115 
116     /**
117      * {@inheritDoc}
118      */
119     public boolean last() throws LdapException, CursorException
120     {
121         checkNotClosed();
122         return false;
123     }
124 
125 
126     /**
127      * {@inheritDoc}
128      */
129     @Override
130     public boolean previous() throws LdapException, CursorException
131     {
132         checkNotClosed();
133         return false;
134     }
135 
136 
137     /**
138      * {@inheritDoc}
139      */
140     @Override
141     public boolean next() throws LdapException, CursorException
142     {
143         checkNotClosed();
144         return false;
145     }
146 
147 
148     /**
149      * {@inheritDoc}
150      */
151     public IndexEntry<K, String> get() throws CursorException
152     {
153         checkNotClosed();
154         throw new InvalidCursorPositionException( I18n.err( I18n.ERR_703 ) );
155     }
156 
157 
158     /**
159      * {@inheritDoc}
160      */
161     public void afterValue( String id, K indexValue ) throws Exception
162     {
163         checkNotClosed();
164     }
165 
166 
167     /**
168      * {@inheritDoc}
169      */
170     public void beforeValue( String id, K indexValue ) throws Exception
171     {
172         checkNotClosed();
173     }
174 
175 
176     /**
177      * {@inheritDoc}
178      */
179     @Override
180     public void close() throws IOException
181     {
182         if ( IS_DEBUG )
183         {
184             LOG_CURSOR.debug( "Closing EmptyIndexCursor {}", this );
185         }
186 
187         super.close();
188     }
189 
190 
191     /**
192      * {@inheritDoc}
193      */
194     @Override
195     public void close( Exception cause ) throws IOException
196     {
197         if ( IS_DEBUG )
198         {
199             LOG_CURSOR.debug( "Closing EmptyIndexCursor {}", this );
200         }
201 
202         super.close( cause );
203     }
204 }