Class JPAExampleCUDRequestHandler
java.lang.Object
com.sap.olingo.jpa.processor.core.api.JPAAbstractCUDRequestHandler
com.sap.olingo.jpa.processor.core.api.example.JPAExampleCUDRequestHandler
- All Implemented Interfaces:
JPACUDRequestHandler
Example implementation at a CUD handler. The main purpose is rapid prototyping.
The implementation requires Getter and Setter. This includes getter for collection properties and collection
navigation properties that return at least empty collections.
To link entities constructor injection is used. So each dependent entity needs a constructor that takes a entity type it depends on as parameter.
To link entities constructor injection is used. So each dependent entity needs a constructor that takes a entity type it depends on as parameter.
- Author:
- Oliver Grande
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateEntity(JPARequestEntity requestEntity, javax.persistence.EntityManager em)Hook to create an entity.voiddeleteEntity(JPARequestEntity requestEntity, javax.persistence.EntityManager em)updateEntity(JPARequestEntity requestEntity, javax.persistence.EntityManager em, org.apache.olingo.commons.api.http.HttpMethod method)Hook to handle all request that change an existing entity.voidvalidateChanges(javax.persistence.EntityManager em)Hook that is called after all changes of one transaction have been processed.
-
Constructor Details
-
JPAExampleCUDRequestHandler
public JPAExampleCUDRequestHandler()
-
-
Method Details
-
createEntity
public Object createEntity(JPARequestEntity requestEntity, javax.persistence.EntityManager em) throws ODataJPAProcessExceptionDescription copied from interface:JPACUDRequestHandlerHook to create an entity. Transaction handling is done outside to guarantee transactional behavior of change sets in batch requests. This method has to return the newly create entity even so validateChanges is implemented.- Specified by:
createEntityin interfaceJPACUDRequestHandler- Overrides:
createEntityin classJPAAbstractCUDRequestHandler- Returns:
- The newly created instance or map of created attributes including default and added values following the same rules as jpaAttributes
- Throws:
ODataJPAProcessException
-
deleteEntity
public void deleteEntity(JPARequestEntity requestEntity, javax.persistence.EntityManager em) throws ODataJPAProcessException- Specified by:
deleteEntityin interfaceJPACUDRequestHandler- Overrides:
deleteEntityin classJPAAbstractCUDRequestHandler- Throws:
ODataJPAProcessException
-
updateEntity
public JPAUpdateResult updateEntity(JPARequestEntity requestEntity, javax.persistence.EntityManager em, org.apache.olingo.commons.api.http.HttpMethod method) throws ODataJPAProcessExceptionDescription copied from interface:JPACUDRequestHandlerHook to handle all request that change an existing entity. This includes update and upsert on entities, updates on properties and values, updates on relations as well as deletions on values and properties.
Note: Deviating from the OData standard changes on collection properties will be provided as PATCH, as it is from an entity point of view is the partial change. An implementation needs to take care that all elements of the collection are exchanged!- Specified by:
updateEntityin interfaceJPACUDRequestHandler- Overrides:
updateEntityin classJPAAbstractCUDRequestHandler- Parameters:
requestEntity- SeeJPARequestEntityem- Instance of an entity manager with an open transaction.method- The original http method: PATCH, PUT, DELETE- Returns:
- The response describes the performed changes (Created or Updated) as well as the result of the operation. It must not be null. Even if nothing was changed => update is idempotent
- Throws:
ODataJPAProcessException- See Also:
- OData Version 4.0 Part 1 - 11.4.3 Update an Entity
OData Version 4.0 Part 1 - 11.4.4 Upsert an Entity
OData Version 4.0 Part 1 - 11.4.6 Modifying Relationships between Entities
OData Version 4.0 Part 1 - 11.4.9 Managing Values and Properties Directly
-
validateChanges
Description copied from interface:JPACUDRequestHandlerHook that is called after all changes of one transaction have been processed. The method shall enable a check of all modification within the new context. This can be imported if multiple entities are changes with the same request (batch request or deep-insert) and consistency constrains exist between them.- Specified by:
validateChangesin interfaceJPACUDRequestHandler- Overrides:
validateChangesin classJPAAbstractCUDRequestHandler- Throws:
ODataJPAProcessException
-