" WHERE " + (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") + precondition + " AND " + relation);
" WHERE " + IN_THIS_MAILBOX_AND + precondition + " AND " + relation);
    public static void alterTag(MailItem item, Tag tag, boolean add) throws ServiceException {        Mailbox mbox = item.getMailbox();        if (mbox != tag.getMailbox())            throw MailServiceException.WRONG_MAILBOX();        if (tag.getId() == Flag.ID_FLAG_UNREAD)            throw ServiceException.FAILURE("unread state must be updated with alterUnread()", null);        Connection conn = mbox.getOperationConnection();        PreparedStatement stmt = null;        try {            String relation, column = (tag instanceof Flag ? "flags" : "tags");            if (item instanceof VirtualConversation)  relation = "id = ?";            else if (item instanceof Conversation)    relation = "parent_id = ?";            else if (item instanceof Folder)          relation = "folder_id = ?";            else if (item instanceof Flag)            relation = "flags & ?";            else if (item instanceof Tag)             relation = "tags & ?";            else                                      relation = "id = ?";            String precondition = (add ? "NOT (" : "(") + column + " & ?)";            stmt = conn.prepareStatement("UPDATE " + getMailItemTableName(item) +                    " SET " + column + " = " + column + (add ? " | ?" : " & ?") + ", mod_metadata = ?, change_date = ?" +                    " WHERE " +                    (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") +                    precondition + " AND " + relation);            int pos = 1;            stmt.setLong(pos++, add ? tag.getBitmask() : ~tag.getBitmask());            stmt.setInt(pos++, mbox.getOperationChangeID());            stmt.setInt(pos++, mbox.getOperationTimestamp());            if (DebugConfig.enableMailboxGroup)                stmt.setInt(pos++, mbox.getId());            stmt.setLong(pos++, tag.getBitmask());            if (item instanceof Tag)                stmt.setLong(pos++, ((Tag) item).getBitmask());            else if (item instanceof VirtualConversation)                stmt.setInt(pos++, ((VirtualConversation) item).getMessageId());            else                stmt.setInt(pos++, item.getId());            stmt.executeUpdate();            // Update the flagset or tagset cache.  Assume that the item's in-memory            // data has already been updated.            if (tag instanceof Flag && areFlagsetsLoaded(mbox.getId())) {                TagsetCache flagsets = getFlagsetCache(conn, mbox.getId());                flagsets.addTagset(item.getInternalFlagBitmask());            } else if (areTagsetsLoaded(mbox.getId())) {                TagsetCache tagsets = getTagsetCache(conn, mbox.getId());                tagsets.addTagset(item.getTagBitmask());            }        } catch (SQLException e) {            throw ServiceException.FAILURE("updating tag data for item " + item.getId(), e);        } finally {            DbPool.closeStatement(stmt);        }    }