public static void deleteFromDB(MUCRoom room, JID alternateJID, String reason) {
        Log.debug("Attempting to delete room '{}' from the database.", room.getName());

        boolean shouldDeleteFromDB = room.isPersistent() && room.wasSavedToDB();

        // If the room should be retired but isn't persistent/saved, we still need to create a retiree entry
        if (!shouldDeleteFromDB && !room.isRetireOnDeletion()) {
            return;
        }

        Connection con = null;
        PreparedStatement pstmt = null;
        boolean abortTransaction = false;
        try {
            con = DbConnectionManager.getTransactionConnection();

            if (shouldDeleteFromDB) {
                // Delete existing data only if the room was actually in the DB
                pstmt = con.prepareStatement(DELETE_AFFILIATIONS);
                pstmt.setLong(1, room.getID());
                pstmt.executeUpdate();
                DbConnectionManager.fastcloseStmt(pstmt);

                pstmt = con.prepareStatement(DELETE_MEMBERS);
                pstmt.setLong(1, room.getID());
                pstmt.executeUpdate();
                DbConnectionManager.fastcloseStmt(pstmt);

                pstmt = con.prepareStatement(DELETE_ROOM);
                pstmt.setLong(1, room.getID());
                pstmt.executeUpdate();
                DbConnectionManager.fastcloseStmt(pstmt);

                if(!room.isPreserveHistOnRoomDeletionEnabled()) {
                    pstmt = con.prepareStatement(DELETE_ROOM_HISTORY);
                    pstmt.setLong(1, room.getID());
                    pstmt.executeUpdate();
                    DbConnectionManager.fastcloseStmt(pstmt);
                }

                // Update the room (in memory) to indicate that it's no longer in the database.
                room.setSavedToDB(false);
            }

            if (room.isRetireOnDeletion()) {
                pstmt = con.prepareStatement(ADD_RETIREE);
                pstmt.setLong(1, XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatServiceID(room.getMUCService().getServiceName()));
                pstmt.setString(2, room.getName());

                if (alternateJID == null) {
                    pstmt.setNull(3, Types.VARCHAR);
                } else {
                    pstmt.setString(3, alternateJID.toString());
                }

                if (reason == null || reason.isBlank()) {
                    pstmt.setNull(4, Types.VARCHAR);
                } else {
                    pstmt.setString(4, reason.trim());
                }

                pstmt.executeUpdate();
                DbConnectionManager.fastcloseStmt(pstmt);
            }
        }
        catch (SQLException sqle) {
            Log.error("A database error occurred while trying to delete room: {}", room.getName(), sqle);
            abortTransaction = true;
        }
        finally {
            DbConnectionManager.closeStatement(pstmt);
            DbConnectionManager.closeTransactionConnection(con, abortTransaction);
        }
    }
Removes the room configuration and its affiliates from the database.

@param room the room to remove from the database.
@param alternateJID an optional alternate JID. Commonly used to provide a replacement room. (can be {@code null})
@param reason an optional reason why the room was destroyed (can be {@code null}).
xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/MUCPersistenceManager.java