Methods Summary |
---|
public final synchronized void | begin()
if( timestamp == -1L ) {
timestamp = (new Date()).getTime();
}
|
public abstract void | commit()
|
public final synchronized void | end()
try {
Iterator obs;
obs = toRemove.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
p.remove(this);
}
obs = toCreate.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
p.create(this);
}
obs = toStore.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
p.store(this);
}
commit();
obs = toRemove.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
p.commit(this);
}
obs = toCreate.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
p.commit(this);
}
obs = toStore.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
p.commit(this);
}
toCreate.clear();
obs = toRemove.iterator();
while( obs.hasNext() ) {
BaseEntity p = (BaseEntity)obs.next();
//p.invalidate();
}
toRemove.clear();
toStore.clear();
Transaction.transactions.remove(userID);
}
catch( TransactionException e ) {
Transaction trans;
Iterator obs;
e.printStackTrace();
rollback();
Transaction.transactions.remove(userID);
// use a different transaction to reload everyone
trans = Transaction.getCurrent(userID);
obs = toRemove.iterator();
while( obs.hasNext() ) {
BaseEntity ob = (BaseEntity)obs.next();
try {
ob.reload(trans);
}
catch( Exception disaster ) {
// remove it from the cache or something
}
}
obs = toStore.iterator();
while( obs.hasNext() ) {
BaseEntity ob = (BaseEntity)obs.next();
try {
ob.reload(trans);
}
catch( Exception disaster ) {
// remove it from the cache or something
}
}
throw e;
}
catch( Exception e ) {
rollback();
throw new TransactionException(e.getMessage());
}
finally {
timestamp = -1L;
}
|
public boolean | equals(java.lang.Object ob)
if( !(ob instanceof Transaction) ) {
return false;
}
else {
Transaction trans = (Transaction)ob;
return trans.userID.equals(userID);
}
|
public static com.imaginary.lwp.Transaction | getCurrent(Identifier id)
Transaction trans;
String cname;
if( id == null ) {
cname = System.getProperty(LWPProperties.XACTION);
try {
trans = (Transaction)Class.forName(cname).newInstance();
trans.userID = id;
}
catch( Exception e ) {
throw new ConfigurationException(e.getMessage());
}
}
synchronized( transactions ) {
if( transactions.containsKey(id) ) {
trans = (Transaction)transactions.get(id);
return trans;
}
cname = System.getProperty(LWPProperties.XACTION);
try {
trans = (Transaction)Class.forName(cname).newInstance();
trans.userID = id;
}
catch( Exception e ) {
throw new ConfigurationException(e.getMessage());
}
transactions.put(id, trans);
}
return trans;
|
public final synchronized Identifier | getIdentifier()
return userID;
|
public final synchronized long | getTimestamp()
return timestamp;
|
public final synchronized boolean | isInProcess()
return (timestamp != -1L);
|
final synchronized void | prepareCreate(BaseEntity ob)
if( toCreate.contains(ob) ) {
return;
}
toCreate.add(ob);
|
final synchronized void | prepareRemove(BaseEntity ob)
if( toRemove.contains(ob) ) {
return;
}
if( toCreate.contains(ob) ) {
toCreate.remove(ob);
return;
}
if( toStore.contains(ob) ) {
toStore.remove(ob);
}
toRemove.add(ob);
|
final synchronized void | prepareStore(BaseEntity ob)
if( toStore.contains(ob) || toCreate.contains(ob) ) {
return;
}
if( toRemove.contains(ob) ) {
return;
}
toStore.add(ob);
|
public abstract void | rollback()
|