@Target(value=METHOD) @Retention(value=RUNTIME) public @interface QueryProvider
Dao
method that delegates the execution of the query to a user-provided
class.
Example:
@Dao public interface SensorDao { @QueryProvider(providerClass = FindSliceProvider.class, entityHelpers = SensorReading.class) PagingIterable<SensorReading> findSlice(int id, Integer month, Integer day); } public class FindSliceProvider { public FindSliceProvider( MapperContext context, EntityHelper<SensorReading> sensorReadingHelper) { ... } public PagingIterable<SensorReading> findSlice(int id, Integer month, Integer day) { ... // implement the query logic here } }
Use this for requests that can't be expressed as static query strings, for example if some clauses are added dynamically depending on the values of some parameters.
The parameters and return type are completely free-form, as long as they match those of the provider method.
Modifier and Type | Required Element and Description |
---|---|
Class<?> |
providerClass
The class that will execute the query.
|
Modifier and Type | Optional Element and Description |
---|---|
Class<?>[] |
entityHelpers
A list of entities for which
EntityHelper instances should be injected into the
provider class's constructor (in addition to the mapper context). |
String |
providerMethod
The method to invoke on the provider class.
|
public abstract Class<?> providerClass
The mapper will create an instance of this class for each DAO instance. It must expose a constructor that is accessible from the DAO interface's package, and takes the following parameter types:
MapperContext
.
EntityHelper
s, as defined by entityHelpers()
.
providerMethod()
.public abstract String providerMethod
It must be accessible from the DAO interface's package, and have the same parameters and return type as the annotated DAO method.
This is optional; if not provided, it defaults to the name of the annotated DAO method.
public abstract Class<?>[] entityHelpers
EntityHelper
instances should be injected into the
provider class's constructor (in addition to the mapper context).
For example, if entityHelpers = {Product.class, Dimensions.class}
, your provider
class must expose a constructor that takes the parameter types(MapperContext,
EntityHelper<Product>, EntityHelper<Dimensions>)
.
All provided classes must be annotated with Entity
. Otherwise, the mapper will issue
a compile-time error.
Copyright © 2017–2020. All rights reserved.