Skip to content

Commit

Permalink
New version and fix for issue 136 (#137)
Browse files Browse the repository at this point in the history
* New version and fix for issue 136

* Usage of JPAEdmNameBuilder in Service Document Factory

* Deprecate setExternalName in PostProcessor

* Increasing Olingo and Jackson version

* Update archetype to new version

* Adopt config to new spring version

* Add test for annotation parsing

* Adjust README and corrections
  • Loading branch information
Oliver Grande committed Oct 12, 2021
1 parent 4082ec6 commit 0d25464
Show file tree
Hide file tree
Showing 45 changed files with 767 additions and 280 deletions.
15 changes: 11 additions & 4 deletions README.md
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/SAP/olingo-jpa-processor-v4.svg?branch=develop)](https://travis-ci.org/github/SAP/olingo-jpa-processor-v4)
[![Coverage Status](https://coveralls.io/repos/github/SAP/olingo-jpa-processor-v4/badge.svg?branch=develop)](https://coveralls.io/github/SAP/olingo-jpa-processor-v4?branch=develop)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE.txt)
[![REUSE status](https://api.reuse.software/badge/github.com/SAP/olingo-jpa-processor-v4)](https://api.reuse.software/info/github.com/SAP/olingo-jpa-processor-v4)
![GitHub last commit (develop)](https://img.shields.io/github/last-commit/SAP/OLINGO-JPA-PROCESSOR-V4/develop.svg)
[![GitHub pre-release](https://img.shields.io/github/release-pre/sap/olingo-jpa-processor-v4.svg?color=orange&label=pre-release)](https://github.com/SAP/olingo-jpa-processor-v4/releases/)
[![REUSE status](https://api.reuse.software/badge/github.com/SAP/olingo-jpa-processor-v4)](https://api.reuse.software/info/github.com/SAP/olingo-jpa-processor-v4)
Expand All @@ -18,19 +19,21 @@ At the current state the JPA Processor provide support for:
More details can be found in the [Tutorials](/jpa-tutorial/Tutorials/Introduction/Introduction.md).

# Requirements

The JPA Processor requires,minimum Java version [1.8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). The current version comes with Olingo 4.7.1. If you want to be updated about Olingo changes subscribe to Olingos [user mailing list](user-subscribe@olingo.apache.org).

Even so no JPA implementation is preferred, as long as it supports [JSR-338 Java Persistence 2.1](https://jcp.org/en/jsr/detail?id=317), it has to be stated that all test have been performed with [Eclipselink 2.7.1](http://www.eclipse.org/eclipselink/). If you have any problem e.g. with [Hibernate](http://hibernate.org) create an [issue](https://github.com/SAP/olingo-jpa-processor-v4/issues), but there is no guaranty that it can be solved, as Hibernate implements some JPA interfaces "differently" than EclipseLink.

# Download and Installation

The JPA Processor is a collection of [Maven](https://maven.apache.org) projects. To use it you need to
clone the repository, import the projects and declare a dependency to either the metadata generation only:

```XML
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-metadata</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.10-SNAPSHOT</version>
</dependency>
```

Expand All @@ -40,17 +43,20 @@ Or to the complete processor:
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.10-SNAPSHOT</version>
</dependency>
```

# Limitations

The project is still in the state of incubation, so some incompatible changes my come up, see To-Do. Nevertheless feel free to use the JPA processor where ever it helps.

# How to obtain support

For bugs, questions and ideas for enhancement please open an issue in github.

# To-Do (upcoming-changes)

The flowing extensions/changes are planned:

* Transient fields
Expand All @@ -63,6 +69,7 @@ The flowing extensions/changes are planned:
* Overload Operations

# License

Copyright (c) 2016-2021 SAP SE or an SAP affiliate company and olingo-jpa-processor-v4 contributors. Please see our [LICENSE.txt](LICENSE.txt) for copyright and license information.
Detailed information including third-party components and their licensing/copyright information is available via the [REUSE tool](https://api.reuse.software/info/github.com/SAP/olingo-jpa-processor-v4).

Expand All @@ -84,5 +91,5 @@ Detailed information including third-party components and their licensing/copyri
|0.3.6|- Enable more flexible transaction handling<br> - Part solution for issue [#83](https://github.com/SAP/olingo-jpa-processor-v4/issues/83)<br> - Increase support of Spring by performing request mapping in case a mapping path is provided via the service context|No|
|0.3.7| - Update Olingo dependency to 4.7.0|No|
|0.3.8| - Update Olingo dependency to 4.7.1<br> - Support of `java.time` data types. Prerequisite is the usage of JPA 2.2. <br> - Support of Absolute Context URL. See issue [#103](https://github.com/SAP/olingo-jpa-processor-v4/issues/103)<br> - Temporal data types do not longer require a Precision [#98](https://github.com/SAP/olingo-jpa-processor-v4/issues/98)<br>Support of MappedSuperclass|No|
|0.3.9| - Solutions for issue [#112](https://github.com/SAP/olingo-jpa-processor-v4/issues/112) <br> Solutions for issue [#114](https://github.com/SAP/olingo-jpa-processor-v4/issues/114)|No|

|0.3.9| - Solutions for issue [#112](https://github.com/SAP/olingo-jpa-processor-v4/issues/112) <br> - Solutions for issue [#114](https://github.com/SAP/olingo-jpa-processor-v4/issues/114)|No|
|0.3.10| - Update Olingo dependency to 4.8.0<br> - Deprecation of ```setExternalName``` in ```IntermediateModelItemAccess```<br>- Solutions for issue [#134](https://github.com/SAP/olingo-jpa-processor-v4/issues/136)<br>- Solutions for issue [#136](https://github.com/SAP/olingo-jpa-processor-v4/issues/136) |No|
6 changes: 3 additions & 3 deletions jpa-archetype/jpa-archetype-spring/pom.xml
Expand Up @@ -3,9 +3,9 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-archetype</artifactId>
<version>0.3.8</version>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-archetype</artifactId>
<version>0.3.10</version>
</parent>
<artifactId>odata-jpa-archetype-spring</artifactId>
<name>Archetype - odata-jpa-archetype-spring</name>
Expand Down
Expand Up @@ -11,12 +11,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<version>2.5.5</version>
<relativePath />
</parent>

<properties>
<jpa-processor>0.3.8-SNAPSHOT</jpa-processor>
<jpa-processor>0.3.10-SNAPSHOT</jpa-processor>
<java.version>1.8</java.version>
</properties>

Expand Down Expand Up @@ -102,13 +102,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.2</version>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.4.2</version><!--$NO-MVN-MAN-VER$-->
<version>1.8.1</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -20,7 +20,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -35,9 +34,8 @@ public class EclipseLinkJpaConfiguration extends JpaBaseConfiguration {
private String punit;

protected EclipseLinkJpaConfiguration(DataSource dataSource, JpaProperties properties,
ObjectProvider<JtaTransactionManager> jtaTransactionManager,
ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
super(dataSource, properties, jtaTransactionManager, transactionManagerCustomizers);
ObjectProvider<JtaTransactionManager> jtaTransactionManager) {
super(dataSource, properties, jtaTransactionManager);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions jpa-archetype/pom.xml
Expand Up @@ -5,14 +5,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-archetype</artifactId>
<version>0.3.9</version>
<version>0.3.10</version>
<packaging>pom</packaging>
<url>https://github.com/SAP/olingo-jpa-processor-v4</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.source>1.8</project.build.source>
<odata.jpa.version>0.3.8-SNAPSHOT</odata.jpa.version>
<odata.jpa.version>0.3.10-SNAPSHOT</odata.jpa.version>
</properties>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion jpa/odata-jpa-annotation/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa</artifactId>
<version>0.3.9-SNAPSHOT</version>
<version>0.3.10-SNAPSHOT</version>
</parent>
<artifactId>odata-jpa-annotation</artifactId>
<name>odata-jpa-annotation</name>
Expand Down
2 changes: 1 addition & 1 deletion jpa/odata-jpa-coverage/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa</artifactId>
<version>0.3.9-SNAPSHOT</version>
<version>0.3.10-SNAPSHOT</version>
</parent>

<artifactId>odata-jpa-coverage</artifactId>
Expand Down
9 changes: 7 additions & 2 deletions jpa/odata-jpa-metadata/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa</artifactId>
<version>0.3.9-SNAPSHOT</version>
<version>0.3.10-SNAPSHOT</version>
</parent>


Expand Down Expand Up @@ -63,6 +63,11 @@
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>net.oneandone.reflections8</groupId>
<artifactId>reflections8</artifactId>
Expand All @@ -77,7 +82,7 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
</dependency>
</dependencies>
<build>
</build>
Expand Down
Expand Up @@ -58,8 +58,7 @@ public JPAEdmProvider(final Metamodel jpaMetamodel, final JPAEdmMetadataPostProc
final String[] packageName, final JPAEdmNameBuilder nameBuilder) throws ODataException {
super();
this.nameBuilder = nameBuilder;
this.serviceDocument = new JPAServiceDocumentFactory(nameBuilder.getNamespace(), jpaMetamodel, postProcessor,
packageName).getServiceDocument();
this.serviceDocument = new JPAServiceDocumentFactory(nameBuilder, jpaMetamodel, postProcessor, packageName).getServiceDocument();
}

@Override
Expand Down
@@ -1,5 +1,7 @@
package com.sap.olingo.jpa.metadata.core.edm.mapper.annotation;

import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.VARIABLE_NOT_SUPPORTED;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -8,6 +10,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException;

@JsonIgnoreProperties(ignoreUnknown = true)
class Term extends CsdlTerm {
Expand Down Expand Up @@ -70,16 +73,39 @@ public CsdlTerm setMaxLength(final Integer maxLength) {
public CsdlTerm setPrecision(final Integer precision) {
return super.setPrecision(precision);
}

@Override
/**
* A non negative integer or floating or variable.</p>
* The value <b>floating</b> means that the decimal property represents a decimal floating-point number whose number
* of
* significant digits is the value of the Precision facet. OData 4.0 responses MUST NOT specify the value floating.
* </p>
* The value <b>variable</b> means that the number of digits to the right of the decimal point may vary from zero to
* the value of the Precision facet.
* {@link https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Scale}
* @throws ODataJPAModelException
*/
@JacksonXmlProperty(localName = "Scale", isAttribute = true)
public CsdlTerm setScale(final Integer scale) {
return super.setScale(scale);
public CsdlTerm setScale(final String scaleValue) throws ODataJPAModelException {
try {
final Integer scale = Integer.valueOf(scaleValue);
return super.setScale(scale);
} catch (final NumberFormatException e) {
throw new ODataJPAModelException(VARIABLE_NOT_SUPPORTED, e, "Scale");
}
}

/**
* For a geometry or geography property the SRID facet identifies which spatial reference system is applied to values
* of the property on type instances.
* </p>
* The value of the SRID facet MUST be a non-negative integer or the special value variable. If no value is specified,
* the attribute defaults to 0 for Geometry types or 4326 for Geography types.
* </p>
* The valid values of the SRID facet and their meanings are as defined by the European Petroleum Survey Group [EPSG].
* @param srid
*/
@JacksonXmlProperty(localName = "SRID", isAttribute = true)
void setSrid(final String srid) {
if (srid != null)
super.setSrid(SRID.valueOf(srid));
void setSrid(final String srid) throws ODataJPAModelException {
super.setSrid(SRID.valueOf(srid));
}
}
Expand Up @@ -6,6 +6,6 @@

public interface JPAAction extends JPAOperation, JPAJavaOperation {

JPAParameter getParameter(Parameter declairedParameter) throws ODataJPAModelException;
JPAParameter getParameter(final Parameter declaredParameter) throws ODataJPAModelException;

}
Expand Up @@ -9,7 +9,7 @@ public interface JPAParameter extends JPAParamaterFacet {
public String getInternalName();

/**
* Externaly used name
* Externally used name
* @return
*/
public String getName();
Expand Down
Expand Up @@ -53,5 +53,7 @@ public interface JPAServiceDocument extends CustomETagSupport {
JPAEnumerationAttribute getEnumType(final EdmEnumType type);

JPAEnumerationAttribute getEnumType(final String fqnAsString);

JPAEdmNameBuilder getNameBuilder();

}
Expand Up @@ -68,6 +68,7 @@ public enum MessageKeys implements ODataJPAMessageKey {
ANNOTATION_STREAM_INCOMPLETE,
ANNOTATION_PARSE_ERROR,
ANNOTATION_PATH_NOT_FOUND,
VARIABLE_NOT_SUPPORTED,
ODATA_ANNOTATION_TWO_EXPRESSIONS,
NAVI_PROPERTY_NOT_FOUND,
ON_LEFT_ATTRIBUTE_NULL,
Expand Down
Expand Up @@ -4,6 +4,7 @@

import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;

import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder;
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement;

public interface IntermediateEntitySetAccess extends JPAElement {
Expand All @@ -15,8 +16,8 @@ public interface IntermediateEntitySetAccess extends JPAElement {
public void addAnnotations(final List<CsdlAnnotation> annotations);

/**
* Enables a rename external, OData, name of an entity set.
* @param externalName
* @deprecated (0.3.10, Overriding the external name not working correctly. Create an {@link JPAEdmNameBuilder} instead )
*/
@Deprecated
void setExternalName(String externalName);
}
@@ -1,5 +1,6 @@
package com.sap.olingo.jpa.metadata.core.edm.mapper.extention;

import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder;
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement;

/**
Expand All @@ -14,9 +15,9 @@ public interface IntermediateModelItemAccess extends JPAElement {
boolean ignore();

/**
* Enables to overwrite the External, OData, name of a model item.
* @param externalName
* @deprecated (0.3.10, Overriding the external name not working correctly. Create an {@link JPAEdmNameBuilder} instead )
*/
@Deprecated
void setExternalName(String externalName);

/**
Expand Down
Expand Up @@ -274,6 +274,11 @@ public boolean hasMediaETag(final EdmBindingTarget entitySetOrSingleton) {
return false;
}

@Override
public JPAEdmNameBuilder getNameBuilder() {
return nameBuilder;
}

private void buildIntermediateSchemas()
throws ODataJPAModelException {
final IntermediateSchema schema = new IntermediateSchema(nameBuilder, jpaMetamodel, reflections);
Expand Down
Expand Up @@ -3,26 +3,32 @@
import javax.persistence.metamodel.Metamodel;

import com.sap.olingo.jpa.metadata.api.JPAEdmMetadataPostProcessor;
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder;
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument;
import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException;

public final class JPAServiceDocumentFactory {

private final String namespace;
private final JPAEdmNameBuilder nameBuilder;
private final Metamodel jpaMetamodel;
private final JPAEdmMetadataPostProcessor postProcessor;
private final String[] packageName;

public JPAServiceDocumentFactory(final String namespace, final Metamodel jpaMetamodel,
public JPAServiceDocumentFactory(final JPAEdmNameBuilder nameBuilder, final Metamodel jpaMetamodel,
final JPAEdmMetadataPostProcessor postProcessor, final String[] packageName) {
super();
this.namespace = namespace;
this.nameBuilder = nameBuilder;
this.jpaMetamodel = jpaMetamodel;
this.postProcessor = postProcessor;
this.packageName = packageName;
}

/**
* Late creation of the service document. A service document contains at least one schema and a container.
* @return
* @throws ODataJPAModelException
*/
public JPAServiceDocument getServiceDocument() throws ODataJPAModelException {
return new IntermediateServiceDocument(namespace, jpaMetamodel, postProcessor, packageName);
return new IntermediateServiceDocument(nameBuilder, jpaMetamodel, postProcessor, packageName);
}
}
Expand Up @@ -76,6 +76,7 @@ ODataJPAModelException.ANNOTATION_STREAM_INCOMPLETE = Either contentType or cont
ODataJPAModelException.ANNOTATION_PARSE_ERROR = Parsing of '%1$s' failed with message '%2$s'
ODataJPAModelException.ANNOTATION_PATH_NOT_FOUND = Path '%1$s' to read the file containing vocabulary '%2$s' is wrong.
ODataJPAModelException.ODATA_ANNOTATION_TWO_EXPRESSIONS = OData annotation only supports either a constant or a dynamic expression. See '%1$s'
ODataJPAModelException.VARIABLE_NOT_SUPPORTED = OData V4.01 string values for attribute '%1$s' are not supported.

ODataJPAModelException.ON_LEFT_ATTRIBUTE_NULL = ON condition left attribute is null / not found
ODataJPAModelException.ON_RIGHT_ATTRIBUTE_NULL = ON condition right attribute is null / not found
Expand Down

0 comments on commit 0d25464

Please sign in to comment.