public class PersistentObject extends DomainObject
The store()
, restore()
, and delete()
methods should be overridden to provide the appropriate logic for
interacting with the persistent store.
This class provides support for time-to-live, timestamping, and expiration.
This support facilitates the implementation of a caching mechanism for
persistent objects. See PersistentObjectPool
for one such
implementation. An object can be explicitly expired via a call to
expire()
; this will cause the object to be removed from
any cache when the cache performs its next expiration sweep.
PersistentObjectPool
Modifier and Type | Field and Description |
---|---|
protected int |
id
The ID of the object.
|
private long |
lastAccess |
protected int |
timeToLive
The object's ttl (time to live) value, in milliseconds.
|
Constructor and Description |
---|
PersistentObject()
Construct a new
PersistentObject . |
PersistentObject(int id)
Construct a new
PersistentObject with the given ID. |
Modifier and Type | Method and Description |
---|---|
void |
delete()
Delete this object from a persistent store, presumably a SQL database.
|
void |
dispose()
Dispose of this object.
|
boolean |
equals(Object o)
Determine if this object is equal to another object.
|
void |
expire()
Expire this object.
|
int |
getID()
Get the ID for this object.
|
int |
hashCode()
Obtain the hashcode for this object.
|
protected boolean |
isExpired(long now)
Determine if this object has expired.
|
boolean |
isNew()
Determine if this object is new.
|
void |
restore()
Restore this object from a persistent store, presumably a SQL database.
|
void |
setID(int id)
Set the ID for this object.
|
void |
store()
Store this object in a persistent store, presumably a SQL database.
|
protected void |
timestamp()
Set the last access time for this object to the current time.
|
String |
toString()
Generate a string representation of this object.
|
ensureNonNegative, ensureNonNegative, ensureNonNegative, ensureNotNull, ensurePositive, ensurePositive, ensurePositive, trapNull
protected int id
private long lastAccess
protected int timeToLive
public PersistentObject()
PersistentObject
. The object will have an
ID of -1.public PersistentObject(int id)
PersistentObject
with the given ID.id
- The ID for the object.protected void timestamp()
public void expire()
protected final boolean isExpired(long now)
now
- The current time.true
if the object has expired, and
false
otherwise.public boolean isNew()
true
if the object is new, and false
otherwise.public int getID()
public void setID(int id)
id
- The new ID.public void dispose()
public int hashCode()
Object.hashCode()
is
called to generate the hashcode.public void store() throws SQLException
SQLException
- If the operation failed.public void restore() throws SQLException
SQLException
- If the operation failed.public void delete() throws SQLException
SQLException
- If the operation failed.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses