" AND resource_filter = " + Constants.ITEM + " AND resource_filter_arg in " +
" AND container_type_id = " + Constants.ITEM + " AND container_id in " +
    private static TableRowIterator policyLookup(Context c, int resource_type, int resource_id, int action_id)        throws SQLException    {        String myquery = "";        // get the policies eonly for this object (rare)        TableRowIterator specific_policies = DatabaseManager.query(c,            "resourcepolicy",            "SELECT resourcepolicy.* FROM resourcepolicy WHERE" +            " resource_type_id=" + resource_type +            " AND action_id=" + action_id +            " AND resource_id=" + resource_id );/*        // find all policies specific to this object        String myquery = "SELECT * from ResourcePolicy where" +            " resource_type_id = " + resource_type +            " AND action_id = " + action_id +            " AND resource_id = " + resource_id;        DatabaseBeanIterator specific_policies = ResourcePolicy.query(myquery);        DatabaseBeanIterator item_policies = null;        DatabaseBeanIterator collection_policies = null;*/        if (resource_type == Constants.BITSTREAM)        {            // if there are item specific policies, they have            //  the highest priority - return them            if (specific_policies.hasNext())            {                return specific_policies;            }            // need to look for policies from containing items            myquery = "SELECT * from ResourcePolicy where" +                    " resource_type_id = " + resource_type +                    " AND action_id = " + action_id +                    " AND resource_filter = " + Constants.ITEM +                    " AND resource_filter_arg in " +                    "(select item_id from Item2Bundle where bundle_id in" +                    "(select bundle_id from Bundle2Bitstream where " +                    " bitstream_id = " + resource_id + "))";            TableRowIterator item_policies = DatabaseManager.query(c,                "resourcepolicy",               myquery );            if (item_policies.hasNext())            {                return item_policies;            }            // now look for policies from containing collections            myquery = "SELECT * from ResourcePolicy where" +                    " resource_type_id = " + resource_type +                    " AND action_id = " + action_id +                    " AND resource_filter = " + Constants.COLLECTION +                    " AND resource_filter_arg in " +                    "(select collection_id from Collection2Item where" +                    " item_id in " +                    "(select item_id from Item2Bundle where bundle_id in" +                    "(select bundle_id from Bundle2Bitstream where " +                    " bitstream_id = " + resource_id + ")))";            TableRowIterator collection_policies = DatabaseManager.query(c,                "resourcepolicy",                myquery );            if (collection_policies.hasNext())            {                return collection_policies;            }        }        // bundles use the same permissions as bitstreams?        // inheriting from items and collections        if (resource_type == Constants.BUNDLE)        {            if (specific_policies.hasNext())            {                return specific_policies;            }            // need to look for policies from containing items            myquery = "SELECT * from ResourcePolicy where" +                    " resource_type_id = " + resource_type +                    " AND action_id = " + action_id +                    " AND resource_filter = " + Constants.ITEM +                    " AND resource_filter_arg in " +                    "(select item_id from Item2Bundle where " +                    " bundle_id = " + resource_id + ")";            TableRowIterator item_policies = DatabaseManager.query(c,                "resourcepolicy",                myquery );            if (item_policies.hasNext())            {                return item_policies;            }            // now look for policies from containing collections            myquery = "SELECT * from ResourcePolicy where" +                    " resource_type_id = " + resource_type +                    " AND action_id = " + action_id +                    " AND resource_filter = " + Constants.COLLECTION +                    " AND resource_filter_arg in " +                    "(select collection_id from Collection2Item where" +                    " item_id in " +                    "(select item_id from Item2Bundle where " +                    " bundle_id =" + resource_id + "))";            TableRowIterator collection_policies = DatabaseManager.query(c,                "resourcepolicy",                myquery );            if (collection_policies.hasNext())            {                return collection_policies;            }        }        // items just inherit from collections        if (resource_type == Constants.ITEM)        {            if (specific_policies.hasNext())            {                return specific_policies;            }            myquery = "SELECT * from ResourcePolicy where" +                    " resource_type_id = " + resource_type +                    " AND action_id = " + action_id +                    " AND resource_filter = " + Constants.COLLECTION +                    " AND resource_filter_arg in " +                    "(select collection_id from Collection2Item where" +                    " item_id = " + resource_id + ")";            TableRowIterator collection_policies = DatabaseManager.query(c,                "resourcepolicy",                myquery );            if (collection_policies.hasNext())            {                return collection_policies;            }        }        // end of special inheritance - handle any other        //  type        return specific_policies;    }