Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa/tests
diff options
context:
space:
mode:
authorkmoore2008-02-15 19:10:28 +0000
committerkmoore2008-02-15 19:10:28 +0000
commitfc41a04e69beaeb2e2a64a0996321f889d24527c (patch)
tree5016163c384b518fd16503674da46c9b79eaad2d /jpa/tests
parent326e4d9ebeec1c7f347cbd02c22a4367e5c38ae2 (diff)
downloadwebtools.dali-fc41a04e69beaeb2e2a64a0996321f889d24527c.tar.gz
webtools.dali-fc41a04e69beaeb2e2a64a0996321f889d24527c.tar.xz
webtools.dali-fc41a04e69beaeb2e2a64a0996321f889d24527c.zip
xml attribute mapping morphing
Diffstat (limited to 'jpa/tests')
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlBasicMappingTests.java216
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedIdMappingTests.java592
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedMappingTests.java186
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlIdMappingTests.java174
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlManyToManyMappingTests.java305
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToManyMappingTests.java306
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToOneMappingTests.java273
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlTransientMappingTests.java147
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlVersionMappingTests.java179
9 files changed, 2194 insertions, 184 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlBasicMappingTests.java
index c1a5d314b5..8e2d098f39 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlBasicMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlBasicMappingTests.java
@@ -16,6 +16,16 @@ import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.context.base.EnumType;
import org.eclipse.jpt.core.internal.context.base.FetchType;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.base.TemporalType;
import org.eclipse.jpt.core.internal.context.orm.XmlBasicMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlColumn;
@@ -405,8 +415,8 @@ public class XmlBasicMappingTests extends ContextModelTestCase
assertNull(xmlBasicMapping.getTemporal());
}
- //TODO test morphing to other mapping types
//TODO test defaults
+ //TODO test overriding java mapping with a different mapping type in xml
public void testBasicMappingNoUnderylingJavaAttribute() throws Exception {
@@ -491,7 +501,7 @@ public class XmlBasicMappingTests extends ContextModelTestCase
public void testVirtualMappingMetadataCompleteTrue() throws Exception {
createTestEntityBasicMapping();
XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
- xmlPersistentType.getMapping().setSpecifiedMetadataComplete(true);
+ xmlPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
assertEquals(2, xmlPersistentType.virtualAttributesSize());
XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.virtualAttributes().next();
@@ -565,4 +575,206 @@ public class XmlBasicMappingTests extends ContextModelTestCase
//2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored
//3. specified mapping (metadata complete=true/false - defaults are taken from java annotations
+
+ public void testBasicMorphToIdMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(TemporalType.TIME, ((IIdMapping) xmlPersistentAttribute.getMapping()).getTemporal());
+ assertEquals("FOO", ((IIdMapping) xmlPersistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ }
+
+ public void testBasicMorphToVersionMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(TemporalType.TIME, ((IVersionMapping) xmlPersistentAttribute.getMapping()).getTemporal());
+ assertEquals("FOO", ((IVersionMapping) xmlPersistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ }
+
+ public void testBasicMorphToTransientMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testBasicMorphToEmbeddedMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testBasicMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testBasicMorphToOneToOneMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testBasicMorphToOneToManyMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testBasicMorphToManyToOneMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testBasicMorphToManyToManyMapping() throws Exception {
+ createTestEntityBasicMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic");
+
+ IBasicMapping basicMapping = (IBasicMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setLob(true);
+ basicMapping.setTemporal(TemporalType.TIME);
+ basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("basic", xmlPersistentAttribute.getMapping().getName());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedIdMappingTests.java
index f7d52f9cb0..68cb0c7bb6 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedIdMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedIdMappingTests.java
@@ -10,26 +10,38 @@
*******************************************************************************/
package org.eclipse.jpt.core.tests.internal.context.orm;
-import java.util.ListIterator;
+import java.util.Iterator;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.jpt.core.internal.context.orm.XmlAttributeOverride;
-import org.eclipse.jpt.core.internal.context.orm.XmlEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IAttributeOverride;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType;
-import org.eclipse.jpt.core.internal.resource.orm.EmbeddedId;
-import org.eclipse.jpt.core.internal.resource.orm.OrmFactory;
+import org.eclipse.jpt.core.internal.resource.java.JPA;
import org.eclipse.jpt.core.internal.resource.persistence.PersistenceFactory;
import org.eclipse.jpt.core.internal.resource.persistence.XmlMappingFileRef;
import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
public class XmlEmbeddedIdMappingTests extends ContextModelTestCase
{
+ private static final String ATTRIBUTE_OVERRIDE_NAME = "city";
+ private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY";
+
public XmlEmbeddedIdMappingTests(String name) {
super(name);
}
-
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -38,194 +50,424 @@ public class XmlEmbeddedIdMappingTests extends ContextModelTestCase
xmlPersistenceUnit().getMappingFiles().add(mappingFileRef);
persistenceResource().save(null);
}
-
- public void testUpdateName() throws Exception {
- XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
- XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
- XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
- EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
-
- assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName());
- assertEquals("embeddedIdMapping", embeddedIdResource.getName());
-
- //set name in the resource model, verify context model updated
- embeddedIdResource.setName("newName");
- assertEquals("newName", xmlEmbeddedIdMapping.getName());
- assertEquals("newName", embeddedIdResource.getName());
- //set name to null in the resource model
- embeddedIdResource.setName(null);
- assertNull(xmlEmbeddedIdMapping.getName());
- assertNull(embeddedIdResource.getName());
+ private void createEntityAnnotation() throws Exception {
+ this.createAnnotationAndMembers("Entity", "String name() default \"\";");
}
- public void testModifyName() throws Exception {
- XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
- XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
- XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
- EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
-
- assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName());
- assertEquals("embeddedIdMapping", embeddedIdResource.getName());
-
- //set name in the context model, verify resource model updated
- xmlEmbeddedIdMapping.setName("newName");
- assertEquals("newName", xmlEmbeddedIdMapping.getName());
- assertEquals("newName", embeddedIdResource.getName());
+ private void createEmbeddedIdAnnotation() throws Exception{
+ this.createAnnotationAndMembers("EmbeddedId", "");
+ }
- //set name to null in the context model
- xmlEmbeddedIdMapping.setName(null);
- assertNull(xmlEmbeddedIdMapping.getName());
- assertNull(embeddedIdResource.getName());
+ private void createColumnAnnotation() throws Exception {
+ this.createAnnotationAndMembers("Column",
+ "String name() default \"\";" +
+ "boolean unique() default false;" +
+ "boolean nullable() default true;" +
+ "boolean insertable() default true;" +
+ "boolean updatable() default true;" +
+ "String columnDefinition() default \"\";" +
+ "String table() default \"\";" +
+ "int length() default 255;" +
+ "int precision() default 0;" +
+ "int scale() default 0;");
}
- public void testAddSpecifiedAttributeOverride() throws Exception {
- XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
- XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
- XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
- EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
-
- XmlAttributeOverride attributeOverride = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0);
- ormResource().save(null);
- attributeOverride.setName("FOO");
- ormResource().save(null);
-
- assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(0).getName());
-
- XmlAttributeOverride attributeOverride2 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0);
- ormResource().save(null);
- attributeOverride2.setName("BAR");
- ormResource().save(null);
-
- assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
- assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(1).getName());
-
- XmlAttributeOverride attributeOverride3 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1);
- ormResource().save(null);
- attributeOverride3.setName("BAZ");
- ormResource().save(null);
-
- assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
- assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName());
- assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName());
-
- ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals(attributeOverride2, attributeOverrides.next());
- assertEquals(attributeOverride3, attributeOverrides.next());
- assertEquals(attributeOverride, attributeOverrides.next());
-
- attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAR", attributeOverrides.next().getName());
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertEquals("FOO", attributeOverrides.next().getName());
+ private void createAttributeOverrideAnnotation() throws Exception {
+ createColumnAnnotation();
+ this.createAnnotationAndMembers("AttributeOverride",
+ "String name();" +
+ "Column column();");
}
+ private IType createTestEntityEmbeddedIdMapping() throws Exception {
+ createEntityAnnotation();
+ createEmbeddedIdAnnotation();
+ createAttributeOverrideAnnotation();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @EmbeddedId");
+ sb.append(CR);
+ sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
- public void testRemoveSpecifiedAttributeOverride() throws Exception {
- XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
- XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
- XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
- EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
- xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO");
- xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR");
- xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ");
+// public void testUpdateName() throws Exception {
+// XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+// XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
+// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
+//
+// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName());
+// assertEquals("embeddedIdMapping", embeddedIdResource.getName());
+//
+// //set name in the resource model, verify context model updated
+// embeddedIdResource.setName("newName");
+// assertEquals("newName", xmlEmbeddedIdMapping.getName());
+// assertEquals("newName", embeddedIdResource.getName());
+//
+// //set name to null in the resource model
+// embeddedIdResource.setName(null);
+// assertNull(xmlEmbeddedIdMapping.getName());
+// assertNull(embeddedIdResource.getName());
+// }
+//
+// public void testModifyName() throws Exception {
+// XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+// XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
+// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
+//
+// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName());
+// assertEquals("embeddedIdMapping", embeddedIdResource.getName());
+//
+// //set name in the context model, verify resource model updated
+// xmlEmbeddedIdMapping.setName("newName");
+// assertEquals("newName", xmlEmbeddedIdMapping.getName());
+// assertEquals("newName", embeddedIdResource.getName());
+//
+// //set name to null in the context model
+// xmlEmbeddedIdMapping.setName(null);
+// assertNull(xmlEmbeddedIdMapping.getName());
+// assertNull(embeddedIdResource.getName());
+// }
+//
+// public void testAddSpecifiedAttributeOverride() throws Exception {
+// XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+// XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
+// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
+//
+// XmlAttributeOverride attributeOverride = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0);
+// ormResource().save(null);
+// attributeOverride.setName("FOO");
+// ormResource().save(null);
+//
+// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(0).getName());
+//
+// XmlAttributeOverride attributeOverride2 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0);
+// ormResource().save(null);
+// attributeOverride2.setName("BAR");
+// ormResource().save(null);
+//
+// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
+// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(1).getName());
+//
+// XmlAttributeOverride attributeOverride3 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1);
+// ormResource().save(null);
+// attributeOverride3.setName("BAZ");
+// ormResource().save(null);
+//
+// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
+// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName());
+// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName());
+//
+// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals(attributeOverride2, attributeOverrides.next());
+// assertEquals(attributeOverride3, attributeOverrides.next());
+// assertEquals(attributeOverride, attributeOverrides.next());
+//
+// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAR", attributeOverrides.next().getName());
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertEquals("FOO", attributeOverrides.next().getName());
+// }
+//
+// public void testRemoveSpecifiedAttributeOverride() throws Exception {
+// XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+// XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
+// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
+//
+// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO");
+// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR");
+// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ");
+//
+// assertEquals(3, embeddedIdResource.getAttributeOverrides().size());
+//
+// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0);
+// assertEquals(2, embeddedIdResource.getAttributeOverrides().size());
+// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
+// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName());
+//
+// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0);
+// assertEquals(1, embeddedIdResource.getAttributeOverrides().size());
+// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName());
+//
+// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0);
+// assertEquals(0, embeddedIdResource.getAttributeOverrides().size());
+// }
+//
+// public void testMoveSpecifiedAttributeOverride() throws Exception {
+// XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+// XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
+// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
+//
+// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO");
+// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR");
+// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ");
+//
+// assertEquals(3, embeddedIdResource.getAttributeOverrides().size());
+//
+//
+// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0);
+// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAR", attributeOverrides.next().getName());
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertEquals("FOO", attributeOverrides.next().getName());
+//
+// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
+// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName());
+// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName());
+//
+//
+// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1);
+// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertEquals("BAR", attributeOverrides.next().getName());
+// assertEquals("FOO", attributeOverrides.next().getName());
+//
+// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName());
+// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName());
+// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName());
+// }
+//
+// public void testUpdateAttributeOverrides() throws Exception {
+// XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
+// XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
+// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
+//
+// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl());
+// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl());
+// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl());
+//
+// embeddedIdResource.getAttributeOverrides().get(0).setName("FOO");
+// embeddedIdResource.getAttributeOverrides().get(1).setName("BAR");
+// embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ");
+//
+// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("FOO", attributeOverrides.next().getName());
+// assertEquals("BAR", attributeOverrides.next().getName());
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertFalse(attributeOverrides.hasNext());
+//
+// embeddedIdResource.getAttributeOverrides().move(2, 0);
+// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAR", attributeOverrides.next().getName());
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertEquals("FOO", attributeOverrides.next().getName());
+// assertFalse(attributeOverrides.hasNext());
+//
+// embeddedIdResource.getAttributeOverrides().move(0, 1);
+// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertEquals("BAR", attributeOverrides.next().getName());
+// assertEquals("FOO", attributeOverrides.next().getName());
+// assertFalse(attributeOverrides.hasNext());
+//
+// embeddedIdResource.getAttributeOverrides().remove(1);
+// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertEquals("FOO", attributeOverrides.next().getName());
+// assertFalse(attributeOverrides.hasNext());
+//
+// embeddedIdResource.getAttributeOverrides().remove(1);
+// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
+// assertEquals("BAZ", attributeOverrides.next().getName());
+// assertFalse(attributeOverrides.hasNext());
+//
+// embeddedIdResource.getAttributeOverrides().remove(0);
+// assertFalse(xmlEmbeddedIdMapping.specifiedAttributeOverrides().hasNext());
+// }
+
+ public void testEmbeddedIdMorphToIdMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
- assertEquals(3, embeddedIdResource.getAttributeOverrides().size());
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
- xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0);
- assertEquals(2, embeddedIdResource.getAttributeOverrides().size());
- assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
- assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName());
-
- xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0);
- assertEquals(1, embeddedIdResource.getAttributeOverrides().size());
- assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName());
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedIdMorphToVersionMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
- xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0);
- assertEquals(0, embeddedIdResource.getAttributeOverrides().size());
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
}
- public void testMoveSpecifiedAttributeOverride() throws Exception {
- XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
- XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
- XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
- EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
-
- xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO");
- xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR");
- xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ");
+ public void testEmbeddedIdMorphToTransientMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
- assertEquals(3, embeddedIdResource.getAttributeOverrides().size());
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedIdMorphToBasicMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
- xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0);
- ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAR", attributeOverrides.next().getName());
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertEquals("FOO", attributeOverrides.next().getName());
-
- assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName());
- assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName());
- assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName());
-
-
- xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1);
- attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertEquals("BAR", attributeOverrides.next().getName());
- assertEquals("FOO", attributeOverrides.next().getName());
-
- assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName());
- assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName());
- assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName());
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
}
- public void testUpdateAttributeOverrides() throws Exception {
- XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
- XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping");
- XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
- EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0);
-
- embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl());
- embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl());
- embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl());
-
- embeddedIdResource.getAttributeOverrides().get(0).setName("FOO");
- embeddedIdResource.getAttributeOverrides().get(1).setName("BAR");
- embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ");
-
- ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("FOO", attributeOverrides.next().getName());
- assertEquals("BAR", attributeOverrides.next().getName());
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertFalse(attributeOverrides.hasNext());
-
- embeddedIdResource.getAttributeOverrides().move(2, 0);
- attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAR", attributeOverrides.next().getName());
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertEquals("FOO", attributeOverrides.next().getName());
- assertFalse(attributeOverrides.hasNext());
-
- embeddedIdResource.getAttributeOverrides().move(0, 1);
- attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertEquals("BAR", attributeOverrides.next().getName());
- assertEquals("FOO", attributeOverrides.next().getName());
- assertFalse(attributeOverrides.hasNext());
-
- embeddedIdResource.getAttributeOverrides().remove(1);
- attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertEquals("FOO", attributeOverrides.next().getName());
- assertFalse(attributeOverrides.hasNext());
-
- embeddedIdResource.getAttributeOverrides().remove(1);
- attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides();
- assertEquals("BAZ", attributeOverrides.next().getName());
- assertFalse(attributeOverrides.hasNext());
+ public void testEmbeddedIdMorphToEmbeddedMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
+
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
+ attributeOverride = ((IEmbeddedMapping) xmlPersistentAttribute.getMapping()).specifiedAttributeOverrides().next();
+ assertEquals("override", attributeOverride.getName());
+ assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName());
+ }
+
+ public void testEmbeddedIdMorphToOneToOneMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
+
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedIdMorphToOneToManyMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
+
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
- embeddedIdResource.getAttributeOverrides().remove(0);
- assertFalse(xmlEmbeddedIdMapping.specifiedAttributeOverrides().hasNext());
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
}
+
+ public void testEmbeddedIdMorphToManyToOneMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
+
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedIdMorphToManyToManyMapping() throws Exception {
+ createTestEntityEmbeddedIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId");
+
+ IEmbeddedIdMapping embeddedIdMapping = (IEmbeddedIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedIdMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedIdMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("embeddedId", xmlPersistentAttribute.getMapping().getName());
+ }
+
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedMappingTests.java
index 1205e1aab8..3debabfaff 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlEmbeddedMappingTests.java
@@ -15,6 +15,17 @@ import java.util.ListIterator;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
+import org.eclipse.jpt.core.internal.context.base.IAttributeOverride;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlAttributeOverride;
import org.eclipse.jpt.core.internal.context.orm.XmlColumn;
import org.eclipse.jpt.core.internal.context.orm.XmlEmbeddedMapping;
@@ -406,7 +417,7 @@ public class XmlEmbeddedMappingTests extends ContextModelTestCase
XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
entityMappings().addXmlPersistentType(IMappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
- xmlPersistentType.getMapping().setSpecifiedMetadataComplete(true);
+ xmlPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
assertEquals(3, xmlPersistentType.virtualAttributesSize());
XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.virtualAttributes().next();
@@ -497,5 +508,178 @@ public class XmlEmbeddedMappingTests extends ContextModelTestCase
// xmlColumn = xmlAttributeOverride.getColumn();
// assertEquals("zip", xmlColumn.getDefaultName());
}
+
+
+ public void testEmbeddedMorphToIdMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToVersionMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToTransientMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToBasicMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ attributeOverride = ((IEmbeddedIdMapping) xmlPersistentAttribute.getMapping()).specifiedAttributeOverrides().next();
+ assertEquals("override", attributeOverride.getName());
+ assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName());
+ }
+
+ public void testEmbeddedMorphToOneToOneMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToOneToManyMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToManyToOneMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testEmbeddedMorphToManyToManyMapping() throws Exception {
+ createTestEntityEmbeddedMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded");
+
+ IEmbeddedMapping embeddedMapping = (IEmbeddedMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+ IAttributeOverride attributeOverride = embeddedMapping.addSpecifiedAttributeOverride(0);
+ attributeOverride.setName("override");
+ attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN");
+ assertFalse(embeddedMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("embedded", xmlPersistentAttribute.getMapping().getName());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlIdMappingTests.java
index 420cfbd6fa..17a5c51108 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlIdMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlIdMappingTests.java
@@ -15,6 +15,16 @@ import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.context.base.GenerationType;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.base.TemporalType;
import org.eclipse.jpt.core.internal.context.orm.XmlColumn;
import org.eclipse.jpt.core.internal.context.orm.XmlGeneratedValue;
@@ -243,8 +253,8 @@ public class XmlIdMappingTests extends ContextModelTestCase
assertNull(xmlIdMapping.getTemporal());
}
- //TODO test morphing to other mapping types
//TODO test defaults
+ //TODO test overriding java mapping with a different mapping type in xml
public void testAddSequenceGenerator() throws Exception {
@@ -547,7 +557,7 @@ public class XmlIdMappingTests extends ContextModelTestCase
public void testVirtualMappingMetadataCompleteTrue() throws Exception {
createTestEntityIdMapping();
XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
- xmlPersistentType.getMapping().setSpecifiedMetadataComplete(true);
+ xmlPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
assertEquals(2, xmlPersistentType.virtualAttributesSize());
XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.virtualAttributes().next();
@@ -616,5 +626,165 @@ public class XmlIdMappingTests extends ContextModelTestCase
//2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored
//3. specified mapping (metadata complete=true/false - defaults are taken from java annotations
+ public void testIdMorphToBasicMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(TemporalType.TIME, ((IBasicMapping) xmlPersistentAttribute.getMapping()).getTemporal());
+ assertEquals("FOO", ((IBasicMapping) xmlPersistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ }
+
+ public void testIdMorphToVersionMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(TemporalType.TIME, ((IVersionMapping) xmlPersistentAttribute.getMapping()).getTemporal());
+ assertEquals("FOO", ((IVersionMapping) xmlPersistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ }
+ public void testIdMorphToTransientMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testIdMorphToEmbeddedMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testIdMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testIdMorphToOneToOneMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testIdMorphToOneToManyMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testIdMorphToManyToOneMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testIdMorphToManyToManyMapping() throws Exception {
+ createTestEntityIdMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id");
+
+ IIdMapping idMapping = (IIdMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setTemporal(TemporalType.TIME);
+ assertFalse(idMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("id", xmlPersistentAttribute.getMapping().getName());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlManyToManyMappingTests.java
index e701113381..6054fca451 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlManyToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlManyToManyMappingTests.java
@@ -13,6 +13,18 @@ package org.eclipse.jpt.core.tests.internal.context.orm;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.context.base.FetchType;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IJoinColumn;
+import org.eclipse.jpt.core.internal.context.base.IJoinTable;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlManyToManyMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType;
@@ -346,4 +358,297 @@ public class XmlManyToManyMappingTests extends ContextModelTestCase
xmlManyToManyMapping.setOrderBy(null);
assertFalse(xmlManyToManyMapping.isCustomOrdering());
}
+
+ public void testManyToManyMorphToIdMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testManyToManyMorphToVersionMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testManyToManyMorphToTransientMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testManyToManyMorphToEmbeddedMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testManyToManyMorphToEmbeddedIdMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testManyToManyMorphToOneToOneMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getCascade().setAll(true);
+ manyToManyMapping.getCascade().setMerge(true);
+ manyToManyMapping.getCascade().setPersist(true);
+ manyToManyMapping.getCascade().setRefresh(true);
+ manyToManyMapping.getCascade().setRemove(true);
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertEquals("mappedBy", ((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getMappedBy());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ }
+
+ public void testManyToManyMorphToOneToManyMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getCascade().setAll(true);
+ manyToManyMapping.getCascade().setMerge(true);
+ manyToManyMapping.getCascade().setPersist(true);
+ manyToManyMapping.getCascade().setRefresh(true);
+ manyToManyMapping.getCascade().setRemove(true);
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertEquals("mappedBy", ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getMappedBy());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ IJoinTable joinTable = ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getJoinTable();
+ assertEquals("MY_JOIN_TABLE", joinTable.getName());
+ assertEquals("name", joinTable.joinColumns().next().getSpecifiedName());
+ assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName());
+ assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName());
+ assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName());
+ }
+
+ public void testManyToManyMorphToManyToOneMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getCascade().setAll(true);
+ manyToManyMapping.getCascade().setMerge(true);
+ manyToManyMapping.getCascade().setPersist(true);
+ manyToManyMapping.getCascade().setRefresh(true);
+ manyToManyMapping.getCascade().setRemove(true);
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ }
+
+ public void testManyToManyMorphToBasicMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany");
+
+ IManyToManyMapping manyToManyMapping = (IManyToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(manyToManyMapping.isDefault());
+ manyToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ manyToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ manyToManyMapping.setOrderBy("customOrder");
+ manyToManyMapping.setMapKey("mapKey");
+ manyToManyMapping.setMappedBy("mappedBy");
+ manyToManyMapping.getCascade().setAll(true);
+ manyToManyMapping.getCascade().setMerge(true);
+ manyToManyMapping.getCascade().setPersist(true);
+ manyToManyMapping.getCascade().setRefresh(true);
+ manyToManyMapping.getCascade().setRemove(true);
+ manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(manyToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("manyToMany", xmlPersistentAttribute.getMapping().getName());
+//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToManyMappingTests.java
index 2261c2dfd3..08c30f526f 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToManyMappingTests.java
@@ -13,6 +13,18 @@ package org.eclipse.jpt.core.tests.internal.context.orm;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.context.base.FetchType;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IJoinColumn;
+import org.eclipse.jpt.core.internal.context.base.IJoinTable;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlOneToManyMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType;
@@ -350,5 +362,297 @@ public class XmlOneToManyMappingTests extends ContextModelTestCase
xmlOneToManyMapping.setOrderBy(null);
assertFalse(xmlOneToManyMapping.isCustomOrdering());
}
-
+
+ public void testOneToManyMorphToIdMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToManyMorphToVersionMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToManyMorphToTransientMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToManyMorphToEmbeddedMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToManyMorphToEmbeddedIdMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToManyMorphToOneToOneMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getCascade().setAll(true);
+ oneToManyMapping.getCascade().setMerge(true);
+ oneToManyMapping.getCascade().setPersist(true);
+ oneToManyMapping.getCascade().setRefresh(true);
+ oneToManyMapping.getCascade().setRemove(true);
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertEquals("mappedBy", ((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getMappedBy());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IOneToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ }
+
+ public void testOneToManyMorphToManyToManyMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getCascade().setAll(true);
+ oneToManyMapping.getCascade().setMerge(true);
+ oneToManyMapping.getCascade().setPersist(true);
+ oneToManyMapping.getCascade().setRefresh(true);
+ oneToManyMapping.getCascade().setRemove(true);
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertEquals("mappedBy", ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getMappedBy());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ IJoinTable joinTable = ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getJoinTable();
+ assertEquals("MY_JOIN_TABLE", joinTable.getName());
+ assertEquals("name", joinTable.joinColumns().next().getSpecifiedName());
+ assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName());
+ assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName());
+ assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName());
+ }
+
+ public void testOneToManyMorphToManyToOneMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getCascade().setAll(true);
+ oneToManyMapping.getCascade().setMerge(true);
+ oneToManyMapping.getCascade().setPersist(true);
+ oneToManyMapping.getCascade().setRefresh(true);
+ oneToManyMapping.getCascade().setRemove(true);
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ }
+
+ public void testOneToManyMorphToBasicMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany");
+
+ IOneToManyMapping oneToManyMapping = (IOneToManyMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToManyMapping.isDefault());
+ oneToManyMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToManyMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToManyMapping.setOrderBy("customOrder");
+ oneToManyMapping.setMapKey("mapKey");
+ oneToManyMapping.setMappedBy("mappedBy");
+ oneToManyMapping.getCascade().setAll(true);
+ oneToManyMapping.getCascade().setMerge(true);
+ oneToManyMapping.getCascade().setPersist(true);
+ oneToManyMapping.getCascade().setRefresh(true);
+ oneToManyMapping.getCascade().setRemove(true);
+ oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE");
+ IJoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ IJoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0);
+ inverseJoinColumn.setSpecifiedName("inverseName");
+ inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName");
+ assertFalse(oneToManyMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("oneToMany", xmlPersistentAttribute.getMapping().getName());
+//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToOneMappingTests.java
index 6c0efbd10a..44c0fef7ab 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToOneMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlOneToOneMappingTests.java
@@ -16,6 +16,17 @@ import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.context.base.FetchType;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IJoinColumn;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlCascade;
import org.eclipse.jpt.core.internal.context.orm.XmlJoinColumn;
import org.eclipse.jpt.core.internal.context.orm.XmlOneToOneMapping;
@@ -607,5 +618,267 @@ public class XmlOneToOneMappingTests extends ContextModelTestCase
assertFalse(xmlCascade.isRemove());
assertFalse(xmlCascade.isRefresh());
}
+
+
+ public void testOneToOneMorphToIdMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToOneMorphToVersionMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToOneMorphToTransientMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToOneMorphToEmbeddedMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToOneMorphToEmbeddedIdMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testOneToOneMorphToManyToManyMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertEquals("mappedBy", ((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getMappedBy());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IManyToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ }
+
+ public void testOneToOneMorphToOneToManyMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertEquals("mappedBy", ((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getMappedBy());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IOneToManyMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+ }
+
+ public void testOneToOneMorphToManyToOneMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(FetchType.EAGER, ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ assertEquals("TargetEntity", ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getSpecifiedTargetEntity());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isAll());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isMerge());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isPersist());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRefresh());
+ assertTrue(((IManyToOneMapping) xmlPersistentAttribute.getMapping()).getCascade().isRemove());
+
+ joinColumn = ((IManyToOneMapping) xmlPersistentAttribute.getMapping()).specifiedJoinColumns().next();
+ assertEquals("name", joinColumn.getName());
+ assertEquals("referenceName", joinColumn.getReferencedColumnName());
+ }
+
+ public void testOneToOneMorphToBasicMapping() throws Exception {
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne");
+
+ IOneToOneMapping oneToOneMapping = (IOneToOneMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(oneToOneMapping.isDefault());
+ oneToOneMapping.setSpecifiedFetch(FetchType.EAGER);
+ oneToOneMapping.setSpecifiedTargetEntity("TargetEntity");
+ oneToOneMapping.setMappedBy("mappedBy");
+ oneToOneMapping.getCascade().setAll(true);
+ oneToOneMapping.getCascade().setMerge(true);
+ oneToOneMapping.getCascade().setPersist(true);
+ oneToOneMapping.getCascade().setRefresh(true);
+ oneToOneMapping.getCascade().setRemove(true);
+ IJoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("name");
+ joinColumn.setSpecifiedReferencedColumnName("referenceName");
+ assertFalse(oneToOneMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("oneToOne", xmlPersistentAttribute.getMapping().getName());
+//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) xmlPersistentAttribute.getMapping()).getSpecifiedFetch());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlTransientMappingTests.java
index 118f676f10..034c894134 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlTransientMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlTransientMappingTests.java
@@ -14,6 +14,15 @@ import java.util.Iterator;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType;
import org.eclipse.jpt.core.internal.context.orm.XmlTransientMapping;
@@ -50,6 +59,7 @@ public class XmlTransientMappingTests extends ContextModelTestCase
private IType createTestEntityTransientMapping() throws Exception {
createEntityAnnotation();
+ createTransientAnnotation();
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
@@ -140,7 +150,7 @@ public class XmlTransientMappingTests extends ContextModelTestCase
public void testVirtualMappingMetadataCompleteTrue() throws Exception {
createTestEntityTransientMapping();
XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
- xmlPersistentType.getMapping().setSpecifiedMetadataComplete(true);
+ xmlPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
assertEquals(2, xmlPersistentType.virtualAttributesSize());
XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.virtualAttributes().next();
@@ -160,4 +170,139 @@ public class XmlTransientMappingTests extends ContextModelTestCase
assertEquals("id", xmlTransientMapping.getName());
}
+
+ public void testTransientMorphToIdMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToVersionMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IVersionMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToTransientMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToEmbeddedMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToOneToOneMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToOneToManyMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToManyToOneMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testTransientMorphToManyToManyMapping() throws Exception {
+ createTestEntityTransientMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient");
+
+ ITransientMapping transientMapping = (ITransientMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("transient", xmlPersistentAttribute.getMapping().getName());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlVersionMappingTests.java
index 1bc2d17ca0..48f23d569f 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlVersionMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/XmlVersionMappingTests.java
@@ -14,6 +14,16 @@ import java.util.Iterator;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.JptCorePlugin;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
import org.eclipse.jpt.core.internal.context.base.TemporalType;
import org.eclipse.jpt.core.internal.context.orm.XmlColumn;
import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute;
@@ -199,8 +209,8 @@ public class XmlVersionMappingTests extends ContextModelTestCase
assertNull(xmlVersionMapping.getTemporal());
}
- //TODO test morphing to other mapping types
//TODO test defaults
+ //TODO test overriding java mapping with a different mapping type in xml
public void testVersionMappingNoUnderylingJavaAttribute() throws Exception {
createTestEntityVersionMapping();
@@ -273,7 +283,7 @@ public class XmlVersionMappingTests extends ContextModelTestCase
public void testVirtualMappingMetadataCompleteTrue() throws Exception {
createTestEntityVersionMapping();
XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
- xmlPersistentType.getMapping().setSpecifiedMetadataComplete(true);
+ xmlPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
assertEquals(2, xmlPersistentType.virtualAttributesSize());
XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.virtualAttributes().next();
@@ -331,5 +341,170 @@ public class XmlVersionMappingTests extends ContextModelTestCase
assertEquals(Integer.valueOf(0), xmlColumn.getDefaultScale());
}
+ public void testVersionMorphToIdMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IIdMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(TemporalType.TIME, ((IIdMapping) xmlPersistentAttribute.getMapping()).getTemporal());
+ assertEquals("FOO", ((IIdMapping) xmlPersistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ }
+
+ public void testVersionMorphToBasicMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IBasicMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ assertEquals(TemporalType.TIME, ((IBasicMapping) xmlPersistentAttribute.getMapping()).getTemporal());
+ assertEquals("FOO", ((IBasicMapping) xmlPersistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ }
+
+ public void testVersionMorphToTransientMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof ITransientMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testVersionMorphToEmbeddedMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testVersionMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testVersionMorphToOneToOneMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToOneMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testVersionMorphToOneToManyMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IOneToManyMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testVersionMorphToManyToOneMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToOneMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
+
+ public void testVersionMorphToManyToManyMapping() throws Exception {
+ createTestEntityVersionMapping();
+ XmlPersistentType xmlPersistentType = entityMappings().addXmlPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ XmlPersistentAttribute xmlPersistentAttribute = xmlPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version");
+
+ IVersionMapping versionMapping = (IVersionMapping) xmlPersistentAttribute.getMapping();
+ assertFalse(versionMapping.isDefault());
+ versionMapping.getColumn().setSpecifiedName("FOO");
+ versionMapping.setTemporal(TemporalType.TIME);
+ assertFalse(versionMapping.isDefault());
+
+ xmlPersistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(1, xmlPersistentType.specifiedAttributesSize());
+ assertEquals(xmlPersistentAttribute, xmlPersistentType.specifiedAttributes().next());
+ assertTrue(xmlPersistentAttribute.getMapping() instanceof IManyToManyMapping);
+ assertEquals("version", xmlPersistentAttribute.getMapping().getName());
+ }
} \ No newline at end of file

Back to the top