|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--rmrs.persist.PersistentObject
Any class needing persistence for its object must inherit from the class PersistentObject. To persist an object it needs a persistence broker assigned to it. A peristence broker is assigned to an object in either of two ways:
void save(PersistenceBroker broker)
,
void save()
without arguments.
A persistence broker is statically assigned to each object. At this point, an object can not migrate from one broker to another, however, this could be made possible quite easily.
Note that persistence brokers are assigned to objects not to entire classes. This means, that the objects of one class can be distributed over multiple persistence brokers.
A class that inherits from PersistentObject only needs to obey to a few conventions, as described in the following checklist:
Provide either a public default constructor (i.e. a constructor without arguments),
or provide a static method without arguments that returns a new java object of the given class. Using that latter method is preferred since it can be private and thus protected from accidential abuse outside the business of perstistence.
To check the consistency of a retireved object and to reset
transient variables that were not stored, the persistent class
should provide a method void notifyRestored()
. The
persistence broker will call this method when the object has
been retrieved.
When an object is saved for the first time it will be assigned a unique object id. Currently that object id is unique only within the persistence broker, but (with only a few more work) it can be made unique accross all objects.
A persistent object can be in any of three principle "moods". This "mood" can not change throughout the life of a Java object.
A real object represents a persistent object in a Java VM. Multiple JVMs can have the same persistent object checked out at the same time, but each persistent object can only occur once as a real object in any JVM. (Note: the concurrency is not currently checked and handled reliably. Needs more work.)
A query example is a java object of a persistent class that is not in itself persistent, does not have an OID, and does not represent an individuum. Conversely, a query example represents an entire class (set) of objects that have are consistent with the specified field values.
An object view is a java object without itself being persistent reflecting other persistent objects one at a time. An object view is like a mirror that can show different faces without being itself a face. Object views will be used to allow scanning through data base tables without incurring the high price of Java object creation. Not currently used.
Field Summary | |
static int |
AUTO_SAVE
object is supposed to be automatically saved upon finalization. |
static int |
NEW
indicates the object is brand new, never saved before. |
static int |
OBJECT_VIEW
indicates that object is an object view, whose values reflect the values of another real object. |
static int |
QUERY_EXAMPLE
indicates that object is a query example used in formulating queries. |
static int |
REAL_OBJECT
indicates that object is a real perisistent object, it can be saved and retrieved. |
static int |
SAVEABLE
object is a real object an not write protected. |
Constructor Summary | |
protected |
PersistentObject()
A constructor called automatically for any new persisten object created. |
Method Summary | |
protected java.lang.Object |
clone()
Cloning becomes important to build convenient query examples (QE) and object views (OV). |
PersistentObject |
cloneQueryExample()
Create a query example to query for all objects that are like this object. |
protected void |
finalize()
This is for the auto save functionality, but finalize is not called at the end of the program, why? Is it not virtual? |
java.util.Date |
getCheckOutTime()
Get accessor to check out time. |
protected int |
getFlags()
Get accessor to the management bitset. |
java.util.Date |
getLastSaveTime()
Get accessor to time the object was last saved time. |
OID |
getOID()
Get accessor to OID field. |
PersistenceBroker |
getPersistenceBroker()
Get currently assigned persistence broker. |
boolean |
isAutoSave()
Predicate telling whether the object is supposed to be saved on finalization. |
boolean |
isNew()
Predicate telling whether the object has never been saved. |
boolean |
isObjectView()
Predicate telling whether the java object is an object view. |
boolean |
isQueryExample()
Predicate telling whether the java object is a query example. |
boolean |
isRealObject()
Predicate telling whether the java object is a real object. |
boolean |
isSaveable()
Predicate telling whether the object can be saved. |
protected void |
notifyRestored()
Call-back method to check the consistency of a retireved object and to reset transient variables that were not stored, the persistent class should overload this method if it maintains transient state. |
protected void |
prepareRestoring(PersistenceBroker pb,
OID oid,
int flags,
java.util.Date cotime,
java.util.Date lstime)
The persistence broker calls this method shortly before retrieval to set the management field. |
ObjectSet |
query()
Query for all objects that are like this query example. |
ObjectSet |
query(PersistenceBroker pb)
Query for all objects that are like this query example. |
void |
save()
Save an object with a previously assigned persistence broker. |
void |
save(PersistenceBroker pb)
Save an object with a persistence broker. |
void |
setAutoSave(boolean v)
Automatically save object in finalization. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int NEW
public static final int REAL_OBJECT
public static final int QUERY_EXAMPLE
public static final int OBJECT_VIEW
public static final int SAVEABLE
public static final int AUTO_SAVE
Constructor Detail |
protected PersistentObject()
Method Detail |
public OID getOID()
public java.util.Date getCheckOutTime()
public java.util.Date getLastSaveTime()
protected int getFlags()
public PersistenceBroker getPersistenceBroker()
public boolean isNew()
public boolean isSaveable()
public boolean isAutoSave()
public boolean isRealObject()
public boolean isQueryExample()
public boolean isObjectView()
public void setAutoSave(boolean v)
v
- true to turn on auto save, false to turn it off.public void save(PersistenceBroker pb) throws PersistException
pb
- a persistence broker that can store this kind of
objects.public void save() throws PersistException
protected void notifyRestored()
protected void prepareRestoring(PersistenceBroker pb, OID oid, int flags, java.util.Date cotime, java.util.Date lstime)
protected void finalize() throws PersistException
protected java.lang.Object clone()
Cloning comes into place at three steps:
a user can clone a real object to create a QE object. The user can then change some values and set other values to null and pass the QE object to a persistence broker's query method.
the persistence broker will clone a QE object to create an OV object, which it returns to present the query results.
the user can clone an OV object to create the real object currently represented by that OV.
This query by example feature is very intuitive and saves the programmer from dealing with lots of artificial query-criteria objects. It is also independent of SQL, i.e., it could work as well in an OODB.
What is arguably nice is that the user deals with one application class (e.g., Employee) and can use it to create real objects, QE objects and OV objects. This allows great uniformity since dealing with those objects is largely independent on their mood. (We call "mood" what distinguishes real objects from QE and QV.)
There is a slight risk, though, that may or may not turn out to be crucial. The programmer must never assign an OV object to other objects as if it where a real object, since an OV object changes its values farther down the road. Same is true for QE objects, but since a QE object is passed to the data base and not returned from it, the mistake to use it right away will occur less likely.
So, all persistent objects are cloneable, but the clone method is not directly used. Instead, the methods cloneQueryExample, cloneObjectView, and cloneRealObject are used.
public PersistentObject cloneQueryExample()
public ObjectSet query(PersistenceBroker pb) throws PersistException
pb
- a persistence brokerpublic ObjectSet query() throws PersistException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |