org.garret.perst
Class Persistent

java.lang.Object
  extended byorg.garret.perst.Persistent
All Implemented Interfaces:
java.io.Externalizable, IPersistent, java.io.Serializable
Direct Known Subclasses:
PersistentComparator, PersistentResource, Relation, TimeSeriesBlock

public class Persistent
extends java.lang.Object
implements IPersistent

Base class for all persistent capable objects

See Also:
Serialized Form

Constructor Summary
Persistent()
           
Persistent(Storage storage)
           
 
Method Summary
 void assignOid(Storage storage, int oid, boolean raw)
          Assign OID to the object.
 void deallocate()
          Deallocate persistent object from the database
 boolean equals(java.lang.Object o)
           
 int getOid()
          Get object identifier (OID)
 Storage getStorage()
          Get storage in which this object is stored
 int hashCode()
           
 void invalidate()
          Invalidate object.
 boolean isDeleted()
          Check if object is deleted by Java GC from process memory
 boolean isModified()
          Check if object was modified within current transaction
 boolean isPersistent()
          Check if object is persistent
 boolean isRaw()
          Check if object is stub and has to be loaded from the database
 void load()
          Load object from the database (if needed)
 void loadAndModify()
          Load object from the database (if needed) and mark it as modified
 void makePersistent(Storage storage)
          Explicitely make object peristent.
 void modify()
          Mark object as modified.
 void onLoad()
          Method called by the database after loading of the object.
 void onStore()
          Method called by the database before storing of the object.
 void readExternal(java.io.ObjectInput s)
           
 boolean recursiveLoading()
          Specified whether object should be automatically loaded when it is referenced by other loaded peristent object.
 void store()
          Save object in the database
 void writeExternal(java.io.ObjectOutput s)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Persistent

public Persistent()

Persistent

public Persistent(Storage storage)
Method Detail

assignOid

public void assignOid(Storage storage,
                      int oid,
                      boolean raw)
Description copied from interface: IPersistent
Assign OID to the object. This method is used by storage class and you should not invoke it directly

Specified by:
assignOid in interface IPersistent
Parameters:
storage - associated storage
oid - object identifier

deallocate

public void deallocate()
Description copied from interface: IPersistent
Deallocate persistent object from the database

Specified by:
deallocate in interface IPersistent

equals

public boolean equals(java.lang.Object o)

getOid

public final int getOid()
Description copied from interface: IPersistent
Get object identifier (OID)

Specified by:
getOid in interface IPersistent
Returns:
OID (0 if object is not persistent yet)

getStorage

public final Storage getStorage()
Description copied from interface: IPersistent
Get storage in which this object is stored

Specified by:
getStorage in interface IPersistent
Returns:
storage containing this object (null if object is not persistent yet)

hashCode

public int hashCode()

invalidate

public void invalidate()
Description copied from interface: IPersistent
Invalidate object. Invalidated object has to be explicitly reloaded usin3g load() method. Attempt to store invalidated object will cause StoraegError exception.

Specified by:
invalidate in interface IPersistent

isDeleted

public final boolean isDeleted()
Description copied from interface: IPersistent
Check if object is deleted by Java GC from process memory

Specified by:
isDeleted in interface IPersistent
Returns:
true if object is deleted by GC

isModified

public final boolean isModified()
Description copied from interface: IPersistent
Check if object was modified within current transaction

Specified by:
isModified in interface IPersistent
Returns:
true if object is persistent and was modified within current transaction

isPersistent

public final boolean isPersistent()
Description copied from interface: IPersistent
Check if object is persistent

Specified by:
isPersistent in interface IPersistent
Returns:
true if object has assigned OID

isRaw

public final boolean isRaw()
Description copied from interface: IPersistent
Check if object is stub and has to be loaded from the database

Specified by:
isRaw in interface IPersistent
Returns:
true if object has to be loaded from the database

load

public void load()
Description copied from interface: IPersistent
Load object from the database (if needed)

Specified by:
load in interface IPersistent

loadAndModify

public void loadAndModify()
Description copied from interface: IPersistent
Load object from the database (if needed) and mark it as modified

Specified by:
loadAndModify in interface IPersistent

makePersistent

public void makePersistent(Storage storage)
Description copied from interface: IPersistent
Explicitely make object peristent. Usually objects are made persistent implicitlely using "persistency on reachability apporach", but this method allows to do it explicitly

Specified by:
makePersistent in interface IPersistent
Parameters:
storage - storage in which object should be stored

modify

public void modify()
Description copied from interface: IPersistent
Mark object as modified. Object will be saved to the database during transaction commit.

Specified by:
modify in interface IPersistent

onLoad

public void onLoad()
Description copied from interface: IPersistent
Method called by the database after loading of the object. It can be used to initialize transient fields of the object. Default implementation of this method do nothing

Specified by:
onLoad in interface IPersistent

onStore

public void onStore()
Description copied from interface: IPersistent
Method called by the database before storing of the object. It can be used to save or close transient fields of the object. Default implementation of this method do nothing

Specified by:
onStore in interface IPersistent

readExternal

public void readExternal(java.io.ObjectInput s)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

recursiveLoading

public boolean recursiveLoading()
Description copied from interface: IPersistent
Specified whether object should be automatically loaded when it is referenced by other loaded peristent object. Default implementation of this method returns true making all cluster of referenced objects loaded together. To avoid main memory overflow you should stop recursive loading of all objects from the database to main memory by redefining this method in some classes and returing false in it. In this case object has to be loaded explicitely using Persistent.load method.

Specified by:
recursiveLoading in interface IPersistent
Returns:
true if object is automatically loaded

store

public void store()
Description copied from interface: IPersistent
Save object in the database

Specified by:
store in interface IPersistent

writeExternal

public void writeExternal(java.io.ObjectOutput s)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException