diff options
author | sdimov | 2011-04-14 16:46:20 +0000 |
---|---|---|
committer | sdimov | 2011-04-14 16:46:20 +0000 |
commit | 5905a2cd0aead1775b3724cc503d5c3bd93ccc3c (patch) | |
tree | e56daa7cd175b29c0a75c99b8267264c22554d4f /jpa_diagram_editor | |
parent | d3de7b3263b61275b25ac9eca1afad7ccd546c71 (diff) | |
download | webtools.dali-5905a2cd0aead1775b3724cc503d5c3bd93ccc3c.tar.gz webtools.dali-5905a2cd0aead1775b3724cc503d5c3bd93ccc3c.tar.xz webtools.dali-5905a2cd0aead1775b3724cc503d5c3bd93ccc3c.zip |
Small fix related to mandatory @MapKey
Diffstat (limited to 'jpa_diagram_editor')
6 files changed, 43 insertions, 32 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java index 1e28ca310b..41d9e2c234 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java @@ -98,16 +98,16 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements Bidir } nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, nameWithNonCapitalLetter); actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, actNameWithNonCapitalLetter); - + boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()); inverseAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, inverse, owner, - JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()) ? JpaArtifactFactory.instance().getIdType(owner) : null, + isMap ? JpaArtifactFactory.instance().getIdType(owner) : null, nameWithNonCapitalLetter, actNameWithNonCapitalLetter, true, inverseCU, ownerCU); - JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute); + JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap); } public RelDir getRelDir() { diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java index bec79d2f28..790c23c61f 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java @@ -60,15 +60,15 @@ public class ManyToManyUniDirRelation extends ManyToManyRelation implements Unid } nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter); - + boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()); ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse, - JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()) ? JpaArtifactFactory.instance().getIdType(inverse) : null, + isMap ? JpaArtifactFactory.instance().getIdType(inverse) : null, nameWithNonCapitalLetter, actNameWithNonCapitalLetter, true, ownerCU, inverseCU); - JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute); + JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap); } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java index 8011eb4965..3442c507f8 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java @@ -87,15 +87,15 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements Bidire } nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, nameWithNonCapitalLetter); actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, actNameWithNonCapitalLetter); - + boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()); inverseAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, inverse, owner, - JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()) ? JpaArtifactFactory.instance().getIdType(owner) : null, + isMap ? JpaArtifactFactory.instance().getIdType(owner) : null, nameWithNonCapitalLetter, actNameWithNonCapitalLetter, true, inverseCU, ownerCU); - JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute); + JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap); } public RelDir getRelDir() { diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java index 02c71939b4..7af06377c6 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java @@ -60,14 +60,14 @@ public class OneToManyUniDirRelation extends OneToManyRelation implements Unidir } nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter); - + boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()); ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse, - JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()) ? JpaArtifactFactory.instance().getIdType(inverse) : null, + isMap ? JpaArtifactFactory.instance().getIdType(inverse) : null, nameWithNonCapitalLetter, actNameWithNonCapitalLetter, true, ownerCU, inverseCU); - JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute); + JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap); } public RelDir getRelDir() { diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java index 6e09e6c179..098f62218e 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java @@ -82,6 +82,7 @@ import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.JoinColumnsAnnotation; import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NestableAttributeOverrideAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NestableJoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; @@ -172,33 +173,33 @@ public class JpaArtifactFactory { } public void addOneToManyUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt, - JavaPersistentAttribute attribute) { + JavaPersistentAttribute attribute, boolean isMap) { addOneToManyRelation(fp, jpt, attribute, null, null, - JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL); + JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL, isMap); } public void addOneToManyBidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt1, JavaPersistentAttribute attribute1, JavaPersistentType jpt2, - JavaPersistentAttribute attribute2) { + JavaPersistentAttribute attribute2, boolean isMap) { addOneToManyRelation(fp, jpt1, attribute1, jpt2, attribute2, - JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL); + JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL, isMap); } public void addManyToOneBidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt1, JavaPersistentAttribute attribute1, JavaPersistentType jpt2, - JavaPersistentAttribute attribute2) { + JavaPersistentAttribute attribute2, boolean isMap) { addManyToOneRelation(fp, jpt1, attribute1, jpt2, attribute2, - JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL); + JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL, isMap); } public void addOneToManyRelation(IFeatureProvider fp, JavaPersistentType singleSideJPT, JavaPersistentAttribute singleSideAttibute, JavaPersistentType manySideJPT, - JavaPersistentAttribute manySideAttribute, int direction) { + JavaPersistentAttribute manySideAttribute, int direction, boolean isMap) { //if(singleSideJPT.getAttributeNamed(singleSideAttibute.getName()) == null){ refreshEntityModel(fp, singleSideJPT); @@ -231,6 +232,8 @@ public class JpaArtifactFactory { annotation.setMappedBy(manySideAttribute.getName()); } + if (isMap) + singleSideAttibute.getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) { if(manySideJPT.getAttributeNamed(manySideAttribute.getName()) == null){ refreshEntityModel(fp, manySideJPT); @@ -341,14 +344,14 @@ public class JpaArtifactFactory { JavaPersistentAttribute attribute) { addManyToOneRelation(fp, jpt, attribute, null, null, - JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL); + JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL, false); } public void addManyToOneRelation(IFeatureProvider fp, JavaPersistentType manySideJPT, JavaPersistentAttribute manySideAttribute, JavaPersistentType singleSideJPT, JavaPersistentAttribute singleSideAttibute, - int direction) { + int direction, boolean isMap) { refreshEntityModel(fp, manySideJPT); @@ -366,27 +369,29 @@ public class JpaArtifactFactory { if (a == null) return; a.setMappedBy(manySideAttribute.getName()); + if (isMap) + singleSideAttibute.getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); } public void addManyToManyBidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt1, JavaPersistentAttribute attribute1, JavaPersistentType jpt2, - JavaPersistentAttribute attribute2) { + JavaPersistentAttribute attribute2, boolean isMap) { addManyToManyRelation(fp, jpt1, attribute1, jpt2, attribute2, - JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL); + JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL, isMap); } public void addManyToManyUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType annotatedJPT, - JavaPersistentAttribute annotatedAttribute) { + JavaPersistentAttribute annotatedAttribute, boolean isMap) { addManyToManyRelation(fp, annotatedJPT, annotatedAttribute, null, null, - JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL); + JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL, isMap); } public void addManyToManyRelation(IFeatureProvider fp, JavaPersistentType ownerSideJPT, JavaPersistentAttribute ownerSideAttribute, JavaPersistentType inverseSideJPT, - JavaPersistentAttribute inverseSideAttibute, int direction) { + JavaPersistentAttribute inverseSideAttibute, int direction, boolean isMap) { if(ownerSideJPT.getAttributeNamed(ownerSideAttribute.getName()) == null){ refreshEntityModel(fp, ownerSideJPT); @@ -396,6 +401,9 @@ public class JpaArtifactFactory { .resolveAttribute(ownerSideAttribute.getName()); resolvedOwnerSideAttribute .setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); + if (isMap) + resolvedOwnerSideAttribute.getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); + if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) { JpaArtifactFactory.instance().refreshEntityModel(null, inverseSideJPT); /* @@ -422,7 +430,9 @@ public class JpaArtifactFactory { } if (a == null) return; - a.setMappedBy(ownerSideAttribute.getName()); + a.setMappedBy(ownerSideAttribute.getName()); + if (isMap) + resolvedInverseSideAttribute.getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); } } @@ -661,7 +671,8 @@ public class JpaArtifactFactory { refreshEntityModel(fp, jpt); } - return getAttributeFromEntity(jpt, actName); + JavaPersistentAttribute res = getAttributeFromEntity(jpt, actName); + return res; } public String getApropriateImplementedCollectionType(String collectionType){ diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java index 7006fef1f5..951aa712b2 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java @@ -307,7 +307,7 @@ public class CreateRelationAttributesTest { createCompilationUnitFrom((IFile)t2.getResource())); assertNotNull(attr); - JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(featureProvider, (JavaPersistentType)t1, attr); + JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(featureProvider, (JavaPersistentType)t1, attr, false); PersistentType pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); while (pt == null) { @@ -368,7 +368,7 @@ public class CreateRelationAttributesTest { createCompilationUnitFrom((IFile)singleSidePersistentType.getResource())); assertNotNull(manySideAttribute); - JpaArtifactFactory.instance().addOneToManyBidirectionalRelation(featureProvider, (JavaPersistentType)singleSidePersistentType, singleSideAttribute, (JavaPersistentType)manySidePersistentType, manySideAttribute); + JpaArtifactFactory.instance().addOneToManyBidirectionalRelation(featureProvider, (JavaPersistentType)singleSidePersistentType, singleSideAttribute, (JavaPersistentType)manySidePersistentType, manySideAttribute, false); // In one-to-many bidirectional relation many side is ALWAYS owner PersistentType inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName()); @@ -528,7 +528,7 @@ public class CreateRelationAttributesTest { createCompilationUnitFrom((IFile)ownerSidePersistentType.getResource())); assertNotNull(inverseSideAttributes); - JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(featureProvider, (JavaPersistentType)ownerSidePersistentType, ownerSideAttribute, (JavaPersistentType)inverseSidePersistentType, inverseSideAttributes); + JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(featureProvider, (JavaPersistentType)ownerSidePersistentType, ownerSideAttribute, (JavaPersistentType)inverseSidePersistentType, inverseSideAttributes, false); PersistentType ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName()); while (ownerPersistentType == null) { @@ -596,7 +596,7 @@ public class CreateRelationAttributesTest { createCompilationUnitFrom((IFile)referencedPersistentType.getResource())); assertNotNull(annotatedSideAttribute); - JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(featureProvider, (JavaPersistentType)annotatedPersistentType, annotatedSideAttribute); + JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(featureProvider, (JavaPersistentType)annotatedPersistentType, annotatedSideAttribute, false); PersistentType persistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName()); while (persistentType == null) { |