Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-08-22 18:25:35 +0000
committerkmoore2011-08-22 18:25:35 +0000
commite30c5458ca84ee92f589346bbf296f71b6b3d4f4 (patch)
treebf3fd00916b8bd91cf7899df1513302d093fb8de /jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa
parenta5bf4aef58f402f78f2830079bdd1bd4f96d8e1b (diff)
downloadwebtools.dali-e30c5458ca84ee92f589346bbf296f71b6b3d4f4.tar.gz
webtools.dali-e30c5458ca84ee92f589346bbf296f71b6b3d4f4.tar.xz
webtools.dali-e30c5458ca84ee92f589346bbf296f71b6b3d4f4.zip
303527 - Map key join column model support and validation
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa')
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java369
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java340
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java339
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java145
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java146
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java144
6 files changed, 1483 insertions, 0 deletions
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java
index 8c4086d4ae..aea21aac8c 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java
@@ -17,6 +17,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jpa.core.MappingKeys;
@@ -30,6 +31,7 @@ import org.eclipse.jpt.jpa.core.context.EnumType;
import org.eclipse.jpt.jpa.core.context.EnumeratedConverter;
import org.eclipse.jpt.jpa.core.context.FetchType;
import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
@@ -56,6 +58,7 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyClass2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyTemporal2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
@@ -240,6 +243,36 @@ public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0Conte
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
}
+
+ private void createTestTargetEntityAddress() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("Address").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int state;").append(CR);
+ sb.append(CR);
+ sb.append(" private int zip;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
+ }
private void createTestEmbeddableState() throws Exception {
SourceWriter sourceWriter = new SourceWriter() {
@@ -286,6 +319,28 @@ public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0Conte
});
}
+ private ICompilationUnit createTestEntityWithEntityKeyElementCollectionMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ElementCollection").append(CR);
+ sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ }
+ });
+ }
+
private void createTestEmbeddablePropertyInfo() throws Exception {
SourceWriter sourceWriter = new SourceWriter() {
public void appendSourceTo(StringBuilder sb) {
@@ -2243,4 +2298,318 @@ public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0Conte
assertFalse(elementCollectionMapping.isDefault());
assertSame(elementCollectionMapping, persistentAttribute.getMapping());
}
+
+ public void testSpecifiedMapKeyJoinColumns() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ ListIterator<? extends JoinColumn> specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+
+ joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ resourceField.moveAnnotation(1, 0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+ }
+
+ public void testSpecifiedMapKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ assertEquals(0, elementCollectionMapping.getSpecifiedMapKeyJoinColumnsSize());
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, elementCollectionMapping.getSpecifiedMapKeyJoinColumnsSize());
+
+ elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(0, elementCollectionMapping.getSpecifiedMapKeyJoinColumnsSize());
+ }
+
+ public void testMapKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithEntityKeyElementCollectionMapping();
+ createTestTargetEntityAddress();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ assertEquals(1, elementCollectionMapping.getMapKeyJoinColumnsSize());
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, elementCollectionMapping.getMapKeyJoinColumnsSize());
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(2, elementCollectionMapping.getMapKeyJoinColumnsSize());
+
+ elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, elementCollectionMapping.getMapKeyJoinColumnsSize());
+ }
+
+ public void testAddSpecifiedMapKeyJoinColumn() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAR");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ Iterator<NestableAnnotation> joinColumnsIterator =
+ resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testAddSpecifiedMapKeyJoinColumn2() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ Iterator<NestableAnnotation> joinColumnsIterator =
+ resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ assertEquals(3, resourceField.getAnnotationsSize(JPA2_0.MAP_KEY_JOIN_COLUMN));
+
+ elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(1);
+
+ Iterator<NestableAnnotation> joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertFalse(joinColumnResources.hasNext());
+
+ Iterator<? extends JoinColumn> joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+
+ elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(1);
+ joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertFalse(joinColumnResources.hasNext());
+
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+
+ elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertFalse(joinColumnResources.hasNext());
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(joinColumnsIterator.hasNext());
+
+ assertNull(resourceField.getAnnotation(0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedJoinColumn() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ Iterator<NestableAnnotation> javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals(3, CollectionTools.size(javaJoinColumns));
+
+
+ elementCollectionMapping.moveSpecifiedMapKeyJoinColumn(2, 0);
+ ListIterator<? extends JoinColumn> joinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getSpecifiedName());
+ assertEquals("BAZ", joinColumns.next().getSpecifiedName());
+ assertEquals("FOO", joinColumns.next().getSpecifiedName());
+
+ javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+
+
+ elementCollectionMapping.moveSpecifiedMapKeyJoinColumn(0, 1);
+ joinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getSpecifiedName());
+ assertEquals("BAR", joinColumns.next().getSpecifiedName());
+ assertEquals("FOO", joinColumns.next().getSpecifiedName());
+
+ javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ }
+
+ public void testUpdateSpecifiedMapKeyJoinColumns() throws Exception {
+ createTestEntityWithElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("FOO");
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAR");
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(2, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<? extends JoinColumn> joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.moveAnnotation(2, 0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.moveAnnotation(0, 1, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testMapKeyJoinColumnIsDefault() throws Exception {
+ createTestEntityWithEntityKeyElementCollectionMapping();
+ createTestTargetEntityAddress();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ assertTrue(elementCollectionMapping.getDefaultMapKeyJoinColumn().isDefault());
+
+ elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0);
+ JoinColumn specifiedJoinColumn = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator().next();
+ assertFalse(specifiedJoinColumn.isDefault());
+
+ assertNull(elementCollectionMapping.getDefaultMapKeyJoinColumn());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java
index 78dc8bea7d..7abad6b13f 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java
@@ -17,6 +17,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
@@ -28,6 +29,7 @@ import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.EnumType;
import org.eclipse.jpt.jpa.core.context.EnumeratedConverter;
import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.JoinTableRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
@@ -57,6 +59,7 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyClass2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyTemporal2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
@@ -277,6 +280,28 @@ public class GenericJavaManyToManyMapping2_0Tests
});
}
+ private ICompilationUnit createTestEntityWithEntityKeyManyToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_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(" @ManyToMany").append(CR);
+ sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ }
+ });
+ }
+
private void createTestEmbeddableAddress() throws Exception {
SourceWriter sourceWriter = new SourceWriter() {
public void appendSourceTo(StringBuilder sb) {
@@ -1610,4 +1635,319 @@ public class GenericJavaManyToManyMapping2_0Tests
assertFalse(manyToManyMapping.isDefault());
assertSame(manyToManyMapping, persistentAttribute.getMapping());
}
+
+ public void testSpecifiedMapKeyJoinColumns() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ ListIterator<? extends JoinColumn> specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+
+ joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ resourceField.moveAnnotation(1, 0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+ }
+
+ public void testSpecifiedMapKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertEquals(0, manyToManyMapping.getSpecifiedMapKeyJoinColumnsSize());
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, manyToManyMapping.getSpecifiedMapKeyJoinColumnsSize());
+
+ manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(0, manyToManyMapping.getSpecifiedMapKeyJoinColumnsSize());
+ }
+
+ public void testMapKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ createTestTargetEntityAddress();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertEquals(1, manyToManyMapping.getMapKeyJoinColumnsSize());
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, manyToManyMapping.getMapKeyJoinColumnsSize());
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(2, manyToManyMapping.getMapKeyJoinColumnsSize());
+
+ manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, manyToManyMapping.getMapKeyJoinColumnsSize());
+ }
+
+ public void testAddSpecifiedMapKeyJoinColumn() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAR");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ Iterator<NestableAnnotation> joinColumnsIterator =
+ resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testAddSpecifiedMapKeyJoinColumn2() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ Iterator<NestableAnnotation> joinColumnsIterator =
+ resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ assertEquals(3, resourceField.getAnnotationsSize(JPA2_0.MAP_KEY_JOIN_COLUMN));
+
+ manyToManyMapping.removeSpecifiedMapKeyJoinColumn(1);
+
+ Iterator<NestableAnnotation> joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertFalse(joinColumnResources.hasNext());
+
+ Iterator<? extends JoinColumn> joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+
+ manyToManyMapping.removeSpecifiedMapKeyJoinColumn(1);
+ joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertFalse(joinColumnResources.hasNext());
+
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+
+ manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertFalse(joinColumnResources.hasNext());
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(joinColumnsIterator.hasNext());
+
+ assertNull(resourceField.getAnnotation(0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedJoinColumn() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ Iterator<NestableAnnotation> javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals(3, CollectionTools.size(javaJoinColumns));
+
+
+ manyToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0);
+ ListIterator<? extends JoinColumn> joinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getSpecifiedName());
+ assertEquals("BAZ", joinColumns.next().getSpecifiedName());
+ assertEquals("FOO", joinColumns.next().getSpecifiedName());
+
+ javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+
+
+ manyToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1);
+ joinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getSpecifiedName());
+ assertEquals("BAR", joinColumns.next().getSpecifiedName());
+ assertEquals("FOO", joinColumns.next().getSpecifiedName());
+
+ javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ }
+
+ public void testUpdateSpecifiedMapKeyJoinColumns() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("FOO");
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAR");
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(2, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<? extends JoinColumn> joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.moveAnnotation(2, 0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.moveAnnotation(0, 1, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testMapKeyJoinColumnIsDefault() throws Exception {
+ createTestEntityWithEntityKeyManyToManyMapping();
+ createTestTargetEntityAddress();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertTrue(manyToManyMapping.getDefaultMapKeyJoinColumn().isDefault());
+
+ manyToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ JoinColumn specifiedJoinColumn = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().next();
+ assertFalse(specifiedJoinColumn.isDefault());
+
+ assertNull(manyToManyMapping.getDefaultMapKeyJoinColumn());
+ }
+
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java
index 35c497f497..bf70de9c6a 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java
@@ -17,6 +17,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jpa.core.MappingKeys;
@@ -58,6 +59,7 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyClass2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyTemporal2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.OneToMany2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
@@ -299,6 +301,28 @@ public class GenericJavaOneToManyMapping2_0Tests
});
}
+ private ICompilationUnit createTestEntityWithEntityKeyOneToManyMapping() throws Exception {
+ return 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.Map<Address, PropertyInfo> parcels;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ }
+ });
+ }
+
private void createTestEmbeddableAddress() throws Exception {
SourceWriter sourceWriter = new SourceWriter() {
public void appendSourceTo(StringBuilder sb) {
@@ -1872,4 +1896,319 @@ public class GenericJavaOneToManyMapping2_0Tests
assertFalse(oneToManyMapping.isDefault());
assertSame(oneToManyMapping, persistentAttribute.getMapping());
}
+
+ public void testSpecifiedMapKeyJoinColumns() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ ListIterator<? extends JoinColumn> specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+
+ joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ joinColumn.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ resourceField.moveAnnotation(1, 0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName());
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName());
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(specifiedMapKeyJoinColumns.hasNext());
+ }
+
+ public void testSpecifiedMapKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertEquals(0, oneToManyMapping.getSpecifiedMapKeyJoinColumnsSize());
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, oneToManyMapping.getSpecifiedMapKeyJoinColumnsSize());
+
+ oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(0, oneToManyMapping.getSpecifiedMapKeyJoinColumnsSize());
+ }
+
+ public void testMapKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ createTestTargetEntityAddress();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertEquals(1, oneToManyMapping.getMapKeyJoinColumnsSize());
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, oneToManyMapping.getMapKeyJoinColumnsSize());
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ assertEquals(2, oneToManyMapping.getMapKeyJoinColumnsSize());
+
+ oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, oneToManyMapping.getMapKeyJoinColumnsSize());
+ }
+
+ public void testAddSpecifiedMapKeyJoinColumn() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAR");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ Iterator<NestableAnnotation> joinColumnsIterator =
+ resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testAddSpecifiedMapKeyJoinColumn2() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ Iterator<NestableAnnotation> joinColumnsIterator =
+ resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName());
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ assertEquals(3, resourceField.getAnnotationsSize(JPA2_0.MAP_KEY_JOIN_COLUMN));
+
+ oneToManyMapping.removeSpecifiedMapKeyJoinColumn(1);
+
+ Iterator<NestableAnnotation> joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertFalse(joinColumnResources.hasNext());
+
+ Iterator<? extends JoinColumn> joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+
+ oneToManyMapping.removeSpecifiedMapKeyJoinColumn(1);
+ joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName());
+ assertFalse(joinColumnResources.hasNext());
+
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+
+ oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertFalse(joinColumnResources.hasNext());
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(joinColumnsIterator.hasNext());
+
+ assertNull(resourceField.getAnnotation(0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedJoinColumn() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ Iterator<NestableAnnotation> javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals(3, CollectionTools.size(javaJoinColumns));
+
+
+ oneToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0);
+ ListIterator<? extends JoinColumn> joinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getSpecifiedName());
+ assertEquals("BAZ", joinColumns.next().getSpecifiedName());
+ assertEquals("FOO", joinColumns.next().getSpecifiedName());
+
+ javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+
+
+ oneToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1);
+ joinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getSpecifiedName());
+ assertEquals("BAR", joinColumns.next().getSpecifiedName());
+ assertEquals("FOO", joinColumns.next().getSpecifiedName());
+
+ javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator();
+ assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName());
+ }
+
+ public void testUpdateSpecifiedMapKeyJoinColumns() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("FOO");
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAR");
+ ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(2, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<? extends JoinColumn> joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.moveAnnotation(2, 0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.moveAnnotation(0, 1, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("BAR", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertEquals("FOO", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumnsIterator.next().getName());
+ assertFalse(joinColumnsIterator.hasNext());
+
+ resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN);
+ getJpaProject().synchronizeContextModel();
+ joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertFalse(joinColumnsIterator.hasNext());
+ }
+
+ public void testMapKeyJoinColumnIsDefault() throws Exception {
+ createTestEntityWithEntityKeyOneToManyMapping();
+ createTestTargetEntityAddress();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertTrue(oneToManyMapping.getDefaultMapKeyJoinColumn().isDefault());
+
+ oneToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ JoinColumn specifiedJoinColumn = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().next();
+ assertFalse(specifiedJoinColumn.isDefault());
+
+ assertNull(oneToManyMapping.getDefaultMapKeyJoinColumn());
+ }
+
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java
index 5ef2a9ba8c..afb0daa0cc 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java
@@ -25,6 +25,7 @@ import org.eclipse.jpt.jpa.core.context.EnumType;
import org.eclipse.jpt.jpa.core.context.EnumeratedConverter;
import org.eclipse.jpt.jpa.core.context.FetchType;
import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
@@ -1563,4 +1564,148 @@ public class GenericOrmElementCollectionMapping2_0Tests extends Generic2_0Contex
assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
}
+ public void testAddSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping");
+ ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ JoinColumn joinColumn = ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0);
+ joinColumn.setSpecifiedName("FOO");
+
+ assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+
+ JoinColumn joinColumn2 = ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0);
+ joinColumn2.setSpecifiedName("BAR");
+
+ assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(1).getName());
+
+ JoinColumn joinColumn3 = ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(1);
+ joinColumn3.setSpecifiedName("BAZ");
+
+ assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(2).getName());
+
+ ListIterator<? extends JoinColumn> joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals(joinColumn2, joinColumns.next());
+ assertEquals(joinColumn3, joinColumns.next());
+ assertEquals(joinColumn, joinColumns.next());
+
+ joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ }
+
+ public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping");
+ ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(3, elementCollectionResource.getMapKeyJoinColumns().size());
+
+ ormElementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(2, elementCollectionResource.getMapKeyJoinColumns().size());
+ assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(1).getName());
+
+ ormElementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, elementCollectionResource.getMapKeyJoinColumns().size());
+ assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+
+ ormElementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(0, elementCollectionResource.getMapKeyJoinColumns().size());
+ }
+
+ public void testMoveSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping");
+ ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(3, elementCollectionResource.getMapKeyJoinColumns().size());
+
+
+ ormElementCollectionMapping.moveSpecifiedMapKeyJoinColumn(2, 0);
+ ListIterator<? extends JoinColumn> joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(2).getName());
+
+
+ ormElementCollectionMapping.moveSpecifiedMapKeyJoinColumn(0, 1);
+ joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(2).getName());
+ }
+
+ public void testUpdateMapKeyJoinColumns() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping");
+ ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ elementCollectionResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+ elementCollectionResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+ elementCollectionResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+
+ elementCollectionResource.getMapKeyJoinColumns().get(0).setName("FOO");
+ elementCollectionResource.getMapKeyJoinColumns().get(1).setName("BAR");
+ elementCollectionResource.getMapKeyJoinColumns().get(2).setName("BAZ");
+
+ ListIterator<? extends JoinColumn> joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ elementCollectionResource.getMapKeyJoinColumns().move(2, 0);
+ joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ elementCollectionResource.getMapKeyJoinColumns().move(0, 1);
+ joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ elementCollectionResource.getMapKeyJoinColumns().remove(1);
+ joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ elementCollectionResource.getMapKeyJoinColumns().remove(1);
+ joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ elementCollectionResource.getMapKeyJoinColumns().remove(0);
+ assertFalse(ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator().hasNext());
+ }
+
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java
index edf717bca4..43ac4cf2c0 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java
@@ -11,6 +11,7 @@
package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm;
import java.util.Iterator;
+import java.util.ListIterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
@@ -21,6 +22,7 @@ import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.EnumType;
import org.eclipse.jpt.jpa.core.context.EnumeratedConverter;
import org.eclipse.jpt.jpa.core.context.FetchType;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
@@ -1047,5 +1049,149 @@ public class GenericOrmManyToManyMapping2_0Tests
assertNull(manyToManyResource.getMapKeyTemporal());
assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
}
+
+ public void testAddSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping");
+ ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ JoinColumn joinColumn = ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ joinColumn.setSpecifiedName("FOO");
+
+ assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+
+ JoinColumn joinColumn2 = ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ joinColumn2.setSpecifiedName("BAR");
+
+ assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(1).getName());
+
+ JoinColumn joinColumn3 = ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(1);
+ joinColumn3.setSpecifiedName("BAZ");
+
+ assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(2).getName());
+
+ ListIterator<? extends JoinColumn> joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals(joinColumn2, joinColumns.next());
+ assertEquals(joinColumn3, joinColumns.next());
+ assertEquals(joinColumn, joinColumns.next());
+
+ joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ }
+
+ public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping");
+ ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(3, manyToManyResource.getMapKeyJoinColumns().size());
+
+ ormManyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(2, manyToManyResource.getMapKeyJoinColumns().size());
+ assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(1).getName());
+
+ ormManyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, manyToManyResource.getMapKeyJoinColumns().size());
+ assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+
+ ormManyToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(0, manyToManyResource.getMapKeyJoinColumns().size());
+ }
+
+ public void testMoveSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping");
+ ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(3, manyToManyResource.getMapKeyJoinColumns().size());
+
+
+ ormManyToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0);
+ ListIterator<? extends JoinColumn> joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(2).getName());
+
+
+ ormManyToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1);
+ joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(2).getName());
+ }
+
+ public void testUpdateMapKeyJoinColumns() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping");
+ ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ manyToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+ manyToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+ manyToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+
+ manyToManyResource.getMapKeyJoinColumns().get(0).setName("FOO");
+ manyToManyResource.getMapKeyJoinColumns().get(1).setName("BAR");
+ manyToManyResource.getMapKeyJoinColumns().get(2).setName("BAZ");
+
+ ListIterator<? extends JoinColumn> joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ manyToManyResource.getMapKeyJoinColumns().move(2, 0);
+ joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ manyToManyResource.getMapKeyJoinColumns().move(0, 1);
+ joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ manyToManyResource.getMapKeyJoinColumns().remove(1);
+ joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ manyToManyResource.getMapKeyJoinColumns().remove(1);
+ joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ manyToManyResource.getMapKeyJoinColumns().remove(0);
+ assertFalse(ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().hasNext());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java
index 693ad5102b..ff0785e334 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm;
import java.util.Iterator;
+import java.util.ListIterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
@@ -1338,5 +1339,148 @@ public class GenericOrmOneToManyMapping2_0Tests
assertNull(oneToManyResource.getMapKeyTemporal());
assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
}
+
+ public void testAddSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping");
+ OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ JoinColumn joinColumn = ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ joinColumn.setSpecifiedName("FOO");
+
+ assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+
+ JoinColumn joinColumn2 = ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0);
+ joinColumn2.setSpecifiedName("BAR");
+
+ assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(1).getName());
+
+ JoinColumn joinColumn3 = ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(1);
+ joinColumn3.setSpecifiedName("BAZ");
+
+ assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(2).getName());
+
+ ListIterator<? extends JoinColumn> joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals(joinColumn2, joinColumns.next());
+ assertEquals(joinColumn3, joinColumns.next());
+ assertEquals(joinColumn, joinColumns.next());
+
+ joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ }
+
+ public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping");
+ OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(3, oneToManyResource.getMapKeyJoinColumns().size());
+
+ ormOneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(2, oneToManyResource.getMapKeyJoinColumns().size());
+ assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(1).getName());
+
+ ormOneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(1, oneToManyResource.getMapKeyJoinColumns().size());
+ assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+
+ ormOneToManyMapping.removeSpecifiedMapKeyJoinColumn(0);
+ assertEquals(0, oneToManyResource.getMapKeyJoinColumns().size());
+ }
+
+ public void testMoveSpecifiedMapKeyJoinColumn() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping");
+ OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO");
+ ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR");
+ ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(3, oneToManyResource.getMapKeyJoinColumns().size());
+
+
+ ormOneToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0);
+ ListIterator<? extends JoinColumn> joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(2).getName());
+
+
+ ormOneToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1);
+ joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(0).getName());
+ assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(1).getName());
+ assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(2).getName());
+ }
+ public void testUpdateMapKeyJoinColumns() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping");
+ OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ oneToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+ oneToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+ oneToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn());
+
+ oneToManyResource.getMapKeyJoinColumns().get(0).setName("FOO");
+ oneToManyResource.getMapKeyJoinColumns().get(1).setName("BAR");
+ oneToManyResource.getMapKeyJoinColumns().get(2).setName("BAZ");
+
+ ListIterator<? extends JoinColumn> joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ oneToManyResource.getMapKeyJoinColumns().move(2, 0);
+ joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ oneToManyResource.getMapKeyJoinColumns().move(0, 1);
+ joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ oneToManyResource.getMapKeyJoinColumns().remove(1);
+ joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ oneToManyResource.getMapKeyJoinColumns().remove(1);
+ joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ oneToManyResource.getMapKeyJoinColumns().remove(0);
+ assertFalse(ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().hasNext());
+ }
}

Back to the top