public class SimpleDataStore extends SerializedDataManager implements java.io.Serializable
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.codes, dataPath, debug, locks, nextLockKey, num_records, objectCache, useCache, useFileLocks
Constructor and Description |
---|
SimpleDataStore()
Constructor for the SimpleDataStore object, restores a serialized SimpleDataStore.
|
SimpleDataStore(java.lang.String dataPath,
boolean useCache)
Constructs a new SimpleDataStore that reads and writes data to the given dataPath
directory.
|
Modifier and Type | Method and Description |
---|---|
boolean |
delete(java.lang.String oid)
Deletes an existing data object iff the object is not locked by another user.
|
boolean |
delete(java.lang.String oid,
java.lang.String lockKey)
Deletes an existing data object, assuming the caller had requested and recieved the
necessary lock.
|
java.util.List |
get(java.util.List oids)
Retrieves a
List of data objects. |
java.lang.Object |
get(java.lang.String oid)
Retrieves a single data object, or null if none exists or unable to retrieve.
|
java.util.List |
getCopy(java.util.List oids)
Retrieves a
List of copied data objects, suitable for modifying. |
java.lang.Object |
getCopy(java.lang.String oid)
Retrieves a copy of a single data object, sutable for modifying, or null if none
exists or unable to retrieve.
|
long |
getLastModifiedDate(java.lang.String oid)
Returns the time that the object denoted by this oid was last modified.
|
java.lang.Object |
put(java.lang.String oid,
java.lang.Object obj)
Adds a new object of data, replacing the existing one if one exists and is not
locked.
|
java.lang.Object |
put(java.lang.String oid,
java.lang.Object obj,
java.lang.String lockKey)
Adds a new object of data, replacing the existing one if one exists and it can be
unlocked with the given key.
|
java.lang.Object |
remove(java.lang.String oid)
Removes an existing data object iff the object is not locked by another user.
|
java.lang.Object |
remove(java.lang.String oid,
java.lang.String lockKey)
Removes an existing data object, assuming the caller had requested and recieved the
necessary lock for the object.
|
java.lang.Object |
update(java.lang.String oid,
java.lang.Object obj)
Updates a new object of data iff the object is not locked by another user.
|
java.lang.Object |
update(java.lang.String oid,
java.lang.Object obj,
java.lang.String lockKey)
Updates a new object of data, assuming the caller had requested and recieved the
necessary lock.
|
decodeFileName, encodeFileName, getIDs, getIDsSorted, getLock, getNextLockKey, getNumFiles, getNumRecords, isLocked, isValidLock, lock, oidExists, prtln, releaseLock, restoreSerializedObject, serailizeObject, setDebug, unlock
public SimpleDataStore(java.lang.String dataPath, boolean useCache) throws java.lang.Exception
get(String)
and
get(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 the getCopy(String)
or getCopy(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.
dataPath
- The directory where the serialzed objects are stored.useCache
- Indicates whether to cache the objects in RAM memory for faster
retrievel.java.lang.Exception
- If error.public SimpleDataStore()
public java.lang.Object get(java.lang.String oid)
get(List)
method. To get a copy of a data item that is safe to modify use the
getCopy(String)
method instead. If caching is not enabled, the effect of
this method is the same as getCopy(String)
.get
in class SerializedDataManager
oid
- The data identifierObject
of data or null.getCopy(String)
public java.lang.Object getCopy(java.lang.String oid)
getCopy
in class SerializedDataManager
oid
- The data identifier.Object
of data that is in this SimpleDataStore
or null.get(String)
public java.util.List get(java.util.List oids)
List
of 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 the get(String)
method. To
get a copy of a data items that are safe to modify use the getCopy(List)
method instead. If caching is not ebabled, the effect of this method is the same as
getCopy(List)
.get
in class SerializedDataManager
oids
- List
of data identifiersList
of corresponding data objectsgetCopy(List)
public java.util.List getCopy(java.util.List oids)
List
of copied data objects, suitable for modifying. The
objects that are returned are safe for modifying without affecting the data that is
in this SimpleDataStore.getCopy
in class SerializedDataManager
oids
- List
of data identifiers.List
of corresponding data objects copies.get(List)
public java.lang.Object remove(java.lang.String oid, java.lang.String lockKey)
remove
in class SerializedDataManager
oid
- The unique identifier that references the data object to be removedlockKey
- The key corresponding to the lock on this data objectpublic java.lang.Object remove(java.lang.String oid)
remove
in class SerializedDataManager
oid
- The unique identifier that references the data object to be removedpublic boolean delete(java.lang.String oid, java.lang.String lockKey)
remove()
except no object is returned and
thus is more efficient if an object is not required.delete
in class SerializedDataManager
oid
- The unique identifier that references the data object to be deletedlockKey
- The key corresponding to the lock on this data objectpublic boolean delete(java.lang.String oid)
remove()
except no object is returned and thus is more efficient. After successful completion
the object is deleted from the DataManager.delete
in class SerializedDataManager
oid
- The unique identifier that references the data object to be deletedpublic java.lang.Object put(java.lang.String oid, java.lang.Object obj)
put
in class SerializedDataManager
oid
- The unique identifier that references the new data objectobj
- The new data objectpublic java.lang.Object put(java.lang.String oid, java.lang.Object obj, java.lang.String lockKey)
oid
- The unique identifier that references the new data objectobj
- The new data objectlockKey
- The key corresponding to the lock on this data objectpublic java.lang.Object update(java.lang.String oid, java.lang.Object obj, java.lang.String lockKey)
update
in class SerializedDataManager
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 objectpublic java.lang.Object update(java.lang.String oid, java.lang.Object obj)
update
in class SerializedDataManager
oid
- The unique identifier that references the data object to be updatedobj
- The new updated data objectpublic long getLastModifiedDate(java.lang.String oid)
getLastModifiedDate
in class SerializedDataManager
oid
- The unique identifier that references the data object