Skip to content

Commit

Permalink
Defect/issues239 (#303)
Browse files Browse the repository at this point in the history
* First level of COUNT query as IN

* Deletion of JPACollectionFilterQuery
  • Loading branch information
wog48 authored and GitHub Enterprise committed Nov 24, 2023
1 parent 005c85a commit cf11992
Show file tree
Hide file tree
Showing 38 changed files with 375 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Converter to convert enumeration value into a number. If no converter is provided, the ordinal is taken.
*/
Class<? extends AttributeConverter<? extends Enum<?>[], ? extends Number>> converter() default DummyConverter.class;
Class<? extends AttributeConverter<? extends Enum<?>[], ? extends Number>> converter() default DummyConverter.class; // NOSONAR

boolean isFlags() default false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
* property collection.
* @return
*/
Class<? extends EdmTransientPropertyCalculator<?>> calculator();
Class<? extends EdmTransientPropertyCalculator<?>> calculator(); // NOSONAR
}
207 changes: 106 additions & 101 deletions jpa/odata-jpa-coverage/pom.xml
Original file line number Diff line number Diff line change
@@ -1,105 +1,110 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa</artifactId>
<version>2.0.1</version>
</parent>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa</artifactId>
<version>2.0.1</version>
</parent>

<artifactId>odata-jpa-coverage</artifactId>
<name>odata-jpa-coverage</name>
<url>https://github.com/SAP/olingo-jpa-processor-v4</url>
<artifactId>odata-jpa-coverage</artifactId>
<name>odata-jpa-coverage</name>
<url>https://github.com/SAP/olingo-jpa-processor-v4</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-annotation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-metadata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor-cb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor-ext</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-odata-vocabularies</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor-parallel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-vocabularies</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
</excludes>
</rule>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls.version}</version>
</plugin>
</plugins>
</build>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-annotation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-metadata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor-cb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor-ext</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-odata-vocabularies</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor-parallel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-vocabularies</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>com/sap/olingo/jpa/processor/core/testmodel/*</exclude>
<exclude>com/sap/olingo/jpa/processor/core/errormodel/*</exclude>
</excludes>
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
</excludes>
</rule>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls.version}</version>
</plugin>
</plugins>
</build>
<packaging>pom</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@

public interface JPAJoinTable {
/**
* Returns the name of the join table including the schema name, using the following pattern: {schema}.{table}
* @return
* @return Name of the join table including the schema name, using the following pattern: {schema}.{table}
*/
public String getTableName();

/**
* @return Entity type of the join table
*/
public JPAEntityType getEntityType();

public List<JPAOnConditionItem> getJoinColumns() throws ODataJPAModelException;

/**
* Returns the list of inverse join columns with exchanged left/right order.
* @return
* @return List of inverse join columns with exchanged left/right order.
* @throws ODataJPAModelException
*/
public List<JPAOnConditionItem> getInverseJoinColumns() throws ODataJPAModelException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.CheckForNull;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.metamodel.PluralAttribute;
Expand Down Expand Up @@ -88,7 +90,7 @@ public IntermediateCollectionProperty(final IntermediateCollectionProperty<?> or
public JPAAssociationPath asAssociation() throws ODataJPAModelException {
if (this.associationPath == null) {
getJoinTable();
this.associationPath = new JPAAssociationPathImpl(this, sourceType,
this.associationPath = new JPAAssociationPathImpl(this,
path == null ? sourceType.getPath(getExternalName()) : path,
joinTable == null ? null : joinTable.getLeftJoinColumns());
}
Expand All @@ -111,17 +113,19 @@ public JPAAttribute getTargetAttribute() throws ODataJPAModelException {
if (isComplex())
return null;
else {
for (final JPAAttribute a : ((IntermediateStructuredType<?>) getJoinTable().getEntityType()).getAttributes()) {
for (final JPAAttribute a : getTargetEntity().getAttributes()) {
if (dbFieldName.equals(((IntermediateProperty) a).getDBFieldName()))
return a;
}
return null;
}
}

@SuppressWarnings("unchecked")
@Override
public JPAStructuredType getTargetEntity() throws ODataJPAModelException {
return getJoinTable().getEntityType();
final JPAJoinTable joinInfo = getJoinTable();
return joinInfo == null ? null : ((IntermediateCollectionTable) joinInfo).getTargetType();
}

@Override
Expand Down Expand Up @@ -209,6 +213,7 @@ String getDefaultValue() throws ODataJPAModelException {
return null;
}

@CheckForNull
JPAJoinTable getJoinTable() throws ODataJPAModelException {
if (joinTable == null) {
final jakarta.persistence.CollectionTable jpaJoinTable = ((AnnotatedElement) this.jpaAttribute.getJavaMember())
Expand Down Expand Up @@ -237,19 +242,23 @@ private Type<?> getRowType() {
private class IntermediateCollectionTable implements JPAJoinTable {
private final CollectionTable jpaJoinTable;
private final List<IntermediateJoinColumn> joinColumns;
private final JPAEntityType jpaEntityType;
private final JPAEntityType jpaTargetType;

public IntermediateCollectionTable(final CollectionTable jpaJoinTable, final IntermediateSchema schema)
throws ODataJPAModelException {
super();
this.jpaJoinTable = jpaJoinTable;
this.jpaEntityType = schema.getEntityType(jpaJoinTable.catalog(), jpaJoinTable.schema(), jpaJoinTable.name());
this.jpaTargetType = schema.getEntityType(jpaJoinTable.catalog(), jpaJoinTable.schema(), jpaJoinTable.name());
this.joinColumns = buildJoinColumns(sourceType);
}

@Override
public JPAEntityType getEntityType() {
return jpaEntityType;
return (JPAEntityType) sourceType;
}

JPAStructuredType getTargetType() {
return jpaTargetType;
}

@Override
Expand All @@ -258,20 +267,21 @@ public List<JPAOnConditionItem> getInverseJoinColumns() throws ODataJPAModelExce

for (final IntermediateJoinColumn column : joinColumns) {
result.add(new JPAOnConditionItemImpl(
((IntermediateEntityType<?>) jpaEntityType).getPathByDBField(column.getReferencedColumnName()),
sourceType.getPathByDBField(column.getName())));
sourceType.getPathByDBField(column.getName()),
((IntermediateEntityType<?>) jpaTargetType).getPathByDBField(column.getReferencedColumnName())));
}
return result;
}

@Override
public List<JPAOnConditionItem> getJoinColumns() throws ODataJPAModelException {
assert jpaEntityType != null;
assert jpaTargetType != null;
final List<JPAOnConditionItem> result = new ArrayList<>();
// Self Join
for (final IntermediateJoinColumn column : joinColumns) {
result.add(new JPAOnConditionItemImpl(
sourceType.getPathByDBField(column.getName()),
((IntermediateEntityType<?>) jpaEntityType).getPathByDBField(column.getReferencedColumnName())));
sourceType.getPathByDBField(column.getName())));
}
return result;
}
Expand Down Expand Up @@ -327,7 +337,7 @@ else if (!(contextType instanceof IntermediateEntityType))

@Override
public List<JPAPath> getRightColumnsList() throws ODataJPAModelException {
return getJoinColumns().stream()
return getInverseJoinColumns().stream()
.map(JPAOnConditionItem::getRightPath)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ final class JPAAssociationPathImpl implements JPAAssociationPath {
* @param joinColumns
* @throws ODataJPAModelException
*/
public JPAAssociationPathImpl(final IntermediateCollectionProperty<?> collectionProperty,
final IntermediateStructuredType<?> source, final JPAPath path, final List<? extends JPAJoinColumn> joinColumns)
throws ODataJPAModelException {
public JPAAssociationPathImpl(final IntermediateCollectionProperty<?> collectionProperty, final JPAPath path,
final List<? extends JPAJoinColumn> joinColumns) throws ODataJPAModelException {

alias = path.getAlias();
this.sourceType = source;
this.targetType = null;
this.sourceType = collectionProperty.getSourceType();
this.targetType = (IntermediateStructuredType<?>) collectionProperty.getTargetEntity();
this.joinColumns = joinColumns;
this.pathElements = path.getPath();
this.cardinality = PersistentAttributeType.ONE_TO_MANY;
Expand Down
Loading

0 comments on commit cf11992

Please sign in to comment.