Package org.dlese.dpc.datamgr
Class SimpleDataStore
java.lang.Object
org.dlese.dpc.datamgr.DataManager
org.dlese.dpc.datamgr.SerializedDataManager
org.dlese.dpc.datamgr.SimpleDataStore
- All Implemented Interfaces:
Serializable
A Hashtable-like interface for reading and writing persistent Java objects from and to
disc. Same as SerializedDataManager except the getter and setter methods return null insted
of throwing exceptions. Objects are stored in serialized form on disc - any object
that implements
Serializable can be stored in this DataManager for
persistent retrieval. The objects can also be held in a RAM cache to provide faster
retrieval. Serialized objects are stored in a directory specified at the time of
construction. Objects stored in a SimpleDataStore can be of mixed type. This class is
safe to use with multiple process and/or JVMs that access the same dataPath
concurrently.- Author:
- John Weatherley
- See Also:
-
Field Summary
Fields inherited from class org.dlese.dpc.datamgr.SerializedDataManager
codes, dataPath, debug, locks, nextLockKey, num_records, objectCache, useCache, useFileLocks -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for the SimpleDataStore object, restores a serialized SimpleDataStore.SimpleDataStore(String dataPath, boolean useCache) Constructs a new SimpleDataStore that reads and writes data to the given dataPath directory. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeletes an existing data object iff the object is not locked by another user.booleanDeletes an existing data object, assuming the caller had requested and recieved the necessary lock.Retrieves a single data object, or null if none exists or unable to retrieve.Retrieves aListof data objects.Retrieves a copy of a single data object, sutable for modifying, or null if none exists or unable to retrieve.Retrieves aListof copied data objects, suitable for modifying.longReturns the time that the object denoted by this oid was last modified.Adds a new object of data, replacing the existing one if one exists and is not locked.Adds a new object of data, replacing the existing one if one exists and it can be unlocked with the given key.Removes an existing data object iff the object is not locked by another user.Removes an existing data object, assuming the caller had requested and recieved the necessary lock for the object.Updates a new object of data iff the object is not locked by another user.Updates a new object of data, assuming the caller had requested and recieved the necessary lock.Methods inherited from class org.dlese.dpc.datamgr.SerializedDataManager
decodeFileName, encodeFileName, getIDs, getIDsSorted, getLock, getNextLockKey, getNumFiles, getNumRecords, isLocked, isValidLock, lock, oidExists, prtln, releaseLock, restoreSerializedObject, serailizeObject, setDebug, unlock
-
Constructor Details
-
SimpleDataStore
Constructs a new SimpleDataStore that reads and writes data to the given dataPath directory. Allows control over whether or not to hold a cache of the objects in RAM memory for faster retrieval. Note that if caching is turned on in this SimpleDataStore, the objects that are returned from theget(String)andget(List)methods are not safe to modify. Specifically, any changes made to the objects will be reflected in subsequent calls to those methods. To get a copy of the data items that are safe to modify the caller should use thegetCopy(String)orgetCopy(List)methods instead. If caching is not turned on, the effect of the get methods are the same as the getCopy methods.This class is safe to use with multiple process and/or JVMs that access the same dataPath.
- Parameters:
dataPath- The directory where the serialzed objects are stored.useCache- Indicates whether to cache the objects in RAM memory for faster retrievel.- Throws:
Exception- If error.
-
SimpleDataStore
public SimpleDataStore()Constructor for the SimpleDataStore object, restores a serialized SimpleDataStore.
-
-
Method Details
-
get
Retrieves a single data object, or null if none exists or unable to retrieve. Note that if caching is turned on in this SimpleDataStore, the object that is returned is not safe to modify. Specifically, if caching is enabled, any changes made to that object will be reflected in subsequent calls to this method and theget(List)method. To get a copy of a data item that is safe to modify use thegetCopy(String)method instead. If caching is not enabled, the effect of this method is the same asgetCopy(String).- Overrides:
getin classSerializedDataManager- Parameters:
oid- The data identifier- Returns:
Objectof data or null.- See Also:
-
getCopy
Retrieves a copy of a single data object, sutable for modifying, or null if none exists or unable to retrieve. The object that is returned is safe for modifying without affecting the data that is in this SimpleDataStore.- Overrides:
getCopyin classSerializedDataManager- Parameters:
oid- The data identifier.- Returns:
- A copy of an
Objectof data that is in this SimpleDataStore or null. - See Also:
-
get
Retrieves aListof data objects. Note that if caching is turned on in this SimpleDataStore, the objects that are returned are not safe to modify. Specifically, if caching is enabled, any changes made to the objects will be reflected in subsequent calls to this method and theget(String)method. To get a copy of a data items that are safe to modify use thegetCopy(List)method instead. If caching is not ebabled, the effect of this method is the same asgetCopy(List).- Overrides:
getin classSerializedDataManager- Parameters:
oids-Listof data identifiers- Returns:
Listof corresponding data objects- See Also:
-
getCopy
Retrieves aListof copied data objects, suitable for modifying. The objects that are returned are safe for modifying without affecting the data that is in this SimpleDataStore.- Overrides:
getCopyin classSerializedDataManager- Parameters:
oids-Listof data identifiers.- Returns:
Listof corresponding data objects copies.- See Also:
-
remove
Removes an existing data object, assuming the caller had requested and recieved the necessary lock for the object. After successful completion the object is removed from the DataManager and returned to the caller.- Overrides:
removein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object to be removedlockKey- The key corresponding to the lock on this data object- Returns:
- The removed data object iff successful, otherwise null
-
remove
Removes an existing data object iff the object is not locked by another user. If the object is locked a LockNotAvailableException is thrown. After successful completion the object is removed from the DataManager and returned to the caller.- Overrides:
removein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object to be removed- Returns:
- The Object that was removed, or null.
-
delete
Deletes an existing data object, assuming the caller had requested and recieved the necessary lock. Similar toremove()except no object is returned and thus is more efficient if an object is not required.- Overrides:
deletein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object to be deletedlockKey- The key corresponding to the lock on this data object- Returns:
- True if object was successfully deleted, otherwise false.
-
delete
Deletes an existing data object iff the object is not locked by another user. If the object is locked a LockNotAvailableException is thrown. Similar toremove()except no object is returned and thus is more efficient. After successful completion the object is deleted from the DataManager.- Overrides:
deletein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object to be deleted- Returns:
- True if object was successfully deleted, otherwise false.
-
put
Adds a new object of data, replacing the existing one if one exists and is not locked. This method is safe for concurrent use among multiple processes and JVMs accessing the same SimpleDataStore.- Overrides:
putin classSerializedDataManager- Parameters:
oid- The unique identifier that references the new data objectobj- The new data object- Returns:
- The added data object iff successful, otherwise null
-
put
Adds a new object of data, replacing the existing one if one exists and it can be unlocked with the given key. The caller retains the lock after this method returns. This method is safe for concurrent use among multiple processes and JVMs accessing the same SimpleDataStore.- Parameters:
oid- The unique identifier that references the new data objectobj- The new data objectlockKey- The key corresponding to the lock on this data object- Returns:
- The added data object iff successful, otherwise null
-
update
Updates a new object of data, assuming the caller had requested and recieved the necessary lock. The caller retains the lock after this method returns.- Overrides:
updatein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object to be updatedobj- The new updated data objectlockKey- The key corresponding to the lock on this data object- Returns:
- The updated data object, if successful otherwise null
-
update
Updates a new object of data iff the object is not locked by another user. If the object is locked a LockNotAvailableException is thrown.- Overrides:
updatein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object to be updatedobj- The new updated data object- Returns:
- The updated data object, if successful otherwise null.
-
getLastModifiedDate
Returns the time that the object denoted by this oid was last modified.- Overrides:
getLastModifiedDatein classSerializedDataManager- Parameters:
oid- The unique identifier that references the data object- Returns:
- A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or -1 if the oid does not exist.
-