コード例 #1
0
ファイル: CommunityDAO.java プロジェクト: weilongw/Breeze
 public void updateUserCount(int x, String name) throws DAOException {
   try {
     Transaction.begin();
     Community comm = factory.lookup(name);
     comm.setUserCount(comm.getUserCount() + x);
     Transaction.commit();
   } catch (RollbackException e) {
     throw new DAOException(e);
   } finally {
     if (Transaction.isActive()) Transaction.rollback();
   }
 }
コード例 #2
0
ファイル: EventDAO.java プロジェクト: cneale/Sample-Code
  public void create(EventBean newEvent) throws DAOException {
    try {
      Transaction.begin();
      EventBean dbEvent = factory.create();
      factory.copyInto(newEvent, dbEvent);
      Transaction.commit();

    } catch (RollbackException e) {
      throw new DAOException(e);
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
    }
  }
コード例 #3
0
 @Override
 public synchronized Course createCourse(String courseName, String createdBy)
     throws MyDAOException {
   try {
     Transaction.begin();
     Course newCourse = factory.create(courseName);
     newCourse.setCreatedBy(createdBy);
     Transaction.commit();
     return newCourse;
   } catch (DuplicateKeyException e) {
     throw new MyDAOException("A course with this name already exists.");
   } catch (RollbackException e) {
     throw new MyDAOException(e);
   }
 }
コード例 #4
0
ファイル: CommunityDAO.java プロジェクト: weilongw/Breeze
  public void create(Community community) throws DAOException {
    try {
      Transaction.begin();
      Community dbcommunity = factory.create(community.getName());
      factory.copyInto(community, dbcommunity);

      Transaction.commit();

    } catch (DuplicateKeyException e) {
      throw new DAOException("Community named " + community.getName() + " already exists.");
    } catch (RollbackException e) {
      throw new DAOException(e);
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
    }
  }
コード例 #5
0
ファイル: UserDAO.java プロジェクト: cneale/Sample-Code
 public void create(UserBean user) throws DAOException {
   String origID = user.getUserID();
   try {
     Transaction.begin();
     user.setUserID(user.getUserID().toLowerCase());
     UserBean dBUser = factory.create(user.getUserID());
     factory.copyInto(user, dBUser);
     Transaction.commit();
   } catch (DuplicateKeyException e) {
     throw new DAOException("UserID: " + user.getUserID() + "already exists.");
   } catch (RollbackException e) {
     throw new DAOException(e);
   } finally {
     if (Transaction.isActive()) Transaction.rollback();
   }
 }
コード例 #6
0
ファイル: UserDAO.java プロジェクト: cneale/Sample-Code
  public void setEvent(int eventid, String userid) throws DAOException {
    try {
      Transaction.begin();
      UserBean dbUser = factory.lookup(userid);

      if (dbUser == null) {
        throw new DAOException("User " + userid + " no longer exists");
      }

      dbUser.seteventAttendingID(eventid);
      Transaction.commit();
    } catch (RollbackException e) {
      throw new DAOException(e);
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
    }
  }
コード例 #7
0
ファイル: EventDAO.java プロジェクト: cneale/Sample-Code
  public void delete(int id, String owner) throws DAOException {
    try {
      Transaction.begin();
      EventBean p = factory.lookup(id);

      if (p == null) {
        throw new DAOException("Event does not exist: id=" + id);
      }

      if (!owner.equals(p.getUserId())) {
        throw new DAOException("Event not owned by " + owner);
      }
      factory.delete(id);
      Transaction.commit();
    } catch (RollbackException e) {
      throw new DAOException(e);
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
    }
  }
コード例 #8
0
  @Override
  public String perform(HttpServletRequest request) {
    ExchangeForm form = formBeanFactory.create(request);
    List<String> errors = prepareErrors(request);
    User curUser = (User) request.getSession().getAttribute("user");
    if (curUser == null) {
      errors.add("You are not logged in");
      return "browse.do";
    }
    if (!form.isPresent()) {
      return "browse.do";
    }
    errors.addAll(form.getValidationErrors());
    if (errors.size() != 0) return "browse.do";

    Exchange xchg = null;
    User admin = null;
    try {
      xchg = exchangeDAO.lookup(form.getExchangeIdAsInt());
      admin = userDAO.lookup("Admin");
      curUser = userDAO.lookup(curUser.getUserName());
    } catch (DAOException e) {
      errors.add(e.getMessage());
      return "browse.do";
    }
    request.getSession().setAttribute("user", curUser);
    if (xchg == null) {
      errors.add("Transaction not found");
      return "browse.do";
    }
    Item item = null;
    try {
      item = itemDAO.getItemById(xchg.getItem().getId());
    } catch (DAOException e) {
      errors.add(e.getMessage());
      return "browse.do";
    }
    if (!xchg.getPoster().getUserName().equals(curUser.getUserName())) {
      errors.add("You are not the owner of the item");
      return "showMyItems.do";
    }
    if (xchg.getStatus() == Exchange.CLOSED || item.getStatus() == Item.CLOSED) {
      errors.add("Item already closed");
      return "showMyItems.do";
    }
    try {
      Transaction.begin();
      if (xchg.getRespondType() == Exchange.ANSWER_REQUEST_FOR_CREDIT) {
        userDAO.transferCredit(item.getCredit(), xchg.getPoster(), xchg.getResponder());
        curUser.setCredit(curUser.getCredit() - item.getCredit());
      }
      String url1 = "<a href=&quot;showItems.do?itemId=" + item.getId() + "&quot;>item</a>";
      itemDAO.closeItem(item.getId());
      exchangeDAO.setSuccessTransaction(xchg.getId());
      messageDAO.send(
          admin,
          curUser,
          "Transaction on (" + item.getItemName() + ") complete",
          "You have accepted the request from ("
              + "<a href=&quot;redirectSend.do?receiver="
              + xchg.getResponder().getUserName()
              + "&quot;>"
              + xchg.getResponder().getUserName()
              + "</a>). Your "
              + url1
              + " is now closed.");
      userDAO.updateNewMsgCount(curUser.getUserName(), 1);
      messageDAO.send(
          admin,
          xchg.getResponder(),
          "Transaction on (" + item.getItemName() + ") complete",
          "The <a href=&quot;redirectSend.do?receiver="
              + item.getOwner().getUserName()
              + "&quot;>owner</a> of "
              + url1
              + " has accepted your request");

      userDAO.updateNewMsgCount(xchg.getResponder().getUserName(), 1);
      Exchange[] pending = exchangeDAO.findItemPendingTransactions(item);
      for (Exchange each : pending) {
        messageDAO.send(
            admin,
            each.getResponder(),
            "Transaction on (" + item.getItemName() + ") dismissed",
            "The item you have reponded to is now closed");
        userDAO.updateNewMsgCount(each.getResponder().getUserName(), 1);
      }
      exchangeDAO.closeItemTransaction(item);
      Transaction.commit();
    } catch (RollbackException e) {
      errors.add(e.getMessage());
      return "showMyItems.do";
    } finally {
      if (Transaction.isActive()) Transaction.rollback();
    }
    try {
      curUser = userDAO.lookup(curUser.getUserName());
    } catch (DAOException e) {
      errors.add(e.getMessage());
      return "showMyItems.do";
    }
    request.getSession().setAttribute("user", curUser);
    request.setAttribute("success", "Congrats, your transaction has been made");
    return "showMyItems.do";
  }