Class DummyIndexedStorageUtility<T extends Persistable>
java.lang.Object
org.javarosa.core.services.storage.util.DummyIndexedStorageUtility<T>
- All Implemented Interfaces:
IStorageUtility<T>,IStorageUtilityIndexed<T>
public class DummyIndexedStorageUtility<T extends Persistable> extends Object implements IStorageUtilityIndexed<T>
- Author:
- ctsims
-
Constructor Summary
Constructors Constructor Description DummyIndexedStorageUtility() -
Method Summary
Modifier and Type Method Description intadd(T e)Add a new record to the store.voidclose()Close all resources associated with this StorageUtility.voiddestroy()Delete the storage utility itself, along with all stored records and meta-databooleanexists(int id)Return whether a record exists in the storeObjectgetAccessLock()Fetch the object that acts as the synchronization lock for this StorageUtilityList<Integer>getIDsForValue(String fieldName, Object value)Retrieves a List of IDs of Externalizable objects in storage for which the field specified contains the value specified.intgetNumRecords()Return the number of records in the storeTgetRecordForValue(String fieldName, Object value)Retrieves a Externalizable object from the storage which is reference by the unique index fieldName.intgetRecordSize(int id)Get the size of a recordintgetTotalSize()Return total size of device storage consumed by this StorageUtilitybooleanisEmpty()Return whether the store is emptyIStorageIterator<T>iterate()Return an iterator to iterate through all records in this storeTread(int id)Read and return the record corresponding to 'id'.byte[]readBytes(int id)Read and return the raw bytes for the record corresponding to 'id'.voidregisterIndex(String filterIndex)Optional.voidremove(int id)Remove record with the given ID from the store.voidremove(Persistable p)Remove object from the storevoidremoveAll()List<Integer>removeAll(EntityFilter ef)voidrepack()Perform any clean-up/consolidation of the StorageUtility's underlying datastructures that is too expensive to do during normal usage (e.g., if all the records are scattered among 10 half-empty RMSes, repack them into 5 full RMSes)voidrepair()If the StorageUtility has been left in a corrupt/inconsistent state, restore it to a non-corrupt state, even if it results in data loss.voidsetReadOnly()voidupdate(int id, T e)Update a record in the store.voidwrite(Persistable p)Write an object to the store.
-
Constructor Details
-
DummyIndexedStorageUtility
public DummyIndexedStorageUtility()
-
-
Method Details
-
getIDsForValue
Description copied from interface:IStorageUtilityIndexedRetrieves a List of IDs of Externalizable objects in storage for which the field specified contains the value specified.- Specified by:
getIDsForValuein interfaceIStorageUtilityIndexed<T extends Persistable>- Parameters:
fieldName- The name of a field which should be evaluatedvalue- The value which should be contained by the field specified- Returns:
- A List of Integers such that retrieving the Externalizable object with any of those integer IDs will result in an object for which the field specified is equal to the value provided.
-
getRecordForValue
public T getRecordForValue(String fieldName, Object value) throws NoSuchElementException, InvalidIndexExceptionDescription copied from interface:IStorageUtilityIndexedRetrieves a Externalizable object from the storage which is reference by the unique index fieldName.- Specified by:
getRecordForValuein interfaceIStorageUtilityIndexed<T extends Persistable>- Parameters:
fieldName- The name of the index field which will be evaluatedvalue- The value which should be set in the index specified by fieldName for the returned object.- Returns:
- An Externalizable object e, such that e.getMetaData(fieldName).equals(value);
- Throws:
NoSuchElementException- If no objects reside in storage for which the return condition can be successful.InvalidIndexException- If the field used is an invalid index, because more than one field in the Storage contains the value of the index requested.
-
add
Description copied from interface:IStorageUtilityAdd a new record to the store. This function always adds a new record; it never updates an existing record. The record ID under which this record is added is allocated by the StorageUtility. If this StorageUtility stores Persistables, you should almost certainly use write() instead.- Specified by:
addin interfaceIStorageUtility<T extends Persistable>- Parameters:
e- object to add- Returns:
- record ID for newly added object
- Throws:
StorageFullException- if not enough space available
-
close
public void close()Description copied from interface:IStorageUtilityClose all resources associated with this StorageUtility. Any attempt to use this StorageUtility after this call will result in error. Though not strictly necessary, it is a good idea to call this when you are done with the StorageUtility, as closing may trigger clean-up in the underlying device storage (reclaiming unused space, etc.).- Specified by:
closein interfaceIStorageUtility<T extends Persistable>
-
destroy
public void destroy()Description copied from interface:IStorageUtilityDelete the storage utility itself, along with all stored records and meta-data- Specified by:
destroyin interfaceIStorageUtility<T extends Persistable>
-
exists
public boolean exists(int id)Description copied from interface:IStorageUtilityReturn whether a record exists in the store- Specified by:
existsin interfaceIStorageUtility<T extends Persistable>- Parameters:
id- record ID- Returns:
- true if a record exists for that ID in the store
-
getAccessLock
Description copied from interface:IStorageUtilityFetch the object that acts as the synchronization lock for this StorageUtility- Specified by:
getAccessLockin interfaceIStorageUtility<T extends Persistable>- Returns:
- lock object
-
getNumRecords
public int getNumRecords()Description copied from interface:IStorageUtilityReturn the number of records in the store- Specified by:
getNumRecordsin interfaceIStorageUtility<T extends Persistable>- Returns:
- number of records
-
getRecordSize
public int getRecordSize(int id)Description copied from interface:IStorageUtilityGet the size of a record- Specified by:
getRecordSizein interfaceIStorageUtility<T extends Persistable>- Parameters:
id- record ID- Returns:
- size of that record, in bytes
-
getTotalSize
public int getTotalSize()Description copied from interface:IStorageUtilityReturn total size of device storage consumed by this StorageUtility- Specified by:
getTotalSizein interfaceIStorageUtility<T extends Persistable>- Returns:
- total size (bytes)
-
isEmpty
public boolean isEmpty()Description copied from interface:IStorageUtilityReturn whether the store is empty- Specified by:
isEmptyin interfaceIStorageUtility<T extends Persistable>- Returns:
- true if there are no records in the store
-
iterate
Description copied from interface:IStorageUtilityReturn an iterator to iterate through all records in this store- Specified by:
iteratein interfaceIStorageUtility<T extends Persistable>- Returns:
- record iterator
-
read
Description copied from interface:IStorageUtilityRead and return the record corresponding to 'id'.- Specified by:
readin interfaceIStorageUtility<T extends Persistable>- Parameters:
id- id of the object- Returns:
- object for 'id'. null if no object is stored under that ID
-
readBytes
public byte[] readBytes(int id)Description copied from interface:IStorageUtilityRead and return the raw bytes for the record corresponding to 'id'.- Specified by:
readBytesin interfaceIStorageUtility<T extends Persistable>- Parameters:
id- id of the object- Returns:
- raw bytes for the record. null if no record is stored under that ID
-
remove
public void remove(int id)Description copied from interface:IStorageUtilityRemove record with the given ID from the store.- Specified by:
removein interfaceIStorageUtility<T extends Persistable>- Parameters:
id- ID of record to remove
-
remove
Description copied from interface:IStorageUtilityRemove object from the store- Specified by:
removein interfaceIStorageUtility<T extends Persistable>- Parameters:
p- object to remove
-
removeAll
public void removeAll()- Specified by:
removeAllin interfaceIStorageUtility<T extends Persistable>
-
removeAll
- Specified by:
removeAllin interfaceIStorageUtility<T extends Persistable>
-
repack
public void repack()Description copied from interface:IStorageUtilityPerform any clean-up/consolidation of the StorageUtility's underlying datastructures that is too expensive to do during normal usage (e.g., if all the records are scattered among 10 half-empty RMSes, repack them into 5 full RMSes)- Specified by:
repackin interfaceIStorageUtility<T extends Persistable>
-
repair
public void repair()Description copied from interface:IStorageUtilityIf the StorageUtility has been left in a corrupt/inconsistent state, restore it to a non-corrupt state, even if it results in data loss. If the integrity is intact, do nothing- Specified by:
repairin interfaceIStorageUtility<T extends Persistable>
-
update
Description copied from interface:IStorageUtilityUpdate a record in the store. The record must have previously been added to the store using add(). If this StorageUtility stores Persistables, you should almost certainly use write() instead.- Specified by:
updatein interfaceIStorageUtility<T extends Persistable>- Parameters:
id- ID of record to updatee- updated object- Throws:
StorageFullException- if not enough space available to update
-
write
Description copied from interface:IStorageUtilityWrite an object to the store. Will either add a new record, or update the existing record (if one exists) for the object's ID. This function should never be used in conjunction with add() and update() within the same StorageUtility- Specified by:
writein interfaceIStorageUtility<T extends Persistable>- Parameters:
p- object to store- Throws:
StorageFullException- if there is not enough room to store the object
-
setReadOnly
public void setReadOnly()- Specified by:
setReadOnlyin interfaceIStorageUtility<T extends Persistable>
-
registerIndex
Description copied from interface:IStorageUtilityIndexedOptional. Register a new index for this storage which may optionally be able for indexed operations going forward. This will likely take a substantial amount of time for larger storage utilities.- Specified by:
registerIndexin interfaceIStorageUtilityIndexed<T extends Persistable>
-