16.6. Using Named Parameters
Expression.param(...)
operator on the right hand side of any comparison operator from the having(...)
:
Example 16.6. Defining Named Parameters
import org.infinispan.query.Search; import org.infinispan.query.dsl.*; [...] QueryFactory queryFactory = Search.getQueryFactory(cache); // Defining a query to search for various authors Query query = queryFactory.from(Book.class) .select("title") .having("author").eq(Expression.param("authorName")) .toBuilder() .build() [...]
By default all declared parameters are null, and all defined parameters must be updated to non-null values before the query must be executed. Once the parameters have been declared they may then be updated by invoking either setParameter(parameterName, value)
or setParameters(parameterMap)
on the query with the new values; in addition, the query does not need to be rebuilt. It may be executed again after the new parameters have been defined.
Example 16.7. Updating Parameters Individually
[...] query.setParameter("authorName","Smith"); // Rerun the query and update the results resultList = query.list(); [...]
Example 16.8. Updating Parameters as a Map
[...] parameterMap.put("authorName","Smith"); query.setParameters(parameterMap); // Rerun the query and update the results resultList = query.list(); [...]