spring-data-geode
spring-data-geode copied to clipboard
Support Function context aware Repositories operating on a local, filtered data set [DATAGEODE-257]
John Blum opened DATAGEODE-257 and commented
It would be ideal if a Function bound, Spring Data Repository took context into consideration when performing Repository data access operations.
For instance, if an application-defined Repository is injected into and used in an Apache Geode Function (perhaps a Function annotated with @GemfireFunction in SDG's Function Annotation support), and if the associated Region of the Repository matches when the Function is "executed" on a Region (with @OnRegion), then the Repository would operate on the "local" (possibly, "filtered") data set provided by the FunctionContext.
One such test example exists here along with it's Function definition and Function execution.
However, there are many things that need to be considered carefully as not to adversely affect any existing functionality or behavior. Using Repositories in Functions is quite common in practice. The following list, though not exhaustive, needs to be taken in consideration:
-
Repositorieswith an@Regionannotation on theRepositoryitself, or indirectly on the associated application domain object does not match theRegionFunctionContextof the Region targeted Function execution. -
Functions executed via
@OnMember(s)or@OnServer{s)should be excluded. -
Repositoriesdefining raw OQL using the@Queryannotation need to be handled appropriately. -
Repositorieswith "custom" implemented methods also need to be handled properly. -
???
Reference URL: https://jira.spring.io/browse/SGF-451
John Blum commented
Additional considerations that must be carefully handled (otherwise, SDG runs the risk of working in some contexts while breaking in others)
-
First, only the
Region.query(:String)API can be used to execute a (OQL) query on the local data set of a PR inside a Function execution. Using theQueryServiceAPI, obtained fromregion.getRegionService().getQueryService()operates on the entireRegion. -
#1 leads to the second limitation, and probably most pertinent... Under-the-hood, SD[G]
Repositoriesuse theQueryServiceAPI and notRegion.query(:String)to execute queries.
Therefore, the underlying infrastructure need to become context sensitive in order to know when to use the Region.query(predicate:String) API call while still preserving the entire Region data access operations in a non-Function context.
-
But, to even be able to operate on the local data set of
Regionupon which the Function maybe executing, you must first be given subclass ofFunctionContext, theRegionFunctionContext. Then, thePartitionRegionHelper.getLocalDataForContext(:RegionFunctionContext)call can be used to get aRegioninstance that refers to the local data set of the PR. The call returns aRegionreference you use to callRegion.query(:String)method from within the application-defined Function which is using theRepository. -
However, using
PartitionRegionHelper.getLocalDataForContext(:RegionFunctionContext)puts a further stipulation on your Function execution that it must have been executed withExecutions.onRegion(String)(on in SDG, using the@OnRegion(s)annotation on the Function execution interface). As such aonServersoronMemberscall will not result in aRegionFunctionContext. -
???