示例#1
0
  private void handleOutOfOffice(Account account) {
    try {
      Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);

      synchronized (DbMailbox.getZimbraSynchronizer(mbox)) {
        Connection conn = null;
        try {
          // clear the OOF database for this account
          conn = DbPool.getConnection(mbox);
          DbOutOfOffice.clear(conn, mbox);
          conn.commit();
          ZimbraLog.misc.info("reset vacation info");

          // Convenient place to prune old data, until we determine that this
          //  needs to be a separate scheduled process.
          // TODO: only prune once a day?
          long interval =
              account.getTimeInterval(
                  Provisioning.A_zimbraPrefOutOfOfficeCacheDuration,
                  Notification.DEFAULT_OUT_OF_OFFICE_CACHE_DURATION_MILLIS);
          DbOutOfOffice.prune(conn, interval);
          conn.commit();
        } catch (ServiceException e) {
          DbPool.quietRollback(conn);
        } finally {
          DbPool.quietClose(conn);
        }
      }
    } catch (ServiceException e) {
      ZimbraLog.misc.warn("error handling out-of-office", e);
    }
  }
 private void useMVCC(Mailbox mbox) throws ServiceException, SQLException {
   // tell HSQLDB to use multiversion so our asserts can read while write is open
   PreparedStatement stmt = null;
   ResultSet rs = null;
   DbConnection conn = DbPool.getConnection(mbox);
   try {
     stmt = conn.prepareStatement("SET DATABASE TRANSACTION CONTROL MVCC");
     stmt.executeUpdate();
   } finally {
     DbPool.closeResults(rs);
     DbPool.quietCloseStatement(stmt);
     DbPool.quietClose(conn);
   }
 }
 private int countInboxMessages(Mailbox mbox) throws ServiceException, SQLException {
   PreparedStatement stmt = null;
   ResultSet rs = null;
   DbConnection conn = DbPool.getConnection(mbox);
   try {
     stmt =
         conn.prepareStatement(
             "SELECT COUNT(*) FROM mboxgroup1.mail_item WHERE mailbox_id = ? and folder_id = ?");
     stmt.setInt(1, mbox.getId());
     stmt.setInt(2, Mailbox.ID_FOLDER_INBOX);
     rs = stmt.executeQuery();
     if (rs.next()) {
       return rs.getInt(1);
     }
     return 0;
   } finally {
     DbPool.closeResults(rs);
     DbPool.quietCloseStatement(stmt);
     DbPool.quietClose(conn);
   }
 }
 @Override
 public Results check(
     Collection<Short> volumeIds, int mboxId, boolean checkSize, boolean reportUsedBlobs)
     throws ServiceException {
   mailboxId = mboxId;
   this.checkSize = checkSize;
   this.reportUsedBlobs = reportUsedBlobs;
   results = new Results();
   Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailboxId);
   DbConnection conn = null;
   assert (StoreManager.getInstance() instanceof ExternalStoreManager);
   ExternalStoreManager sm = (ExternalStoreManager) StoreManager.getInstance();
   try {
     unexpectedBlobPaths = sm.getAllBlobPaths(mbox);
   } catch (IOException ioe) {
     log.error("IOException getting remote blob list", ioe);
   }
   try {
     conn = DbPool.getConnection();
     int mailboxMaxId = DbBlobConsistency.getMaxId(conn, mbox);
     int minId = 0;
     int maxId = CHUNK_SIZE;
     while (minId <= mailboxMaxId) {
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalMailItemBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalMailItemDumpsterBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalRevisionBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalRevisionDumpsterBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       minId = maxId + 1;
       maxId += CHUNK_SIZE;
     }
   } finally {
     DbPool.quietClose(conn);
   }
   for (String unexpected : unexpectedBlobPaths) {
     BlobInfo bi = new BlobInfo();
     bi.external = true;
     bi.locator = unexpected;
     bi.path = unexpected;
     results.unexpectedBlobs.put(0, bi);
     try {
       Blob blob = sm.getLocalBlob(mbox, unexpected, false);
       bi.fileSize = blob.getFile().length();
     } catch (IOException ioe) {
       // log this?
       bi.fileSize = 0L;
       bi.fetchException = ioe;
     }
   }
   return results;
 }