/** * {@inheritDoc} */ @Override public void close() { indexStoreReader.close(); }
/** * Iterates over the entire stream of data. * * @return An iterator for reading objects from the data store. This * iterator must be released after use. */ public Iterator<T> iterate() { return iterate(0); }
/** * 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; }
/** * Iterates over the entire stream of data. * * @param offset * The location in the storage file to begin reading. * @return An iterator for reading objects from the data store. This * iterator must be released after use. */ public Iterator<T> iterate(long offset) { seek(offset); return new ObjectDataInputIterator<T>(objectReader); }
/** * 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 RandomAccessObjectStoreReader<T> createReader() { initializeReadingStage(); try { BufferedRandomAccessFileInputStream randomFileReader; randomFileReader = new BufferedRandomAccessFileInputStream(storageFile); return new RandomAccessObjectStoreReader<T>( randomFileReader, serializationFactory.createObjectReader( new DataInputStoreReader( new DataInputStream(randomFileReader)), storeClassRegister) ); } catch (FileNotFoundException e) { throw new OsmosisRuntimeException( "Unable to create object stream reading from file " + storageFile + ".", e); } }
/** * 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; }
/** * Reads the object at the specified file offset. * * @param offset * The file offset to read an object from. * @return The requested object. */ @SuppressWarnings("unchecked") public T get(long offset) { seek(offset); return (T) objectReader.readObject(); }
/** * 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 RandomAccessObjectStoreReader<T> createReader() { initializeReadingStage(); try { BufferedRandomAccessFileInputStream randomFileReader; randomFileReader = new BufferedRandomAccessFileInputStream(storageFile); return new RandomAccessObjectStoreReader<T>( randomFileReader, serializationFactory.createObjectReader( new DataInputStoreReader( new DataInputStream(randomFileReader)), storeClassRegister) ); } catch (FileNotFoundException e) { throw new OsmosisRuntimeException( "Unable to create object stream reading from file " + storageFile + ".", e); } }
/** * {@inheritDoc} */ @Override public void close() { indexStoreReader.close(); }
/** * Iterates over the entire stream of data. * * @return An iterator for reading objects from the data store. This * iterator must be released after use. */ public Iterator<T> iterate() { return iterate(0); }
/** * 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."); }
/** * Reads the object at the specified file offset. * * @param offset * The file offset to read an object from. * @return The requested object. */ @SuppressWarnings("unchecked") public T get(long offset) { seek(offset); return (T) objectReader.readObject(); }
/** * {@inheritDoc} */ @Override public void close() { objectStoreReader.close(); indexStoreReader.close(); } }
/** * 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 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."); }
/** * Iterates over the entire stream of data. * * @param offset * The location in the storage file to begin reading. * @return An iterator for reading objects from the data store. This * iterator must be released after use. */ public Iterator<T> iterate(long offset) { seek(offset); return new ObjectDataInputIterator<T>(objectReader); }
/** * {@inheritDoc} */ @Override public void close() { objectStoreReader.close(); indexStoreReader.close(); } }
/** * 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 ); }