Search in sources :

Example 1 with DeleteItem

use of com.zimbra.cs.redolog.op.DeleteItem in project zm-mailbox by Zimbra.

the class Mailbox method deletedBatchOfItemsInFolder.

private boolean deletedBatchOfItemsInFolder(OperationContext octxt, QueryParams params, TargetConstraint tcon) throws ServiceException {
    // Lock this mailbox to make sure that no one modifies the items we're about to delete.
    lock.lock();
    try {
        DeleteItem redoRecorder = new DeleteItem(mId, MailItem.Type.UNKNOWN, tcon);
        boolean success = false;
        try {
            beginTransaction("delete", octxt, redoRecorder);
            setOperationTargetConstraint(tcon);
            PendingDelete info = DbMailItem.getLeafNodes(this, params);
            if (info.itemIds.isEmpty()) {
                return false;
            }
            redoRecorder.setIds(ArrayUtil.toIntArray(info.itemIds.getAllIds()));
            MailItem.delete(this, info, null, true, /* writeTombstones */
            false);
            success = true;
        } finally {
            endTransaction(success);
        }
    } finally {
        lock.release();
    }
    return true;
}
Also used : DeleteItem(com.zimbra.cs.redolog.op.DeleteItem) PendingDelete(com.zimbra.cs.mailbox.MailItem.PendingDelete)

Example 2 with DeleteItem

use of com.zimbra.cs.redolog.op.DeleteItem in project zm-mailbox by Zimbra.

the class Mailbox method delete.

/**
 * Delete the <tt>MailItem</tt>s with the given ids.  If there is no <tt>MailItem</tt> for a given id, that id is
 * ignored.  If the id maps to an existing <tt>MailItem</tt> of an incompatible type, however, an error is thrown.
 *
 * @param octxt operation context or {@code null}
 * @param itemIds item ids
 * @param type item type or {@link MailItem.Type#UNKNOWN}
 * @param tcon target constraint or {@code null}
 * @param useEmptyForFolders empty folder {@code true} or {@code false}
 * @param nonExistingItems object of {@link ArrayList} or {@code null}
 */
private void delete(OperationContext octxt, int[] itemIds, MailItem.Type type, TargetConstraint tcon, boolean useEmptyForFolders, List<Integer> nonExistingItems) throws ServiceException {
    DeleteItem redoRecorder = new DeleteItem(mId, itemIds, type, tcon);
    List<Integer> folderIds = Lists.newArrayList();
    boolean success = false;
    try {
        beginTransaction("delete", octxt, redoRecorder);
        setOperationTargetConstraint(tcon);
        for (int id : itemIds) {
            if (id == ID_AUTO_INCREMENT) {
                continue;
            }
            MailItem item;
            try {
                item = getItemById(id, MailItem.Type.UNKNOWN);
            } catch (NoSuchItemException nsie) {
                if (nonExistingItems != null) {
                    nonExistingItems.add(id);
                }
                // trying to delete nonexistent things is A-OK!
                continue;
            }
            // however, trying to delete messages and passing in a folder ID is not OK
            if (!MailItem.isAcceptableType(type, item.getType())) {
                throw MailItem.noSuchItem(id, type);
            } else if (!checkItemChangeID(item) && item instanceof Tag) {
                throw MailServiceException.MODIFY_CONFLICT();
            }
            if (useEmptyForFolders && MailItem.Type.FOLDER.equals(item.getType())) {
                // removed later to allow batching delete of contents in there own transactions
                folderIds.add(id);
            } else {
                // delete the item, but don't write the tombstone until we're finished...
                item.delete(false);
            }
        }
        // deletes have already been collected, so fetch the tombstones and write once
        TypedIdList tombstones = collectPendingTombstones();
        if (tombstones != null && !tombstones.isEmpty()) {
            DbMailItem.writeTombstones(this, tombstones);
        }
        success = true;
    } finally {
        endTransaction(success);
    }
    for (Integer folderId : folderIds) {
        emptyFolder(octxt, folderId, true, /* removeTopLevelFolder */
        true, /* removeSubfolders */
        tcon);
    }
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) DeleteItem(com.zimbra.cs.redolog.op.DeleteItem) AlterItemTag(com.zimbra.cs.redolog.op.AlterItemTag) CreateTag(com.zimbra.cs.redolog.op.CreateTag) DbTag(com.zimbra.cs.db.DbTag) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Aggregations

DeleteItem (com.zimbra.cs.redolog.op.DeleteItem)2 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)1 DbMailItem (com.zimbra.cs.db.DbMailItem)1 DbTag (com.zimbra.cs.db.DbTag)1 PendingDelete (com.zimbra.cs.mailbox.MailItem.PendingDelete)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)1 TypedIdList (com.zimbra.cs.mailbox.util.TypedIdList)1 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 CreateTag (com.zimbra.cs.redolog.op.CreateTag)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1