StringBuilder ids = null; if (info != null) { if (info.itemIds == null || info.itemIds.size() == 0) return; ids = new StringBuilder(); for (int i = 0; i < info.itemIds.size(); i++) ids.append(i == 0 ? "" : ",").append(info.itemIds.get(i));
for (Map.Entry<Byte, List<Integer>> entry : tombstones) { byte type = entry.getKey(); if (type == MailItem.TYPE_CONVERSATION || type == MailItem.TYPE_VIRTUAL_CONVERSATION) continue; StringBuilder ids = new StringBuilder(); for (Integer id : entry.getValue()) ids.append(ids.length() == 0 ? "" : ",").append(id);  stmt = conn.prepareStatement("INSERT INTO " + getTombstoneTableName(mbox) + "(" + (!DebugConfig.disableMailboxGroup ? "mailbox_id, " : "") + "sequence, date, type, ids)" + " VALUES (" + (!DebugConfig.disableMailboxGroup ? "?, " : "") + "?, ?, ?, ?)"); int pos = 1; if (!DebugConfig.disableMailboxGroup) stmt.setInt(pos++, mbox.getId()); stmt.setInt(pos++, mbox.getOperationChangeID()); stmt.setInt(pos++, mbox.getOperationTimestamp()); stmt.setByte(pos++, type); stmt.setString(pos++, ids.toString()); stmt.executeUpdate(); stmt.close();
    public static void writeTombstone(Mailbox mbox, PendingDelete info) throws ServiceException {        Connection conn = mbox.getOperationConnection();        PreparedStatement stmt = null;        try {            StringBuilder ids = null;            if (info != null) {                if (info.itemIds == null || info.itemIds.size() == 0)                    return;                ids = new StringBuilder();                for (int i = 0; i < info.itemIds.size(); i++)                    ids.append(i == 0 ? "" : ",").append(info.itemIds.get(i));            }            stmt = conn.prepareStatement("INSERT INTO " + getTombstoneTableName(mbox) + "(" +                    (!DebugConfig.disableMailboxGroup ? "mailbox_id, " : "") +                    "sequence, date, ids) VALUES (" +                    (!DebugConfig.disableMailboxGroup ? "?, " : "") +                    "?,?,?)");            int pos = 1;            if (!DebugConfig.disableMailboxGroup)                stmt.setInt(pos++, mbox.getId());            stmt.setInt(pos++, mbox.getOperationChangeID());            stmt.setInt(pos++, mbox.getOperationTimestamp());            if (ids != null)                stmt.setString(pos++, ids.toString());            else                stmt.setNull(pos++, Types.VARCHAR);            stmt.executeUpdate();        } catch (SQLException e) {            if (info == null)                throw ServiceException.FAILURE("writing change sequence checkpoint", e);            else                throw ServiceException.FAILURE("writing tombstones for item(s): " + info.itemIds, e);        } finally {            DbPool.closeStatement(stmt);        }    }