Package models

Examples of models.TransactionAccountFromModel


import siena.SienaException;


public class Transaction extends Controller {
  public static void index() {
    TransactionAccountFromModel accFrom = new TransactionAccountFromModel(1000L);
    TransactionAccountToModel accTo = new TransactionAccountToModel(1000L);
   
    accFrom.insert();
    accTo.insert();
     
    Cache.set("accFrom", accFrom.id);
    Cache.set("accTo", accTo.id);
    renderTemplate("Transaction/index.html", accFrom, accTo);
View Full Code Here


  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);
View Full Code Here

  public static void failure() {
    Long accFromId = (Long)Cache.get("accFrom");
    Long accToId = (Long)Cache.get("accTo");
   
    TransactionAccountFromModel accFrom = Model.getByKey(TransactionAccountFromModel.class, accFromId);
    TransactionAccountToModel accTo = Model.getByKey(TransactionAccountToModel.class, accToId);

    try {
      accFrom.getPersistenceManager().beginTransaction();
      accFrom.amount-=100L;
      accFrom.save();
      accTo.amount+=100L;
      accTo.save();
      throw new SienaException("problem");
    }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);
View Full Code Here

TOP

Related Classes of models.TransactionAccountFromModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.