1 11 package org.eclipse.core.internal.indexing; 12 13 import java.util.Vector ; 14 15 18 public class Index { 19 20 private IndexedStore store; 21 private ObjectAddress anchorAddress; 22 23 26 Index(IndexedStore store, ObjectAddress anchorAddress) { 27 this.store = store; 28 this.anchorAddress = anchorAddress; 29 } 30 31 36 public synchronized Vector getObjectIdentifiersMatching(byte[] key) throws IndexedStoreException { 37 IndexCursor cursor = open(); 38 cursor.find(key); 39 Vector vector = new Vector (20); 40 while (cursor.keyMatches(key)) { 41 vector.addElement(cursor.getValueAsObjectID()); 42 cursor.next(); 43 } 44 cursor.close(); 45 return vector; 46 } 47 48 54 public synchronized void insert(byte[] key, byte[] value) throws IndexedStoreException { 55 if (key.length > 1024) 56 throw new IndexedStoreException(IndexedStoreException.EntryKeyLengthError); 57 if (value.length > 2048) 58 throw new IndexedStoreException(IndexedStoreException.EntryValueLengthError); 59 IndexAnchor anchor = store.acquireAnchor(anchorAddress); 60 anchor.insert(key, value); 61 anchor.release(); 62 } 63 64 public synchronized void insert(byte[] key, Insertable value) throws IndexedStoreException { 65 insert(key, value.toByteArray()); 66 } 67 68 public synchronized void insert(String key, byte[] value) throws IndexedStoreException { 69 insert(Convert.toUTF8(key), value); 70 } 71 72 76 public synchronized IndexCursor open() throws IndexedStoreException { 77 IndexCursor c = new IndexCursor(store, anchorAddress); 78 return c; 79 } 80 } 81 | Popular Tags |