diff options
author | pfullbright | 2010-01-29 17:29:50 +0000 |
---|---|---|
committer | pfullbright | 2010-01-29 17:29:50 +0000 |
commit | 7b4ab3fc9250a4d416c2d2af84e80614e8903cb4 (patch) | |
tree | 85a6abc859a00e68070696017bc1d0a5478ef19f | |
parent | 6ccbf1d71754fbdb2612e08951d122ea9911dea7 (diff) | |
download | webtools.dali-7b4ab3fc9250a4d416c2d2af84e80614e8903cb4.tar.gz webtools.dali-7b4ab3fc9250a4d416c2d2af84e80614e8903cb4.tar.xz webtools.dali-7b4ab3fc9250a4d416c2d2af84e80614e8903cb4.zip |
predominant joining strategy updates on resource model API changes
23 files changed, 1061 insertions, 25 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java index a886b844d1..32abc18455 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java @@ -84,12 +84,22 @@ public abstract class AbstractJavaOneToManyRelationshipReference return this.mappedByJoiningStrategy; } - public void setMappedByJoiningStrategy() { + public final void setMappedByJoiningStrategy() { + setMappedByJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void setMappedByJoiningStrategy_() { this.mappedByJoiningStrategy.addStrategy(); this.joinTableJoiningStrategy.removeStrategy(); } - public void unsetMappedByJoiningStrategy() { + public final void unsetMappedByJoiningStrategy() { + unsetMappedByJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void unsetMappedByJoiningStrategy_() { this.mappedByJoiningStrategy.removeStrategy(); } @@ -112,12 +122,22 @@ public abstract class AbstractJavaOneToManyRelationshipReference return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; } - public void setJoinTableJoiningStrategy() { + public final void setJoinTableJoiningStrategy() { + setJoinTableJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void setJoinTableJoiningStrategy_() { // join table is default, so no need to add annotation this.mappedByJoiningStrategy.removeStrategy(); } - public void unsetJoinTableJoiningStrategy() { + public final void unsetJoinTableJoiningStrategy() { + unsetJoinTableJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void unsetJoinTableJoiningStrategy_() { this.joinTableJoiningStrategy.removeStrategy(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java index 41c77fceaf..9e0fb0628c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java @@ -58,6 +58,10 @@ public abstract class AbstractJavaRelationshipReference return this.cachedPredominantJoiningStrategy; } + protected void setPredominantJoiningStrategy() { + setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); + } + protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; this.cachedPredominantJoiningStrategy = newJoiningStrategy; @@ -76,7 +80,7 @@ public abstract class AbstractJavaRelationshipReference public void update() { updateJoiningStrategies(); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); + setPredominantJoiningStrategy(); } protected abstract void updateJoiningStrategies(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java index 5808c4beb4..289b0066bd 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java @@ -99,10 +99,12 @@ public class GenericJavaManyToManyRelationshipReference public void setMappedByJoiningStrategy() { this.mappedByJoiningStrategy.addStrategy(); this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetMappedByJoiningStrategy() { this.mappedByJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean usesMappedByJoiningStrategy() { @@ -127,10 +129,12 @@ public class GenericJavaManyToManyRelationshipReference public void setJoinTableJoiningStrategy() { // join table is default option, so no need to add to resource this.mappedByJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetJoinTableJoiningStrategy() { this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinTable() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java index bfa5d4fa87..9f05fdd78e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java @@ -81,10 +81,12 @@ public class GenericJavaManyToOneRelationshipReference public void setJoinColumnJoiningStrategy() { // join columns are default (and only, so far) strategy, so no need // to add to resource model + setPredominantJoiningStrategy(); } public void unsetJoinColumnJoiningStrategy() { this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinColumn() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java index 8df83efda7..f63a81d133 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java @@ -115,10 +115,12 @@ public class GenericJavaOneToOneRelationshipReference this.mappedByJoiningStrategy.addStrategy(); this.joinColumnJoiningStrategy.removeStrategy(); this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetMappedByJoiningStrategy() { this.mappedByJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { @@ -140,10 +142,12 @@ public class GenericJavaOneToOneRelationshipReference this.mappedByJoiningStrategy.removeStrategy(); this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); // join columns are default, so no need to add annotations + setPredominantJoiningStrategy(); } public void unsetJoinColumnJoiningStrategy() { this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinColumn() { @@ -166,10 +170,12 @@ public class GenericJavaOneToOneRelationshipReference this.primaryKeyJoinColumnJoiningStrategy.addStrategy(); this.mappedByJoiningStrategy.removeStrategy(); this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetPrimaryKeyJoinColumnJoiningStrategy() { this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultPrimaryKeyJoinColumn() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java index 09cf1d8505..64f46b2175 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java @@ -107,12 +107,22 @@ public abstract class AbstractOrmOneToManyRelationshipReference return this.mappedByJoiningStrategy; } - public void setMappedByJoiningStrategy() { + public final void setMappedByJoiningStrategy() { + setMappedByJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void setMappedByJoiningStrategy_() { this.mappedByJoiningStrategy.addStrategy(); this.joinTableJoiningStrategy.removeStrategy(); } - public void unsetMappedByJoiningStrategy() { + public final void unsetMappedByJoiningStrategy() { + unsetMappedByJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void unsetMappedByJoiningStrategy_() { this.mappedByJoiningStrategy.removeStrategy(); } @@ -135,12 +145,22 @@ public abstract class AbstractOrmOneToManyRelationshipReference return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; } - public void setJoinTableJoiningStrategy() { + public final void setJoinTableJoiningStrategy() { + setJoinTableJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void setJoinTableJoiningStrategy_() { // join table is default, so no need to add to resource this.mappedByJoiningStrategy.removeStrategy(); } - public void unsetJoinTableJoiningStrategy() { + public final void unsetJoinTableJoiningStrategy() { + unsetJoinTableJoiningStrategy_(); + setPredominantJoiningStrategy(); + } + + protected void unsetJoinTableJoiningStrategy_() { this.joinTableJoiningStrategy.removeStrategy(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java index 80bd196088..f7f679f267 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java @@ -33,6 +33,7 @@ public abstract class AbstractOrmRelationshipReference protected AbstractOrmRelationshipReference( OrmRelationshipMapping parent, AbstractXmlRelationshipMapping resourceMapping) { + super(parent); this.resourceMapping = resourceMapping; this.initialize(); @@ -81,6 +82,10 @@ public abstract class AbstractOrmRelationshipReference return this.cachedPredominantJoiningStrategy; } + protected void setPredominantJoiningStrategy() { + setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); + } + protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; this.cachedPredominantJoiningStrategy = newJoiningStrategy; @@ -100,7 +105,7 @@ public abstract class AbstractOrmRelationshipReference public void update() { updateJoiningStrategies(); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); + setPredominantJoiningStrategy(); } protected abstract void updateJoiningStrategies(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java index be0a784f15..831ca0a58a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java @@ -126,10 +126,12 @@ public class GenericOrmManyToManyRelationshipReference public void setMappedByJoiningStrategy() { this.mappedByJoiningStrategy.addStrategy(); this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetMappedByJoiningStrategy() { this.mappedByJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { @@ -150,10 +152,12 @@ public class GenericOrmManyToManyRelationshipReference public void setJoinTableJoiningStrategy() { // join table is the default strategy, so no need to add to resource this.mappedByJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetJoinTableJoiningStrategy() { this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinTable() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java index 46104045a0..e61479e025 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java @@ -99,10 +99,12 @@ public class GenericOrmManyToOneRelationshipReference public void setJoinColumnJoiningStrategy() { // join columns are default (only strategy in fact) so no need to add to resource + setPredominantJoiningStrategy(); } public void unsetJoinColumnJoiningStrategy() { this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinColumn() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java index 31b766c09f..149e9da5a0 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java @@ -148,10 +148,12 @@ public class GenericOrmOneToOneRelationshipReference this.mappedByJoiningStrategy.addStrategy(); this.joinColumnJoiningStrategy.removeStrategy(); this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetMappedByJoiningStrategy() { this.mappedByJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { @@ -173,10 +175,12 @@ public class GenericOrmOneToOneRelationshipReference this.mappedByJoiningStrategy.removeStrategy(); this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); // join columns are default, so no need to add annotations + setPredominantJoiningStrategy(); } public void unsetJoinColumnJoiningStrategy() { this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinColumn() { @@ -199,10 +203,12 @@ public class GenericOrmOneToOneRelationshipReference this.primaryKeyJoinColumnJoiningStrategy.addStrategy(); this.mappedByJoiningStrategy.removeStrategy(); this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetPrimaryKeyJoinColumnJoiningStrategy() { this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultPrimaryKeyJoinColumn() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java index d85cb0692e..57f007fbad 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java @@ -17,11 +17,11 @@ import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyRelations public class GenericJavaOneToManyRelationshipReference extends AbstractJavaOneToManyRelationshipReference { - public GenericJavaOneToManyRelationshipReference(JavaOneToManyMapping parent) { super(parent); } + @Override protected JoiningStrategy calculatePredominantJoiningStrategy() { if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { @@ -29,5 +29,4 @@ public class GenericJavaOneToManyRelationshipReference } return this.joinTableJoiningStrategy; } - } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkOneToManyRelationshipReference.java index 5cc467d12b..ec96386b86 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkOneToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkOneToManyRelationshipReference.java @@ -76,8 +76,8 @@ public class JavaEclipseLinkOneToManyRelationshipReference // **************** mapped by ********************************************** @Override - public void setMappedByJoiningStrategy() { - super.setMappedByJoiningStrategy(); + protected void setMappedByJoiningStrategy_() { + super.setMappedByJoiningStrategy_(); this.joinColumnJoiningStrategy.removeStrategy(); } @@ -91,8 +91,8 @@ public class JavaEclipseLinkOneToManyRelationshipReference // **************** join table ********************************************* @Override - public void setJoinTableJoiningStrategy() { - super.setJoinTableJoiningStrategy(); + protected void setJoinTableJoiningStrategy_() { + super.setJoinTableJoiningStrategy_(); this.joinColumnJoiningStrategy.removeStrategy(); } @@ -117,10 +117,12 @@ public class JavaEclipseLinkOneToManyRelationshipReference this.joinColumnJoiningStrategy.addStrategy(); this.mappedByJoiningStrategy.removeStrategy(); this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetJoinColumnJoiningStrategy() { this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinColumn() { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyRelationshipReference.java index dbc2f8522d..37b287c91f 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyRelationshipReference.java @@ -92,8 +92,8 @@ public class OrmEclipseLinkOneToManyRelationshipReference // **************** mapped by ********************************************** @Override - public void setMappedByJoiningStrategy() { - super.setMappedByJoiningStrategy(); + protected void setMappedByJoiningStrategy_() { + super.setMappedByJoiningStrategy_(); this.joinColumnJoiningStrategy.removeStrategy(); } @@ -107,8 +107,8 @@ public class OrmEclipseLinkOneToManyRelationshipReference // **************** join table ********************************************* @Override - public void setJoinTableJoiningStrategy() { - super.setJoinTableJoiningStrategy(); + protected void setJoinTableJoiningStrategy_() { + super.setJoinTableJoiningStrategy_(); this.joinColumnJoiningStrategy.removeStrategy(); } @@ -133,10 +133,12 @@ public class OrmEclipseLinkOneToManyRelationshipReference this.joinColumnJoiningStrategy.addStrategy(); this.mappedByJoiningStrategy.removeStrategy(); this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public void unsetJoinColumnJoiningStrategy() { this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); } public boolean mayHaveDefaultJoinColumn() { diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java index dad78b3d98..7b5cfa2b5a 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java @@ -20,6 +20,7 @@ import org.eclipse.jpt.core.context.EmbeddedMapping; import org.eclipse.jpt.core.context.FetchType; import org.eclipse.jpt.core.context.IdMapping; import org.eclipse.jpt.core.context.ManyToManyMapping; +import org.eclipse.jpt.core.context.ManyToManyRelationshipReference; import org.eclipse.jpt.core.context.ManyToOneMapping; import org.eclipse.jpt.core.context.OneToManyMapping; import org.eclipse.jpt.core.context.OneToOneMapping; @@ -676,8 +677,79 @@ public class JavaManyToManyMappingTests extends ContextModelTestCase assertNull(manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); assertNull(manyToMany.getMappedBy()); } - - + + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToManyMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + ManyToManyAnnotation annotation = (ManyToManyAnnotation) resourceAttribute.getAnnotation(JPA.MANY_TO_MANY); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + ManyToManyMapping mapping = (ManyToManyMapping) contextAttribute.getMapping(); + ManyToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinTableJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToManyMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + ManyToManyAnnotation annotation = (ManyToManyAnnotation) resourceAttribute.getAnnotation(JPA.MANY_TO_MANY); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + ManyToManyMapping mapping = (ManyToManyMapping) contextAttribute.getMapping(); + ManyToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.JOIN_TABLE); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + public void testCandidateMappedByAttributeNames() throws Exception { createTestEntityWithValidManyToManyMapping(); createTestTargetEntityAddress(); diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java index 61a90b25ef..dfcac10aa7 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java @@ -21,6 +21,7 @@ import org.eclipse.jpt.core.context.JoinColumn; import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; import org.eclipse.jpt.core.context.ManyToManyMapping; import org.eclipse.jpt.core.context.ManyToOneMapping; +import org.eclipse.jpt.core.context.ManyToOneRelationshipReference; import org.eclipse.jpt.core.context.OneToManyMapping; import org.eclipse.jpt.core.context.OneToOneMapping; import org.eclipse.jpt.core.context.PersistentAttribute; @@ -812,6 +813,46 @@ public class JavaManyToOneMappingTests extends ContextModelTestCase assertNull(joinColumns.getDefaultJoinColumn()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToOneMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + ManyToOneMapping mapping = (ManyToOneMapping) contextAttribute.getMapping(); + ManyToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + + relationshipReference.setJoinColumnJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToOneMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + ManyToOneMapping mapping = (ManyToOneMapping) contextAttribute.getMapping(); + ManyToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + } + public void testDefaultTargetEntity() throws Exception { createTestEntityWithValidManyToOneMapping(); createTestTargetEntityAddress(); diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java index 597426ac6d..9fb4db30ab 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java @@ -22,6 +22,7 @@ import org.eclipse.jpt.core.context.IdMapping; import org.eclipse.jpt.core.context.ManyToManyMapping; import org.eclipse.jpt.core.context.ManyToOneMapping; import org.eclipse.jpt.core.context.OneToManyMapping; +import org.eclipse.jpt.core.context.OneToManyRelationshipReference; import org.eclipse.jpt.core.context.OneToOneMapping; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.TransientMapping; @@ -718,7 +719,79 @@ public class JavaOneToManyMappingTests extends ContextModelTestCase AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); assertNull(stateFooMapping); } - + + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + OneToManyMapping mapping = (OneToManyMapping) contextAttribute.getMapping(); + OneToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinTableJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + OneToManyMapping mapping = (OneToManyMapping) contextAttribute.getMapping(); + OneToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.JOIN_TABLE); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + public void testDefaultTargetEntity() throws Exception { createTestEntityWithValidOneToManyMapping(); createTestTargetEntityAddress(); diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java index 18f0764263..d58418b2bc 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java @@ -26,6 +26,7 @@ import org.eclipse.jpt.core.context.ManyToOneMapping; import org.eclipse.jpt.core.context.MappedByJoiningStrategy; import org.eclipse.jpt.core.context.OneToManyMapping; import org.eclipse.jpt.core.context.OneToOneMapping; +import org.eclipse.jpt.core.context.OneToOneRelationshipReference; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; import org.eclipse.jpt.core.context.PrimaryKeyJoinColumnJoiningStrategy; @@ -1394,4 +1395,118 @@ public class JavaOneToOneMappingTests extends ContextModelTestCase joinColumns = strategy.primaryKeyJoinColumns(); assertFalse(joinColumns.hasNext()); } + + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToOneMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + OneToOneMapping mapping = (OneToOneMapping) contextAttribute.getMapping(); + OneToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setPrimaryKeyJoinColumnJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinColumnJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToOneMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + OneToOneMapping mapping = (OneToOneMapping) contextAttribute.getMapping(); + OneToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java index f45e0eb9b2..057238faf3 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java @@ -30,16 +30,19 @@ import org.eclipse.jpt.core.context.TransientMapping; import org.eclipse.jpt.core.context.VersionMapping; import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; +import org.eclipse.jpt.core.context.orm.OrmManyToManyRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.orm.OrmFactory; +import org.eclipse.jpt.core.resource.orm.XmlEntity; import org.eclipse.jpt.core.resource.orm.XmlManyToMany; import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; +import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @SuppressWarnings("nls") @@ -70,6 +73,28 @@ public class OrmManyToManyMappingTests extends ContextModelTestCase }); } + private void createTestEntityWithManyToManyMapping() throws Exception { + createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@ManyToMany").append(CR); + } + }); + OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + for (OrmPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { + each.makeSpecified(); + } + } + private ICompilationUnit createTestEntityWithValidManyToManyMapMapping() throws Exception { return this.createTestType(new DefaultAnnotationWriter() { @Override @@ -376,6 +401,76 @@ public class OrmManyToManyMappingTests extends ContextModelTestCase assertNull(manyToMany.getMappedBy()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmManyToManyMapping contextMapping = (OrmManyToManyMapping) contextAttribute.getMapping(); + OrmManyToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlManyToMany resourceMapping = resourceEntity.getAttributes().getManyToManys().get(0); + + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinTableJoiningStrategy(); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmManyToManyMapping contextMapping = (OrmManyToManyMapping) contextAttribute.getMapping(); + OrmManyToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlManyToMany resourceMapping = resourceEntity.getAttributes().getManyToManys().get(0); + + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setJoinTable(null); + getJpaProject().synchronizeContextModel(); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + public void testUpdateMapKey() throws Exception { OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java index abdef3938e..68b5d77580 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java @@ -19,14 +19,18 @@ import org.eclipse.jpt.core.context.FetchType; import org.eclipse.jpt.core.context.orm.OrmJoinColumn; import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; +import org.eclipse.jpt.core.context.orm.OrmManyToOneRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.core.resource.orm.OrmFactory; +import org.eclipse.jpt.core.resource.orm.XmlEntity; import org.eclipse.jpt.core.resource.orm.XmlManyToOne; import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; +import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @SuppressWarnings("nls") @@ -70,6 +74,28 @@ public class OrmManyToOneMappingTests extends ContextModelTestCase }); } + private void createTestEntityWithManyToOneMapping() throws Exception { + createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@ManyToOne").append(CR); + } + }); + OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + for (OrmPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { + each.makeSpecified(); + } + } + private void createTestTargetEntityAddress() throws Exception { SourceWriter sourceWriter = new SourceWriter() { public void appendSourceTo(StringBuilder sb) { @@ -341,6 +367,46 @@ public class OrmManyToOneMappingTests extends ContextModelTestCase assertEquals(0, manyToOneResource.getJoinColumns().size()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToOneMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmManyToOneMapping contextMapping = (OrmManyToOneMapping) contextAttribute.getMapping(); + OrmManyToOneRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); + + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + + relationshipReference.setJoinColumnJoiningStrategy(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithManyToOneMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmManyToOneMapping contextMapping = (OrmManyToOneMapping) contextAttribute.getMapping(); + OrmManyToOneRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); + + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + + resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + + resourceMapping.getJoinColumns().clear(); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + } + public void testMoveSpecifiedJoinColumn() throws Exception { OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java index d9ac09d1cd..9532d3fde0 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java @@ -31,15 +31,18 @@ import org.eclipse.jpt.core.context.VersionMapping; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; +import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.orm.OrmFactory; +import org.eclipse.jpt.core.resource.orm.XmlEntity; import org.eclipse.jpt.core.resource.orm.XmlOneToMany; import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; +import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @SuppressWarnings("nls") @@ -82,6 +85,28 @@ public class OrmOneToManyMappingTests extends ContextModelTestCase this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); } + private void createTestEntityWithOneToManyMapping() throws Exception { + createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@OneToMany").append(CR); + } + }); + OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + for (OrmPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { + each.makeSpecified(); + } + } + private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { return this.createTestType(new DefaultAnnotationWriter() { @Override @@ -350,6 +375,75 @@ public class OrmOneToManyMappingTests extends ContextModelTestCase assertNull(oneToMany.getMappedBy()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmOneToManyMapping contextMapping = (OrmOneToManyMapping) contextAttribute.getMapping(); + OrmOneToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); + + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinTableJoiningStrategy(); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmOneToManyMapping contextMapping = (OrmOneToManyMapping) contextAttribute.getMapping(); + OrmOneToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); + + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setJoinTable(null); + getJpaProject().synchronizeContextModel(); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } public void testUpdateMapKey() throws Exception { OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java index 26549bd0d2..4342d5fa50 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java @@ -33,16 +33,20 @@ import org.eclipse.jpt.core.context.VersionMapping; import org.eclipse.jpt.core.context.orm.OrmJoinColumn; import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; +import org.eclipse.jpt.core.context.orm.OrmOneToOneRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnJoiningStrategy; import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.core.resource.orm.OrmFactory; +import org.eclipse.jpt.core.resource.orm.XmlEntity; import org.eclipse.jpt.core.resource.orm.XmlOneToOne; import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; +import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @SuppressWarnings("nls") @@ -86,6 +90,28 @@ public class OrmOneToOneMappingTests extends ContextModelTestCase }); } + private void createTestEntityWithOneToOneMapping() throws Exception { + createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@OneToOne").append(CR); + } + }); + OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + for (OrmPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { + each.makeSpecified(); + } + } + private void createTestTargetEntityAddress() throws Exception { SourceWriter sourceWriter = new SourceWriter() { public void appendSourceTo(StringBuilder sb) { @@ -334,6 +360,117 @@ public class OrmOneToOneMappingTests extends ContextModelTestCase assertNull(oneToOne.getMappedBy()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToOneMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmOneToOneMapping contextMapping = (OrmOneToOneMapping) contextAttribute.getMapping(); + OrmOneToOneRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToOne resourceMapping = (XmlOneToOne) resourceEntity.getAttributes().getOneToOnes().get(0); + + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setPrimaryKeyJoinColumnJoiningStrategy(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinColumnJoiningStrategy(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToOneMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmOneToOneMapping contextMapping = (OrmOneToOneMapping) contextAttribute.getMapping(); + OrmOneToOneRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToOne resourceMapping = (XmlOneToOne) resourceEntity.getAttributes().getOneToOnes().get(0); + + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.getPrimaryKeyJoinColumns().clear(); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.getJoinColumns().clear(); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } public void testUpdateSpecifiedOptional() throws Exception { OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java index 9bb7aa0fb5..b2df9c6c51 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java @@ -10,7 +10,6 @@ package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; import java.util.Iterator; - import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.FetchType; @@ -23,6 +22,7 @@ import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyRelationshipReference; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkPrivateOwned; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; @@ -34,6 +34,23 @@ import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @SuppressWarnings("nls") public class EclipseLinkJavaOneToManyMappingTests extends EclipseLinkContextModelTestCase { + private ICompilationUnit createTestEntityWithOneToManyMapping() throws Exception { + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@OneToMany").append(CR); + } + }); + } private ICompilationUnit createTestEntityWithPrivateOwnedOneToMany() throws Exception { return this.createTestType(new DefaultAnnotationWriter() { @@ -251,6 +268,119 @@ public class EclipseLinkJavaOneToManyMappingTests extends EclipseLinkContextMode assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping mapping = (EclipseLinkOneToManyMapping) contextAttribute.getMapping(); + EclipseLinkOneToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinColumnJoiningStrategy(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinTableJoiningStrategy(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); + OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); + PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping mapping = (EclipseLinkOneToManyMapping) contextAttribute.getMapping(); + EclipseLinkOneToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); + + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.JOIN_TABLE); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNotNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + annotation.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); + getJpaProject().synchronizeContextModel(); + assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); + getJpaProject().synchronizeContextModel(); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); + assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); + assertNull(annotation.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } public void testDefaultOneToMany() throws Exception { createTestEntityWithDefaultOneToMany(); diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java index 6fa2b76306..7cc6d2e7c9 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java @@ -18,14 +18,17 @@ import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.core.resource.orm.OrmFactory; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyMapping; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyRelationshipReference; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToMany; +import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @SuppressWarnings("nls") @@ -121,6 +124,28 @@ public class EclipseLinkOrmOneToManyMappingTests this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); } + private void createTestEntityWithOneToManyMapping() throws Exception { + createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@OneToMany").append(CR); + } + }); + OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + for (OrmPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { + each.makeSpecified(); + } + } + private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { return this.createTestType(new DefaultAnnotationWriter() { @Override @@ -513,4 +538,116 @@ public class EclipseLinkOrmOneToManyMappingTests mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); assertEquals(false, mapKeyNames.hasNext()); } + + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); + OrmEclipseLinkOneToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); + + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinColumnJoiningStrategy(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setMappedByJoiningStrategy(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + relationshipReference.setJoinTableJoiningStrategy(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } + + public void testUpdatePredominantJoiningStrategy() throws Exception { + createTestEntityWithOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); + OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); + OrmEclipseLinkOneToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); + + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy("foo"); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getJoinTable()); + assertNotNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertTrue(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setMappedBy(null); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertNotNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.setJoinTable(null); + getJpaProject().synchronizeContextModel(); + assertFalse(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); + assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + + resourceMapping.getJoinColumns().clear(); + getJpaProject().synchronizeContextModel(); + assertTrue(resourceMapping.getJoinColumns().isEmpty()); + assertNull(resourceMapping.getJoinTable()); + assertNull(resourceMapping.getMappedBy()); + assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); + assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); + assertFalse(relationshipReference.usesMappedByJoiningStrategy()); + } } |