/** * Creates a new reader capable of accessing the contents of this store. The * reader must be explicitly released when no longer required. Readers must * be released prior to this store. * * @return A store reader. */ public IndexStoreReader<K, T> createReader() { return new IndexStoreReader<K, T>(indexStore.createReader(), ordering); }
/** * {@inheritDoc} */ @Override public void close() { objectStoreReader.close(); indexStoreReader.close(); } }
/** * Returns the object identified by id. * * @param id * The identifier for the object to be retrieved. * @return The requested object. */ public T get(long id) { long objectOffset; T data; // Get the object offset from the index store. objectOffset = indexStoreReader.get(id).getValue(); // Read the object from the object store. data = objectStoreReader.get(objectOffset); return data; }
/** * Returns all elements in the range specified by the begin and end keys. * All elements with keys matching and lying between the two keys will be * returned. * * @param beginKey * The key marking the beginning of the required index elements. * @param endKey * The key marking the end of the required index elements. The * identifier for the index element to be retrieved. * @return An iterator pointing to the requested range. */ public Iterator<T> getRange(K beginKey, K endKey) { long keyIndex; // Determine the location of the begin key within the index. keyIndex = getKeyIndex(beginKey); // Iterate across the range. return new IndexRangeIterator<K, T>( indexStoreReader.iterate(keyIndex * elementSize), beginKey, endKey, ordering ); }
/** * Returns the object identified by id. * * @param id * The identifier for the object to be retrieved. * @return The requested object. */ public T get(long id) { long objectOffset; T data; // Get the object offset from the index store. objectOffset = indexStoreReader.get(id).getValue(); // Read the object from the object store. data = objectStoreReader.get(objectOffset); return data; }
/** * Returns all elements in the range specified by the begin and end keys. * All elements with keys matching and lying between the two keys will be * returned. * * @param beginKey * The key marking the beginning of the required index elements. * @param endKey * The key marking the end of the required index elements. The * identifier for the index element to be retrieved. * @return An iterator pointing to the requested range. */ public Iterator<T> getRange(K beginKey, K endKey) { long keyIndex; // Determine the location of the begin key within the index. keyIndex = getKeyIndex(beginKey); // Iterate across the range. return new IndexRangeIterator<K, T>( indexStoreReader.iterate(keyIndex * elementSize), beginKey, endKey, ordering ); }
/** * {@inheritDoc} */ @Override public void close() { objectStoreReader.close(); indexStoreReader.close(); } }
/** * Provides access to the contents of this store. * * @param chunk * The chunk to read objects from. * @return An iterator providing access to contents of the store. */ public ReleasableIterator<T> iterate(long chunk) { complete(); if (indexStoreReader == null) { indexStoreReader = indexStore.createReader(); } // Retrieve the file position and number of objects for the specified // chunk and iterate. return objectStore.iterate( indexStoreReader.get(chunk * 2).getValue(), indexStoreReader.get(chunk * 2 + 1).getValue() ); }
/** * Returns the index element identified by id. * * @param key * The identifier for the index element to be retrieved. * @return The requested object. */ public T get(K key) { long keyIndex; // Determine the location of the key within the index. keyIndex = getKeyIndex(key); if (keyIndex < elementCount) { T element; K locatedKey; element = indexStoreReader.get(keyIndex * elementSize); locatedKey = element.getKey(); if (ordering.compare(key, locatedKey) == 0) { return element; } } throw new NoSuchIndexElementException("Requested key " + key + " does not exist."); }
/** * Creates a new reader capable of accessing the contents of this store. The * reader must be explicitly released when no longer required. Readers must * be released prior to this store. * * @return A store reader. */ public IndexStoreReader<K, T> createReader() { return new IndexStoreReader<K, T>(indexStore.createReader(), ordering); }
/** * {@inheritDoc} */ public void close() { objectStore.close(); if (indexStoreReader != null) { indexStoreReader.close(); indexStoreReader = null; } indexStore.close(); } }
/** * Provides access to the contents of this store. * * @param chunk * The chunk to read objects from. * @return An iterator providing access to contents of the store. */ public ReleasableIterator<T> iterate(long chunk) { complete(); if (indexStoreReader == null) { indexStoreReader = indexStore.createReader(); } // Retrieve the file position and number of objects for the specified // chunk and iterate. return objectStore.iterate( indexStoreReader.get(chunk * 2).getValue(), indexStoreReader.get(chunk * 2 + 1).getValue() ); }
/** * Returns the index element identified by id. * * @param key * The identifier for the index element to be retrieved. * @return The requested object. */ public T get(K key) { long keyIndex; // Determine the location of the key within the index. keyIndex = getKeyIndex(key); if (keyIndex < elementCount) { T element; K locatedKey; element = indexStoreReader.get(keyIndex * elementSize); locatedKey = element.getKey(); if (ordering.compare(key, locatedKey) == 0) { return element; } } throw new NoSuchIndexElementException("Requested key " + key + " does not exist."); }
/** * {@inheritDoc} */ public void close() { objectStore.close(); if (indexStoreReader != null) { indexStoreReader.close(); indexStoreReader = null; } indexStore.close(); } }