When using the querybuilder, what's the difference if any, between injecting he querybuilder services, versus adapting from a resource resolver?
Since you must call createQuery() with a Session, I think the result will likely be the same for both of these cases. Is there any particular version that considered "best practice?"
@Model(adaptables = SlingHttpServletRequest.class) public class MyClass { @OSGiService QueryBuilder qb; @Inject SlingHttpServletRequest request; public void myMethod() { //...build out predicates ResourceResolver resourceResolver = request.getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); Query query = qb.createQuery(pg,session); } }
vs
@Model(adaptables = SlingHttpServletRequest.class) public class MyClass { @Inject SlingHttpServletRequest request; public void myMethod() { //...build out predicates ResourceResolver resourceResolver = request.getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); QueryBuilder qb = resourceResolver.adaptTo(Querybuilder.class); Query query = qb.createQuery(pg,session); } }
Thanks