Read Tutorial
Like in the Write Example some parameters must be defined. For simplicity, this time only the folder of the DRUMS-table must be given.
GlobalParameters gp = new GlobalParameters(folderOfDRUMS);
Now, DRUMS can be opend for reading.
DRUMS drums = DRUMSInstantiator.openTable(gp);
To perform efficient selects, it is recommended to use the DRUMSReader. Use the factory method
#getReader()
in the DRUMS-object to get an instance.
DRUMSReader reader = drums.getReader();
Single selects
Single selects can be performed using
#select(keys[]...)
from the DRUMS-instance or
#get(keys[]...)
from the DRUMSReader.
List result = drums.select(key1, key2, ..., keyN);or
List result = reader.get(key1, key2, ..., keyN);
Range selects
Range selects can only be performed using the DRUMSReader. The method
#getRange(byte[], byte[])
must be used carefully. The returned list might be very large and might need a lot of memory.
List result = reader.getRange(lowerKey, upperKey);
Iterator
DRUMS provides also the option to use an iterator to scan a large range of the table.
DRUMSIterator iterator = drums.getIterator(); while (iterator.hasNext() ) { // do something }; iterator.close();
Filtering data
DRUMS doesn't provide the possibility to formulate detailed select conditions like MySQL (... WHERE ...). Therefore the returned lists of records must be filtered.
Iterator iterator = result.iterator(); while (iterator.hasNext()) { Data record = iterator.next(); if (condition is fullfilled) { // add element to a final result list } }
drums.close();
Example
For a concrete example please have a look at BioDRUMS. This file provides a full functional example for performing the above mentioned operations on a filled DRUMS table.