001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.kahadb.index; 018 019import java.io.IOException; 020import java.util.Iterator; 021import java.util.Map; 022 023import org.apache.kahadb.page.Transaction; 024import org.apache.kahadb.util.Marshaller; 025 026/** 027 * Simpler than a Map 028 * 029 * 030 */ 031public interface Index<Key,Value> { 032 033 /** 034 * Set the marshaller for key objects 035 * 036 * @param marshaller 037 */ 038 void setKeyMarshaller(Marshaller<Key> marshaller); 039 040 /** 041 * Set the marshaller for key objects 042 * 043 * @param marshaller 044 */ 045 void setValueMarshaller(Marshaller<Value> marshaller); 046 047 /** 048 * load indexes 049 */ 050 void load(Transaction tx) throws IOException; 051 052 /** 053 * unload indexes 054 * 055 * @throws IOException 056 */ 057 void unload(Transaction tx) throws IOException; 058 059 /** 060 * clear the index 061 * 062 * @throws IOException 063 * 064 */ 065 void clear(Transaction tx) throws IOException; 066 067 /** 068 * @param key 069 * @return true if it contains the key 070 * @throws IOException 071 */ 072 boolean containsKey(Transaction tx, Key key) throws IOException; 073 074 /** 075 * remove the index key 076 * 077 * @param key 078 * @return StoreEntry removed 079 * @throws IOException 080 */ 081 Value remove(Transaction tx, Key key) throws IOException; 082 083 /** 084 * store the key, item 085 * 086 * @param key 087 * @param entry 088 * @throws IOException 089 */ 090 Value put(Transaction tx, Key key, Value entry) throws IOException; 091 092 /** 093 * @param key 094 * @return the entry 095 * @throws IOException 096 */ 097 Value get(Transaction tx, Key key) throws IOException; 098 099 /** 100 * @return true if the index is transient 101 */ 102 boolean isTransient(); 103 104 /** 105 * @param tx 106 * @return 107 * @throws IOException 108 * @trhows UnsupportedOperationException 109 * if the index does not support fast iteration of the elements. 110 */ 111 Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx) throws IOException, UnsupportedOperationException; 112 113}