if (b.getID() == getPrimaryBitstreamID()) { unsetPrimaryBitstreamID(); }
    public void removeBitstream(Bitstream b) throws AuthorizeException,            SQLException, IOException    {        // Check authorisation        AuthorizeManager.authorizeAction(ourContext, this, Constants.REMOVE);        log.info(LogManager.getHeader(ourContext, "remove_bitstream",                "bundle_id=" + getID() + ",bitstream_id=" + b.getID()));        // Remove from internal list of bitstreams        ListIterator li = bitstreams.listIterator();        while (li.hasNext())        {            Bitstream existing = (Bitstream) li.next();            if (b.getID() == existing.getID())            {                // We've found the bitstream to remove                li.remove();            }        }        // Delete the mapping row        DatabaseManager.updateQuery(ourContext,                "DELETE FROM bundle2bitstream WHERE bundle_id= ? "+                "AND bitstream_id= ? ",                 getID(), b.getID());        // If the bitstream is orphaned, it's removed        TableRowIterator tri = DatabaseManager.query(ourContext,                "SELECT * FROM bundle2bitstream WHERE bitstream_id= ? ",                b.getID());        if (!tri.hasNext())        {            // The bitstream is an orphan, delete it            b.delete();        }        // close the TableRowIterator to free up resources        tri.close();    }