org.apache.olingo.odata2.jpa.processor.api
Class ODataJPAServiceFactory

java.lang.Object
  extended by org.apache.olingo.odata2.api.ODataServiceFactory
      extended by org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory
Direct Known Subclasses:
JPAReferenceServiceFactory

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>
  


Field Summary
 
Fields inherited from class org.apache.olingo.odata2.api.ODataServiceFactory
FACTORY_CLASSLOADER_LABEL, FACTORY_LABEL, PATH_SPLIT_LABEL
 
Constructor Summary
ODataJPAServiceFactory()
           
 
Method Summary
 ODataService createService(ODataContext ctx)
          Creates an OData Service based on the values set in ODataJPAContext and ODataContext.
<T extends ODataCallback>
T
getCallback(Class<? extends ODataCallback> callbackInterface)
          A service can return implementation classes for various callback interfaces.
 ODataJPAContext getODataJPAContext()
           
abstract  ODataJPAContext initializeODataJPAContext()
          Implement this method and initialize OData JPA Context.
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.
protected  void setOnWriteJPAContent(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ODataJPAServiceFactory

public ODataJPAServiceFactory()
Method Detail

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
Parameters:
ctx - OData context object
Returns:
A new service instance.
Throws:
ODataException - in case of error

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

getODataJPAContext

public final ODataJPAContext getODataJPAContext()
                                         throws ODataJPARuntimeException
Returns:
an instance of type ODataJPAContext
Throws:
ODataJPARuntimeException

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

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

getCallback

public <T extends ODataCallback> T getCallback(Class<? extends ODataCallback> callbackInterface)
Description copied from class: ODataServiceFactory
A service can return implementation classes for various callback interfaces.

Overrides:
getCallback in class ODataServiceFactory
Parameters:
callbackInterface - a interface type to query for implementation
Returns:
a callback implementation for this interface or null


Copyright © 2013-2015 The Apache Software Foundation. All Rights Reserved.