org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext Java Examples

The following examples show how to use org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CarsODataJPAServiceFactory.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * This method will be called by Olingo on every request to
 * initialize the ODataJPAContext that will be used. 
 */
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {

    log.info("[I32] >>> initializeODataJPAContext()");
    ODataJPAContext ctx = getODataJPAContext();
    ODataContext octx = ctx.getODataContext();
    HttpServletRequest request = (HttpServletRequest)octx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
    EntityManager em = (EntityManager)request.getAttribute(JerseyConfig.EntityManagerFilter.EM_REQUEST_ATTRIBUTE);
            
    // Here we're passing the EM that was created by the EntityManagerFilter (see JerseyConfig)
    ctx.setEntityManager(new EntityManagerWrapper(em));
    ctx.setPersistenceUnitName("default");
    
    // We're managing the EM's lifecycle, so we must inform Olingo that it should not
    // try to manage transactions and/or persistence sessions
    ctx.setContainerManaged(true);                
    return ctx;
}
 
Example #2
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
    final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
  ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
  ExpandSelectTreeNode expandSelectTree = null;
  try {
    entityFeedPropertiesBuilder =
        EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
    expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
    entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
    entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
        .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }

  return entityFeedPropertiesBuilder.build();
}
 
Example #3
Source File: EspmServiceFactory.java    From cloud-espm-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext()
		throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = this.getODataJPAContext();
	EntityManagerFactory emf;
	try {
		emf = JpaEntityManagerFactory.getEntityManagerFactory();
		oDataJPAContext.setEntityManagerFactory(emf);
		oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
		oDataJPAContext.setJPAEdmExtension(new EspmProcessingExtension());
		oDataJPAContext.setJPAEdmMappingModel("EspmEdmMapping.xml");
		return oDataJPAContext;
	} catch (Exception e) {
		throw new ODataRuntimeException(e);
	}

}
 
Example #4
Source File: BenefitsODataServiceFactory.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = this.getODataJPAContext();
	try {
		oDataJPAContext.setEntityManagerFactory(EntityManagerFactoryProvider.getInstance().getEntityManagerFactory());
		oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
		oDataJPAContext.setJPAEdmExtension(new BenefitsJPAEdmExtension());

		setContextInThreadLocal(oDataJPAContext.getODataContext());
		return oDataJPAContext;
	} catch (Exception e) {
		throw new ODataRuntimeException("Cannot initialize OData JPA Context", e); //$NON-NLS-1$
	}

}
 
Example #5
Source File: PersonsListServiceFactory.java    From cloud-personslist-scenario with Apache License 2.0 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext()
		throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = this.getODataJPAContext();
	try {
		EntityManagerFactory emf = JpaEntityManagerFactory
				.getEntityManagerFactory();
		oDataJPAContext.setEntityManagerFactory(emf);
		oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
		return oDataJPAContext;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #6
Source File: ODataJPACarServiceFactory.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext()
		throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = getODataJPAContext();
	EmfHolder emfHolder = EmfHolder.createInstance();
	oDataJPAContext.setEntityManagerFactory(emfHolder.getEntityManagerFactory());
	oDataJPAContext.setPersistenceUnitName(emfHolder.getPersistenceUnitName());

	oDataJPAContext.setPageSize(PAGE_SIZE);
	setDetailErrors(true);

	return oDataJPAContext;
}
 
Example #7
Source File: JPAReferenceServiceFactory.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext()
    throws ODataJPARuntimeException {
  ODataJPAContext oDataJPAContext = getODataJPAContext();
  oDataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory.getEntityManagerFactory(PUNIT_NAME));
  oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
  oDataJPAContext.setJPAEdmMappingModel(MAPPING_MODEL);
  oDataJPAContext.setJPAEdmExtension(new SalesOrderProcessingExtension());
  oDataJPAContext.setPageSize(PAGE_SIZE);
  oDataJPAContext.setDefaultNaming(false);
  oDataJPAContext.getODataContext().setDebugMode(true);
  setErrorLevel();
  setOnWriteJPAContent(onDBWriteContent);
  return oDataJPAContext;
}
 
Example #8
Source File: ODataJPAResponseBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataJPAContext getODataJPAContext() {
  ODataJPAContext objODataJPAContext = EasyMock.createMock(ODataJPAContext.class);
  EasyMock.expect(objODataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
  EasyMock.expect(objODataJPAContext.getPageSize()).andReturn(10);
  EasyMock.expect(objODataJPAContext.getPaging()).andReturn(mockJPAPaging()).anyTimes();
  EasyMock.replay(objODataJPAContext);
  return objODataJPAContext;
}
 
Example #9
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  ODataContextMock odataContextMock = new ODataContextMock();
  ODataContext context;
  try {
    context = odataContextMock.mock();
    ODataJPAContext odataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
    builder = new JPAQueryBuilder(odataJPAContext);
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #10
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataJPAContext getLocalmockODataJPAContext() {
  ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
  EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
  EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
  EasyMock.expect(odataJPAContext.getODataJPATransaction()).andStubReturn(getLocalJpaTransaction());
  EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
  EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
  EasyMock.expect(odataJPAContext.getPageSize()).andReturn(10).anyTimes();
  odataJPAContext.setPaging(EasyMock.isA(JPAPaging.class));
  EasyMock.expectLastCall();
  EasyMock.replay(odataJPAContext);
  return odataJPAContext;
}
 
Example #11
Source File: JPAEntityTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataJPAContext mockODataJPAContext() throws ODataException {
  PathInfoMock pathInfoMock = new PathInfoMock();
  try {
    pathInfoMock.setServiceRootURI("http://olingo.apache.org/service.svc");
  } catch (URISyntaxException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
        + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  ODataContextMock contextMock = new ODataContextMock();
  contextMock.setPathInfo(pathInfoMock.mock());
  ODataContext context = contextMock.mock();
  ODataJPAContext jpaContext = ODataJPAContextMock.mockODataJPAContext(context);
  return jpaContext;
}
 
Example #12
Source File: ODataJPAServiceFactoryMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
  ODataJPAContext oDataJPAContext = null;
  oDataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
  setOnWriteJPAContent(new OnJPAWriteContentMock());
  return oDataJPAContext;
}
 
Example #13
Source File: ODataJPAContextMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static ODataJPAContext mockODataJPAContext(final ODataContext context) {
  ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
  EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn(NAMESPACE);
  EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andReturn(mockEntityManagerFactory());
  EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(mockEntityManager());
  EasyMock.expect(odataJPAContext.getJPAEdmMappingModel()).andReturn(MAPPING_MODEL);
  EasyMock.expect(odataJPAContext.getJPAEdmExtension()).andReturn(null);
  EasyMock.expect(odataJPAContext.getDefaultNaming()).andReturn(true);
  EasyMock.expect(odataJPAContext.getODataContext()).andReturn(context).anyTimes();
  EasyMock.expect(odataJPAContext.getPageSize()).andReturn(0);

  EasyMock.replay(odataJPAContext);
  return odataJPAContext;
}
 
Example #14
Source File: ODataJPAContextMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static ODataJPAContext mockODataJPAContext() {
  ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
  EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn(NAMESPACE);
  EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andReturn(mockEntityManagerFactory());
  EasyMock.expect(odataJPAContext.getEntityManager()).andReturn(mockEntityManager());
  EasyMock.expect(odataJPAContext.getJPAEdmMappingModel()).andReturn(MAPPING_MODEL);
  EasyMock.expect(odataJPAContext.getJPAEdmExtension()).andReturn(null);
  EasyMock.expect(odataJPAContext.getDefaultNaming()).andReturn(true);

  EasyMock.replay(odataJPAContext);
  return odataJPAContext;
}
 
Example #15
Source File: ODataJPADefaultProcessorTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataJPAContext getLocalmockODataJPAContext() {
  ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
  EasyMock.expect(odataJPAContext.getPageSize()).andReturn(0).anyTimes();
  EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
  EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
  EasyMock.expect(odataJPAContext.getODataJPATransaction()).andStubReturn(getLocalJpaTransaction());
  EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
  odataJPAContext.setODataContext((ODataContext) EasyMock.anyObject());
  EasyMock.expectLastCall().anyTimes();
  EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
  EasyMock.expect(odataJPAContext.isContainerManaged()).andReturn(false);
  EasyMock.expectLastCall().anyTimes();
  EasyMock.replay(odataJPAContext);
  return odataJPAContext;
}
 
Example #16
Source File: JPAEdmMappingModelService.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public JPAEdmMappingModelService(final ODataJPAContext ctx) {
  JPAEdmExtension ext = null;
  mappingModelName = ctx.getJPAEdmMappingModel();
  if (mappingModelName == null) {
    ext = ctx.getJPAEdmExtension();
    if (ext != null) {
      mappingModelStream = ext.getJPAEdmMappingModelStream();
    }
  }

  mappingModelExists = mappingModelName != null || mappingModelStream != null;
}
 
Example #17
Source File: JPAEntity.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public JPAEntity(final EdmEntityType oDataEntityType, final EdmEntitySet oDataEntitySet,
    final ODataJPAContext context) {
  this.oDataEntityType = oDataEntityType;
  this.oDataEntitySet = oDataEntitySet;
  oDataJPAContext = context;
  try {
    JPAEdmMapping mapping = (JPAEdmMapping) oDataEntityType.getMapping();
    jpaType = mapping.getJPAType();
  } catch (EdmException e) {
    return;
  }
  jpaEntityParser = new JPAEntityParser();
  onJPAWriteContent = oDataJPAContext.getODataContext().getServiceFactory().getCallback(OnJPAWriteContent.class);
}
 
Example #18
Source File: JPAEdmBaseViewImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public JPAEdmBaseViewImpl(final ODataJPAContext context) {
  pUnitName = context.getPersistenceUnitName();
  metaModel = context.getEntityManager().getMetamodel();
  jpaEdmMappingModelAccess =
      ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmMappingModelAccess(context);
  jpaEdmExtension = context.getJPAEdmExtension();
  jpaEdmMappingModelAccess.loadMappingModel();
  skipDefaultNaming = !context.getDefaultNaming();
}
 
Example #19
Source File: JPAServiceFactory.java    From lemonaid with MIT License 5 votes vote down vote up
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = getODataJPAContext();

	EntityManagerFactory factory = (EntityManagerFactory) SpringContextsUtil.getBean(ENTITY_MANAGER_FACTORY_ID);

	oDataJPAContext.setEntityManagerFactory(factory);
	oDataJPAContext.setPersistenceUnitName(DEFAULT_ENTITY_UNIT_NAME);
	oDataJPAContext.setJPAEdmExtension(new JPAEdmExtension());
	ODataContextUtil.setODataContext(oDataJPAContext.getODataContext());

	return oDataJPAContext;
}
 
Example #20
Source File: JPAServiceFactory.java    From lemonaid with MIT License 5 votes vote down vote up
/**
 * @return an instance of type {@link ODataJPAContext}
 * @throws ODataJPARuntimeException
 */
public final ODataJPAContext getODataJPAContext() throws ODataJPARuntimeException {
	if (oDataJPAContext == null) {
		oDataJPAContext = ODataJPAFactory.createFactory().getODataJPAAccessFactory().createODataJPAContext();
	}
	if (oDataContext != null) {
		oDataJPAContext.setODataContext(oDataContext);
	}
	return oDataJPAContext;

}
 
Example #21
Source File: JPAServiceFactory.java    From odata-boilerplate with MIT License 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = getODataJPAContext();

	EntityManagerFactory factory = (EntityManagerFactory) SpringContextsUtil.getBean(ENTITY_MANAGER_FACTORY_ID);

	oDataJPAContext.setEntityManagerFactory(factory);
	oDataJPAContext.setPersistenceUnitName(DEFAULT_ENTITY_UNIT_NAME);
	oDataJPAContext.setJPAEdmExtension(new JPAEdmExtension());
	ODataContextUtil.setODataContext(oDataJPAContext.getODataContext());
	
	return oDataJPAContext;
}
 
Example #22
Source File: ODataEntityParser.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ODataEntityParser(final ODataJPAContext context) {
  this.context = context;
  try {
    serviceRoot = context.getODataContext().getPathInfo().getServiceRoot().toString();
  } catch (ODataException e) {
    serviceRoot = "";
  }
}
 
Example #23
Source File: ODataJPAEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ODataJPAEdmProvider(final ODataJPAContext oDataJPAContext) {
  if (oDataJPAContext == null) {
    throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
  }
  entityTypes = new LinkedHashMap<String, EntityType>();
  entityContainerInfos = new LinkedHashMap<String, EntityContainerInfo>();
  complexTypes = new LinkedHashMap<String, ComplexType>();
  associations = new LinkedHashMap<String, Association>();
  functionImports = new LinkedHashMap<String, FunctionImport>();
  jpaEdmModel = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmModelView(oDataJPAContext);
}
 
Example #24
Source File: ODataJPAFactoryImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public JPAEdmModelView getJPAEdmModelView(final ODataJPAContext oDataJPAContext) {
  JPAEdmModelView view = null;

  view = new JPAEdmModel(oDataJPAContext);
  return view;
}
 
Example #25
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static EntityProviderWriteProperties getEntityProviderPropertiesforPost(
    final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException {
  ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
  try {
    entityFeedPropertiesBuilder =
        EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }

  return entityFeedPropertiesBuilder.build();
}
 
Example #26
Source File: ODataJPAEdmProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public void setODataJPAContext(final ODataJPAContext jpaContext) {
  oDataJPAContext = jpaContext;
}
 
Example #27
Source File: ODataJPAProcessor.java    From lemonaid with MIT License 4 votes vote down vote up
public ODataJPAProcessor(ODataJPAContext oDataJPAContext) {
	super(oDataJPAContext);
	this.authorization = (ODataAuthorization) SpringContextsUtil.getBean("ODataAuthorization");
}
 
Example #28
Source File: JPAReferenceServiceFactory.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext context) {
  return new CustomODataJPAProcessor(context);
}
 
Example #29
Source File: CustomODataJPAProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public CustomODataJPAProcessor(ODataJPAContext oDataJPAContext) {
  super(oDataJPAContext);
}
 
Example #30
Source File: ODataJPAEdmProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public ODataJPAContext getODataJPAContext() {
  return oDataJPAContext;
}