1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.kahadb.index; 18 19 import java.io.IOException; 20 import java.util.Iterator; 21 import java.util.Map; 22 23 import org.apache.kahadb.page.Transaction; 24 import org.apache.kahadb.util.Marshaller; 25 26 /** 27 * Simpler than a Map 28 * 29 * @version $Revision: 713421 $ 30 */ 31 public interface Index<Key,Value> { 32 33 /** 34 * Set the marshaller for key objects 35 * 36 * @param marshaller 37 */ 38 void setKeyMarshaller(Marshaller<Key> marshaller); 39 40 /** 41 * Set the marshaller for key objects 42 * 43 * @param marshaller 44 */ 45 void setValueMarshaller(Marshaller<Value> marshaller); 46 47 /** 48 * load indexes 49 */ 50 void load(Transaction tx) throws IOException; 51 52 /** 53 * unload indexes 54 * 55 * @throws IOException 56 */ 57 void unload(Transaction tx) throws IOException; 58 59 /** 60 * clear the index 61 * 62 * @throws IOException 63 * 64 */ 65 void clear(Transaction tx) throws IOException; 66 67 /** 68 * @param key 69 * @return true if it contains the key 70 * @throws IOException 71 */ 72 boolean containsKey(Transaction tx, Key key) throws IOException; 73 74 /** 75 * remove the index key 76 * 77 * @param key 78 * @return StoreEntry removed 79 * @throws IOException 80 */ 81 Value remove(Transaction tx, Key key) throws IOException; 82 83 /** 84 * store the key, item 85 * 86 * @param key 87 * @param entry 88 * @throws IOException 89 */ 90 Value put(Transaction tx, Key key, Value entry) throws IOException; 91 92 /** 93 * @param key 94 * @return the entry 95 * @throws IOException 96 */ 97 Value get(Transaction tx, Key key) throws IOException; 98 99 /** 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 }