Class ODataJPAServiceFactory


  • public abstract class ODataJPAServiceFactory
    extends ODataServiceFactory

    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.

    Sample Configuration:
     
     <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>
      
    • Constructor Detail

      • ODataJPAServiceFactory

        public ODataJPAServiceFactory()
    • 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 type EntityManagerFactory into the context. An exception of type ODataJPARuntimeException is 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
      • setOnWriteJPAContent

        protected void setOnWriteJPAContent​(OnJPAWriteContent onJPAWriteContent)
        The methods sets the context with a callback implementation for JPA provider specific content. For details refer to OnJPAWriteContent
        Parameters:
        onJPAWriteContent - is an instance of type OnJPAWriteContent
      • setODataJPATransaction

        protected void setODataJPATransaction​(ODataJPATransaction oDataJPATransaction)
        The methods sets the context with a callback implementation for JPA transaction specific content. For details refer to ODataJPATransaction
        Parameters:
        oDataJPATransaction - is an instance of type ODataJPATransaction
      • 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