Interface RestDataStoreExtension
- All Superinterfaces:
org.springframework.core.Ordered
Register an implementation as a Spring bean. For each request, the store calls every extension whose
supports(String, MetaClass) method returns true, in the order defined by getOrder().
The load and save methods receive root entities only: the entities that are loaded or saved directly, not the entities they reference. Removing entities does not call any method.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classData passed toafterLoad(AfterLoadContext).static classData passed toafterSave(AfterSaveContext).static classData passed tobeforeCount(BeforeCountContext).static classData passed tobeforeLoad(BeforeLoadContext).static classData passed tobeforeSave(BeforeSaveContext). -
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptiondefault voidCalled for each loaded root entity, with the JSON object the entity was read from.default voidCalled after the remote service returns a saved root entity.default voidCalled before the store sends a request that counts entities.default voidCalled before the store sends a request that loads entities.default voidCalled before the store sends a root entity to be created or updated.default intgetOrder()booleanReturns whether the store must call this extension for the given data store and entity.
-
Method Details
-
supports
Returns whether the store must call this extension for the given data store and entity.- Parameters:
dataStoreName- name of the REST data storemetaClass- metaclass of the entity being loaded, counted or saved
-
beforeLoad
Called before the store sends a request that loads entities.Parameters put into
RestDataStoreExtension.BeforeLoadContext.getRequestParameters()are sent to the remote service: in the query string of a GET request, or as fields of the JSON body when the store uses the search endpoint. Names that the store sets itself (fetchPlan,limit,offset,sort,filter,returnCount) andnullvalues are not allowed. -
afterLoad
Called for each loaded root entity, with the JSON object the entity was read from.JSON properties that the entity's metaclass does not have are skipped when the entity is read, so this method is the only place where they are available. The method is not called when loading by id finds no entity.
-
beforeCount
Called before the store sends a request that counts entities. Request parameters follow the same rules as inbeforeLoad(BeforeLoadContext).If the count is computed by loading the entities (for example, because in-memory row-level policies apply),
beforeLoad(BeforeLoadContext)is called instead. -
beforeSave
Called before the store sends a root entity to be created or updated. Changes made toRestDataStoreExtension.BeforeSaveContext.getEntityJson()are sent to the remote service.FileRefvalues in the JSON contain the local names of file storages. The store replaces them with the remote names after this method. -
afterSave
Called after the remote service returns a saved root entity.The returned JSON contains the attributes of the
_basefetch plan only, so values thatbeforeSave(BeforeSaveContext)added to the request are not in it. Take them fromRestDataStoreExtension.AfterSaveContext.getEntity()if needed.Unless
SaveContext.isDiscardSaved()is set, the saved entities are then loaded again, and the caller receives the loaded instances, notRestDataStoreExtension.AfterSaveContext.getSavedEntity(). This load callsbeforeLoad(BeforeLoadContext)andafterLoad(AfterLoadContext)with a newLoadContext, which does not have the hints of the save. -
getOrder
default int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-