diff options
author | kmoore | 2010-02-23 19:19:25 +0000 |
---|---|---|
committer | kmoore | 2010-02-23 19:19:25 +0000 |
commit | bdd5d6dd7fdb322c35aed984a32affae13376009 (patch) | |
tree | c0b87c9d0c54cd32df21929a8dfb7da6779b37db /jpa | |
parent | 5346e8d80e47e0bc8663eba50fc32d21d842bb07 (diff) | |
download | webtools.dali-bdd5d6dd7fdb322c35aed984a32affae13376009.tar.gz webtools.dali-bdd5d6dd7fdb322c35aed984a32affae13376009.tar.xz webtools.dali-bdd5d6dd7fdb322c35aed984a32affae13376009.zip |
301437 - added joinColumns support to generic 2.0 1-1 mappings
Diffstat (limited to 'jpa')
42 files changed, 1576 insertions, 58 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java index e3b92a817b..bf26e69298 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java @@ -55,7 +55,6 @@ import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; import org.eclipse.jpt.core.context.java.JavaNamedQuery; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaOrderable; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; @@ -390,7 +389,7 @@ public abstract class AbstractJpaFactory return new GenericJavaNullConverter(parent); } - public JavaOrderable buildJavaOrderable(JavaAttributeMapping parent, Orderable2_0.Owner owner) { + public JavaOrderable2_0 buildJavaOrderable(JavaAttributeMapping parent, Orderable2_0.Owner owner) { return new GenericJavaOrderable(parent, owner); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java index 0bd2913d66..cfab97217f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java @@ -26,7 +26,6 @@ import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.java.JavaBaseColumn; import org.eclipse.jpt.core.context.java.JavaColumn; import org.eclipse.jpt.core.context.java.JavaMultiRelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaOrderable; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.internal.context.MappingTools; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; @@ -34,6 +33,7 @@ import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.jpa2.JpaFactory2_0; import org.eclipse.jpt.core.jpa2.context.CollectionMapping2_0; import org.eclipse.jpt.core.jpa2.context.Orderable2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaOrderable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; @@ -57,7 +57,7 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi extends AbstractJavaRelationshipMapping<T> implements JavaMultiRelationshipMapping, CollectionMapping2_0 { - protected final JavaOrderable orderable; + protected final JavaOrderable2_0 orderable; protected Embeddable resolvedTargetEmbeddable; @@ -79,7 +79,7 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi protected AbstractJavaMultiRelationshipMapping(JavaPersistentAttribute parent) { super(parent); - this.orderable = getJpaFactory().buildJavaOrderable(this, buildOrderableOwner()); + this.orderable = ((JpaFactory2_0) this.getJpaFactory()).buildJavaOrderable(this, buildOrderableOwner()); this.mapKeyColumn = ((JpaFactory2_0) this.getJpaFactory()).buildJavaMapKeyColumn(parent, this.buildMapKeyColumnOwner()); } @@ -146,7 +146,7 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi // ********** ordering ********** - public JavaOrderable getOrderable() { + public JavaOrderable2_0 getOrderable() { return this.orderable; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java index b936a215f1..00b7478dca 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java @@ -16,6 +16,7 @@ import org.eclipse.jpt.core.context.java.JavaOneToManyRelationshipReference; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.jpa2.JpaFactory2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyRelationshipReference2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; import org.eclipse.jpt.core.resource.java.JPA; @@ -71,8 +72,8 @@ public abstract class AbstractJavaOneToManyMapping<T extends OneToManyAnnotation } @Override - public JavaOneToManyRelationshipReference getRelationshipReference() { - return (JavaOneToManyRelationshipReference) super.getRelationshipReference(); + public JavaOneToManyRelationshipReference2_0 getRelationshipReference() { + return (JavaOneToManyRelationshipReference2_0) super.getRelationshipReference(); } // ********** JavaOrphanRemovalHolder2_0 implementation ********** 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 32abc18455..5ae75dca17 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 @@ -19,7 +19,7 @@ import org.eclipse.jpt.core.context.RelationshipMapping; import org.eclipse.jpt.core.context.java.JavaJoinTableJoiningStrategy; import org.eclipse.jpt.core.context.java.JavaMappedByJoiningStrategy; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyRelationshipReference; +import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyRelationshipReference2_0; import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; import org.eclipse.jpt.utility.Filter; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -27,7 +27,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractJavaOneToManyRelationshipReference extends AbstractJavaRelationshipReference - implements JavaOneToManyRelationshipReference + implements JavaOneToManyRelationshipReference2_0 { protected final JavaMappedByJoiningStrategy mappedByJoiningStrategy; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java index f2b80d2327..7006cdcbf4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java @@ -30,6 +30,7 @@ import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; import org.eclipse.jpt.core.resource.java.NestableAnnotation; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.db.Table; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -51,15 +52,18 @@ public class GenericJavaJoinColumnJoiningStrategy } public String getTableName() { - return getTypeMapping().getPrimaryTableName(); + TypeMapping typeMapping = getTypeMapping(); + return typeMapping == null ? null : typeMapping.getPrimaryTableName(); } public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); + TypeMapping typeMapping = getTypeMapping(); + return typeMapping == null ? null : typeMapping.getDbTable(tableName); } public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); + TypeMapping typeMapping = getTypeMapping(); + return typeMapping == null ? false : typeMapping.tableNameIsInvalid(tableName); } public String getColumnTableNotValidDescription() { @@ -164,22 +168,28 @@ public class GenericJavaJoinColumnJoiningStrategy } public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); + TypeMapping typeMapping = getTypeMapping(); + return typeMapping == null ? false : typeMapping.tableNameIsInvalid(tableName); } /** * the join column can be on a secondary table */ public Iterator<String> candidateTableNames() { - return getTypeMapping().associatedTableNamesIncludingInherited(); + TypeMapping typeMapping = getTypeMapping(); + if (typeMapping == null) { + return EmptyIterator.instance(); + } + return typeMapping.associatedTableNamesIncludingInherited(); } public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); + return GenericJavaJoinColumnJoiningStrategy.this.getTypeMapping(); } public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); + TypeMapping typeMapping = getTypeMapping(); + return typeMapping == null ? null : typeMapping.getDbTable(tableName); } public Table getReferencedColumnDbTable() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java index 6db06bcb26..681843a614 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java @@ -11,9 +11,9 @@ package org.eclipse.jpt.core.internal.context.orm; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationshipReference2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; @@ -62,8 +62,8 @@ public abstract class AbstractOrmOneToManyMapping<T extends XmlOneToMany> } @Override - public OrmOneToManyRelationshipReference getRelationshipReference() { - return (OrmOneToManyRelationshipReference) super.getRelationshipReference(); + public OrmOneToManyRelationshipReference2_0 getRelationshipReference() { + return (OrmOneToManyRelationshipReference2_0) super.getRelationshipReference(); } // ********** OrmOrphanRemovalHolder2_0 implementation ********** 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 64f46b2175..ebe6d24086 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 @@ -19,16 +19,16 @@ import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; 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.OrmOwnableRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; +import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationshipReference2_0; import org.eclipse.jpt.core.resource.orm.XmlOneToMany; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractOrmOneToManyRelationshipReference extends AbstractOrmRelationshipReference - implements OrmOneToManyRelationshipReference + implements OrmOneToManyRelationshipReference2_0 { protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; 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 57f007fbad..47cccff961 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 @@ -11,17 +11,47 @@ package org.eclipse.jpt.core.internal.jpa1.context.java; import org.eclipse.jpt.core.context.JoiningStrategy; +import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyRelationshipReference; public class GenericJavaOneToManyRelationshipReference extends AbstractJavaOneToManyRelationshipReference { + protected final JavaJoinColumnJoiningStrategy joinColumnJoiningStrategy; + public GenericJavaOneToManyRelationshipReference(JavaOneToManyMapping parent) { super(parent); + this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); } - - + + protected JavaJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { + return new NullJavaJoinColumnJoiningStrategy(this); + } + + // **************** join columns ******************************************* + + public JavaJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { + return this.joinColumnJoiningStrategy; + } + + public boolean usesJoinColumnJoiningStrategy() { + return false; + } + + public void setJoinColumnJoiningStrategy() { + throw new UnsupportedOperationException("join column joining strategy not supported on a 1.0 1-m mapping"); //$NON-NLS-1$ + } + + public void unsetJoinColumnJoiningStrategy() { + throw new UnsupportedOperationException("join column joining strategy not supported on a 1.0 1-m mapping"); //$NON-NLS-1$ + } + + public boolean mayHaveDefaultJoinColumn() { + return false; + } + + @Override protected JoiningStrategy calculatePredominantJoiningStrategy() { if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/NullJavaJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/NullJavaJoinColumnJoiningStrategy.java new file mode 100644 index 0000000000..21085ad3eb --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/NullJavaJoinColumnJoiningStrategy.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa1.context.java; + +import java.util.ListIterator; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.context.JoinColumn; +import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; +import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; +import org.eclipse.jpt.core.context.RelationshipMapping; +import org.eclipse.jpt.core.context.TypeMapping; +import org.eclipse.jpt.core.context.java.JavaJoinColumn; +import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.db.Table; + +public class NullJavaJoinColumnJoiningStrategy + extends AbstractJavaJpaContextNode + implements JavaJoinColumnJoiningStrategy +{ + + protected NullJavaJoinColumnJoiningStrategy(JoinColumnEnabledRelationshipReference parent) { + super(parent); + } + + public void initializeFrom(JoinColumnJoiningStrategy oldStrategy) { + throw new UnsupportedOperationException(); + } + + @Override + public JoinColumnEnabledRelationshipReference getParent() { + return (JoinColumnEnabledRelationshipReference) super.getParent(); + } + + public JoinColumnEnabledRelationshipReference getRelationshipReference() { + return this.getParent(); + } + + public RelationshipMapping getRelationshipMapping() { + return this.getRelationshipReference().getRelationshipMapping(); + } + + public void addStrategy() { + throw new UnsupportedOperationException(); + } + + public void removeStrategy() { + throw new UnsupportedOperationException(); + } + + + // **************** join columns ******************************************* + + public ListIterator<JavaJoinColumn> joinColumns() { + throw new UnsupportedOperationException(); + + } + + public int joinColumnsSize() { + throw new UnsupportedOperationException(); + } + + + // **************** default join column ************************************ + + public JavaJoinColumn getDefaultJoinColumn() { + throw new UnsupportedOperationException(); + } + + // **************** specified join columns ********************************* + + public ListIterator<JavaJoinColumn> specifiedJoinColumns() { + throw new UnsupportedOperationException(); + } + + public int specifiedJoinColumnsSize() { + throw new UnsupportedOperationException(); + } + + public boolean hasSpecifiedJoinColumns() { + throw new UnsupportedOperationException(); + } + + public JavaJoinColumn addSpecifiedJoinColumn(int index) { + throw new UnsupportedOperationException(); + } + + public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { + throw new UnsupportedOperationException(); + } + + public void removeSpecifiedJoinColumn(int index) { + throw new UnsupportedOperationException(); + } + + public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { + throw new UnsupportedOperationException(); + } + + + // **************** resource => context ************************************ + + public void initialize() { + //no-op + } + + + public void update() { + //no-op + } + + public TextRange getValidationTextRange(CompilationUnit astRoot) { + throw new UnsupportedOperationException(); + } + + public String getColumnTableNotValidDescription() { + throw new UnsupportedOperationException(); + } + + public Table getDbTable(String tableName) { + throw new UnsupportedOperationException(); + } + + public String getTableName() { + return null; + } + + public boolean isOverridableAssociation() { + return false; + } + + public boolean tableNameIsInvalid(String tableName) { + throw new UnsupportedOperationException(); + } + + public TypeMapping getTypeMapping() { + return getRelationshipMapping().getTypeMapping(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java index acdc8bd152..f430455a0d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jpt.core.internal.jpa1.context.orm; +import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToManyRelationshipReference; @@ -18,12 +19,25 @@ import org.eclipse.jpt.core.resource.orm.XmlOneToMany; public class GenericOrmOneToManyRelationshipReference extends AbstractOrmOneToManyRelationshipReference { + protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; + public GenericOrmOneToManyRelationshipReference( OrmOneToManyMapping parent, XmlOneToMany resource) { super(parent, resource); } + @Override + protected void initializeJoiningStrategies() { + this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); + super.initializeJoiningStrategies(); + } + + + protected OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { + return new NullOrmJoinColumnJoiningStrategy(this); + } + @Override protected OrmJoiningStrategy calculatePredominantJoiningStrategy() { @@ -32,4 +46,28 @@ public class GenericOrmOneToManyRelationshipReference } return this.joinTableJoiningStrategy; } + + + // **************** join columns ******************************************* + + public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { + return this.joinColumnJoiningStrategy; + } + + public boolean usesJoinColumnJoiningStrategy() { + return false; + } + + public void setJoinColumnJoiningStrategy() { + throw new UnsupportedOperationException("join column joining strategy not supported on a 1.0 1-m mapping"); //$NON-NLS-1$ + } + + public void unsetJoinColumnJoiningStrategy() { + throw new UnsupportedOperationException("join column joining strategy not supported on a 1.0 1-m mapping"); //$NON-NLS-1$ + } + + public boolean mayHaveDefaultJoinColumn() { + return false; + } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/NullOrmJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/NullOrmJoinColumnJoiningStrategy.java new file mode 100644 index 0000000000..b1dd4aa3f9 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/NullOrmJoinColumnJoiningStrategy.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa1.context.orm; + +import java.util.ListIterator; +import org.eclipse.jpt.core.context.JoinColumn; +import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; +import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; +import org.eclipse.jpt.core.context.RelationshipMapping; +import org.eclipse.jpt.core.context.TypeMapping; +import org.eclipse.jpt.core.context.orm.OrmJoinColumn; +import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; +import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.db.Table; + +public class NullOrmJoinColumnJoiningStrategy + extends AbstractOrmXmlContextNode + implements OrmJoinColumnJoiningStrategy +{ + + protected NullOrmJoinColumnJoiningStrategy(JoinColumnEnabledRelationshipReference parent) { + super(parent); + } + + public void initializeFrom(JoinColumnJoiningStrategy oldStrategy) { + throw new UnsupportedOperationException(); + } + + @Override + public JoinColumnEnabledRelationshipReference getParent() { + return (JoinColumnEnabledRelationshipReference) super.getParent(); + } + + public JoinColumnEnabledRelationshipReference getRelationshipReference() { + return this.getParent(); + } + + public RelationshipMapping getRelationshipMapping() { + return this.getRelationshipReference().getRelationshipMapping(); + } + + public void addStrategy() { + throw new UnsupportedOperationException(); + } + + public void removeStrategy() { + throw new UnsupportedOperationException(); + } + + + // **************** join columns ******************************************* + + public ListIterator<OrmJoinColumn> joinColumns() { + throw new UnsupportedOperationException(); + } + + public int joinColumnsSize() { + throw new UnsupportedOperationException(); + } + + + // **************** default join column ************************************ + + public OrmJoinColumn getDefaultJoinColumn() { + throw new UnsupportedOperationException(); + } + + // **************** specified join columns ********************************* + + public ListIterator<OrmJoinColumn> specifiedJoinColumns() { + throw new UnsupportedOperationException(); + } + + public int specifiedJoinColumnsSize() { + throw new UnsupportedOperationException(); + } + + public boolean hasSpecifiedJoinColumns() { + throw new UnsupportedOperationException(); + } + + public OrmJoinColumn addSpecifiedJoinColumn(int index) { + throw new UnsupportedOperationException(); + } + + public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { + throw new UnsupportedOperationException(); + } + + public void removeSpecifiedJoinColumn(int index) { + throw new UnsupportedOperationException(); + } + + public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { + throw new UnsupportedOperationException(); + } + + // **************** resource => context ************************************ + + public void update() { + //no-op + } + + public TextRange getValidationTextRange() { + throw new UnsupportedOperationException(); + } + + public String getColumnTableNotValidDescription() { + throw new UnsupportedOperationException(); + } + + public Table getDbTable(String tableName) { + throw new UnsupportedOperationException(); + } + + public String getTableName() { + return null; + } + + public boolean isOverridableAssociation() { + return false; + } + + public boolean tableNameIsInvalid(String tableName) { + throw new UnsupportedOperationException(); + } + + public TypeMapping getTypeMapping() { + return getRelationshipMapping().getTypeMapping(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java index 08839c6cff..09b68eb834 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java @@ -21,6 +21,7 @@ import org.eclipse.jpt.core.context.java.JavaEmbeddable; import org.eclipse.jpt.core.context.java.JavaJpaContextNode; import org.eclipse.jpt.core.context.java.JavaNamedColumn; import org.eclipse.jpt.core.context.java.JavaNamedQuery; +import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; @@ -35,6 +36,7 @@ import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaDerivedIdentit import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaElementCollectionMapping2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaEmbeddable2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaNamedQuery2_0; +import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaOneToManyMapping2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaOrderColumn2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaOrphanRemoval2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaPersistentAttribute2_0; @@ -165,4 +167,9 @@ public class GenericJpaFactory2_0 public JavaColumn buildJavaMapKeyColumn(JavaJpaContextNode parent, Owner owner) { return new GenericJavaColumn(parent, owner); } + + @Override + public JavaOneToManyMapping buildJavaOneToManyMapping(JavaPersistentAttribute parent) { + return new GenericJavaOneToManyMapping2_0(parent); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0.java new file mode 100644 index 0000000000..1eb4ca5812 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.context.java.JavaRelationshipReference; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyMapping; +import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; + + +public class GenericJavaOneToManyMapping2_0 + extends AbstractJavaOneToManyMapping<OneToManyAnnotation> +{ + + public GenericJavaOneToManyMapping2_0(JavaPersistentAttribute parent) { + super(parent); + } + + @Override + protected JavaRelationshipReference buildRelationshipReference() { + return new GenericJavaOneToManyRelationshipReference2_0(this); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToManyRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToManyRelationshipReference2_0.java new file mode 100644 index 0000000000..73468cd669 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToManyRelationshipReference2_0.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa2.context.java; + +import java.util.Iterator; +import java.util.List; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.context.JoiningStrategy; +import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; +import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyRelationshipReference; +import org.eclipse.jpt.core.internal.context.java.GenericJavaJoinColumnJoiningStrategy; +import org.eclipse.jpt.utility.Filter; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +public class GenericJavaOneToManyRelationshipReference2_0 + extends AbstractJavaOneToManyRelationshipReference +{ + protected final JavaJoinColumnJoiningStrategy joinColumnJoiningStrategy; + + public GenericJavaOneToManyRelationshipReference2_0(JavaOneToManyMapping parent) { + super(parent); + this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); + } + + protected JavaJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { + return new GenericJavaJoinColumnJoiningStrategy(this); + } + + @Override + protected void initializeJoiningStrategies() { + this.joinColumnJoiningStrategy.initialize(); + super.initializeJoiningStrategies(); + } + + @Override + protected void updateJoiningStrategies() { + this.joinColumnJoiningStrategy.update(); + super.updateJoiningStrategies(); + } + + @Override + protected JoiningStrategy calculatePredominantJoiningStrategy() { + if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { + return this.mappedByJoiningStrategy; + } + else if (this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns()) { + return this.joinColumnJoiningStrategy; + } + else { + return this.joinTableJoiningStrategy; + } + } + + @Override + public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { + Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); + if (result == null) { + result = this.joinColumnJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); + } + return result; + } + + // **************** mapped by ********************************************** + + @Override + protected void setMappedByJoiningStrategy_() { + super.setMappedByJoiningStrategy_(); + this.joinColumnJoiningStrategy.removeStrategy(); + } + + // **************** join table ********************************************* + + @Override + protected void setJoinTableJoiningStrategy_() { + super.setJoinTableJoiningStrategy_(); + this.joinColumnJoiningStrategy.removeStrategy(); + } + + @Override + public boolean mayHaveDefaultJoinTable() { + return super.mayHaveDefaultJoinTable() + && ! this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns(); + } + + // **************** join columns ******************************************* + + public JavaJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { + return this.joinColumnJoiningStrategy; + } + + public boolean usesJoinColumnJoiningStrategy() { + return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; + } + + public void setJoinColumnJoiningStrategy() { + this.joinColumnJoiningStrategy.addStrategy(); + this.mappedByJoiningStrategy.removeStrategy(); + this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); + } + + public void unsetJoinColumnJoiningStrategy() { + this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); + } + + public boolean mayHaveDefaultJoinColumn() { + return this.mappedByJoiningStrategy.getMappedByAttribute() == null + && this.joinTableJoiningStrategy.getJoinTable() == null; + } + + // **************** Validation ********************************************* + + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + this.joinColumnJoiningStrategy.validate(messages, reporter, astRoot); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0.java new file mode 100644 index 0000000000..bbac26096d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006, 2009 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0, which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa2.context.orm; + +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; +import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToManyMapping; +import org.eclipse.jpt.core.resource.orm.XmlOneToMany; + + +public class GenericOrmOneToManyMapping2_0 extends AbstractOrmOneToManyMapping<XmlOneToMany> +{ + + public GenericOrmOneToManyMapping2_0(OrmPersistentAttribute parent, XmlOneToMany resourceMapping) { + super(parent, resourceMapping); + } + + @Override + protected OrmRelationshipReference buildRelationshipReference() { + return new GenericOrmOneToManyRelationshipReference2_0(this, this.resourceAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmOneToManyRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmOneToManyRelationshipReference2_0.java new file mode 100644 index 0000000000..e5c9dcfbec --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmOneToManyRelationshipReference2_0.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa2.context.orm; + +import java.util.List; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.AttributeMapping; +import org.eclipse.jpt.core.context.JoinColumn; +import org.eclipse.jpt.core.context.orm.OrmJoinColumn; +import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; +import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; +import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; +import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; +import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; +import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToManyRelationshipReference; +import org.eclipse.jpt.core.internal.context.orm.GenericOrmJoinColumnJoiningStrategy; +import org.eclipse.jpt.core.resource.orm.XmlOneToMany; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +public class GenericOrmOneToManyRelationshipReference2_0 + extends AbstractOrmOneToManyRelationshipReference +{ + protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; + + public GenericOrmOneToManyRelationshipReference2_0( + OrmOneToManyMapping parent, XmlOneToMany resource) { + + super(parent, resource); + } + + @Override + protected void initializeJoiningStrategies() { + this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); + super.initializeJoiningStrategies(); + } + + + protected OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { + return new GenericOrmJoinColumnJoiningStrategy(this, getResourceMapping()); + } + + @Override + public void initializeOn(OrmRelationshipReference newRelationshipReference) { + super.initializeOn(newRelationshipReference); + newRelationshipReference.initializeFromJoinColumnEnabledRelationshipReference(this); + } + + @Override + public void initializeFromJoinColumnEnabledRelationshipReference( + OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { + super.initializeFromJoinColumnEnabledRelationshipReference(oldRelationshipReference); + int index = 0; + for (JoinColumn joinColumn : + CollectionTools.iterable( + oldRelationshipReference.getJoinColumnJoiningStrategy().specifiedJoinColumns())) { + OrmJoinColumn newJoinColumn = getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(index++); + newJoinColumn.initializeFrom(joinColumn); + } + } + + @Override + public XmlOneToMany getResourceMapping() { + return super.getResourceMapping(); + } + + @Override + protected OrmJoiningStrategy calculatePredominantJoiningStrategy() { + if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { + return this.mappedByJoiningStrategy; + } + else if (this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns()) { + return this.joinColumnJoiningStrategy; + } + else { + return this.joinTableJoiningStrategy; + } + } + + + // **************** mapped by ********************************************** + + @Override + protected void setMappedByJoiningStrategy_() { + super.setMappedByJoiningStrategy_(); + this.joinColumnJoiningStrategy.removeStrategy(); + } + + @Override + public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { + return super.mayBeMappedBy(mappedByMapping) || + mappedByMapping.getKey() == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; + } + + + // **************** join table ********************************************* + + @Override + protected void setJoinTableJoiningStrategy_() { + super.setJoinTableJoiningStrategy_(); + this.joinColumnJoiningStrategy.removeStrategy(); + } + + @Override + public boolean mayHaveDefaultJoinTable() { + return super.mayHaveDefaultJoinTable() + && ! this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns(); + } + + + // **************** join columns ******************************************* + + public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { + return this.joinColumnJoiningStrategy; + } + + public boolean usesJoinColumnJoiningStrategy() { + return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; + } + + public void setJoinColumnJoiningStrategy() { + this.joinColumnJoiningStrategy.addStrategy(); + this.mappedByJoiningStrategy.removeStrategy(); + this.joinTableJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); + } + + public void unsetJoinColumnJoiningStrategy() { + this.joinColumnJoiningStrategy.removeStrategy(); + setPredominantJoiningStrategy(); + } + + public boolean mayHaveDefaultJoinColumn() { + return false; + } + + + // **************** resource => context ************************************ + + @Override + protected void updateJoiningStrategies() { + this.joinColumnJoiningStrategy.update(); + super.updateJoiningStrategies(); + } + + + // **************** Validation ********************************************* + + @Override + public void validate(List<IMessage> messages, IReporter reporter) { + super.validate(messages, reporter); + this.joinColumnJoiningStrategy.validate(messages, reporter); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java index 303d79d717..df052926b6 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java @@ -27,6 +27,7 @@ import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; import org.eclipse.jpt.core.context.orm.OrmEmbeddable; import org.eclipse.jpt.core.context.orm.OrmNamedQuery; +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.context.orm.OrmSequenceGenerator; @@ -134,6 +135,11 @@ public class GenericOrmXml2_0ContextNodeFactory extends AbstractOrmXmlContextNod return new GenericOrmCollectionTable2_0(parent, resource); } + @Override + public OrmOneToManyMapping buildOrmOneToManyMapping(OrmPersistentAttribute parent, XmlOneToMany resourceMapping) { + return new GenericOrmOneToManyMapping2_0(parent, resourceMapping); + } + // ********** ORM Virtual Resource Model ********** @Override diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java index 022d219330..ca2a94e6ba 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java @@ -10,8 +10,11 @@ package org.eclipse.jpt.core.internal.jpa2.context.orm; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.util.EObjectContainmentEList; +import org.eclipse.jpt.core.context.JoinColumn; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.core.internal.context.orm.VirtualXmlColumn; +import org.eclipse.jpt.core.internal.context.orm.VirtualXmlJoinColumn; import org.eclipse.jpt.core.internal.context.orm.VirtualXmlOneToMany; import org.eclipse.jpt.core.internal.context.orm.VirtualXmlOrderColumn; import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; @@ -23,6 +26,7 @@ import org.eclipse.jpt.core.resource.orm.AccessType; import org.eclipse.jpt.core.resource.orm.CascadeType; import org.eclipse.jpt.core.resource.orm.FetchType; import org.eclipse.jpt.core.resource.orm.MapKey; +import org.eclipse.jpt.core.resource.orm.OrmPackage; import org.eclipse.jpt.core.resource.orm.XmlColumn; import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; import org.eclipse.jpt.core.resource.orm.XmlJoinTable; @@ -30,6 +34,7 @@ import org.eclipse.jpt.core.resource.orm.XmlMapKeyClass; import org.eclipse.jpt.core.resource.orm.XmlOneToMany; import org.eclipse.jpt.core.resource.orm.XmlOrderColumn; import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.utility.internal.CollectionTools; /** * VirtualBasic is an implementation of Basic used when there is @@ -224,7 +229,18 @@ public class VirtualXmlOneToMany2_0 extends XmlOneToMany @Override public EList<XmlJoinColumn> getJoinColumns() { - return this.virtualXmlOneToMany.getJoinColumns(); + EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_ONE_TO_MANY__JOIN_COLUMNS); + if (isOrmMetadataComplete()) { + return joinColumns; + } + for (JoinColumn joinColumn : + CollectionTools.iterable( + this.javaAttributeMapping.getRelationshipReference(). + getJoinColumnJoiningStrategy().specifiedJoinColumns())) { + XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); + joinColumns.add(xmlJoinColumn); + } + return joinColumns; } @Override diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/JpaFactory2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/JpaFactory2_0.java index 7275c0d495..0722b75553 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/JpaFactory2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/JpaFactory2_0.java @@ -12,12 +12,14 @@ package org.eclipse.jpt.core.jpa2; import org.eclipse.jpt.core.JpaDataSource; import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaBaseColumn; import org.eclipse.jpt.core.context.java.JavaColumn; import org.eclipse.jpt.core.context.java.JavaJpaContextNode; import org.eclipse.jpt.core.context.java.JavaNamedColumn; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.jpa2.context.PersistentType2_0; +import org.eclipse.jpt.core.jpa2.context.Orderable2_0.Owner; import org.eclipse.jpt.core.jpa2.context.java.JavaCacheable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaCacheableHolder2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaCollectionTable2_0; @@ -76,4 +78,6 @@ public interface JpaFactory2_0 JavaCollectionTable2_0 buildJavaCollectionTable(JavaElementCollectionMapping2_0 parent); JavaColumn buildJavaMapKeyColumn(JavaJpaContextNode parent, JavaBaseColumn.Owner owner); + + JavaOrderable2_0 buildJavaOrderable(JavaAttributeMapping parent, Owner owner); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyMapping2_0.java index 479d517012..05721e8760 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyMapping2_0.java @@ -20,4 +20,7 @@ import org.eclipse.jpt.core.context.OneToManyMapping; */ public interface OneToManyMapping2_0 extends OneToManyMapping, CollectionMapping2_0 -{} +{ + OneToManyRelationshipReference2_0 getRelationshipReference(); + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyRelationshipReference2_0.java new file mode 100644 index 0000000000..d927ec36fc --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToManyRelationshipReference2_0.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.jpa2.context; + +import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; +import org.eclipse.jpt.core.context.OneToManyRelationshipReference; + + +/** + * Represents the {@link RelationshipReference} of a {@link OneToManyMapping} + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface OneToManyRelationshipReference2_0 + extends OneToManyRelationshipReference, + JoinColumnEnabledRelationshipReference +{ + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaCollectionMapping2_0.java new file mode 100644 index 0000000000..a2773547fd --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaCollectionMapping2_0.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.jpa2.context.java; + +import org.eclipse.jpt.core.jpa2.context.CollectionMapping2_0; + +/** + * 1:m, m:m, element collection are all collection mappings. + * <p> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface JavaCollectionMapping2_0 + extends CollectionMapping2_0 +{ + + JavaOrderable2_0 getOrderable(); + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToManyMapping2_0.java index 0bfb2cabb2..1c54e0ab96 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToManyMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToManyMapping2_0.java @@ -23,5 +23,8 @@ import org.eclipse.jpt.core.jpa2.context.ManyToManyMapping2_0; * @since 2.3 */ public interface JavaManyToManyMapping2_0 - extends JavaManyToManyMapping, ManyToManyMapping2_0 -{}
\ No newline at end of file + extends + JavaManyToManyMapping, + ManyToManyMapping2_0 +{ +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyMapping2_0.java index 3cea02a805..9406838030 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyMapping2_0.java @@ -24,4 +24,8 @@ import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; */ public interface JavaOneToManyMapping2_0 extends JavaOneToManyMapping, OneToManyMapping2_0 -{}
\ No newline at end of file +{ + JavaOneToManyRelationshipReference2_0 getRelationshipReference(); + + public JavaOrderable2_0 getOrderable(); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyRelationshipReference2_0.java new file mode 100644 index 0000000000..734183b9a1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToManyRelationshipReference2_0.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.jpa2.context.java; + +import org.eclipse.jpt.core.context.RelationshipReference; +import org.eclipse.jpt.core.context.java.JavaJoinColumnEnabledRelationshipReference; +import org.eclipse.jpt.core.context.java.JavaOneToManyRelationshipReference; +import org.eclipse.jpt.core.jpa2.context.OneToManyRelationshipReference2_0; + +/** + * Represents the {@link RelationshipReference} of a {@link JavaOneToManyMapping} + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface JavaOneToManyRelationshipReference2_0 + extends + JavaOneToManyRelationshipReference, + JavaJoinColumnEnabledRelationshipReference, + OneToManyRelationshipReference2_0 +{ + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmManyToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmManyToManyMapping2_0.java index 2cc2068121..4182a1e43e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmManyToManyMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmManyToManyMapping2_0.java @@ -23,5 +23,7 @@ import org.eclipse.jpt.core.jpa2.context.ManyToManyMapping2_0; * @since 2.3 */ public interface OrmManyToManyMapping2_0 - extends OrmManyToManyMapping, ManyToManyMapping2_0 + extends + OrmManyToManyMapping, + ManyToManyMapping2_0 {} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyMapping2_0.java index d76f8d14e1..08d5f95799 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyMapping2_0.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.jpa2.context.orm; import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; +import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationshipReference; import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; /** @@ -24,4 +25,6 @@ import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; */ public interface OrmOneToManyMapping2_0 extends OrmOneToManyMapping, OneToManyMapping2_0 -{} +{ + OrmOneToManyRelationshipReference2_0 getRelationshipReference(); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyRelationshipReference2_0.java new file mode 100644 index 0000000000..18dd0947ff --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/orm/OrmOneToManyRelationshipReference2_0.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.jpa2.context.orm; + +import org.eclipse.jpt.core.context.RelationshipReference; +import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; +import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationshipReference; +import org.eclipse.jpt.core.jpa2.context.OneToManyRelationshipReference2_0; + +/** + * Represents the {@link RelationshipReference} of an {@link OrmOneToManyMapping} + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface OrmOneToManyRelationshipReference2_0 + extends + OrmOneToManyRelationshipReference, + OrmJoinColumnEnabledRelationshipReference, + OneToManyRelationshipReference2_0 +{ +} 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 ec96386b86..b8e6f56457 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 @@ -16,19 +16,17 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.AttributeMapping; import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaJoinColumnEnabledRelationshipReference; import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyRelationshipReference; import org.eclipse.jpt.core.internal.context.java.GenericJavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyRelationshipReference; +import org.eclipse.jpt.eclipselink.core.v2_0.context.EclipseLinkOneToManyRelationshipReference2_0; import org.eclipse.jpt.utility.Filter; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class JavaEclipseLinkOneToManyRelationshipReference extends AbstractJavaOneToManyRelationshipReference - implements EclipseLinkOneToManyRelationshipReference, - JavaJoinColumnEnabledRelationshipReference + implements EclipseLinkOneToManyRelationshipReference2_0 { protected final JavaJoinColumnJoiningStrategy joinColumnJoiningStrategy; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyMapping.java index 53c7a09868..1f561e32ac 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkOneToManyMapping.java @@ -18,11 +18,12 @@ import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkPrivateOwned; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToMany; +import org.eclipse.jpt.eclipselink.core.v2_0.context.EclipseLinkOneToManyMapping2_0; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class OrmEclipseLinkOneToManyMapping extends AbstractOrmOneToManyMapping<XmlOneToMany> - implements EclipseLinkOneToManyMapping + implements EclipseLinkOneToManyMapping2_0 { protected OrmEclipseLinkPrivateOwned privateOwned; 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 77a202b073..5904a72cad 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 @@ -21,16 +21,15 @@ import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToManyRelationshipReference; import org.eclipse.jpt.core.internal.context.orm.GenericOrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyRelationshipReference; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToMany; +import org.eclipse.jpt.eclipselink.core.v2_0.context.EclipseLinkOneToManyRelationshipReference2_0; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class OrmEclipseLinkOneToManyRelationshipReference extends AbstractOrmOneToManyRelationshipReference - implements EclipseLinkOneToManyRelationshipReference, - OrmJoinColumnEnabledRelationshipReference + implements EclipseLinkOneToManyRelationshipReference2_0 { protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyMapping2_0.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyMapping2_0.java index dcf3ccbdd6..d5433092bb 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyMapping2_0.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. +* Copyright (c) 2009, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -24,4 +24,6 @@ import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; */ public interface EclipseLinkOneToManyMapping2_0 extends EclipseLinkOneToManyMapping, OneToManyMapping2_0 -{} +{ + EclipseLinkOneToManyRelationshipReference2_0 getRelationshipReference(); +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyRelationshipReference2_0.java new file mode 100644 index 0000000000..6204d68b13 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/context/EclipseLinkOneToManyRelationshipReference2_0.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.v2_0.context; + +import org.eclipse.jpt.core.context.RelationshipReference; +import org.eclipse.jpt.core.jpa2.context.OneToManyRelationshipReference2_0; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyRelationshipReference; + + +/** + * Represents the {@link RelationshipReference} of an + * {@link EclipseLinkOneToManyMapping} + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface EclipseLinkOneToManyRelationshipReference2_0 + extends + EclipseLinkOneToManyRelationshipReference, + OneToManyRelationshipReference2_0 +{ + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractOneToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractOneToManyMappingComposite.java index 8eaf0b5e02..0570edadf5 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractOneToManyMappingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractOneToManyMappingComposite.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.ui.internal.details; import org.eclipse.jpt.core.context.Cascade; import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToManyRelationshipReference; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.details.JpaComposite; import org.eclipse.jpt.ui.internal.widgets.Pane; @@ -78,15 +77,6 @@ public abstract class AbstractOneToManyMappingComposite<T extends OneToManyMappi super(subjectHolder, parent, widgetFactory); } - protected PropertyValueModel<OneToManyRelationshipReference> buildJoiningHolder() { - return new TransformationPropertyValueModel<T, OneToManyRelationshipReference>(getSubjectHolder()) { - @Override - protected OneToManyRelationshipReference transform_(T value) { - return value.getRelationshipReference(); - } - }; - } - protected PropertyValueModel<Cascade> buildCascadeHolder() { return new TransformationPropertyValueModel<T, Cascade>(getSubjectHolder()) { @Override diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingComposite.java index 2f1e4bf9ce..15ade02660 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingComposite.java @@ -10,7 +10,9 @@ package org.eclipse.jpt.ui.internal.details; import org.eclipse.jpt.core.context.OneToManyMapping; +import org.eclipse.jpt.core.context.OneToManyRelationshipReference; import org.eclipse.jpt.ui.WidgetFactory; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -83,4 +85,12 @@ public class OneToManyMappingComposite new OrderingComposite(this, container); } + protected PropertyValueModel<OneToManyRelationshipReference> buildJoiningHolder() { + return new TransformationPropertyValueModel<OneToManyMapping, OneToManyRelationshipReference>(getSubjectHolder()) { + @Override + protected OneToManyRelationshipReference transform_(OneToManyMapping value) { + return value.getRelationshipReference(); + } + }; + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/OneToManyJoiningStrategy2_0Pane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/OneToManyJoiningStrategy2_0Pane.java new file mode 100644 index 0000000000..a9554efb6d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/OneToManyJoiningStrategy2_0Pane.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.ui.internal.jpa2.details; + +import org.eclipse.jpt.core.context.OneToManyRelationshipReference; +import org.eclipse.jpt.core.jpa2.context.OneToManyRelationshipReference2_0; +import org.eclipse.jpt.ui.internal.details.JoinColumnJoiningStrategyPane; +import org.eclipse.jpt.ui.internal.details.JoinTableJoiningStrategyPane; +import org.eclipse.jpt.ui.internal.details.JptUiDetailsMessages; +import org.eclipse.jpt.ui.internal.details.MappedByJoiningStrategyPane; +import org.eclipse.jpt.ui.internal.widgets.Pane; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * Here is the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | - Joining Strategy ------------------------------------------------------ | + * | | | | + * | | o MappedByJoiningStrategyPane _______________________________________ | | + * | | | | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | + * | | o JoinTableStrategyPane _____________________________________________ | | + * | | | | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see {@link OneToManyMapping} + * @see {@link OneToManyRelationshipReference} + * @see {@link OneToManyMappingComposite} + * @see {@link MappedByStrategyPane} + * @see {@link JoinTableStrategyPane} + * + * @version 2.1 + * @since 2.1 + */ +public class OneToManyJoiningStrategy2_0Pane + extends Pane<OneToManyRelationshipReference2_0> +{ + public OneToManyJoiningStrategy2_0Pane( + Pane<?> parentPane, + PropertyValueModel<? extends OneToManyRelationshipReference2_0> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + + @Override + protected void initializeLayout(Composite container) { + Composite composite = addCollapsibleSection( + container, + JptUiDetailsMessages.Joining_title, + new SimplePropertyValueModel<Boolean>(Boolean.TRUE)); + + new MappedByJoiningStrategyPane(this, composite); + + JoinColumnJoiningStrategyPane. + buildJoinColumnJoiningStrategyPaneWithIncludeOverrideCheckBox(this, composite); + + new JoinTableJoiningStrategyPane(this, composite); + + addSubPane(composite, 5); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/java/JavaOneToManyMapping2_0Composite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/java/JavaOneToManyMapping2_0Composite.java index 93a4a47e82..7291072fab 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/java/JavaOneToManyMapping2_0Composite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/java/JavaOneToManyMapping2_0Composite.java @@ -12,6 +12,7 @@ package org.eclipse.jpt.ui.internal.jpa2.details.java; import org.eclipse.jpt.core.jpa2.context.OrphanRemovable2_0; import org.eclipse.jpt.core.jpa2.context.OrphanRemovalHolder2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyRelationshipReference2_0; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.internal.details.AbstractOneToManyMappingComposite; import org.eclipse.jpt.ui.internal.details.CascadeComposite; @@ -19,9 +20,11 @@ import org.eclipse.jpt.ui.internal.details.FetchTypeComposite; import org.eclipse.jpt.ui.internal.details.OneToManyJoiningStrategyPane; import org.eclipse.jpt.ui.internal.details.OrderingComposite; import org.eclipse.jpt.ui.internal.details.TargetEntityComposite; +import org.eclipse.jpt.ui.internal.jpa2.details.OneToManyJoiningStrategy2_0Pane; import org.eclipse.jpt.ui.internal.jpa2.details.Ordering2_0Composite; import org.eclipse.jpt.ui.internal.jpa2.details.OrphanRemoval2_0Composite; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -85,7 +88,7 @@ public class JavaOneToManyMapping2_0Composite<T extends JavaOneToManyMapping2_0> int groupBoxMargin = getGroupBoxMargin(); new TargetEntityComposite(this, this.addPane(container, groupBoxMargin)); - new OneToManyJoiningStrategyPane(this, this.buildJoiningHolder(), container); + new OneToManyJoiningStrategy2_0Pane(this, this.buildJoiningHolder(), container); new FetchTypeComposite(this, this.addPane(container, groupBoxMargin)); new OrphanRemoval2_0Composite(this, this.buildOrphanRemovableHolder(), this.addPane(container, groupBoxMargin)); new CascadeComposite(this, this.buildCascadeHolder(), this.addSubPane(container, 5)); @@ -100,4 +103,14 @@ public class JavaOneToManyMapping2_0Composite<T extends JavaOneToManyMapping2_0> } }; } + + protected PropertyValueModel<JavaOneToManyRelationshipReference2_0> buildJoiningHolder() { + return new TransformationPropertyValueModel<T, JavaOneToManyRelationshipReference2_0>(getSubjectHolder()) { + @Override + protected JavaOneToManyRelationshipReference2_0 transform_(T value) { + return value.getRelationshipReference(); + } + }; + } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/orm/OrmOneToManyMapping2_0Composite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/orm/OrmOneToManyMapping2_0Composite.java index 53c217072e..605775c9cc 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/orm/OrmOneToManyMapping2_0Composite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/details/orm/OrmOneToManyMapping2_0Composite.java @@ -15,6 +15,7 @@ import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; import org.eclipse.jpt.core.jpa2.context.OrphanRemovable2_0; import org.eclipse.jpt.core.jpa2.context.OrphanRemovalHolder2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationshipReference2_0; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.internal.details.AbstractOneToManyMappingComposite; import org.eclipse.jpt.ui.internal.details.AccessTypeComposite; @@ -23,9 +24,11 @@ import org.eclipse.jpt.ui.internal.details.FetchTypeComposite; import org.eclipse.jpt.ui.internal.details.OneToManyJoiningStrategyPane; import org.eclipse.jpt.ui.internal.details.OrderingComposite; import org.eclipse.jpt.ui.internal.details.TargetEntityComposite; +import org.eclipse.jpt.ui.internal.jpa2.details.OneToManyJoiningStrategy2_0Pane; import org.eclipse.jpt.ui.internal.jpa2.details.Ordering2_0Composite; import org.eclipse.jpt.ui.internal.jpa2.details.OrphanRemoval2_0Composite; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -94,7 +97,7 @@ public class OrmOneToManyMapping2_0Composite<T extends OrmOneToManyMapping2_0> int groupBoxMargin = getGroupBoxMargin(); new TargetEntityComposite(this, this.addPane(container, groupBoxMargin)); - new OneToManyJoiningStrategyPane(this, this.buildJoiningHolder(), container); + new OneToManyJoiningStrategy2_0Pane(this, this.buildJoiningHolder(), container); new AccessTypeComposite(this, this.buildAccessHolderHolder(), this.addPane(container, groupBoxMargin)); new FetchTypeComposite(this, this.addPane(container, groupBoxMargin)); new OrphanRemoval2_0Composite(this, this.buildOrphanRemovableHolder(), this.addPane(container, groupBoxMargin)); @@ -119,4 +122,14 @@ public class OrmOneToManyMapping2_0Composite<T extends OrmOneToManyMapping2_0> } }; } + + protected PropertyValueModel<OrmOneToManyRelationshipReference2_0> buildJoiningHolder() { + return new TransformationPropertyValueModel<T, OrmOneToManyRelationshipReference2_0>(getSubjectHolder()) { + @Override + protected OrmOneToManyRelationshipReference2_0 transform_(T value) { + return value.getRelationshipReference(); + } + }; + } + } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java index 55af6491f5..976e197c11 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java @@ -15,9 +15,11 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jpt.core.context.AttributeMapping; import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.core.context.OneToManyMapping; +import org.eclipse.jpt.core.context.OneToManyRelationshipReference; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.OneToManyRelationshipReference2_0; import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; import org.eclipse.jpt.core.jpa2.context.Orderable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; @@ -30,6 +32,7 @@ import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; +import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; @@ -839,4 +842,118 @@ public class GenericJavaOneToManyMapping2_0Tests assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); } + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithValidOneToManyMapping(); + 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(); + OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); + OneToManyRelationshipReference2_0 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 { + createTestEntityWithValidOneToManyMapping(); + 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(); + OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); + OneToManyRelationshipReference2_0 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()); + } + } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java index e2d4cc4176..3111b62b9d 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java @@ -27,14 +27,17 @@ import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; import org.eclipse.jpt.core.jpa2.context.Orderable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationshipReference2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; 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.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; 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") @@ -116,8 +119,8 @@ public class GenericOrmOneToManyMapping2_0Tests this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); } - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { + private void createTestEntityWithValidOneToManyMapping() throws Exception { + this.createTestType(new DefaultAnnotationWriter() { @Override public Iterator<String> imports() { return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); @@ -136,6 +139,10 @@ public class GenericOrmOneToManyMapping2_0Tests sb.append(" @Id").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 { @@ -834,4 +841,116 @@ public class GenericOrmOneToManyMapping2_0Tests assertNull(ormColumn.getSpecifiedTable()); assertEquals("ORM_TABLE_Address", ormColumn.getDefaultTable()); } + + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithValidOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); + OrmOneToManyMapping2_0 contextMapping = (OrmOneToManyMapping2_0) contextAttribute.getMapping(); + OrmOneToManyRelationshipReference2_0 relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = 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 { + createTestEntityWithValidOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); + OrmOneToManyMapping2_0 contextMapping = (OrmOneToManyMapping2_0) contextAttribute.getMapping(); + OrmOneToManyRelationshipReference2_0 relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = 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()); + } } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java index 3e6607ea26..eacde95c3a 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java @@ -18,6 +18,7 @@ import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; +import org.eclipse.jpt.core.jpa2.context.OneToManyRelationshipReference2_0; import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; import org.eclipse.jpt.core.jpa2.context.Orderable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; @@ -30,6 +31,7 @@ import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; +import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; @@ -735,8 +737,117 @@ public class EclipseLink2_0JavaOneToManyMappingTests assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); } - //TODO - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntity(); + 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(); + OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); + OneToManyRelationshipReference2_0 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 { + createTestEntity(); + 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(); + OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); + OneToManyRelationshipReference2_0 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()); } - } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java index 49714d62d3..fe5516fe8b 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java @@ -31,6 +31,10 @@ import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.orm.OrmFactory; import org.eclipse.jpt.core.resource.orm.XmlOneToMany; import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; +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.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; /** @@ -76,6 +80,32 @@ public class EclipseLink2_0OrmOneToManyMappingTests this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); } + private void createTestEntityWithValidOneToManyMapping() throws Exception { + this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append(CR); + sb.append(" @OneToMany").append(CR); + sb.append(" private java.util.Collection<Address> addresses;").append(CR); + sb.append(CR); + sb.append(" @Id").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 @@ -658,4 +688,116 @@ public class EclipseLink2_0OrmOneToManyMappingTests assertNull(ormColumn.getSpecifiedTable()); assertEquals("ORM_TABLE_Address", ormColumn.getDefaultTable()); } + + public void testModifyPredominantJoiningStrategy() throws Exception { + createTestEntityWithValidOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); + OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); + OrmEclipseLinkOneToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = 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 { + createTestEntityWithValidOneToManyMapping(); + OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); + OrmPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); + OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); + OrmEclipseLinkOneToManyRelationshipReference relationshipReference = contextMapping.getRelationshipReference(); + XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getResourceTypeMapping(); + XmlOneToMany resourceMapping = 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()); + } } |