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 public void before( IndexEntry<K, String> element ) throws LdapException, CursorException 063 { 064 checkNotClosed(); 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 protected String getUnsupportedMessage() 072 { 073 return UNSUPPORTED_MSG; 074 } 075 076 077 /** 078 * {@inheritDoc} 079 */ 080 public void after( IndexEntry<K, String> element ) throws LdapException, CursorException 081 { 082 checkNotClosed(); 083 } 084 085 086 /** 087 * {@inheritDoc} 088 */ 089 public void beforeFirst() throws LdapException, CursorException 090 { 091 checkNotClosed(); 092 } 093 094 095 /** 096 * {@inheritDoc} 097 */ 098 public void afterLast() throws LdapException, CursorException 099 { 100 checkNotClosed(); 101 } 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 public boolean first() throws LdapException, CursorException 108 { 109 checkNotClosed(); 110 return false; 111 } 112 113 114 /** 115 * {@inheritDoc} 116 */ 117 public boolean last() throws LdapException, CursorException 118 { 119 checkNotClosed(); 120 return false; 121 } 122 123 124 /** 125 * {@inheritDoc} 126 */ 127 @Override 128 public boolean previous() throws LdapException, CursorException 129 { 130 checkNotClosed(); 131 return false; 132 } 133 134 135 /** 136 * {@inheritDoc} 137 */ 138 @Override 139 public boolean next() throws LdapException, CursorException 140 { 141 checkNotClosed(); 142 return false; 143 } 144 145 146 /** 147 * {@inheritDoc} 148 */ 149 public IndexEntry<K, String> get() throws CursorException 150 { 151 checkNotClosed(); 152 throw new InvalidCursorPositionException( I18n.err( I18n.ERR_703 ) ); 153 } 154 155 156 /** 157 * {@inheritDoc} 158 */ 159 public void afterValue( String id, K indexValue ) throws Exception 160 { 161 checkNotClosed(); 162 } 163 164 165 /** 166 * {@inheritDoc} 167 */ 168 public void beforeValue( String id, K indexValue ) throws Exception 169 { 170 checkNotClosed(); 171 } 172 173 174 /** 175 * {@inheritDoc} 176 */ 177 public void close() throws IOException 178 { 179 if ( IS_DEBUG ) 180 { 181 LOG_CURSOR.debug( "Closing EmptyIndexCursor {}", this ); 182 } 183 184 super.close(); 185 } 186 187 188 /** 189 * {@inheritDoc} 190 */ 191 public void close( Exception cause ) throws IOException 192 { 193 if ( IS_DEBUG ) 194 { 195 LOG_CURSOR.debug( "Closing EmptyIndexCursor {}", this ); 196 } 197 198 super.close( cause ); 199 } 200}