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 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>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>
  
  • Constructor Details

    • ODataJPAServiceFactory

      public ODataJPAServiceFactory()
  • Method Details

    • initializeODataJPAContext

      public abstract ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException
      Implement this method and initialize OData JPA Context. It is mandatory to set an instance of type
      invalid reference
      javax.persistence.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 - Caso ocorra exceção
    • createService

      public final ODataService createService(ODataContext ctx) throws ODataException
      Creates an OData Service based on the values set in ODataJPAContext and ODataContext.
      Specified by:
      createService in class ODataServiceFactory
      Throws:
      ODataException
    • createCustomODataProcessor

      public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext oDataJPAContext)
    • getODataJPAContext

      public final ODataJPAContext getODataJPAContext() throws ODataJPARuntimeException
      Returns:
      an instance of type ODataJPAContext
      Throws:
      ODataJPARuntimeException - Caso ocorra exceção
    • getCallback

      public <T extends ODataCallback> T getCallback(Class<T> callbackInterface)
      Overrides:
      getCallback in class ODataServiceFactory
    • 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