Class QueryPopulatorImpl
java.lang.Object
ch.tocco.nice2.persist.core.impl.util.QueryPopulatorImpl
- All Implemented Interfaces:
QueryPopulator
Implements QueryPopulator
using a list of
contributed ArgumentFactory
s.
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 ArgumentFactory
s may be contributed via Spring beans:
@Bean
public ArgumentFactoryContribution todayStartArgumentFactory(DatetimeArgumentFactory factory) {
return new ArgumentFactoryContribution("today_start", factory);
}
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addArgumentFactory
(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 aQuery
object.Returns all parameter names that are known to this service.void
populateQuery
(Query q, FuncallNode qstr, Context context) void
populateQuery
(Query q, String qstr, Context context) Populates the given query according to the parameter names it recognizes.void
removeArgumentFactory
(String paramName) Removes the factory for the registered named parameter.void
setArgumentFactories
(List<ArgumentFactoryContribution> contribs)
-
Constructor Details
-
QueryPopulatorImpl
public QueryPopulatorImpl()
-
-
Method Details
-
populateQuery
Description copied from interface:QueryPopulator
Populates 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:
populateQuery
in interfaceQueryPopulator
- Parameters:
q
- the compiled queryqstr
- the string used to compile the querycontext
- the persist context to use- Throws:
PersistException
-
populateQuery
- Specified by:
populateQuery
in interfaceQueryPopulator
- Throws:
PersistException
-
createAndPopulateQuery
Description copied from interface:QueryPopulator
CallsQueryPopulator.populateQuery(Query, String, Context)
after compiling the query string into aQuery
object.- Specified by:
createAndPopulateQuery
in interfaceQueryPopulator
- Parameters:
queryStr
- the query stringcontext
- the persist context to use- Returns:
- the compiled and populated query
- Throws:
PersistException
-
getRegisteredParameterNames
Description copied from interface:QueryPopulator
Returns all parameter names that are known to this service.- Specified by:
getRegisteredParameterNames
in 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
-