Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-08-12 21:01:03 +0000
committerkmoore2011-08-12 21:01:03 +0000
commit728f3d9b7e7cff1d5fa517079b97a025e7d274e2 (patch)
tree7cff10b8540d38e79d9eedbfef0ca8ba19302321 /jpa/tests/org.eclipse.jpt.jpa.core.tests
parent53bbc7bc023cf939d2e08cbb0e8dba503d77cd09 (diff)
downloadwebtools.dali-728f3d9b7e7cff1d5fa517079b97a025e7d274e2.tar.gz
webtools.dali-728f3d9b7e7cff1d5fa517079b97a025e7d274e2.tar.xz
webtools.dali-728f3d9b7e7cff1d5fa517079b97a025e7d274e2.zip
Bug 354054 - [JPA2.0] MapKeyTemporal and MapKeyEnumerated model support
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.core.tests')
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java112
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java110
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java114
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java107
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java124
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java120
6 files changed, 674 insertions, 13 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 395b7d260f..8c4086d4ae 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
@@ -26,6 +26,8 @@ import org.eclipse.jpt.jpa.core.context.BasicMapping;
import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
+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.ManyToManyMapping;
@@ -34,6 +36,8 @@ import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.TransientMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.core.context.VersionMapping;
@@ -51,6 +55,8 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotatio
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.MapKeyTemporal2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
@@ -178,7 +184,7 @@ public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0Conte
}
});
}
-
+
private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
@@ -2133,4 +2139,108 @@ public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0Conte
JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("elementCollection").getMapping();
assertFalse(elementCollectionMapping.getAllOverridableAttributeMappingNames().iterator().hasNext());
}
+
+ public void testSetSpecifiedMapKeyEnumerated() throws Exception {
+ createTestEntityWithValidGenericMapElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+ assertNull(elementCollectionMapping.getMapKeyConverter().getType());
+
+ elementCollectionMapping.setMapKeyConverter(EnumeratedConverter.class);
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME);
+
+ assertNotNull(enumerated);
+ assertEquals(null, enumerated.getValue());
+
+ ((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue());
+
+ ((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(null);
+ assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ assertNull(enumerated.getValue());
+
+ elementCollectionMapping.setMapKeyConverter(null);
+ assertNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testGetSpecifiedMapKeyEnumeratedUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithValidGenericMapElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ assertNull(elementCollectionMapping.getMapKeyConverter().getType());
+
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.addAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME);
+ enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ enumerated.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ assertNull(((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertFalse(elementCollectionMapping.isDefault());
+ assertSame(elementCollectionMapping, persistentAttribute.getMapping());
+ }
+
+ public void testSetMapKeyTemporal() throws Exception {
+ createTestEntityWithValidGenericMapElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+ assertNull(elementCollectionMapping.getMapKeyConverter().getType());
+
+ elementCollectionMapping.setMapKeyConverter(TemporalConverter.class);
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME);
+
+ assertNotNull(temporal);
+ assertEquals(null, temporal.getValue());
+
+ ((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue());
+
+ ((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).setTemporalType(null);
+ assertNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testGetMapKeyTemporalUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithValidGenericMapElementCollectionMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping();
+
+ assertNull(elementCollectionMapping.getMapKeyConverter().getType());
+
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.addAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME);
+ temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(TemporalType.TIME, ((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).getTemporalType());
+
+ temporal.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME));
+ assertNull(((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).getTemporalType());
+ assertFalse(elementCollectionMapping.isDefault());
+ assertSame(elementCollectionMapping, persistentAttribute.getMapping());
+ }
}
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 40d500277c..78dc8bea7d 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
@@ -25,6 +25,8 @@ import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
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.JoinTableRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
@@ -34,6 +36,8 @@ import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.TransientMapping;
import org.eclipse.jpt.jpa.core.context.VersionMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride;
@@ -52,6 +56,8 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotatio
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.MapKeyTemporal2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
@@ -1500,4 +1506,108 @@ public class GenericJavaManyToManyMapping2_0Tests
assertEquals("city", specifiedOverrides.next().getName());
assertFalse(specifiedOverrides.hasNext());
}
+
+ public void testSetSpecifiedMapKeyEnumerated() throws Exception {
+ createTestEntityWithValidGenericMapManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping();
+ assertNull(manyToManyMapping.getMapKeyConverter().getType());
+
+ manyToManyMapping.setMapKeyConverter(EnumeratedConverter.class);
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME);
+
+ assertNotNull(enumerated);
+ assertEquals(null, enumerated.getValue());
+
+ ((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue());
+
+ ((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(null);
+ assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ assertNull(enumerated.getValue());
+
+ manyToManyMapping.setMapKeyConverter(null);
+ assertNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testGetSpecifiedMapKeyEnumeratedUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithValidGenericMapManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertNull(manyToManyMapping.getMapKeyConverter().getType());
+
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.addAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME);
+ enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ enumerated.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ assertNull(((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertFalse(manyToManyMapping.isDefault());
+ assertSame(manyToManyMapping, persistentAttribute.getMapping());
+ }
+
+ public void testSetMapKeyTemporal() throws Exception {
+ createTestEntityWithValidGenericMapManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping();
+ assertNull(manyToManyMapping.getMapKeyConverter().getType());
+
+ manyToManyMapping.setMapKeyConverter(TemporalConverter.class);
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME);
+
+ assertNotNull(temporal);
+ assertEquals(null, temporal.getValue());
+
+ ((TemporalConverter) manyToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue());
+
+ ((TemporalConverter) manyToManyMapping.getMapKeyConverter()).setTemporalType(null);
+ assertNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testGetMapKeyTemporalUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithValidGenericMapManyToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertNull(manyToManyMapping.getMapKeyConverter().getType());
+
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.addAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME);
+ temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(TemporalType.TIME, ((TemporalConverter) manyToManyMapping.getMapKeyConverter()).getTemporalType());
+
+ temporal.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME));
+ assertNull(((TemporalConverter) manyToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertFalse(manyToManyMapping.isDefault());
+ assertSame(manyToManyMapping, persistentAttribute.getMapping());
+ }
}
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 498dd1085d..35c497f497 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
@@ -12,9 +12,9 @@ package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java;
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;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
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.iterables.EmptyIterable;
@@ -26,6 +26,8 @@ import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
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.JoinColumnRelationship;
@@ -35,6 +37,8 @@ import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.TransientMapping;
import org.eclipse.jpt.jpa.core.context.VersionMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride;
@@ -53,6 +57,8 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation;
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.MapKeyTemporal2_0Annotation;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.OneToMany2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
@@ -551,7 +557,7 @@ public class GenericJavaOneToManyMapping2_0Tests
assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME));
}
- public void testMorphToManyToManyMapping() throws Exception {
+ public void testMorphToOneToManyMapping() throws Exception {
createTestEntityWithValidOneToManyMapping();
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
@@ -1762,4 +1768,108 @@ public class GenericJavaOneToManyMapping2_0Tests
assertEquals("city", specifiedOverrides.next().getName());
assertFalse(specifiedOverrides.hasNext());
}
+
+ public void testSetSpecifiedMapKeyEnumerated() throws Exception {
+ createTestEntityWithValidGenericMapOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping();
+ assertNull(oneToManyMapping.getMapKeyConverter().getType());
+
+ oneToManyMapping.setMapKeyConverter(EnumeratedConverter.class);
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME);
+
+ assertNotNull(enumerated);
+ assertEquals(null, enumerated.getValue());
+
+ ((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue());
+
+ ((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(null);
+ assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ assertNull(enumerated.getValue());
+
+ oneToManyMapping.setMapKeyConverter(null);
+ assertNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testGetSpecifiedMapKeyEnumeratedUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithValidGenericMapOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertNull(oneToManyMapping.getMapKeyConverter().getType());
+
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.addAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME);
+ enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ enumerated.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME));
+ assertNull(((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertFalse(oneToManyMapping.isDefault());
+ assertSame(oneToManyMapping, persistentAttribute.getMapping());
+ }
+
+ public void testSetMapKeyTemporal() throws Exception {
+ createTestEntityWithValidGenericMapOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping();
+ assertNull(oneToManyMapping.getMapKeyConverter().getType());
+
+ oneToManyMapping.setMapKeyConverter(TemporalConverter.class);
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME);
+
+ assertNotNull(temporal);
+ assertEquals(null, temporal.getValue());
+
+ ((TemporalConverter) oneToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue());
+
+ ((TemporalConverter) oneToManyMapping.getMapKeyConverter()).setTemporalType(null);
+ assertNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME));
+ }
+
+ public void testGetMapKeyTemporalUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithValidGenericMapOneToManyMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next();
+ JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping();
+
+ assertNull(oneToManyMapping.getMapKeyConverter().getType());
+
+
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE);
+ JavaResourceField resourceField = resourceType.getFields().iterator().next();
+ MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.addAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME);
+ temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(TemporalType.TIME, ((TemporalConverter) oneToManyMapping.getMapKeyConverter()).getTemporalType());
+
+ temporal.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME));
+ assertNull(((TemporalConverter) oneToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertFalse(oneToManyMapping.isDefault());
+ assertSame(oneToManyMapping, persistentAttribute.getMapping());
+ }
}
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 81879526a7..5ef2a9ba8c 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
@@ -21,6 +21,8 @@ import org.eclipse.jpt.jpa.core.context.BasicMapping;
import org.eclipse.jpt.jpa.core.context.Column;
import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
+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.ManyToManyMapping;
@@ -28,6 +30,8 @@ import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.TransientMapping;
import org.eclipse.jpt.jpa.core.context.VersionMapping;
import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride;
@@ -1456,4 +1460,107 @@ public class GenericOrmElementCollectionMapping2_0Tests extends Generic2_0Contex
ElementCollectionMapping2_0 mapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("elementCollection").getMapping();
assertFalse(mapping.getAllOverridableAttributeMappingNames().iterator().hasNext());
}
+
+ public void testUpdateSpecifiedEnumerated() 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");
+ OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ assertNull(elementCollectionResource.getMapKeyEnumerated());
+
+ //set enumerated in the resource model, verify context model updated
+ elementCollectionResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL);
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, elementCollectionResource.getMapKeyEnumerated());
+
+ elementCollectionResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING);
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, elementCollectionResource.getMapKeyEnumerated());
+
+ //set enumerated to null in the resource model
+ elementCollectionResource.setMapKeyEnumerated(null);
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ assertNull(elementCollectionResource.getMapKeyEnumerated());
+ }
+
+ public void testModifySpecifiedEnumerated() 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");
+ OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ assertNull(elementCollectionResource.getMapKeyEnumerated());
+
+ //set enumerated in the context model, verify resource model updated
+ ormElementCollectionMapping.setMapKeyConverter(EnumeratedConverter.class);
+ ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.ORDINAL);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, elementCollectionResource.getMapKeyEnumerated());
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, elementCollectionResource.getMapKeyEnumerated());
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ //set enumerated to null in the context model
+ ormElementCollectionMapping.setMapKeyConverter(null);
+ assertNull(elementCollectionResource.getMapKeyEnumerated());
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ }
+
+ public void testUpdateSpecifiedTemporal() 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");
+ OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ assertNull(elementCollectionResource.getMapKeyTemporal());
+
+ //set temporal in the resource model, verify context model updated
+ elementCollectionResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE);
+ assertEquals(TemporalType.DATE, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, elementCollectionResource.getMapKeyTemporal());
+
+ elementCollectionResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME);
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, elementCollectionResource.getMapKeyTemporal());
+
+ elementCollectionResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP);
+ assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP, elementCollectionResource.getMapKeyTemporal());
+
+ //set temporal to null in the resource model
+ elementCollectionResource.setMapKeyTemporal(null);
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ assertNull(elementCollectionResource.getMapKeyTemporal());
+ }
+
+ public void testModifySpecifiedTemporal() 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");
+ OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping();
+ XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0);
+
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ assertNull(elementCollectionResource.getMapKeyTemporal());
+
+ //set temporal in the context model, verify resource model updated
+ ormElementCollectionMapping.setMapKeyConverter(TemporalConverter.class);
+ ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).setTemporalType(TemporalType.DATE);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, elementCollectionResource.getMapKeyTemporal());
+ assertEquals(TemporalType.DATE, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType());
+
+ ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, elementCollectionResource.getMapKeyTemporal());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType());
+
+ //set temporal to null in the context model
+ ormElementCollectionMapping.setMapKeyConverter(null);
+ assertNull(elementCollectionResource.getMapKeyTemporal());
+ assertNull(ormElementCollectionMapping.getMapKeyConverter().getType());
+ }
+
} \ 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 0cfb6a561f..edf717bca4 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
@@ -18,16 +18,21 @@ import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.Column;
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.ManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmEntity;
import org.eclipse.jpt.jpa.core.context.orm.OrmManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.ManyToManyMapping2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0;
@@ -38,6 +43,7 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
import org.eclipse.jpt.jpa.core.resource.orm.XmlManyToMany;
+import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlManyToMany_2_0;
import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase;
@SuppressWarnings("nls")
@@ -212,7 +218,7 @@ public class GenericOrmManyToManyMapping2_0Tests
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
- return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY);
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, JPA2_0.MAP_KEY_ENUMERATED, JPA.ENUM_TYPE);
}
@Override
public void appendTypeAnnotationTo(StringBuilder sb) {
@@ -226,7 +232,8 @@ public class GenericOrmManyToManyMapping2_0Tests
sb.append(CR);
sb.append(" @OrderBy(\"city\"");
sb.append(CR);
- sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(" @MapKeyEnumerated(EnumType.STRING)").append(CR);
+ sb.append(" private java.util.Map<String, Address> address;").append(CR);
sb.append(CR);
sb.append(" @Id");
}
@@ -885,11 +892,12 @@ public class GenericOrmManyToManyMapping2_0Tests
assertEquals(3, ormPersistentType.getVirtualAttributesSize());
OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.getVirtualAttributes().iterator().next();
- ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) virtualAttribute.getMapping();
+ ManyToManyMapping2_0 virtualManyToManyMapping = (ManyToManyMapping2_0) virtualAttribute.getMapping();
assertEquals("address", virtualManyToManyMapping.getName());
assertEquals(FetchType.EAGER, virtualManyToManyMapping.getSpecifiedFetch());
assertEquals("Address", virtualManyToManyMapping.getSpecifiedTargetEntity());
assertNull(virtualManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute());
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) virtualManyToManyMapping.getMapKeyConverter()).getEnumType());
Cascade2_0 cascade = (Cascade2_0) virtualManyToManyMapping.getCascade();
assertTrue(cascade.isAll());
@@ -909,21 +917,22 @@ public class GenericOrmManyToManyMapping2_0Tests
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
- ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
assertEquals(3, ormPersistentType.getVirtualAttributesSize());
OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address");
assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey());
assertTrue(virtualPersistentAttribute.isVirtual());
-
virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
OrmReadOnlyPersistentAttribute ormPersistentAttribute= ormPersistentType.getSpecifiedAttributes().iterator().next();
- OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping();
+ ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping();
assertEquals("address", ormManyToManyMapping.getName());
assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch());
assertEquals("test.Address", ormManyToManyMapping.getTargetEntity());
assertNull(ormManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute());
+ assertTrue(ormManyToManyMapping.getMapKeyConverter() instanceof NullOrmConverter);
Cascade2_0 cascade = (Cascade2_0) ormManyToManyMapping.getCascade();
assertFalse(cascade.isAll());
@@ -936,4 +945,107 @@ public class GenericOrmManyToManyMapping2_0Tests
assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering());
assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
}
+
+ public void testUpdateSpecifiedEnumerated() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping");
+ OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ assertNull(manyToManyResource.getMapKeyEnumerated());
+
+ //set enumerated in the resource model, verify context model updated
+ manyToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL);
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, manyToManyResource.getMapKeyEnumerated());
+
+ manyToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING);
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, manyToManyResource.getMapKeyEnumerated());
+
+ //set enumerated to null in the resource model
+ manyToManyResource.setMapKeyEnumerated(null);
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ assertNull(manyToManyResource.getMapKeyEnumerated());
+ }
+
+ public void testModifySpecifiedEnumerated() 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");
+ OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ assertNull(manyToManyResource.getMapKeyEnumerated());
+
+ //set enumerated in the context model, verify resource model updated
+ ormManyToManyMapping.setMapKeyConverter(EnumeratedConverter.class);
+ ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.ORDINAL);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, manyToManyResource.getMapKeyEnumerated());
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, manyToManyResource.getMapKeyEnumerated());
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ //set enumerated to null in the context model
+ ormManyToManyMapping.setMapKeyConverter(null);
+ assertNull(manyToManyResource.getMapKeyEnumerated());
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ }
+
+ public void testUpdateSpecifiedTemporal() 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");
+ OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ assertNull(manyToManyResource.getMapKeyTemporal());
+
+ //set temporal in the resource model, verify context model updated
+ manyToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE);
+ assertEquals(TemporalType.DATE, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, manyToManyResource.getMapKeyTemporal());
+
+ manyToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME);
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, manyToManyResource.getMapKeyTemporal());
+
+ manyToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP);
+ assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP, manyToManyResource.getMapKeyTemporal());
+
+ //set temporal to null in the resource model
+ manyToManyResource.setMapKeyTemporal(null);
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ assertNull(manyToManyResource.getMapKeyTemporal());
+ }
+
+ public void testModifySpecifiedTemporal() 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");
+ OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0);
+
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ assertNull(manyToManyResource.getMapKeyTemporal());
+
+ //set temporal in the context model, verify resource model updated
+ ormManyToManyMapping.setMapKeyConverter(TemporalConverter.class);
+ ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.DATE);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, manyToManyResource.getMapKeyTemporal());
+ assertEquals(TemporalType.DATE, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType());
+
+ ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, manyToManyResource.getMapKeyTemporal());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType());
+
+ //set temporal to null in the context model
+ ormManyToManyMapping.setMapKeyConverter(null);
+ assertNull(manyToManyResource.getMapKeyTemporal());
+ assertNull(ormManyToManyMapping.getMapKeyConverter().getType());
+ }
+
}
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 e6f3d2a45e..693ad5102b 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
@@ -11,20 +11,24 @@ package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm;
import java.util.Iterator;
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;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.Column;
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.OneToManyMapping;
import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmEntity;
@@ -32,6 +36,7 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmOneToManyMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter;
import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyMapping2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyRelationship2_0;
@@ -49,6 +54,7 @@ import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity;
import org.eclipse.jpt.jpa.core.resource.orm.XmlOneToMany;
+import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlOneToMany_2_0;
import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase;
@SuppressWarnings("nls")
@@ -248,7 +254,7 @@ public class GenericOrmOneToManyMapping2_0Tests
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
- return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY);
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, JPA2_0.MAP_KEY_ENUMERATED, JPA.ENUM_TYPE);
}
@Override
public void appendTypeAnnotationTo(StringBuilder sb) {
@@ -262,6 +268,7 @@ public class GenericOrmOneToManyMapping2_0Tests
sb.append(CR);
sb.append(" @OrderBy(\"city\"");
sb.append(CR);
+ sb.append(" @MapKeyEnumerated(EnumType.STRING)").append(CR);
sb.append(" private java.util.Collection<Address> address;").append(CR);
sb.append(CR);
sb.append(" @Id");
@@ -1171,12 +1178,13 @@ public class GenericOrmOneToManyMapping2_0Tests
assertEquals(3, ormPersistentType.getVirtualAttributesSize());
OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next();
- OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) virtualPersistentAttribute.getMapping();
+ OneToManyMapping2_0 virtualOneToManyMapping = (OneToManyMapping2_0) virtualPersistentAttribute.getMapping();
assertEquals("address", virtualOneToManyMapping.getName());
assertEquals(FetchType.EAGER, virtualOneToManyMapping.getSpecifiedFetch());
assertEquals("Address", virtualOneToManyMapping.getSpecifiedTargetEntity());
assertNull(virtualOneToManyMapping.getRelationship().
getMappedByStrategy().getMappedByAttribute());
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) virtualOneToManyMapping.getMapKeyConverter()).getEnumType());
Cascade2_0 cascade = (Cascade2_0) virtualOneToManyMapping.getCascade();
assertTrue(cascade.isAll());
@@ -1208,11 +1216,12 @@ public class GenericOrmOneToManyMapping2_0Tests
virtualPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next();
- OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping();
+ OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
assertEquals("address", ormOneToManyMapping.getName());
assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch());
assertEquals("test.Address", ormOneToManyMapping.getTargetEntity());
assertNull(ormOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute());
+ assertTrue(ormOneToManyMapping.getMapKeyConverter() instanceof NullOrmConverter);
Cascade2_0 cascade = (Cascade2_0) ormOneToManyMapping.getCascade();
assertFalse(cascade.isAll());
@@ -1227,4 +1236,107 @@ public class GenericOrmOneToManyMapping2_0Tests
assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval());
}
+
+ public void testUpdateSpecifiedEnumerated() 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");
+ OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ assertNull(oneToManyResource.getMapKeyEnumerated());
+
+ //set enumerated in the resource model, verify context model updated
+ oneToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL);
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, oneToManyResource.getMapKeyEnumerated());
+
+ oneToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING);
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, oneToManyResource.getMapKeyEnumerated());
+
+ //set enumerated to null in the resource model
+ oneToManyResource.setMapKeyEnumerated(null);
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ assertNull(oneToManyResource.getMapKeyEnumerated());
+ }
+
+ public void testModifySpecifiedEnumerated() 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");
+ OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ assertNull(oneToManyResource.getMapKeyEnumerated());
+
+ //set enumerated in the context model, verify resource model updated
+ ormOneToManyMapping.setMapKeyConverter(EnumeratedConverter.class);
+ ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.ORDINAL);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, oneToManyResource.getMapKeyEnumerated());
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, oneToManyResource.getMapKeyEnumerated());
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType());
+
+ //set enumerated to null in the context model
+ ormOneToManyMapping.setMapKeyConverter(null);
+ assertNull(oneToManyResource.getMapKeyEnumerated());
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ }
+
+ public void testUpdateSpecifiedTemporal() 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");
+ OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ assertNull(oneToManyResource.getMapKeyTemporal());
+
+ //set temporal in the resource model, verify context model updated
+ oneToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE);
+ assertEquals(TemporalType.DATE, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, oneToManyResource.getMapKeyTemporal());
+
+ oneToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME);
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, oneToManyResource.getMapKeyTemporal());
+
+ oneToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP);
+ assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType());
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP, oneToManyResource.getMapKeyTemporal());
+
+ //set temporal to null in the resource model
+ oneToManyResource.setMapKeyTemporal(null);
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ assertNull(oneToManyResource.getMapKeyTemporal());
+ }
+
+ public void testModifySpecifiedTemporal() 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");
+ OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
+ XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
+
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ assertNull(oneToManyResource.getMapKeyTemporal());
+
+ //set temporal in the context model, verify resource model updated
+ ormOneToManyMapping.setMapKeyConverter(TemporalConverter.class);
+ ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.DATE);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, oneToManyResource.getMapKeyTemporal());
+ assertEquals(TemporalType.DATE, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType());
+
+ ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, oneToManyResource.getMapKeyTemporal());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType());
+
+ //set temporal to null in the context model
+ ormOneToManyMapping.setMapKeyConverter(null);
+ assertNull(oneToManyResource.getMapKeyTemporal());
+ assertNull(ormOneToManyMapping.getMapKeyConverter().getType());
+ }
+
}

Back to the top