Class ODataJPAServiceFactory
java.lang.Object
org.apache.olingo.odata2.api.ODataServiceFactory
org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory
Extend this factory class and create own instance of ODataService that
transforms Java Persistence
Models into an OData Service. The factory class instantiates instances of
type EdmProvider and
ODataSingleProcessor. The OData
JPA Processor library provides a default implementation for EdmProvider and
OData Single Processor.
The factory implementation is passed as servlet init parameter to a JAX-RS
runtime which will instantiate a ODataService implementation using this factory.
Mandatory: Implement the abstract method initializeODataJPAContext. Fill
ODataJPAContext with context
values.
<servlet>
<servlet-name>ReferenceScenarioServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jakarta.ws.rs.Application</param-name>
<param-value>org.apache.olingo.odata2.core.rest.ODataApplication</param-value>
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.service.factory</param-name>
<param-value>foo.bar.sample.service.SampleProcessorFactory</param-value>
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.path.split</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
-
Field Summary
Fields inherited from class org.apache.olingo.odata2.api.ODataServiceFactory
ACCEPT_FORM_ENCODING, FACTORY_CLASSLOADER_LABEL, FACTORY_INSTANCE_LABEL, FACTORY_LABEL, PATH_SPLIT_LABEL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateCustomODataProcessor(ODataJPAContext oDataJPAContext) final ODataServiceCreates an OData Service based on the values set inODataJPAContextandODataContext.<T extends ODataCallback>
TgetCallback(Class<T> callbackInterface) final ODataJPAContextabstract ODataJPAContextImplement this method and initialize OData JPA Context.protected voidsetDetailErrors(boolean setDetailErrors) The method sets the context whether a detail error message should be thrown or a less detail error message should be thrown by the library.protected voidsetODataJPATransaction(ODataJPATransaction oDataJPATransaction) The methods sets the context with a callback implementation for JPA transaction specific content.protected voidsetOnWriteJPAContent(OnJPAWriteContent onJPAWriteContent) The methods sets the context with a callback implementation for JPA provider specific content.Methods inherited from class org.apache.olingo.odata2.api.ODataServiceFactory
createODataSingleProcessorService, handleException
-
Constructor Details
-
ODataJPAServiceFactory
public ODataJPAServiceFactory()
-
-
Method Details
-
initializeODataJPAContext
Implement this method and initialize OData JPA Context. It is mandatory to set an instance of typeinto the context. An exception of typeinvalid reference
javax.persistence.EntityManagerFactoryODataJPARuntimeExceptionis thrown if EntityManagerFactory is not initialized.
Sample Code:public class JPAReferenceServiceFactory extends ODataJPAServiceFactory{
private static final String PUNIT_NAME = "punit";
}
public ODataJPAContext initializeODataJPAContext() {ODataJPAContext oDataJPAContext = this.getODataJPAContext();
}
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PUNIT_NAME);
oDataJPAContext.setEntityManagerFactory(emf); oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
return oDataJPAContext;- Returns:
- an instance of type
ODataJPAContext - Throws:
ODataJPARuntimeException- Caso ocorra exceção
-
createService
Creates an OData Service based on the values set inODataJPAContextandODataContext.- Specified by:
createServicein classODataServiceFactory- Throws:
ODataException
-
createCustomODataProcessor
-
getODataJPAContext
- Returns:
- an instance of type
ODataJPAContext - Throws:
ODataJPARuntimeException- Caso ocorra exceção
-
getCallback
- Overrides:
getCallbackin classODataServiceFactory
-
setOnWriteJPAContent
The methods sets the context with a callback implementation for JPA provider specific content. For details refer toOnJPAWriteContent- Parameters:
onJPAWriteContent- is an instance of typeOnJPAWriteContent
-
setODataJPATransaction
The methods sets the context with a callback implementation for JPA transaction specific content. For details refer toODataJPATransaction- Parameters:
oDataJPATransaction- is an instance of typeODataJPATransaction
-
setDetailErrors
protected void setDetailErrors(boolean setDetailErrors) The method sets the context whether a detail error message should be thrown or a less detail error message should be thrown by the library.- Parameters:
setDetailErrors- takes- true - to indicate that library should throw a detailed error message
- false - to indicate that library should not throw a detailed error message
-