Repository: olingo-odata2 Updated Branches: refs/heads/master 0e99c0170 -> db50903b1
[OLINGO-306] Replace Static fields with Instance fields to prevent concurrent modifications to the ArrayList. Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/db50903b Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/db50903b Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/db50903b Branch: refs/heads/master Commit: db50903b1856ef3cb079d6e0e9e21b5a376b67c2 Parents: 0e99c01 Author: Chandan V A <[email protected]> Authored: Sun Jun 15 16:02:33 2014 +0530 Committer: Chandan V A <[email protected]> Committed: Sun Jun 15 16:02:33 2014 +0530 ---------------------------------------------------------------------- .../processor/api/model/JPAEdmPropertyView.java | 8 +++ .../processor/core/model/JPAEdmProperty.java | 9 ++- .../model/JPAEdmReferentialConstraintRole.java | 62 ++------------------ .../JPAEdmReferentialConstraintRoleTest.java | 19 ++++++ .../model/JPAEdmReferentialConstraintTest.java | 18 ++++++ .../core/model/JPAEdmTestModelView.java | 7 +++ 6 files changed, 66 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/db50903b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java index ce06f68..419d622 100644 --- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java +++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java @@ -20,6 +20,7 @@ package org.apache.olingo.odata2.jpa.processor.api.model; import java.util.List; +import javax.persistence.JoinColumn; import javax.persistence.metamodel.Attribute; import org.apache.olingo.odata2.api.edm.provider.Property; @@ -110,4 +111,11 @@ public interface JPAEdmPropertyView extends JPAEdmBaseView { * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView} */ JPAEdmComplexTypeView getJPAEdmComplexTypeView(); + + /** + * The method returns a list of JPA Join Column Annotations for the given JPA Attribute + * @return + * an instance of type {@link javax.persistence.JoinColumn} + */ + List<JoinColumn> getJPAJoinColumns(); } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/db50903b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java ---------------------------------------------------------------------- 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 8ea02f7..7298a58 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 @@ -74,6 +74,7 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements private Attribute<?, ?> currentRefAttribute; private boolean isBuildModeComplexType; private Map<String, Integer> associationCount; + private ArrayList<JoinColumn> bJoinColumns = null; public JPAEdmProperty(final JPAEdmSchemaView view) { super(view); @@ -138,6 +139,11 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements return navigationPropertyView; } + @Override + public List<JoinColumn> getJPAJoinColumns() { + return bJoinColumns; + } + private class JPAEdmPropertyBuilder implements JPAEdmBuilder { /* * @@ -352,6 +358,8 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements return; } } else { + bJoinColumns = bJoinColumns == null ? new ArrayList<JoinColumn>() : bJoinColumns; + bJoinColumns.add(joinColumn); if (joinColumn.insertable() && joinColumn.updatable()) { EntityType<?> referencedEntityType = metaModel.entity(jpaAttribute.getJavaType()); for (Attribute<?, ?> referencedAttribute : referencedEntityType.getAttributes()) { @@ -419,5 +427,4 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements } return isExcluded; } - } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/db50903b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java index 2a2426b..b36398a 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java @@ -18,14 +18,12 @@ ******************************************************************************/ package org.apache.olingo.odata2.jpa.processor.core.model; -import java.lang.reflect.AnnotatedElement; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.metamodel.Attribute; import org.apache.olingo.odata2.api.edm.provider.Association; @@ -43,14 +41,6 @@ import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView; import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView; public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { - /* - * Static Buffer - */ - private static Attribute<?, ?> bufferedJPAAttribute = null; - private static ArrayList<JoinColumn> bufferedJoinColumns = new ArrayList<JoinColumn>(); - /* - * Static Buffer - */ private boolean firstBuild = true; @@ -60,6 +50,7 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen private Attribute<?, ?> jpaAttribute; private ArrayList<String> jpaColumnNames; private Association association; + private List<JoinColumn> bufferedJoinColumns = null; private boolean roleExists = false; @@ -75,6 +66,7 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen this.roleType = roleType; jpaAttribute = propertyView.getJPAAttribute(); + bufferedJoinColumns = propertyView.getJPAJoinColumns(); association = associationView.getEdmAssociation(); } @@ -141,12 +133,12 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen firstBuild = false; isConsistent = false; - extractJoinColumns(); - - if (!roleExists) { + if (bufferedJoinColumns == null || bufferedJoinColumns.isEmpty()) { + roleExists = false; return; + } else { + roleExists = true; } - jpaColumnNames = new ArrayList<String>(); for (JoinColumn joinColumn : bufferedJoinColumns) { @@ -156,7 +148,6 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen jpaColumnNames.add(joinColumn.name()); } } - } private void buildRole() throws SecurityException, NoSuchFieldException { @@ -213,46 +204,5 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen } } - - private void extractJoinColumns() { - /* - * Check against Static Buffer whether the join column was already - * extracted. - */ - if (!jpaAttribute.equals(bufferedJPAAttribute)) { - bufferedJPAAttribute = jpaAttribute; - bufferedJoinColumns.clear(); - } else if (bufferedJoinColumns.isEmpty()) { - roleExists = false; - return; - } else { - roleExists = true; - return; - } - - AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember(); - - if (annotatedElement == null) { - return; - } - - JoinColumn joinColumn = annotatedElement.getAnnotation(JoinColumn.class); - if (joinColumn == null) { - JoinColumns joinColumns = annotatedElement.getAnnotation(JoinColumns.class); - - if (joinColumns != null) { - JoinColumn[] joinColumnArray = joinColumns.value(); - - for (JoinColumn element : joinColumnArray) { - bufferedJoinColumns.add(element); - } - } else { - return; - } - } else { - bufferedJoinColumns.add(joinColumn); - } - roleExists = true; - } } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/db50903b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java index 5737c41..cee6ead 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java @@ -55,6 +55,7 @@ public class JPAEdmReferentialConstraintRoleTest extends JPAEdmTestModelView { private static JPAEdmReferentialConstraintRole objJPAEdmReferentialConstraintRole = null; private static JPAEdmReferentialConstraintRoleTest objJPAEdmReferentialConstraintRoleTest = null; + private List<JoinColumn> bufferedJoinColumns = null; @Before public void setUp() { @@ -147,6 +148,21 @@ public class JPAEdmReferentialConstraintRoleTest extends JPAEdmTestModelView { } @Override + public List<JoinColumn> getJPAJoinColumns() { + if (bufferedJoinColumns == null) { + JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class); + EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID"); + EasyMock.expect(joinColumn.name()).andReturn("SOID"); + + EasyMock.replay(joinColumn); + + bufferedJoinColumns = new ArrayList<JoinColumn>(); + bufferedJoinColumns.add(joinColumn); + } + return bufferedJoinColumns; + } + + @Override public Association getEdmAssociation() { Association association = new Association(); association.setName("Assoc_SalesOrderHeader_SalesOrderItem"); @@ -227,6 +243,9 @@ public class JPAEdmReferentialConstraintRoleTest extends JPAEdmTestModelView { EasyMock.expect(joinColumn.name()).andReturn("SOID"); EasyMock.replay(joinColumn); + + bufferedJoinColumns = new ArrayList<JoinColumn>(); + bufferedJoinColumns.add(joinColumn); return (T) joinColumn; } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/db50903b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java index 6e7f6b3..86181b7 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java @@ -25,6 +25,8 @@ import static org.junit.Assert.fail; import java.lang.annotation.Annotation; import java.lang.reflect.Member; +import java.util.ArrayList; +import java.util.List; import javax.persistence.JoinColumn; import javax.persistence.metamodel.Attribute; @@ -48,6 +50,7 @@ public class JPAEdmReferentialConstraintTest extends JPAEdmTestModelView { private static JPAEdmReferentialConstraint objJPAEdmReferentialConstraint = null; private static JPAEdmReferentialConstraintTest objJPAEdmReferentialConstraintTest = null; + private List<JoinColumn> bufferedJoinColumns = null; @Before public void setUp() { @@ -125,6 +128,21 @@ public class JPAEdmReferentialConstraintTest extends JPAEdmTestModelView { return getJPAAttributeLocal(); } + @Override + public List<JoinColumn> getJPAJoinColumns() { + if (bufferedJoinColumns == null) { + JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class); + EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID"); + EasyMock.expect(joinColumn.name()).andReturn("SOID"); + + EasyMock.replay(joinColumn); + + bufferedJoinColumns = new ArrayList<JoinColumn>(); + bufferedJoinColumns.add(joinColumn); + } + return bufferedJoinColumns; + } + @SuppressWarnings("hiding") private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/db50903b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java index 7a6f90f..639ad52 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java @@ -21,6 +21,7 @@ package org.apache.olingo.odata2.jpa.processor.core.model; import java.util.HashMap; import java.util.List; +import javax.persistence.JoinColumn; import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.EmbeddableType; import javax.persistence.metamodel.Metamodel; @@ -403,4 +404,10 @@ public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAsso return null; } + @Override + public List<JoinColumn> getJPAJoinColumns() { + // TODO Auto-generated method stub + return null; + } + }
