This is an automated email from the ASF dual-hosted git repository.
mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git
The following commit(s) were added to refs/heads/master by this push:
new fd5e784 [OLINGO-1275] attribute overrides fix (#18)
fd5e784 is described below
commit fd5e784e2cee8ed58b6c37393190d4d954391e8d
Author: Manuel Blechschmidt <[email protected]>
AuthorDate: Sun Mar 6 21:15:46 2022 +0100
[OLINGO-1275] attribute overrides fix (#18)
* Implemented AttributeOverrides
* [OLINGO-1275] attribute overrides fix
---
.../jpa/processor/core/model/JPAEdmProperty.java | 38 +++++++++++++++++++---
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
index 4a5caf4..2e2c2be 100644
---
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
+++
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
@@ -26,11 +26,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.Attribute.PersistentAttributeType;
+import javax.persistence.metamodel.EmbeddableType;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.SingularAttribute;
@@ -367,13 +370,13 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl
implements
}
private void buildForeignKey(final JoinColumn joinColumn, final
Attribute<?, ?> jpaAttribute)
- throws ODataJPAModelException,
- ODataJPARuntimeException {
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
joinColumnNames = joinColumnNames == null ? new ArrayList<String[]>() :
joinColumnNames;
String[] name = { null, null };
- name[0] = "".equals(joinColumn.name()) == true ? jpaAttribute.getName()
: joinColumn.name();
+ name[0] = "".equals(joinColumn.name()) ? jpaAttribute.getName() :
joinColumn.name();
- EntityType<?> referencedEntityType = null;
+ EntityType<?> referencedEntityType;
if (jpaAttribute.isCollection()) {
referencedEntityType =
metaModel.entity(((PluralAttribute<?, ?, ?>)
currentAttribute).getElementType().getJavaType());
@@ -410,6 +413,33 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl
implements
joinColumnNames.add(name);
currentRefAttribute = referencedAttribute;
break;
+ } else
if(annotatedElement2.getAnnotation(AttributeOverrides.class) != null) {
+ AttributeOverrides attributeOverrides =
annotatedElement2.getAnnotation(AttributeOverrides.class);
+ if(attributeOverrides != null && referencedAttribute instanceof
SingularAttribute) {
+ boolean found = false;
+ // Check if the column name is in the defined overrides
+ for(AttributeOverride attributeOverride :
attributeOverrides.value()) {
+ if(attributeOverride.column() != null &&
+
joinColumn.referencedColumnName().equals(attributeOverride.column().name())) {
+ name[1] = attributeOverride.column().name();
+ // add the column
+ joinColumnNames.add(name);
+ // get the correct attribute from the embeddable type
+ if(((SingularAttribute<?,?>)referencedAttribute).getType()
instanceof EmbeddableType) {
+ EmbeddableType<?> embeddableTypeAttribute =
+ (EmbeddableType<?>) ((SingularAttribute<?, ?>)
referencedAttribute).getType();
+ currentRefAttribute =
embeddableTypeAttribute.getDeclaredAttribute(attributeOverride.name());
+ } else {
+ currentRefAttribute = referencedAttribute;
+ }
+ found = true;
+ break;
+ }
+ }
+ if(found) {
+ break;
+ }
+ }
}
}
}