示例#1
0
 public void create(TagBean newTagBean) throws RollbackException {
   try {
     Transaction.begin();
     createAutoIncrement(newTagBean);
     Transaction.commit();
   } finally {
     if (Transaction.isActive()) Transaction.rollback();
   }
 }
示例#2
0
  public void delete(int id, int rid) throws RollbackException {
    try {
      Transaction.begin();
      TagBean item = read(id);

      if (item == null) {
        throw new RollbackException("Step does not exist: id=" + id);
      }

      if (rid != item.getRid()) {
        throw new RollbackException("Step not owned by recipe id:" + rid);
      }

      delete(id);
      Transaction.commit();
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
    }
  }
示例#3
0
  public String perform(HttpServletRequest request) {
    HttpSession session = request.getSession();
    List<String> errors = new ArrayList<String>();
    // authority judge
    if ((EmployeeBean) session.getAttribute("employee") == null) {
      return "employeelogin.do";
    }

    request.setAttribute("errors", errors);
    EmployeeBean employee = (EmployeeBean) session.getAttribute("employee");
    if (employee == null) {
      return "employeelogin.do";
    }

    /*
     * Check the deposit form.
     */
    DepositCheckForm depositcheckform = new DepositCheckForm(request);
    request.setAttribute("depositcheckform", depositcheckform);
    if (!depositcheckform.isPresent()) {
      return "employee_deposit_check.jsp";
    }
    errors.addAll(depositcheckform.getValidationErrors());
    if (errors.size() != 0) {
      return "employee_deposit_check.jsp";
    }

    CustomerBean customer = (CustomerBean) session.getAttribute("modifyCustomer");
    int id = customer.getCustomerId();
    try {
      customer = customerDAO.read(id);
    } catch (RollbackException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    double amount = depositcheckform.getAmount();

    //////////////////////
    // Transaction START //
    //////////////////////
    try {
      Transaction.begin();
      TransactionBean transaction = new TransactionBean();
      // what kind of transaction
      transaction.setTransactionType(TransactionType.DEPOSIT.toString());
      // who request the deposit
      transaction.setCustomerId(customer.getCustomerId());
      // how much money(in long)
      transaction.writeAmount(amount);
      // Create transaction
      transactionDAO.create(transaction);

      // update balance&available immediately.
      customer.writeCashBalance(amount);
      customerDAO.update(customer);

      Transaction.commit();
    } catch (RollbackException e) {
      e.printStackTrace();
    }
    ////////////////////
    // Transaction END//
    ////////////////////

    session.setAttribute("modifyCustomer", customer);
    // session.setAttribute("customer", customer);

    session.setAttribute(
        "message", "Thank you! You have successfully sent your deposit check request!");
    return "success_employee.jsp";
  }