public static void commit() {
Object accFromId = (Long)Cache.get("accFrom");
Object accToId = (Long)Cache.get("accTo");
TransactionAccountFromModel accFrom = TransactionAccountFromModel.getByKey(TransactionAccountFromModel.class, accFromId);
TransactionAccountToModel accTo = TransactionAccountToModel.getByKey(TransactionAccountToModel.class, accToId);
try {
accFrom.getPersistenceManager().beginTransaction();
accFrom.amount-=100L;
accFrom.save();
accTo.amount+=100L;
accTo.save();
accFrom.getPersistenceManager().commitTransaction();
}catch(SienaException e){
accFrom.getPersistenceManager().rollbackTransaction();
}finally{
accFrom.getPersistenceManager().closeConnection();
}
// refetches it to be sure of sure
accFrom = Model.getByKey(TransactionAccountFromModel.class, accFrom.id);
accTo = Model.getByKey(TransactionAccountToModel.class, accTo.id);