Class ODataJPAServiceFactory
- java.lang.Object
-
- org.apache.olingo.odata2.api.ODataServiceFactory
-
- org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory
-
public abstract class ODataJPAServiceFactory extends ODataServiceFactory
Extend this factory class and create own instance of
ODataServicethat transforms Java Persistence Models into an OData Service. The factory class instantiates instances of typeEdmProviderandODataSingleProcessor. 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
ODataServiceimplementation using this factory.Mandatory: Implement the abstract method initializeODataJPAContext. Fill
Sample Configuration:ODataJPAContextwith context values.<servlet> <servlet-name>ReferenceScenarioServlet</servlet-name> <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class> <init-param> <param-name>javax.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 Constructor Description ODataJPAServiceFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ODataSingleProcessorcreateCustomODataProcessor(ODataJPAContext oDataJPAContext)ODataServicecreateService(ODataContext ctx)Creates an OData Service based on the values set inODataJPAContextandODataContext.<T extends ODataCallback>
TgetCallback(Class<T> callbackInterface)ODataJPAContextgetODataJPAContext()abstract ODataJPAContextinitializeODataJPAContext()Implement 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
-
-
-
-
Method Detail
-
initializeODataJPAContext
public abstract ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException
Implement this method and initialize OData JPA Context. It is mandatory to set an instance of typeEntityManagerFactoryinto the context. An exception of typeODataJPARuntimeExceptionis 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
-
createService
public final ODataService createService(ODataContext ctx) throws ODataException
Creates an OData Service based on the values set inODataJPAContextandODataContext.- Specified by:
createServicein classODataServiceFactory- Throws:
ODataException
-
createCustomODataProcessor
public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext oDataJPAContext)
-
getODataJPAContext
public final ODataJPAContext getODataJPAContext() throws ODataJPARuntimeException
- Returns:
- an instance of type
ODataJPAContext - Throws:
ODataJPARuntimeException
-
getCallback
public <T extends ODataCallback> T getCallback(Class<T> callbackInterface)
- Overrides:
getCallbackin classODataServiceFactory
-
setOnWriteJPAContent
protected void setOnWriteJPAContent(OnJPAWriteContent onJPAWriteContent)
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
protected void setODataJPATransaction(ODataJPATransaction oDataJPATransaction)
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
-
-