try{
result = doc.getResult();
broker = getBroker(new PBKey(site.getDbConnectionAlias()));
broker.beginTransaction();
broker.store(doc, ObjectModificationDefaultImpl.INSERT);
broker.commitTransaction();
//IF THERE IS NO SPECIAL REASON FOR THIS, IT IS NOT NECESSARY
// broker.clearCache(); result.setValidity(IResult.SAVED_SUCCESS);
return doc;
}catch( Exception e ){
if ( ( broker != null ) && ( broker.isInTransaction() ) ) {
broker.abortTransaction();
}
pb.removeFromCache( doc ); //Make sure it is not cached
throw new ServiceException(e);
}finally{
if( broker != null ){
broker.close();
}
}Note that the content of the 'doc' instance that you return will not be rolled back, you have to reload its contents from the database.
bye danilo
hi,
i cant make a rollback if a PersistenceBorker transaction is failed... my snippet is as followed.... pls advised.... thanks....
try{ result = doc.getResult(); broker = getBroker(new PBKey(site.getDbConnectionAlias())); broker.beginTransaction(); if(broker.isInTransaction()) broker.store(doc, ObjectModificationDefaultImpl.INSERT); else{ broker.abortTransaction(); } broker.commitTransaction(); broker.clearCache(); result.setValidity(IResult.SAVED_SUCCESS); return doc; }catch(TransactionAbortedException e){ broker.abortTransaction(); throw new ServiceException(e); }catch(PersistenceBrokerException e){ broker.abortTransaction(); throw new ServiceException(e); }finally{ if(broker != null){ broker.close(); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
