コード例 #1
0
ファイル: SchedulerTask.java プロジェクト: CpuID/jentrata-msh
  /**
   * Attempt to clean out the AS2 database
   *
   * @param months
   * @throws Exception
   * @throws DAOException
   * @throws DAOException
   */
  protected Transaction cleanAS2(int months) throws Exception {
    try {
      MessageDAO dao = (MessageDAO) AS2Processor.core.dao.createDAO(MessageDAO.class);
      Transaction tr = ((MessageDataSourceDAO) dao).getFactory().createTransaction();
      RepositoryDAO repDao = (RepositoryDAO) AS2Processor.core.dao.createDAO(RepositoryDAO.class);
      dao.setTransaction(tr);
      repDao.setTransaction(tr);
      tr.begin();

      List list = dao.findMessagesBeforeTime(months);
      AS2Logging(Integer.toString(list.size()) + " messages will be removed.");
      AS2Logging("Initializing...");

      Iterator itr = list.iterator();
      MessageDVO dvo;
      RepositoryDVO repDvo;

      while (itr.hasNext()) {
        dvo = (MessageDVO) itr.next();
        repDvo = (RepositoryDVO) repDao.createDVO();
        repDvo.setMessageId(dvo.getMessageId());
        repDvo.setMessageBox(dvo.getMessageBox());
        repDao.remove(repDvo);
        dao.remove(dvo);
      }
      return tr;
    } catch (DAOException e) {
      AS2Error("Error encountered while cleaning.");
      throw new Exception("Error encountered while cleaning AS2.", e);
    }
  }
コード例 #2
0
ファイル: SchedulerTask.java プロジェクト: CpuID/jentrata-msh
  /**
   * Attempt to clean the EBMS messages.
   *
   * @param months
   * @return
   * @throws Exception
   * @throws Exception
   * @throws DAOException
   */
  protected Transaction cleanEBMS(int months) throws Exception {
    try {
      hk.hku.cecid.ebms.spa.dao.MessageDAO dao =
          (hk.hku.cecid.ebms.spa.dao.MessageDAO)
              EbmsProcessor.core.dao.createDAO(hk.hku.cecid.ebms.spa.dao.MessageDAO.class);
      InboxDAO inboxDao = (InboxDAO) EbmsProcessor.core.dao.createDAO(InboxDAO.class);
      OutboxDAO outboxDao = (OutboxDAO) EbmsProcessor.core.dao.createDAO(OutboxDAO.class);
      hk.hku.cecid.ebms.spa.dao.RepositoryDAO repDao =
          (hk.hku.cecid.ebms.spa.dao.RepositoryDAO)
              EbmsProcessor.core.dao.createDAO(hk.hku.cecid.ebms.spa.dao.RepositoryDAO.class);

      Transaction tr =
          ((hk.hku.cecid.ebms.spa.dao.MessageDataSourceDAO) dao).getFactory().createTransaction();

      dao.setTransaction(tr);
      inboxDao.setTransaction(tr);
      outboxDao.setTransaction(tr);
      repDao.setTransaction(tr);
      tr.begin();

      List list = dao.findMessagesBeforeTime(months);
      EBMSLogging(Integer.toString(list.size()) + " messages will be removed.");
      EBMSLogging("Initializing...");

      Iterator itr = list.iterator();

      hk.hku.cecid.ebms.spa.dao.MessageDVO dvo;
      InboxDVO inboxDvo;
      OutboxDVO outboxDvo;
      hk.hku.cecid.ebms.spa.dao.RepositoryDVO repDvo;

      while (itr.hasNext()) {
        dvo = (hk.hku.cecid.ebms.spa.dao.MessageDVO) itr.next();
        if (dvo.getMessageBox().equals("inbox")) {
          /** delete the inbox entry */
          inboxDvo = (InboxDVO) inboxDao.createDVO();
          inboxDvo.setMessageId(dvo.getMessageId());
          inboxDao.remove(inboxDvo);
        } else if (dvo.getMessageBox().equals("outbox")) {
          /** delete the outbox entry */
          outboxDvo = (OutboxDVO) outboxDao.createDVO();
          outboxDvo.setMessageId(dvo.getMessageId());
          outboxDao.remove(outboxDvo);
        } else {
          EBMSError("Unknown value in MessageBox relation.");
          throw new Exception("Error, unknown value in MessageBox relation.");
        }
        /** remove entry in repository */
        repDvo = (hk.hku.cecid.ebms.spa.dao.RepositoryDVO) repDao.createDVO();
        repDvo.setMessageId(dvo.getMessageId());
        repDvo.setMessageBox(dvo.getMessageBox());
        repDao.remove(repDvo);
        /** finally remove from message table */
        dao.remove(dvo);
      }
      return tr;
    } catch (DAOException e) {
      EBMSError("Error encountered while cleaning.");
      throw new Exception("Error encountered while cleaning EBmS.", e);
    }
  }