Methods Summary |
---|
public void | abort()Aborts any persistence operations in process and allows
persistent objects which have already done their operation
to take it back.
Persistent[] obs = getPersistents();
for(int i=0; i<obs.length; i++) {
try {
if( obs[i].isSaving() ) {
obs[i].abort();
}
}
catch( PersistenceException e ) {
e.printStackTrace();
}
}
|
synchronized void | addPersistent(Persistent p)Ties a new Persistent instance to this transactioon.
if( !objects.contains(p) ) {
objects.addElement(p);
}
|
public void | commit()This method should be extended in data store specific
transaction objects for sending a commit to the data store.
Within the Transaction class, it lets all locked objects know
that any data store commit was successful.
Persistent[] obs = getPersistents();
for(int i=0; i<obs.length; i++) {
if( obs[i].isSaving() ) {
obs[i].commit();
}
}
// commit done, prepare for new set of modifications
objects = new Vector();
|
synchronized Persistent[] | getPersistents()
Persistent[] obs = new Persistent[objects.size()];
objects.copyInto(obs);
return obs;
|
public static imaginary.persist.Transaction | getTransaction()Gets an instance of a Transaction subclass based on the URL
set by the application. Currently, only database persistence
is supported so all URL's are assumed to be JDBC URL's.
return new DatabaseTransaction(url, properties);
|
synchronized void | removePersistent(Persistent p)Removes the specified persistent from this transaction
if( objects.contains(p) ) {
objects.removeElement(p);
}
|
public void | restore(PersistentSet set, java.util.Hashtable data)Calls for the restoration of the specified PersistentSet
using a hashtable of query parameters.
set.restore(this, data);
|
public void | restore(Persistent p)Calls for the restoration of a particular object using this
Transaction.
p.restore(this);
|
public void | restore(Persistent p, java.util.Hashtable data)Calls for the restoration of the specified Persistent using
a hashtable of query parameters.
p.restore(this, data);
|
public void | save()This method goes through and triggers a save on all locked objects.
If the saves are all successful, then a commit() is triggered. If
any one of the saves fails, however, then an abort() is triggered.
Persistent[] obs = getPersistents();
for(int i=0; i<obs.length; i++) {
try {
if( obs[i].isModified() ) { // only save modified objects
obs[i].save();
}
}
catch( PersistenceException e ) {
abort(); // abort on error
throw e;
}
}
try {
commit(); // commit on success
}
catch( PersistenceException e ) {
abort(); // abort if the commit failed
throw e;
}
|