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;
}
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);
}
}
Aggregations