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 */ 019package org.apache.directory.server.xdbm; 020 021 022import java.io.IOException; 023 024import org.apache.directory.api.ldap.model.constants.Loggers; 025import org.apache.directory.api.ldap.model.cursor.CursorException; 026import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException; 027import org.apache.directory.api.ldap.model.exception.LdapException; 028import org.apache.directory.server.core.api.partition.PartitionTxn; 029import org.apache.directory.server.i18n.I18n; 030import org.slf4j.Logger; 031import org.slf4j.LoggerFactory; 032 033 034/** 035 * An empty Cursor implementation. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class EmptyIndexCursor<K> extends AbstractIndexCursor<K> 040{ 041 /** A dedicated log for cursors */ 042 private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() ); 043 044 /** Speedup for logs */ 045 private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled(); 046 047 048 public EmptyIndexCursor( PartitionTxn partitionTxn ) 049 { 050 if ( IS_DEBUG ) 051 { 052 LOG_CURSOR.debug( "Creating EmptyIndexCursor {}", this ); 053 } 054 055 this.partitionTxn = partitionTxn; 056 } 057 058 059 /** 060 * {@inheritDoc} 061 */ 062 @Override 063 public void before( IndexEntry<K, String> element ) throws LdapException, CursorException 064 { 065 checkNotClosed(); 066 } 067 068 069 /** 070 * {@inheritDoc} 071 */ 072 protected String getUnsupportedMessage() 073 { 074 return UNSUPPORTED_MSG; 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public void after( IndexEntry<K, String> element ) throws LdapException, CursorException 083 { 084 checkNotClosed(); 085 } 086 087 088 /** 089 * {@inheritDoc} 090 */ 091 public void beforeFirst() throws LdapException, CursorException 092 { 093 checkNotClosed(); 094 } 095 096 097 /** 098 * {@inheritDoc} 099 */ 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}