Refactored queries to use optional data provider injection

Query builders refactored to duck type and call
method setDataProvider if implemented by query.