Class QueryPopulatorImpl
java.lang.Object
ch.tocco.nice2.persist.core.impl.util.QueryPopulatorImpl
- All Implemented Interfaces:
QueryPopulator
Implements QueryPopulator using a list of
contributed ArgumentFactorys.
Each ArgumentFactory can create the value for one named parameter. If
the query string contains any named parameters that an ArgumentFactory
exists for, the value from the factory is set into the query.
The ArgumentFactorys may be contributed via Spring beans:
@Bean
public ArgumentFactoryContribution todayStartArgumentFactory(DatetimeArgumentFactory factory) {
return new ArgumentFactoryContribution("today_start", factory);
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArgumentFactory(String paramName, ArgumentFactory argFac) Add a new factory for the given named parameter.createAndPopulateQuery(String queryStr, Context context) CallsQueryPopulator.populateQuery(Query, String, Context)after compiling the query string into aQueryobject.Returns all parameter names that are known to this service.voidpopulateQuery(Query q, FuncallNode qstr, Context context) voidpopulateQuery(Query q, String qstr, Context context) Populates the given query according to the parameter names it recognizes.voidremoveArgumentFactory(String paramName) Removes the factory for the registered named parameter.voidsetArgumentFactories(List<ArgumentFactoryContribution> contribs)
-
Constructor Details
-
QueryPopulatorImpl
public QueryPopulatorImpl()
-
-
Method Details
-
populateQuery
Description copied from interface:QueryPopulatorPopulates the given query according to the parameter names it recognizes.
It searches the query string for any occurence of a registered named parameter and invokes
Query.setParameter(String, Object)with the appropriate value.- Specified by:
populateQueryin interfaceQueryPopulator- Parameters:
q- the compiled queryqstr- the string used to compile the querycontext- the persist context to use- Throws:
PersistException
-
populateQuery
- Specified by:
populateQueryin interfaceQueryPopulator- Throws:
PersistException
-
createAndPopulateQuery
Description copied from interface:QueryPopulatorCallsQueryPopulator.populateQuery(Query, String, Context)after compiling the query string into aQueryobject.- Specified by:
createAndPopulateQueryin interfaceQueryPopulator- Parameters:
queryStr- the query stringcontext- the persist context to use- Returns:
- the compiled and populated query
- Throws:
PersistException
-
getRegisteredParameterNames
Description copied from interface:QueryPopulatorReturns all parameter names that are known to this service.- Specified by:
getRegisteredParameterNamesin interfaceQueryPopulator
-
addArgumentFactory
Add a new factory for the given named parameter. Any factory already registered is silently replaced.- Parameters:
paramName- the named parameter in the query to which the factory is appliedargFac- the argument factory
-
removeArgumentFactory
Removes the factory for the registered named parameter.- Parameters:
paramName- the named parameter for which to remove the argument factory mapping
-
setArgumentFactories
-