diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context')
37 files changed, 0 insertions, 29468 deletions
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java deleted file mode 100644 index efc6a77229..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context; - -import org.eclipse.jpt.jpa.core.JpaFacet; -import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.jpa.core.platform.GenericPlatform; -import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription; -import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public abstract class Generic2_0ContextModelTestCase extends ContextModelTestCase -{ - protected Generic2_0ContextModelTestCase(String name) { - super(name); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_2_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_2_0); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - @Override - protected String getJpaFacetVersionString() { - return JpaFacet.VERSION_2_0.getVersionString(); - } - - @Override - protected JpaPlatformDescription getJpaPlatformDescription() { - return GenericPlatform.VERSION_2_0; - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java deleted file mode 100644 index 2f80cfeb5f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class Generic2_0JavaContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(Generic2_0JavaContextModelTests.class.getPackage().getName()); - suite.addTestSuite(GenericJavaAssociationOverride2_0Tests.class); - suite.addTestSuite(GenericJavaBasicMapping2_0Tests.class); - suite.addTestSuite(GenericJavaCascade2_0Tests.class); - suite.addTestSuite(GenericJavaCollectionTable2_0Tests.class); - suite.addTestSuite(GenericJavaElementCollectionMapping2_0Tests.class); - suite.addTestSuite(GenericJavaEntity2_0Tests.class); - suite.addTestSuite(GenericJavaEmbeddedMapping2_0Tests.class); - suite.addTestSuite(GenericJavaEmbeddedIdMapping2_0Tests.class); - suite.addTestSuite(GenericJavaIdMapping2_0Tests.class); - suite.addTestSuite(GenericJavaManyToManyMapping2_0Tests.class); - suite.addTestSuite(GenericJavaManyToOneMapping2_0Tests.class); - suite.addTestSuite(GenericJavaOneToManyMapping2_0Tests.class); - suite.addTestSuite(GenericJavaOneToOneMapping2_0Tests.class); - suite.addTestSuite(GenericJavaPersistentAttribute2_0Tests.class); - suite.addTestSuite(GenericJavaPersistentType2_0Tests.class); - suite.addTestSuite(GenericJavaSequenceGenerator2_0Tests.class); - suite.addTestSuite(GenericJavaVersionMapping2_0Tests.class); - return suite; - } - - private Generic2_0JavaContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java deleted file mode 100644 index fa0ff6e174..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java +++ /dev/null @@ -1,580 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.context.AssociationOverride; -import org.eclipse.jpt.jpa.core.context.Entity; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.JoinTable; -import org.eclipse.jpt.jpa.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualJoinTable; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.jpa2.context.OverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaAssociationOverride2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME"; - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - sb.append(CR); - sb.append(" private java.util.Collection<AnnotationTestTypeChild> address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public GenericJavaAssociationOverride2_0Tests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - javaAssociationOverride = ((VirtualAssociationOverride) javaAssociationOverride).convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.getOverrides().iterator().hasNext()); - - //set name in the resource model, verify context model updated - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - //set name to null in the resource model - associationOverrideResource.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - assertNull(associationOverrideResource.getName()); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, overrideContainer.getSpecifiedOverridesSize()); - javaAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - resourceType.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - assertFalse(overrideContainer.getSpecifiedOverrides().iterator().hasNext()); - assertFalse(resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator().hasNext()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - AssociationOverride specifiedAssociationOverride = virtualAssociationOverride.convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", specifiedAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.getOverrides().iterator().hasNext()); - - //set name in the context model, verify resource model modified - specifiedAssociationOverride.setName("foo"); - assertEquals("foo", specifiedAssociationOverride.getName()); - assertEquals("foo", associationOverrideResource.getName()); - - //set name to null in the context model - specifiedAssociationOverride.setName(null); - assertNull(specifiedAssociationOverride.getName()); - associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - assertNull(associationOverrideResource.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedOverride = overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - - JoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - ListIterator<? extends JoinColumn> joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = javaAssociationOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - assertEquals(1, associationOverrideResource.getJoinColumnsSize()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.getJoinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, associationOverrideResource.getJoinColumnsSize()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, associationOverrideResource.getJoinColumnsSize()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, associationOverrideResource.getJoinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, associationOverrideResource.getJoinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = javaAssociationOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.getJoinColumnsSize()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaVirtualAssociationOverride virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - JavaAssociationOverride specifiedAssociationOverride = virtualAssociationOverride.convertToSpecified(); - JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedAssociationOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - associationOverrideResource.addJoinColumn(0); - associationOverrideResource.addJoinColumn(1); - associationOverrideResource.addJoinColumn(2); - - associationOverrideResource.joinColumnAt(0).setName("FOO"); - associationOverrideResource.joinColumnAt(1).setName("BAR"); - associationOverrideResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("address_id", joinColumns.next().getName()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.getSpecifiedJoinColumns().iterator().hasNext()); - } - - public void testGetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertEquals("FOO", specifiedAssociationOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - specifiedAssociationOverride.setName("FOO"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - assertEquals("FOO", associationOverrideResource.getName()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", associationOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertTrue(associationOverride.isVirtual()); - } - - - public void testSetJoinTableName() throws Exception { - createTestMappedSuperclassManyToMany(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - javaAssociationOverride = ((VirtualAssociationOverride) javaAssociationOverride).convertToSpecified(); - JoinTableRelationshipStrategy joiningStrategy = ((OverrideRelationship2_0) javaAssociationOverride.getRelationship()).getJoinTableStrategy(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverride2_0Annotation associationOverrideResource = (AssociationOverride2_0Annotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - - JoinTable joinTable = joiningStrategy.getJoinTable(); - joinTable.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.getJoinTable().getName()); - } - - public void testUpdateJoinTable() throws Exception { - createTestMappedSuperclassManyToMany(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - javaAssociationOverride = ((VirtualAssociationOverride) javaAssociationOverride).convertToSpecified(); - JoinTableRelationshipStrategy joiningStrategy = ((OverrideRelationship2_0) javaAssociationOverride.getRelationship()).getJoinTableStrategy(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", Kind.TYPE); - AssociationOverride2_0Annotation associationOverrideResource = (AssociationOverride2_0Annotation) resourceType.getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.getJoinTable().setName("MY_JOIN_TABLE"); - getJpaProject().synchronizeContextModel(); - assertEquals("MY_JOIN_TABLE", joiningStrategy.getJoinTable().getSpecifiedName()); - - associationOverrideResource.getJoinTable().removeJoinColumn(0); // remove default - associationOverrideResource.getJoinTable().addJoinColumn(0); - associationOverrideResource.getJoinTable().addJoinColumn(1); - associationOverrideResource.getJoinTable().addJoinColumn(2); - - associationOverrideResource.getJoinTable().joinColumnAt(0).setName("FOO"); - associationOverrideResource.getJoinTable().joinColumnAt(1).setName("BAR"); - associationOverrideResource.getJoinTable().joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends JoinColumn> joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator().hasNext()); - } - - public void testDefaultJoinTableName() throws Exception { - createTestMappedSuperclassManyToMany(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - VirtualOverrideRelationship2_0 rel = (VirtualOverrideRelationship2_0) javaAssociationOverride.getRelationship(); - VirtualJoinTable joinTable = rel.getJoinTableStrategy().getJoinTable(); - - assertEquals("AnnotationTestTypeChild_AnnotationTestTypeChild", joinTable.getName()); - - - getJavaEntity().getTable().setSpecifiedName("FOO"); - assertEquals("FOO_FOO", joinTable.getName()); - - PersistentType mappedSuperclass = getJavaEntity().getPersistentType().getSuperPersistentType(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) mappedSuperclass.getAttributeNamed("address").getMapping(); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("BAR"); - - assertEquals("BAR", joinTable.getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaBasicMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaBasicMapping2_0Tests.java deleted file mode 100644 index f957f6b0a7..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaBasicMapping2_0Tests.java +++ /dev/null @@ -1,417 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.LobAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaBasicMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - - public GenericJavaBasicMapping2_0Tests(String name) { - super(name); - } - - public void testBasicMorphToDefaultBasic() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(EnumeratedConverter.class); - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getEnumType()); - - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToVersion() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbedded() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbeddedId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToTransient() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((OneToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((OneToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((OneToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - public void testBasicMorphToManyToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((ManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((ManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToManyToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - -// assertEquals(FetchType.EAGER, ((ManyToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToElementCollection() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - resourceField.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(LobAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - -// assertEquals(FetchType.EAGER, ((ElementCollectionMapping2_0) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java deleted file mode 100644 index f7858aa4ed..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaCascade2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.OneToOne2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaCascade2_0Tests - extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - - public GenericJavaCascade2_0Tests(String name) { - super(name); - } - - - public void testUpdateCascadeDetach() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - OneToOne2_0Annotation annotation = (OneToOne2_0Annotation) resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaOneToOneMapping2_0 mapping = (JavaOneToOneMapping2_0) persistentAttribute.getMapping(); - JavaCascade2_0 cascade = (JavaCascade2_0) mapping.getCascade(); - - assertFalse(cascade.isDetach()); - assertFalse(annotation.isCascadeDetach()); - - //set detach in the resource model, verify context model updated - annotation.setCascadeDetach(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadeDetach()); - assertTrue(cascade.isDetach()); - - //set detach to false in the resource model - annotation.setCascadeDetach(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadeDetach()); - assertFalse(cascade.isDetach()); - } - - public void testModifyCascadeDetach() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - OneToOne2_0Annotation annotation = (OneToOne2_0Annotation) resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaOneToOneMapping2_0 mapping = (JavaOneToOneMapping2_0) persistentAttribute.getMapping(); - JavaCascade2_0 cascade = (JavaCascade2_0) mapping.getCascade(); - - assertFalse(cascade.isDetach()); - assertFalse(annotation.isCascadeDetach()); - - //set detach in the context model, verify resource model updated - cascade.setDetach(true); - assertTrue(annotation.isCascadeDetach()); - assertTrue(cascade.isDetach()); - - //set detach to false in the context model - cascade.setDetach(false); - assertFalse(annotation.isCascadeDetach()); - assertFalse(cascade.isDetach()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java deleted file mode 100644 index 58a2b8f8b1..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java +++ /dev/null @@ -1,723 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.jpa.core.jpa2.context.CollectionTable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaCollectionTable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.CollectionTable2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaCollectionTable2_0Tests extends Generic2_0ContextModelTestCase -{ - public GenericJavaCollectionTable2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection"); - } - }); - } - - private ICompilationUnit createTestEntityWithValidElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - sb.append(" private Collection<String> projects;").append(CR); - } - }); - } - - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable); - - - //set name in the resource model, verify context model updated - resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedName()); - assertEquals("FOO", resourceCollectionTable.getName()); - - //set name to null in the resource model - resourceCollectionTable.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable.getName()); - - resourceCollectionTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedName()); - assertEquals("FOO", resourceCollectionTable.getName()); - - resourceField.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation resourceCollectionTable3 = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable3); - - //set name in the context model, verify resource model modified - collectionTable.setSpecifiedName("foo"); - resourceCollectionTable3 = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedName()); - assertEquals("foo", resourceCollectionTable3.getName()); - - //set name to null in the context model - collectionTable.setSpecifiedName(null); - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - - //add the collection table annotation, verify default collection table name is the same - resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); - assertNotNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - - //set the entity name, verify default collection table name updates - getJavaEntity().setSpecifiedName("Foo"); - assertEquals("Foo_projects", collectionTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable); - - - //set schema in the resource model, verify context model updated - resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceCollectionTable.getSchema()); - - //set schema to null in the resource model - resourceCollectionTable.setSchema(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable.getSchema()); - - resourceCollectionTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceCollectionTable.getSchema()); - - resourceField.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedSchema() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable); - - //set schema in the context model, verify resource model modified - collectionTable.setSpecifiedSchema("foo"); - resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedSchema()); - assertEquals("foo", resourceCollectionTable.getSchema()); - - //set schema to null in the context model - collectionTable.setSpecifiedSchema(null); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable); - - - //set catalog in the resource model, verify context model updated - resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceCollectionTable.getCatalog()); - - //set catalog to null in the resource model - resourceCollectionTable.setCatalog(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable.getCatalog()); - - resourceCollectionTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceCollectionTable.getCatalog()); - - resourceField.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedCatalog() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable); - - //set catalog in the context model, verify resource model modified - collectionTable.setSpecifiedCatalog("foo"); - resourceCollectionTable = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedCatalog()); - assertEquals("foo", resourceCollectionTable.getCatalog()); - - //set catalog to null in the context model - collectionTable.setSpecifiedCatalog(null); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - - JoinColumn joinColumn = collectionTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = collectionTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = collectionTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - ListIterator<JavaJoinColumn> joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.getJoinColumnsSize()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.getJoinColumnsSize()); - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.getJoinColumnsSize()); - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.getJoinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.getJoinColumnsSize()); - - - collectionTable.moveSpecifiedJoinColumn(2, 0); - ListIterator<JavaJoinColumn> joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - - collectionTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - joinTableResource.addJoinColumn(0); - joinTableResource.addJoinColumn(1); - joinTableResource.addJoinColumn(2); - - joinTableResource.joinColumnAt(0).setName("FOO"); - joinTableResource.joinColumnAt(1).setName("BAR"); - joinTableResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<JavaJoinColumn> joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(collectionTable.getSpecifiedJoinColumns().iterator().hasNext()); - } - - public void testGetDefaultJoinColumn() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(0, collectionTable.getSpecifiedJoinColumnsSize()); - - collectionTable.addSpecifiedJoinColumn(0); - assertEquals(1, collectionTable.getSpecifiedJoinColumnsSize()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, collectionTable.getSpecifiedJoinColumnsSize()); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(0, collectionTable.getUniqueConstraintsSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, collectionTable.getUniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.getUniqueConstraints().iterator(); - - assertEquals("BAZ", uniqueConstraints.next().columnNameAt(0)); - assertEquals("BAR", uniqueConstraints.next().columnNameAt(0)); - assertEquals("FOO", uniqueConstraints.next().columnNameAt(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.getUniqueConstraints().iterator(); - - assertEquals("BAZ", uniqueConstraints.next().columnNameAt(0)); - assertEquals("FOO", uniqueConstraints.next().columnNameAt(0)); - assertEquals("BAR", uniqueConstraints.next().columnNameAt(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.getUniqueConstraintsSize()); - - collectionTable.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = joinTableAnnotation.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<JavaUniqueConstraint> uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - collectionTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = joinTableAnnotation.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - collectionTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = joinTableAnnotation.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.getUniqueConstraintsSize()); - - - collectionTable.moveUniqueConstraint(2, 0); - ListIterator<JavaUniqueConstraint> uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = joinTableAnnotation.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNameAt(0)); - - - collectionTable.moveUniqueConstraint(0, 1); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = joinTableAnnotation.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNameAt(0)); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNameAt(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) resourceField.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - - ListIterator<JavaUniqueConstraint> uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java deleted file mode 100644 index aea21aac8c..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java +++ /dev/null @@ -1,2615 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeOverride; -import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.Embeddable; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.TypeMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyTemporal2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - public static final String EMBEDDABLE_TYPE_NAME = "Address"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericEmbeddableElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericBasicElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<String> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithNonGenericElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map<Integer, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithEntityKeyElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddablePropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - private void createSelfReferentialElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.List<Foo> elementCollection;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public GenericJavaElementCollectionMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - ElementCollection2_0Annotation elementCollectionAnnotation = (ElementCollection2_0Annotation) resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollectionAnnotation.getTargetClass()); - - //set target class in the resource model, verify context model updated - elementCollectionAnnotation.setTargetClass("newTargetClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetClass", elementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollectionAnnotation.getTargetClass()); - - //set target class to null in the resource model - elementCollectionAnnotation.setTargetClass(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollectionAnnotation.getTargetClass()); - } - - public void testModifySpecifiedTargetClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedTargetClass("newTargetClass"); - assertEquals("newTargetClass", elementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the context model - elementCollectionMapping.setSpecifiedTargetClass(null); - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - public void testDefaultTargetClass() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Embeddable, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassNonGenericCollection() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassGenericCollection() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassNonGenericMap() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassGenericMap() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testTargetClass() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getTargetClass()); - - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertEquals("foo", elementCollectionMapping.getTargetClass()); - - elementCollectionMapping.setSpecifiedTargetClass(null); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getTargetClass()); - } - - protected Embeddable getResolvedTargetEmbeddable(ElementCollectionMapping2_0 mapping) { - return (Embeddable) ReflectionTools.executeMethod(mapping, "getResolvedTargetEmbeddable"); - } - - public void testResolvedTargetEmbeddable() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //target embeddable not in the persistence unit - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - //add target embeddable to the persistence unit, now target embeddable should resolve - createTestTargetEmbeddableAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - - elementCollectionMapping.setSpecifiedTargetClass(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - - elementCollectionMapping.setSpecifiedTargetClass(null); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - } - - public void testResolvedTargetEmbeddableWithBasicType() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //target is a basic type, so resolved target embeddable is null - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the resource model, verify context model updated - elementCollection.setFetch(org.eclipse.jpt.jpa.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(org.eclipse.jpt.jpa.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the resource model - elementCollection.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.FetchType.EAGER, elementCollection.getFetch()); - - elementCollectionMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the context model - elementCollectionMapping.setSpecifiedFetch(null); - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testGetValueTypeEmbeddable() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeNone() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.NO_TYPE, elementCollectionMapping.getValueType()); - - elementCollectionMapping.setSpecifiedTargetClass("Address"); - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeBasic() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - resourceField.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", elementCollectionMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - resourceField.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", elementCollectionMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - elementCollectionMapping.setSpecifiedMapKey(null); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - elementCollectionMapping.setNoMapKey(true); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping2_0 = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Iterator<String> mapKeyNames = - elementCollectionMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping2_0 = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Iterator<String> mapKeyNames = elementCollectionMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - elementCollectionMapping2_0.setSpecifiedTargetClass("Address"); - mapKeyNames = elementCollectionMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - elementCollectionMapping2_0.setSpecifiedTargetClass("String"); - mapKeyNames = elementCollectionMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - resourceField.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClass); - - //set mapKey name in the resource model, verify context model updated - mapKeyClass.setValue("myMapKeyClass"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKeyClass", elementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClass.getValue()); - - //set mapKey name to null in the resource model - mapKeyClass.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClass.getValue()); - - mapKeyClass.setValue("myMapKeyClass"); - resourceField.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", elementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - elementCollectionMapping.setSpecifiedMapKeyClass(null); - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", elementCollectionMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", elementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", elementCollectionMapping.getMapKeyClass()); - - elementCollectionMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", elementCollectionMapping.getMapKeyClass()); - - elementCollectionMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", elementCollectionMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) elementCollectionMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - } - - public void testGetValueColumn() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getValueColumn().getSpecifiedName()); - assertEquals("id", elementCollectionMapping.getValueColumn().getName()); - assertEquals(TYPE_NAME + "_id", elementCollectionMapping.getValueColumn().getTable()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - ColumnAnnotation column = (ColumnAnnotation) resourceField.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", elementCollectionMapping.getValueColumn().getSpecifiedName()); - assertEquals("foo", elementCollectionMapping.getValueColumn().getName()); - assertEquals("id", elementCollectionMapping.getValueColumn().getDefaultName()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertEquals("addresses", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_addresses", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("addresses", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_addresses", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.getSpecifiedOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.getSpecifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(6, attributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(6, attributeOverrideContainer.getOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("state.name"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME_ + "State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.getVirtualOverrides().iterator().next().getName()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertFalse(attributeOverrides.hasNext()); - - Iterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.name", virtualAttributeOverrides.next().getName()); - assertEquals("state.abbr", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - resourceField.moveAnnotation(1, 0, AttributeOverrideAnnotation.ANNOTATION_NAME); - - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - PersistentType persistentType = specifiedClassRefs.next().getJavaPersistentType(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - ReadOnlyAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("state").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.getVirtualOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("abbr", virtualAttributeOverride.getName()); - - PersistentType statePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping abbrMapping = (BasicMapping) statePersistentType.getAttributeNamed("abbr").getMapping(); - abbrMapping.getColumn().setSpecifiedName("BLAH"); - abbrMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - abbrMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - abbrMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - abbrMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - abbrMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - abbrMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.state) attribute override to verify it is getting settings from the specified column on State.abbr - virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("state").getMapping()).getAttributeOverrideContainer().getOverrideNamed("abbr"); - assertEquals("abbr", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - } - - public void testGetMapKeyColumn() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", elementCollectionMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_addresses", elementCollectionMapping.getMapKeyColumn().getTable());//collection table name - - elementCollectionMapping.getCollectionTable().setSpecifiedName("MY_COLLECTION_TABLE"); - assertEquals("MY_COLLECTION_TABLE", elementCollectionMapping.getMapKeyColumn().getTable()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", elementCollectionMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", elementCollectionMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", elementCollectionMapping.getMapKeyColumn().getDefaultName()); - } - - public void testMapKeyValueSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - ListIterator<JavaAttributeOverride> specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertEquals("parcels", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - - - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("parcelNumber", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - classRefs.next(); - Embeddable propertyInfoEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping parcelNumberMapping = (BasicMapping) propertyInfoEmbeddable.getPersistentType().getAttributeNamed("parcelNumber").getMapping(); - parcelNumberMapping.getColumn().setSpecifiedName("FOO1"); - parcelNumberMapping.getColumn().setSpecifiedTable("BAR1"); - parcelNumberMapping.getColumn().setColumnDefinition("COLUMN_DEF1"); - parcelNumberMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - parcelNumberMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - parcelNumberMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - parcelNumberMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", resourceField.getName()); - - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("FOO1", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR1", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF1", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - parcelNumberMapping.getColumn().setSpecifiedName(null); - parcelNumberMapping.getColumn().setSpecifiedTable(null); - parcelNumberMapping.getColumn().setColumnDefinition(null); - parcelNumberMapping.getColumn().setSpecifiedInsertable(null); - parcelNumberMapping.getColumn().setSpecifiedUpdatable(null); - parcelNumberMapping.getColumn().setSpecifiedUnique(null); - parcelNumberMapping.getColumn().setSpecifiedNullable(null); - parcelNumberMapping.getColumn().setSpecifiedLength(null); - parcelNumberMapping.getColumn().setSpecifiedPrecision(null); - parcelNumberMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("parcelNumber", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - annotation = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("value.parcelNumber"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, valueAttributeOverrideContainer.getSpecifiedOverridesSize()); - assertEquals(0, mapKeyAttributeOverrideContainer.getSpecifiedOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, valueAttributeOverrideContainer.getSpecifiedOverridesSize()); - assertEquals(1, mapKeyAttributeOverrideContainer.getSpecifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.getOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.getOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(5, mapKeyAttributeOverrideContainer.getOverridesSize()); - assertEquals(5, valueAttributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, mapKeyAttributeOverrideContainer.getOverridesSize()); - assertEquals(6, valueAttributeOverrideContainer.getOverridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.getVirtualOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.getVirtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.city"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.parcelNumber"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(2, valueAttributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.state.name"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(1, valueAttributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME_ + "PropertyInfo"); - addXmlClassRef(PACKAGE_NAME_ + "State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - valueOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - valueOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> overrideAnnotations = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - valueOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - mapKeyOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - overrideAnnotations = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - assertEquals("parcelNumber", valueOverrideContainer.getVirtualOverrides().iterator().next().getName()); - assertEquals(2, valueOverrideContainer.getVirtualOverridesSize()); - assertEquals("city", mapKeyOverrideContainer.getVirtualOverrides().iterator().next().getName()); - assertEquals(3, mapKeyOverrideContainer.getVirtualOverridesSize()); - - valueOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - mapKeyOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - overrideAnnotations = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertFalse(overrideAnnotations.hasNext()); - - Iterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = valueOverrideContainer.getVirtualOverrides().iterator(); - assertEquals("parcelNumber", virtualAttributeOverrides.next().getName()); - assertEquals("size", virtualAttributeOverrides.next().getName()); - assertEquals("tax", virtualAttributeOverrides.next().getName()); - assertEquals(3, valueOverrideContainer.getVirtualOverridesSize()); - - virtualAttributeOverrides = mapKeyOverrideContainer.getVirtualOverrides().iterator(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.name", virtualAttributeOverrides.next().getName()); - assertEquals("state.abbr", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyOverrideContainer.getVirtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - valueAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - valueAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - ListIterator<? extends AttributeOverride> specifiedOverrides = valueAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertEquals("size", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - resourceField.moveAnnotation(1, 0, AttributeOverrideAnnotation.ANNOTATION_NAME); - this.getJpaProject().synchronizeContextModel(); - getJpaProject().synchronizeContextModel(); - - Iterator<NestableAnnotation> overrideAnnotations = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - specifiedOverrides = valueAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("size", specifiedOverrides.next().getName()); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - - resourceField.moveAnnotation(3, 2, AttributeOverrideAnnotation.ANNOTATION_NAME); - this.getJpaProject().synchronizeContextModel(); - getJpaProject().synchronizeContextModel(); - - overrideAnnotations = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - specifiedOverrides = valueAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("size", specifiedOverrides.next().getName()); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } - - public void testSelfReferentialElementCollection() throws Exception { - createSelfReferentialElementCollection(); - addXmlClassRef(PACKAGE_NAME + ".Foo"); - - //If there is a StackOverflowError you will not be able to get the mapping - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("elementCollection").getMapping(); - assertFalse(elementCollectionMapping.getAllOverridableAttributeMappingNames().iterator().hasNext()); - } - - public void testSetSpecifiedMapKeyEnumerated() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertNull(elementCollectionMapping.getMapKeyConverter().getType()); - - elementCollectionMapping.setMapKeyConverter(EnumeratedConverter.class); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME); - - assertNotNull(enumerated); - assertEquals(null, enumerated.getValue()); - - ((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue()); - - ((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(null); - assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - assertNull(enumerated.getValue()); - - elementCollectionMapping.setMapKeyConverter(null); - assertNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - } - - public void testGetSpecifiedMapKeyEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getMapKeyConverter().getType()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.addAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - enumerated.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - assertNull(((EnumeratedConverter) elementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertFalse(elementCollectionMapping.isDefault()); - assertSame(elementCollectionMapping, persistentAttribute.getMapping()); - } - - public void testSetMapKeyTemporal() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertNull(elementCollectionMapping.getMapKeyConverter().getType()); - - elementCollectionMapping.setMapKeyConverter(TemporalConverter.class); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME); - - assertNotNull(temporal); - assertEquals(null, temporal.getValue()); - - ((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue()); - - ((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).setTemporalType(null); - assertNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME)); - } - - public void testGetMapKeyTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getMapKeyConverter().getType()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.addAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.TIME, ((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).getTemporalType()); - - temporal.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME)); - assertNull(((TemporalConverter) elementCollectionMapping.getMapKeyConverter()).getTemporalType()); - assertFalse(elementCollectionMapping.isDefault()); - assertSame(elementCollectionMapping, persistentAttribute.getMapping()); - } - - public void testSpecifiedMapKeyJoinColumns() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - ListIterator<? extends JoinColumn> specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - - joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - } - - public void testSpecifiedMapKeyJoinColumnsSize() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(0, elementCollectionMapping.getSpecifiedMapKeyJoinColumnsSize()); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(1, elementCollectionMapping.getSpecifiedMapKeyJoinColumnsSize()); - - elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(0, elementCollectionMapping.getSpecifiedMapKeyJoinColumnsSize()); - } - - public void testMapKeyJoinColumnsSize() throws Exception { - createTestEntityWithEntityKeyElementCollectionMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(1, elementCollectionMapping.getMapKeyJoinColumnsSize()); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(1, elementCollectionMapping.getMapKeyJoinColumnsSize()); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(2, elementCollectionMapping.getMapKeyJoinColumnsSize()); - - elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(1, elementCollectionMapping.getMapKeyJoinColumnsSize()); - } - - public void testAddSpecifiedMapKeyJoinColumn() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAR"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedMapKeyJoinColumn2() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertEquals(3, resourceField.getAnnotationsSize(JPA2_0.MAP_KEY_JOIN_COLUMN)); - - elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(1); - - Iterator<NestableAnnotation> joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<? extends JoinColumn> joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(1); - joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - elementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(resourceField.getAnnotation(0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - Iterator<NestableAnnotation> javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - elementCollectionMapping.moveSpecifiedMapKeyJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getSpecifiedName()); - assertEquals("BAZ", joinColumns.next().getSpecifiedName()); - assertEquals("FOO", joinColumns.next().getSpecifiedName()); - - javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - - - elementCollectionMapping.moveSpecifiedMapKeyJoinColumn(0, 1); - joinColumns = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getSpecifiedName()); - assertEquals("BAR", joinColumns.next().getSpecifiedName()); - assertEquals("FOO", joinColumns.next().getSpecifiedName()); - - javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedMapKeyJoinColumns() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("FOO"); - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAR"); - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(2, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends JoinColumn> joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.moveAnnotation(2, 0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.moveAnnotation(0, 1, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testMapKeyJoinColumnIsDefault() throws Exception { - createTestEntityWithEntityKeyElementCollectionMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertTrue(elementCollectionMapping.getDefaultMapKeyJoinColumn().isDefault()); - - elementCollectionMapping.addSpecifiedMapKeyJoinColumn(0); - JoinColumn specifiedJoinColumn = elementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator().next(); - assertFalse(specifiedJoinColumn.isDefault()); - - assertNull(elementCollectionMapping.getDefaultMapKeyJoinColumn()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedIdMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedIdMapping2_0Tests.java deleted file mode 100644 index a8557f089f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedIdMapping2_0Tests.java +++ /dev/null @@ -1,368 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaEmbeddedIdMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@EmbeddedId").append(CR); - sb.append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME +" myEmbeddedId;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - - public GenericJavaEmbeddedIdMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((JavaEmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().getOverrides().iterator().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - - assertNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java deleted file mode 100644 index 194856a99c..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java +++ /dev/null @@ -1,1608 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AssociationOverride; -import org.eclipse.jpt.jpa.core.context.AttributeOverride; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.Embeddable; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.VirtualJoinColumn; -import org.eclipse.jpt.jpa.core.context.VirtualJoinColumnRelationship; -import org.eclipse.jpt.jpa.core.context.VirtualJoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.VirtualJoinTable; -import org.eclipse.jpt.jpa.core.context.VirtualJoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaEmbeddedMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createAddressEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Address {"); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - public GenericJavaEmbeddedMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((JavaEmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().getOverrides().iterator().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof JavaEmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testDefaultEmbeddedMappingGenericEmbeddable() throws Exception { - createTestEntityWithDefaultEmbeddedMapping(); - createTestGenericEmbeddable(); - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Embeddable1"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbeddable"); - assertNotNull(persistentAttribute.getMapping()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - private void createTestEntityWithDefaultEmbeddedMapping() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 { ").append(CR); - sb.append("private Embeddable1<Integer> myEmbeddable;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericEmbeddable() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class Embeddable1<T> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Embeddable1.java", sourceWriter); - } - - private void createSelfReferentialEmbedded() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Foo embedded;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - - assertNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertEquals("myEmbedded", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbedded", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.getSpecifiedOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.getSpecifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.getOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.getVirtualOverrides().iterator().next().getName()); - assertEquals(1, attributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertFalse(attributeOverrides.hasNext()); - - Iterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - resourceField.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) resourceField.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - resourceField.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - VirtualJoinColumnRelationshipStrategy joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.getJoinColumnsSize()); - VirtualJoinColumn virtualJoinColumn = joiningStrategy.getJoinColumns().iterator().next(); - assertEquals("address_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaPersistentType javaEmbeddable = classRefs.next().getJavaPersistentType(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) javaEmbeddable.getAttributeNamed("address").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.getJoinColumnsSize()); - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - virtualJoinColumn = joiningStrategy.getJoinColumns().iterator().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.getJoinColumns().iterator().next().getName()); - - - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.getSpecifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(0, overrideContainer.getVirtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getOverridesSize()); - - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, overrideContainer.getOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - Iterator<NestableAnnotation> associationOverrides = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("addresses", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator<JavaVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - Iterator<NestableAnnotation> associationOverrides = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - - assertEquals("addresses", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - assertEquals(2, CollectionTools.size(resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator())); - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - - Iterator<NestableAnnotation> associationOverrideResources = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals("addresses", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator<JavaAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("addresses", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - associationOverrideResources = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - Iterator<NestableAnnotation> javaAssociationOverrides = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator<JavaAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("addresses", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - javaAssociationOverrides = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals("addresses", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("addresses", associationOverrides.next().getName()); - - javaAssociationOverrides = resourceField.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("addresses", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - ((AssociationOverrideAnnotation) resourceField.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE)).setName("FOO"); - ((AssociationOverrideAnnotation) resourceField.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE)).setName("BAR"); - ((AssociationOverrideAnnotation) resourceField.addAnnotation(2, JPA.ASSOCIATION_OVERRIDE)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<JavaAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceField.moveAnnotation(2, 0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceField.moveAnnotation(0, 1, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceField.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceField.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator<JavaVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - ReadOnlyAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - - public void testVirtualAssociationOverrideJoinTableDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = CollectionTools.get(overrideContainer.getVirtualOverrides(), 1); - VirtualJoinTableRelationshipStrategy joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - VirtualJoinTable joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals("AnnotationTestType_Address", joinTable.getName()); - assertEquals(1, joinTable.getJoinColumnsSize()); - VirtualJoinColumn virtualJoinColumn = joinTable.getJoinColumns().iterator().next(); - assertEquals("AnnotationTestType_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.getInverseJoinColumnsSize()); - VirtualJoinColumn virtualInverseJoinColumn = joinTable.getInverseJoinColumns().iterator().next(); - assertEquals("addresses_id", virtualInverseJoinColumn.getName()); - assertEquals("id", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualInverseJoinColumn.getTable()); - assertEquals(null, virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(true, virtualInverseJoinColumn.isInsertable()); - assertEquals(true, virtualInverseJoinColumn.isUpdatable()); - assertEquals(false, virtualInverseJoinColumn.isUnique()); - assertEquals(true, virtualInverseJoinColumn.isNullable()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaPersistentType javaEmbeddable = classRefs.next().getJavaPersistentType(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) javaEmbeddable.getAttributeNamed("addresses").getMapping(); - JoinTableRelationshipStrategy joinTableStrategy = oneToManyMapping.getRelationship().getJoinTableStrategy(); - joinTableStrategy.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = joinTableStrategy.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumn inverseJoinColumn = joinTableStrategy.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("MY_INVERSE_JOIN_COLUMN"); - inverseJoinColumn.setSpecifiedReferencedColumnName("MY_INVERSE_REFERENCE_COLUMN"); - inverseJoinColumn.setSpecifiedTable("INVERSE_BAR"); - inverseJoinColumn.setColumnDefinition("INVERSE_COLUMN_DEF"); - inverseJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUnique(Boolean.TRUE); - inverseJoinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = CollectionTools.get(overrideContainer.getVirtualOverrides(), 1); - joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals(1, joinTable.getJoinColumnsSize()); - virtualJoinColumn = joinTable.getJoinColumns().iterator().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.getInverseJoinColumnsSize()); - virtualInverseJoinColumn = joinTable.getInverseJoinColumns().iterator().next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - assertEquals("INVERSE_COLUMN_DEF", virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(false, virtualInverseJoinColumn.isInsertable()); - assertEquals(false, virtualInverseJoinColumn.isUpdatable()); - assertEquals(true, virtualInverseJoinColumn.isUnique()); - assertEquals(false, virtualInverseJoinColumn.isNullable()); - - - assertNull(resourceField.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(5, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - JavaEmbeddedMapping nestedEmbeddedMapping = (JavaEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - JavaAttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.getVirtualOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((JavaEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((JavaEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((JavaEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - virtualAttributeOverride = (VirtualAttributeOverride) ((JavaEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testSelfReferentialEmbeddedMapping() throws Exception { - createSelfReferentialEmbedded(); - addXmlClassRef(PACKAGE_NAME + ".Foo"); - - //If there is a StackOverflowError you will not be able to get the mapping - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("embedded").getMapping(); - assertFalse(embeddedMapping.getAllOverridableAttributeMappingNames().iterator().hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java deleted file mode 100644 index 7c9ee50303..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java +++ /dev/null @@ -1,2057 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AssociationOverride; -import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.AttributeOverride; -import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.Entity; -import org.eclipse.jpt.jpa.core.context.InheritanceType; -import org.eclipse.jpt.jpa.core.context.JoinTable; -import org.eclipse.jpt.jpa.core.context.MappedSuperclass; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaEntity; -import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Cacheable2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.NamedQuery2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaEntity2_0Tests extends Generic2_0ContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public GenericJavaEntity2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - private void createTestMappedSuperclassCustomerWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<Address> address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEntityLongTimeCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("LongTimeCustomer extends Customer "); - sb.append("{}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "LongTimeCustomer.java", sourceWriter); - } - - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@AssociationOverride(name=\"a\", joinTable=@JoinTable)"); - } - }); - } - - - private LockModeType2_0 lockModeOf(NamedQuery2_0Annotation resourceQuery) { - return resourceQuery == null ? null : LockModeType2_0.fromJavaResourceModel(resourceQuery.getLockMode()); - } - - public void testAddNamedQuery2_0() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = this.getJavaEntity(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(0); - namedQuery1.setName("FOO"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - Iterator<NestableAnnotation> javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - NamedQuery2_0Annotation queryAnnotation = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("FOO", queryAnnotation.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(queryAnnotation)); - - NamedQuery2_0 namedQuery2 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.READ); - - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - queryAnnotation = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", queryAnnotation.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(queryAnnotation)); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - - NamedQuery2_0 namedQuery3 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - namedQuery3.setSpecifiedLockMode(LockModeType2_0.WRITE); - - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals("BAR", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - queryAnnotation = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAZ", queryAnnotation.getName()); - assertEquals(LockModeType2_0.WRITE, this.lockModeOf(queryAnnotation)); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery1, namedQueries.next()); - - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("foo"); - } - - public void testRemoveNamedQuery2_0() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.READ); - - NamedQuery2_0 namedQuery2 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(2); - namedQuery2.setName("BAZ"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - Iterator<NestableAnnotation> javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - NamedQuery2_0Annotation annotation1 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", annotation1.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(annotation1)); - - NamedQuery2_0Annotation annotation2 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAZ", annotation2.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation2)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - annotation2 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAZ", annotation2.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation2)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testMoveNamedQuery2_0() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - NamedQuery2_0Annotation annotation1 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", annotation1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation1)); - assertEquals("BAZ", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAZ", namedQueries.next().getName()); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = resourceType.getAnnotations(JPA.NAMED_QUERY).iterator(); - assertEquals("BAZ", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - annotation1 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", annotation1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation1)); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedQueries2_0() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - assertEquals(0, entity.getPersistenceUnit().getQueriesSize()); - - ((NamedQuery2_0Annotation) resourceType.addAnnotation(0, JPA.NAMED_QUERY)).setName("FOO"); - ((NamedQuery2_0Annotation) resourceType.addAnnotation(1, JPA.NAMED_QUERY)).setName("BAR"); - NamedQuery2_0Annotation annotation1 = (NamedQuery2_0Annotation) resourceType.addAnnotation(1, JPA.NAMED_QUERY); - annotation1.setName("BAZ"); - annotation1.setLockMode(org.eclipse.jpt.jpa.core.jpa2.resource.java.LockModeType_2_0.OPTIMISTIC); - getJpaProject().synchronizeContextModel(); - - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("FOO", namedQueries.next().getName()); - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAR", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().getQueriesSize()); - - resourceType.moveAnnotation(2, 0, NamedQueryAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - resourceType.moveAnnotation(0, 1, NamedQueryAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAR", namedQueries.next().getName()); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - resourceType.removeAnnotation(1, JPA.NAMED_QUERY); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().getQueriesSize()); - - resourceType.removeAnnotation(1, JPA.NAMED_QUERY); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAR", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().getQueriesSize()); - - resourceType.removeAnnotation(0, JPA.NAMED_QUERY); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().getNamedQueries().iterator(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().getQueriesSize()); - } - - public void testNamedQueries2_0Size() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - assertEquals(0, entity.getQueryContainer().getNamedQueriesSize()); - - ((NamedQuery2_0Annotation) resourceType.addAnnotation(0, JPA.NAMED_QUERY)).setName("FOO"); - ((NamedQuery2_0Annotation) resourceType.addAnnotation(1, JPA.NAMED_QUERY)).setName("BAR"); - ((NamedQuery2_0Annotation) resourceType.addAnnotation(2, JPA.NAMED_QUERY)).setName("BAZ"); - - this.getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().getNamedQueriesSize()); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().getOverridableAttributeNames().iterator(); - assertFalse(overridableAttributes.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = getJavaEntity().getOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = getJavaEntity().getOverridableAttributeNames().iterator(); - assertFalse(overridableAttributeNames.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = getJavaEntity().getOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAttributes = abstractEntity.getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAssociations = abstractEntity.getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = getJavaEntity().getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - ListIterator<? extends AttributeOverride> specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceType.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceType.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceType.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceType.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - resourceType.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - resourceType.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - resourceType.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - } - - public void testVirtualAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceType.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceType.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.getSpecifiedOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(0, overrideContainer.getVirtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(3, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(3, overrideContainer.getOverridesSize()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) resourceType.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, overrideContainer.getOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - Iterator<NestableAnnotation> attributeOverrides = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - Iterator<NestableAnnotation> attributeOverrides = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - assertEquals(3, CollectionTools.size(resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator())); - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - - Iterator<NestableAnnotation> attributeOverrideResources = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator<? extends AttributeOverride> attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrideResources = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrideResources = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(attributeOverrides.hasNext()); - - assertNull(resourceType.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - - Iterator<NestableAnnotation> javaAttributeOverrides = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator<? extends AttributeOverride> attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("name", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = resourceType.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("name", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - } -// - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - ((AttributeOverrideAnnotation) resourceType.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE)).setName("FOO"); - ((AttributeOverrideAnnotation) resourceType.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE)).setName("BAR"); - ((AttributeOverrideAnnotation) resourceType.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends AttributeOverride> attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - resourceType.moveAnnotation(2, 0, AttributeOverrideAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - resourceType.moveAnnotation(0, 1, AttributeOverrideAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - resourceType.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - resourceType.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - resourceType.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = overrideContainer.getVirtualOverrides().iterator(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - - public void testOverridableAssociations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().getOverridableAssociationNames().iterator(); - assertFalse(overridableAssociations.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = getJavaEntity().getOverridableAssociationNames().iterator(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = getJavaEntity().getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertEquals("address3", overridableAssociationNames.next()); - assertEquals("address4", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<? extends AssociationOverride> specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) resourceType.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) resourceType.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) resourceType.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceType.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - resourceType.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - resourceType.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - resourceType.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.getVirtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - - //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); - //idMapping.getColumn().setSpecifiedName("FOO"); - //idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - //idMapping.getColumn().setSpecifiedName(null); - //idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, resourceType.getName()); - assertNull(resourceType.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, resourceType.getName()); -//// assertNull(resourceType.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(resourceType.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, resourceType.getName()); -//// assertNull(resourceType.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(resourceType.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) resourceType.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) resourceType.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.getSpecifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(0, overrideContainer.getVirtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(4, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(4, overrideContainer.getOverridesSize()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) resourceType.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, overrideContainer.getOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - Iterator<NestableAnnotation> associationOverrides = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ListIterator<? extends VirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - Iterator<NestableAnnotation> associationOverrides = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - assertEquals(2, CollectionTools.size(resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator())); - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - - Iterator<NestableAnnotation> associationOverrideResources = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator<? extends AssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - associationOverrideResources = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - - assertNull(resourceType.getAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_SUB_TYPE_NAME, Kind.TYPE); - - Iterator<NestableAnnotation> javaAssociationOverrides = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedOverride(1, 0); - Iterator<? extends AssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - javaAssociationOverrides = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals("address2", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - javaAssociationOverrides = resourceType.getAnnotations(JPA.ASSOCIATION_OVERRIDE).iterator(); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address2", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - - ((AssociationOverrideAnnotation) resourceType.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE)).setName("FOO"); - ((AssociationOverrideAnnotation) resourceType.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE)).setName("BAR"); - ((AssociationOverrideAnnotation) resourceType.addAnnotation(2, JPA.ASSOCIATION_OVERRIDE)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends AssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceType.moveAnnotation(2, 0, AssociationOverrideAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceType.moveAnnotation(0, 1, AssociationOverrideAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceType.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceType.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceType.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ListIterator<JavaVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - JavaVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AttributeOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAttributeOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AttributeOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AssociationOverrideContainer associationOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, associationOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends VirtualAssociationOverride> virtualAssociationOverrides = associationOverrideContainer.getVirtualOverrides().iterator(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testNestedVirtualAssociationOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AssociationOverrideContainer associationOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, associationOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends VirtualAssociationOverride> virtualAssociationOverrides = associationOverrideContainer.getVirtualOverrides().iterator(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testSetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheable.setSpecifiedCacheable(null); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testGetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - getJavaPersistentType().getJavaResourceType().addAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(true)", cu); - - cacheableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - getJavaPersistentType().getJavaResourceType().removeAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testIsDefaultCacheable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - assertEquals(SharedCacheMode.UNSPECIFIED, persistenceUnit2_0.getSharedCacheMode()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testInheritedIsDefaultCacheable() throws Exception { - createTestEntity(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity().getParentEntity()).getCacheable(); - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - - //This is a test for bug 301892 - public void testAssociationOverrideJoinTableUpdate() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverride associationOverride = getJavaEntity().getAssociationOverrideContainer().getSpecifiedOverrides().iterator().next(); - assertEquals("a", associationOverride.getName()); - - AssociationOverride2_0Annotation annotation = (AssociationOverride2_0Annotation) getJavaPersistentType().getJavaResourceType().getAnnotation(0, JPA.ASSOCIATION_OVERRIDE); - annotation.getJoinTable().setName("FOO"); - annotation.getJoinTable().addInverseJoinColumn(0).setName("BAR"); - - getJpaProject().synchronizeContextModel(); - - associationOverride = getJavaEntity().getAssociationOverrideContainer().getSpecifiedOverrides().iterator().next(); - assertEquals("a", associationOverride.getName()); - JoinTable joinTable = ((JavaOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("BAR", joinTable.getInverseJoinColumns().iterator().next().getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaIdMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaIdMapping2_0Tests.java deleted file mode 100644 index 263c0dde49..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaIdMapping2_0Tests.java +++ /dev/null @@ -1,423 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaIdMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - public GenericJavaIdMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME));//OneToOne with Id annotation is valid in JPA 2.0 - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME));//ManyToOne with Id annotation is valid in JPA 2.0 - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - - assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java deleted file mode 100644 index 7abad6b13f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java +++ /dev/null @@ -1,1953 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.Embeddable; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.Entity; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ManyToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaManyToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyTemporal2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaManyToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaManyToManyMapping2_0Tests(String name) { - super(name); - } - - - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map<Integer, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Collection<AnnotationTestType> employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<State> state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private String address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithEntityKeyManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityPropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employees", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employees", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - resourceField.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - resourceField.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKey(null); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - mapKey = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKey.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping2_0 = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> mapKeyNames = - manyToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employees", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping2_0 = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> mapKeyNames = manyToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - manyToManyMapping2_0.setSpecifiedTargetEntity("Address"); - mapKeyNames = manyToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employees", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - manyToManyMapping2_0.setSpecifiedTargetEntity("String"); - mapKeyNames = manyToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - resourceField.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", manyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - resourceField.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", manyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", manyToManyMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", manyToManyMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", manyToManyMapping.getMapKeyClass()); - - manyToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", manyToManyMapping.getMapKeyClass()); - - manyToManyMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", manyToManyMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - addXmlClassRef(PACKAGE_NAME + ".PrintQueue"); - addXmlClassRef(PACKAGE_NAME + ".PrintJob"); - JavaPersistentType printQueuePersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintQueue"); - ManyToManyMapping jobsMapping = (ManyToManyMapping) printQueuePersistentType.getAttributeNamed("jobs").getMapping(); - JavaPersistentType printJobPersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ManyToManyMapping queuesMapping = (ManyToManyMapping) printJobPersistentType.getAttributeNamed("queues").getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - OrderColumn2_0 jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(null, jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); //the join table name - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - OrderColumn2_0 queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(null, queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - jobsOrderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderColumn.setSpecifiedName("BAR"); - assertEquals("BAR", queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - assertEquals("MY_TABLE_PrintQueue", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printQueuePersistentType.getMapping()).getTable().setSpecifiedName("OTHER_TABLE"); - assertEquals("MY_TABLE_OTHER_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_OTHER_TABLE", queuesOrderColumn.getTable()); - - queuesMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_JOIN_TABLE", queuesOrderColumn.getTable()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany(mappedBy=\"queues\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List<PrintJob> jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List<PrintQueue> queues;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testGetMapKeyColumn() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", manyToManyMapping.getMapKeyColumn().getTable());//join table name - - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnMappedByStrategy() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - manyToManyMapping.getRelationship().setStrategyToMappedBy(); - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("employees"); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address_" + TYPE_NAME, manyToManyMapping.getMapKeyColumn().getTable());//join table name of owning many-to-many - - PersistentType persistentType = getPersistenceUnit().getPersistentType("test.Address"); - ManyToManyMapping owningManyToManyMapping = (ManyToManyMapping) persistentType.getAttributeNamed("employees").getMapping(); - ((JoinTableRelationshipStrategy) owningManyToManyMapping.getRelationship().getStrategy()).getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnJoinTableStrategy() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", manyToManyMapping.getMapKeyColumn().getTable());//join table name - - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - - public void testMapKeySpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertEquals("parcels", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, mapKeyAttributeOverrideContainer.getSpecifiedOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, mapKeyAttributeOverrideContainer.getSpecifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.getOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(7, mapKeyAttributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.state.foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.getOverridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.state.foo"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertFalse(attributeOverrides.hasNext()); - - Iterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.foo", virtualAttributeOverrides.next().getName()); - assertEquals("state.address", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - ListIterator<JavaAttributeOverride> specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - resourceField.moveAnnotation(1, 0, AttributeOverrideAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } - - public void testSetSpecifiedMapKeyEnumerated() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping(); - assertNull(manyToManyMapping.getMapKeyConverter().getType()); - - manyToManyMapping.setMapKeyConverter(EnumeratedConverter.class); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME); - - assertNotNull(enumerated); - assertEquals(null, enumerated.getValue()); - - ((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue()); - - ((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(null); - assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - assertNull(enumerated.getValue()); - - manyToManyMapping.setMapKeyConverter(null); - assertNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - } - - public void testGetSpecifiedMapKeyEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyConverter().getType()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.addAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - enumerated.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - assertNull(((EnumeratedConverter) manyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertFalse(manyToManyMapping.isDefault()); - assertSame(manyToManyMapping, persistentAttribute.getMapping()); - } - - public void testSetMapKeyTemporal() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping(); - assertNull(manyToManyMapping.getMapKeyConverter().getType()); - - manyToManyMapping.setMapKeyConverter(TemporalConverter.class); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME); - - assertNotNull(temporal); - assertEquals(null, temporal.getValue()); - - ((TemporalConverter) manyToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue()); - - ((TemporalConverter) manyToManyMapping.getMapKeyConverter()).setTemporalType(null); - assertNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME)); - } - - public void testGetMapKeyTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyConverter().getType()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.addAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.TIME, ((TemporalConverter) manyToManyMapping.getMapKeyConverter()).getTemporalType()); - - temporal.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME)); - assertNull(((TemporalConverter) manyToManyMapping.getMapKeyConverter()).getTemporalType()); - assertFalse(manyToManyMapping.isDefault()); - assertSame(manyToManyMapping, persistentAttribute.getMapping()); - } - - public void testSpecifiedMapKeyJoinColumns() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - ListIterator<? extends JoinColumn> specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - - joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - } - - public void testSpecifiedMapKeyJoinColumnsSize() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals(0, manyToManyMapping.getSpecifiedMapKeyJoinColumnsSize()); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(1, manyToManyMapping.getSpecifiedMapKeyJoinColumnsSize()); - - manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(0, manyToManyMapping.getSpecifiedMapKeyJoinColumnsSize()); - } - - public void testMapKeyJoinColumnsSize() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals(1, manyToManyMapping.getMapKeyJoinColumnsSize()); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(1, manyToManyMapping.getMapKeyJoinColumnsSize()); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(2, manyToManyMapping.getMapKeyJoinColumnsSize()); - - manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(1, manyToManyMapping.getMapKeyJoinColumnsSize()); - } - - public void testAddSpecifiedMapKeyJoinColumn() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAR"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedMapKeyJoinColumn2() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertEquals(3, resourceField.getAnnotationsSize(JPA2_0.MAP_KEY_JOIN_COLUMN)); - - manyToManyMapping.removeSpecifiedMapKeyJoinColumn(1); - - Iterator<NestableAnnotation> joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<? extends JoinColumn> joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - manyToManyMapping.removeSpecifiedMapKeyJoinColumn(1); - joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - manyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(resourceField.getAnnotation(0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - manyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - Iterator<NestableAnnotation> javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - manyToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getSpecifiedName()); - assertEquals("BAZ", joinColumns.next().getSpecifiedName()); - assertEquals("FOO", joinColumns.next().getSpecifiedName()); - - javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - - - manyToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1); - joinColumns = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getSpecifiedName()); - assertEquals("BAR", joinColumns.next().getSpecifiedName()); - assertEquals("FOO", joinColumns.next().getSpecifiedName()); - - javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedMapKeyJoinColumns() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("FOO"); - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAR"); - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(2, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends JoinColumn> joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.moveAnnotation(2, 0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.moveAnnotation(0, 1, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testMapKeyJoinColumnIsDefault() throws Exception { - createTestEntityWithEntityKeyManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertTrue(manyToManyMapping.getDefaultMapKeyJoinColumn().isDefault()); - - manyToManyMapping.addSpecifiedMapKeyJoinColumn(0); - JoinColumn specifiedJoinColumn = manyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().next(); - assertFalse(specifiedJoinColumn.isDefault()); - - assertNull(manyToManyMapping.getDefaultMapKeyJoinColumn()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java deleted file mode 100644 index 8d38365920..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java +++ /dev/null @@ -1,682 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaIdMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaDerivedIdentity2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaManyToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaManyToOneMapping2_0Tests(String name) { - super(name); - } - - - private ICompilationUnit createTestEntityWithManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdDerivedIdentity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceField.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceField.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - annotation.setValue("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceField.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("foo"); - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("bar"); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName(null); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceField.addAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceField.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceField.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaIdMapping); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaManyToOneMapping2_0); - - contextAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaBasicMapping); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping2_0 mapping = (ManyToOneMapping2_0) contextAttribute.getMapping(); - ManyToOneRelationship2_0 rel = (ManyToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().getAttributes().iterator().next(); - ManyToOneMapping2_0 mapping = (ManyToOneMapping2_0) contextAttribute.getMapping(); - ManyToOneRelationship2_0 rel = (ManyToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceField.addAnnotation(0, JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceField.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - resourceField.removeAnnotation(0, JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - resourceField.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java deleted file mode 100644 index bf70de9c6a..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java +++ /dev/null @@ -1,2214 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.Embeddable; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.Entity; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinColumnRelationship; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOrphanRemovable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyTemporal2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.OneToMany2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaOneToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaOneToManyMapping2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(orphanRemoval=false)").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map<Integer, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private AnnotationTestType employee;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<State> state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private String address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithEntityKeyOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map<Address, PropertyInfo> parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityPropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employee", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employee", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - private JavaOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) { - return ((JavaOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval(); - } - - public void testDefaultOneToManyGetDefaultOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToManyMapping).isDefaultOrphanRemoval()); - } - - public void testSpecifiedOneToManyGetDefaultOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToManyMapping).isDefaultOrphanRemoval()); - } - - public void testGetOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertEquals(false, mappingsOrphanRemoval.isOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(true, mappingsOrphanRemoval.isOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_MANY); - oneToMany.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testSetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_MANY); - - assertEquals(Boolean.TRUE, oneToMany.getOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(resourceField.getAnnotation(JPA.ONE_TO_MANY)); // .getElement); - } - - public void testSetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_MANY); - - assertEquals(Boolean.TRUE, oneToMany.getOrphanRemoval()); - - oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(resourceField.getAnnotation(JPA.ONE_TO_MANY)); - - oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - } - - public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_MANY); - oneToMany.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - oneToMany.setOrphanRemoval(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertSame(oneToManyMapping, persistentAttribute.getMapping()); - - oneToMany.setOrphanRemoval(Boolean.FALSE); - resourceField.setPrimaryAnnotation(null, EmptyIterable.<String>instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - resourceField.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - resourceField.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKey(null); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) resourceField.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping2_0 = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - Iterator<String> mapKeyNames = - oneToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employee", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping2_0 = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - Iterator<String> mapKeyNames = oneToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - oneToManyMapping2_0.setSpecifiedTargetEntity("Address"); - mapKeyNames = oneToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employee", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - oneToManyMapping2_0.setSpecifiedTargetEntity("String"); - mapKeyNames = oneToManyMapping2_0.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - resourceField.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - resourceField.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(resourceField.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", oneToManyMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", oneToManyMapping.getMapKeyClass()); - - oneToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", oneToManyMapping.getMapKeyClass()); - - oneToManyMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", oneToManyMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - addXmlClassRef(PACKAGE_NAME + ".PrintQueue"); - addXmlClassRef(PACKAGE_NAME + ".PrintJob"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) getJavaPersistentType().getAttributeNamed("jobs").getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - JavaPersistentType printJobPersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - - assertEquals("MY_TABLE", orderColumn.getTable()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @OneToMany(mappedBy=\"queue\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List<PrintJob> jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private PrintQueue queue;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testGetMapKeyColumnMappedByStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - oneToManyMapping.getRelationship().setStrategyToMappedBy(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("employee"); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//owing entity table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnJoinTableStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", oneToManyMapping.getMapKeyColumn().getTable());//join table name - - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testTargetForeignKeyJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - JoinColumn joinColumn = ((JoinColumnRelationship) oneToManyMapping.getRelationship()).getJoinColumnStrategy().getSpecifiedJoinColumns().iterator().next(); - - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("Address", joinColumn.getDefaultTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - joinColumn.setSpecifiedName("FOO"); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - } - - //target foreign key case - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - } - - //target foreign key case - public void testOrderColumnDefaultsJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - ((Orderable2_0) oneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("Address", orderColumn.getTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceField.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); - OneToManyRelationship2_0 rel = (OneToManyRelationship2_0) mapping.getRelationship(); - - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceField.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); - OneToManyRelationship2_0 rel = (OneToManyRelationship2_0) mapping.getRelationship(); - - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceField.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceField.addAnnotation(0, JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceField.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceField.removeAnnotation(0, JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testMapKeySpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - resourceField.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - assertEquals("parcels", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", resourceField.getName()); - assertNull(resourceField.getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, mapKeyAttributeOverrideContainer.getSpecifiedOverridesSize()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, mapKeyAttributeOverrideContainer.getSpecifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.getOverridesSize()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(7, mapKeyAttributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.getOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.state.foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.getOverridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("key.state.foo"); - attributeOverride = (AttributeOverrideAnnotation) resourceField.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - assertFalse(attributeOverrides.hasNext()); - - Iterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.foo", virtualAttributeOverrides.next().getName()); - assertEquals("state.address", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.getVirtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - ListIterator<JavaAttributeOverride> specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - - resourceField.moveAnnotation(1, 0, AttributeOverrideAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator<NestableAnnotation> attributeOverrides = resourceField.getAnnotations(JPA.ATTRIBUTE_OVERRIDE).iterator(); - - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } - - public void testSetSpecifiedMapKeyEnumerated() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping(); - assertNull(oneToManyMapping.getMapKeyConverter().getType()); - - oneToManyMapping.setMapKeyConverter(EnumeratedConverter.class); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME); - - assertNotNull(enumerated); - assertEquals(null, enumerated.getValue()); - - ((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue()); - - ((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(null); - assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - assertNull(enumerated.getValue()); - - oneToManyMapping.setMapKeyConverter(null); - assertNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - } - - public void testGetSpecifiedMapKeyEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getMapKeyConverter().getType()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) resourceField.addAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - enumerated.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(MapKeyEnumerated2_0Annotation.ANNOTATION_NAME)); - assertNull(((EnumeratedConverter) oneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertFalse(oneToManyMapping.isDefault()); - assertSame(oneToManyMapping, persistentAttribute.getMapping()); - } - - public void testSetMapKeyTemporal() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping(); - assertNull(oneToManyMapping.getMapKeyConverter().getType()); - - oneToManyMapping.setMapKeyConverter(TemporalConverter.class); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME); - - assertNotNull(temporal); - assertEquals(null, temporal.getValue()); - - ((TemporalConverter) oneToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue()); - - ((TemporalConverter) oneToManyMapping.getMapKeyConverter()).setTemporalType(null); - assertNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME)); - } - - public void testGetMapKeyTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getMapKeyConverter().getType()); - - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) resourceField.addAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.TIME, ((TemporalConverter) oneToManyMapping.getMapKeyConverter()).getTemporalType()); - - temporal.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(MapKeyTemporal2_0Annotation.ANNOTATION_NAME)); - assertNull(((TemporalConverter) oneToManyMapping.getMapKeyConverter()).getTemporalType()); - assertFalse(oneToManyMapping.isDefault()); - assertSame(oneToManyMapping, persistentAttribute.getMapping()); - } - - public void testSpecifiedMapKeyJoinColumns() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - ListIterator<? extends JoinColumn> specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - //add an annotation to the resource model and verify the context model is updated - MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - - joinColumn = (MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceField.moveAnnotation(1, 0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", specifiedMapKeyJoinColumns.next().getName()); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", specifiedMapKeyJoinColumns.next().getName()); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyJoinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(specifiedMapKeyJoinColumns.hasNext()); - } - - public void testSpecifiedMapKeyJoinColumnsSize() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals(0, oneToManyMapping.getSpecifiedMapKeyJoinColumnsSize()); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(1, oneToManyMapping.getSpecifiedMapKeyJoinColumnsSize()); - - oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(0, oneToManyMapping.getSpecifiedMapKeyJoinColumnsSize()); - } - - public void testMapKeyJoinColumnsSize() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals(1, oneToManyMapping.getMapKeyJoinColumnsSize()); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(1, oneToManyMapping.getMapKeyJoinColumnsSize()); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0); - assertEquals(2, oneToManyMapping.getMapKeyJoinColumnsSize()); - - oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(1, oneToManyMapping.getMapKeyJoinColumnsSize()); - } - - public void testAddSpecifiedMapKeyJoinColumn() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAR"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedMapKeyJoinColumn2() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - assertEquals(3, resourceField.getAnnotationsSize(JPA2_0.MAP_KEY_JOIN_COLUMN)); - - oneToManyMapping.removeSpecifiedMapKeyJoinColumn(1); - - Iterator<NestableAnnotation> joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<? extends JoinColumn> joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - oneToManyMapping.removeSpecifiedMapKeyJoinColumn(1); - joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - oneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - joinColumnResources = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(resourceField.getAnnotation(0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - oneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - Iterator<NestableAnnotation> javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - oneToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getSpecifiedName()); - assertEquals("BAZ", joinColumns.next().getSpecifiedName()); - assertEquals("FOO", joinColumns.next().getSpecifiedName()); - - javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - - - oneToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1); - joinColumns = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getSpecifiedName()); - assertEquals("BAR", joinColumns.next().getSpecifiedName()); - assertEquals("FOO", joinColumns.next().getSpecifiedName()); - - javaJoinColumns = resourceField.getAnnotations(JPA2_0.MAP_KEY_JOIN_COLUMN).iterator(); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedMapKeyJoinColumns() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("FOO"); - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAR"); - ((MapKeyJoinColumn2_0Annotation) resourceField.addAnnotation(2, JPA2_0.MAP_KEY_JOIN_COLUMN)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends JoinColumn> joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.moveAnnotation(2, 0, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.moveAnnotation(0, 1, MapKeyJoinColumn2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - resourceField.removeAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testMapKeyJoinColumnIsDefault() throws Exception { - createTestEntityWithEntityKeyOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertTrue(oneToManyMapping.getDefaultMapKeyJoinColumn().isDefault()); - - oneToManyMapping.addSpecifiedMapKeyJoinColumn(0); - JoinColumn specifiedJoinColumn = oneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().next(); - assertFalse(specifiedJoinColumn.isDefault()); - - assertNull(oneToManyMapping.getDefaultMapKeyJoinColumn()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java deleted file mode 100644 index bd18b5f42f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java +++ /dev/null @@ -1,1141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaDerivedIdentity2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOrphanRemovable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.OneToOne2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaOneToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaOneToOneMapping2_0Tests(String name) { - super(name); - } - - - private void createTestEntity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithIdDerivedIdentity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(orphanRemoval=false)"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<State> state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceField.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceField.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - annotation.setValue("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceField.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("foo"); - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("bar"); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName(null); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceField.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceField.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceField.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceField.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - - ((MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID)).setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceField.getAnnotation(JPA.ID)); - assertFalse(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertFalse(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertFalse(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceField.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceField.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - private JavaOrphanRemovable2_0 getOrphanRemovalOf(OneToOneMapping2_0 oneToOneMapping) { - return ((JavaOrphanRemovalHolder2_0) oneToOneMapping).getOrphanRemoval(); - } - - public void testDefaultOneToOneGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToOneMapping).isDefaultOrphanRemoval()); - } - - public void testSpecifiedOneToOneGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToOneMapping).isDefaultOrphanRemoval()); - } - - public void testGetOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertEquals(false, mappingsOrphanRemoval.isOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(true, mappingsOrphanRemoval.isOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_ONE); - oneToOne.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - - assertEquals(Boolean.FALSE, this.getOrphanRemovalOf(oneToOneMapping).getSpecifiedOrphanRemoval()); - } - - public void testSetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_ONE); - - assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(resourceField.getAnnotation(JPA.ONE_TO_ONE)); // .getElement); - } - - public void testSetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_ONE); - - assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); - - oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(resourceField.getAnnotation(JPA.ONE_TO_ONE)); - } - - public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) resourceField.getAnnotation(JPA.ONE_TO_ONE); - oneToOne.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - oneToOne.setOrphanRemoval(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertSame(oneToOneMapping, persistentAttribute.getMapping()); - - oneToOne.setOrphanRemoval(Boolean.FALSE); - resourceField.setPrimaryAnnotation(null, EmptyIterable.<String>instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceField.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 mapping = (OneToOneMapping2_0) contextAttribute.getMapping(); - OneToOneRelationship2_0 rel = (OneToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToMappedBy(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceField.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().getAttributes().iterator().next(); - OneToOneMapping2_0 mapping = (OneToOneMapping2_0) contextAttribute.getMapping(); - OneToOneRelationship2_0 rel = (OneToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceField.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceField.addAnnotation(0, JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceField.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNotNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceField.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceField.removeAnnotation(0, JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceField.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceField.getAnnotation(0, JPA.JOIN_COLUMN)); - assertNull(resourceField.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceField.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java deleted file mode 100644 index 024ecacb5f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AccessType; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaPersistentAttribute2_0Tests extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestEntityForDerivedId() throws Exception { - return createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntitySpecifiedAccessField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.BASIC, JPA.TRANSIENT, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.FIELD)"); - } - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("transient"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestEntitySpecifiedAccessProperty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.BASIC, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Access(AccessType.FIELD)"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public GenericJavaPersistentAttribute2_0Tests(String name) { - super(name); - } - - public void testGetAccessField() throws Exception { - createTestEntitySpecifiedAccessField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute namePersistentAttribute = getJavaPersistentType().getAttributeNamed("name"); - assertEquals(AccessType.FIELD, namePersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, namePersistentAttribute.getDefaultAccess()); - assertEquals(null, namePersistentAttribute.getSpecifiedAccess()); - - PersistentAttribute idPersistentAttribute = getJavaPersistentType().getAttributeNamed("id"); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, idPersistentAttribute.getMappingKey()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getDefaultAccess()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getSpecifiedAccess()); - } - - public void testGetAccessProperty() throws Exception { - createTestEntitySpecifiedAccessProperty(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute namePersistentAttribute = getJavaPersistentType().getAttributeNamed("name"); - assertEquals(AccessType.FIELD, namePersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, namePersistentAttribute.getDefaultAccess()); - assertEquals(AccessType.FIELD, namePersistentAttribute.getSpecifiedAccess()); - - PersistentAttribute idPersistentAttribute = getJavaPersistentType().getAttributeNamed("id"); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, idPersistentAttribute.getMappingKey()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getDefaultAccess()); - assertEquals(null, idPersistentAttribute.getSpecifiedAccess()); - } - - public void testDerivedIdMappingInitialization() throws Exception { - createTestEntityForDerivedId(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaPersistentAttribute id = getJavaPersistentType().getAttributeNamed("id"); - assertEquals(id.getMappingKey(), MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - - id.getResourceAttribute().addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - id.getResourceAttribute().addAnnotation(JPA.ONE_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(id.getResourceAttribute().getAnnotation(JPA.ID)); - - id.getResourceAttribute().removeAnnotation(JPA.ONE_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - id.getResourceAttribute().addAnnotation(JPA.MANY_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(id.getResourceAttribute().getAnnotation(JPA.ID)); - - id.getResourceAttribute().removeAnnotation(JPA.MANY_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - id.getResourceAttribute().setPrimaryAnnotation(null, EmptyIterable.<String>instance()); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java deleted file mode 100644 index 37bff06833..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java +++ /dev/null @@ -1,863 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AccessType; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.internal.context.java.FieldAccessor; -import org.eclipse.jpt.jpa.core.internal.context.java.PropertyAccessor; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaPersistentType2_0Tests extends Generic2_0ContextModelTestCase -{ - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Access(AccessType.PROPERTY)"); - } - - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedPropertyFieldSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createTestSubTypeWithFieldAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeWithMethodAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - }); - } - - private ICompilationUnit createTestSubTypePersistentExtendsNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild2.java", "AnnotationTestTypeChild2", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends AnnotationTestTypeChild "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public GenericJavaPersistentType2_0Tests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, getJavaPersistentType().getName()); - } - - public void testGetAccessNothingAnnotated() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAndMethodAnnotated() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAnnotatedPropertySpecified() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().getAttributes().iterator(); - JavaPersistentAttribute javaPersistentAttribute = attributes.next(); - assertEquals("name", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMapping().getKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - assertFalse(attributes.hasNext()); - } - - public void testAccessPropertyAnnotatedFieldSpecified() throws Exception { - createTestEntityAnnotatedPropertyFieldSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().getAttributes().iterator(); - JavaPersistentAttribute javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("name", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - assertFalse(attributes.hasNext()); - - attributes = getJavaPersistentType().getAttributes().iterator(); - attributes.next().getResourceAttribute().setPrimaryAnnotation(TransientAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - attributes = getJavaPersistentType().getAttributes().iterator(); - javaPersistentAttribute = attributes.next(); - - javaPersistentAttribute = attributes.next(); - assertEquals("name", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - assertFalse(attributes.hasNext()); - } - - public void testAccessInheritance() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance2() throws Exception { - createTestEntityAnnotatedField(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessInheritance3() throws Exception { - createTestEntityAnnotatedField(); - createTestSubTypeWithMethodAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance4() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inherited class having annotations set wins over the default access set on persistence-unit-defaults - public void testAccessInheritancePersistenceUnitDefaultAccess() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlNoAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is property - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inheritance wins over entity-mappings specified access - public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childEntityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - - createTestEntityAnnotatedMethod(); - createTestSubType(); - JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType(); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess()); - } - - public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, java has field annotations so the access should be field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - } - - public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testSuperPersistentType() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testSuperPersistentType2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - //super is not added to the getPersistenceUnit, but it should still be found - //as the superPersistentType because of impliedClassRefs and changes for bug 190317 - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType(); - - assertNotNull(javaPersistentType.getSuperPersistentType()); - } - - //Entity extends Non-Entity extends Entity - public void testSuperPersistentType3() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testInheritanceHierarchy() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.getInheritanceHierarchy().iterator(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testInheritanceHierarchy2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().getSpecifiedClassRefs().iterator(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.getInheritanceHierarchy().iterator(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testGetMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testMappingKeyNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - assertNotNull(resourceType.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - assertNotNull(resourceType.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - assertNull(resourceType.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - resourceType.setPrimaryAnnotation(EmbeddableAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - this.getJpaProject().synchronizeContextModel(); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - resourceType.setPrimaryAnnotation(EntityAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - this.getJpaProject().synchronizeContextModel(); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testIsMapped() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaPersistentType().isMapped()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertFalse(getJavaPersistentType().isMapped()); - } - - public void testAttributes() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().getAttributes().iterator(); - - assertEquals("id", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributes2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().getAttributes().iterator(); - - JavaPersistentAttribute attribute = attributes.next(); - assertEquals("id", attribute.getName()); - assertTrue(attribute.getAccessor() instanceof FieldAccessor); - attribute = attributes.next(); - assertEquals("name", attribute.getName()); - assertTrue(attribute.getAccessor() instanceof FieldAccessor); - attribute = attributes.next(); - assertEquals("id", attribute.getName()); - assertTrue(attribute.getAccessor() instanceof PropertyAccessor); - assertFalse(attributes.hasNext()); - } - - public void testAttributesSize() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(1, getJavaPersistentType().getAttributesSize()); - } - - public void testAttributesSize2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, getJavaPersistentType().getAttributesSize()); - } - - public void testAttributeNamed() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("id"); - - assertEquals("id", attribute.getName()); - assertNull(getJavaPersistentType().getAttributeNamed("name")); - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testAttributeNamed2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("name"); - - assertEquals("name", attribute.getName()); - - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testRenameAttribute() throws Exception { - ICompilationUnit testType = createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().getAttributes().iterator(); - JavaPersistentAttribute idAttribute = attributes.next(); - JavaPersistentAttribute nameAttribute = attributes.next(); - - - assertEquals("id", idAttribute.getName()); - assertEquals("name", nameAttribute.getName()); - - IField idField = testType.findPrimaryType().getField("id"); - idField.rename("id2", false, null); - - attributes = getJavaPersistentType().getAttributes().iterator(); - JavaPersistentAttribute nameAttribute2 = attributes.next(); - JavaPersistentAttribute id2Attribute = attributes.next(); - - assertNotSame(idAttribute, id2Attribute); - assertEquals("id2", id2Attribute.getName()); - assertEquals(nameAttribute, nameAttribute2); - assertEquals("name", nameAttribute2.getName()); - assertFalse(attributes.hasNext()); - } - - public void testSuperPersistentTypeGeneric() throws Exception { - createTestGenericEntity(); - createTestGenericMappedSuperclass(); - - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Entity2"); - - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals("test.Entity1", javaPersistentType.getName()); - assertNotNull(javaPersistentType.getSuperPersistentType()); - - assertEquals("test.Entity2", javaPersistentType.getSuperPersistentType().getName()); - } - - private void createTestGenericEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 "); - sb.append("extends Entity2<Integer> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericMappedSuperclass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class Entity2<K> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity2.java", sourceWriter); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java deleted file mode 100644 index 2632244b86..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.jpa2.context.SequenceGenerator2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.SequenceGenerator2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -/** - * GenericJavaSequenceGenerator2_0Tests - */ -@SuppressWarnings("nls") -public class GenericJavaSequenceGenerator2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String SEQUENCE_GENERATOR_NAME = "TEST_SEQUENCE_GENERATOR"; - - public GenericJavaSequenceGenerator2_0Tests(String name) { - super(name); - } - - // ********** catalog ********** - - public void testGetCatalog() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getCatalog()); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) resourceField.getAnnotation(JPA.SEQUENCE_GENERATOR); - - annotation.setCatalog("testCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("testCatalog", sequenceGenerator.getCatalog()); - assertEquals("testCatalog", sequenceGenerator.getSpecifiedCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getDefaultCatalog()); - - sequenceGenerator.setSpecifiedCatalog("testCatalog"); - - assertNull(sequenceGenerator.getDefaultCatalog()); - assertEquals("testCatalog", sequenceGenerator.getSpecifiedCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - sequenceGenerator.setSpecifiedCatalog("testCatalog"); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) resourceField.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals("testCatalog", annotation.getCatalog()); - - sequenceGenerator.setSpecifiedCatalog(null); - assertNull(annotation.getCatalog()); - } - - // ********** schema ********** - - public void testGetSchema() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) this.getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getSchema()); - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) resourceField.getAnnotation(JPA.SEQUENCE_GENERATOR); - - annotation.setSchema("testSchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("testSchema", sequenceGenerator.getSchema()); - assertEquals("testSchema", sequenceGenerator.getSpecifiedSchema()); - } - - public void testGetDefaultSchema() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getDefaultSchema()); - - sequenceGenerator.setSpecifiedSchema("testSchema"); - - assertNull(sequenceGenerator.getDefaultSchema()); - assertEquals("testSchema", sequenceGenerator.getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntityWithSequenceGenerator(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - IdMapping idMapping = (IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getDefaultSchema()); - - this.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", sequenceGenerator.getDefaultSchema()); - - this.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", sequenceGenerator.getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", sequenceGenerator.getDefaultSchema()); - - this.getEntityMappings().removePersistentType(0); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - assertEquals("FOO", sequenceGenerator.getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - sequenceGenerator.setSpecifiedSchema("testSchema"); - - JavaResourceField resourceField = ((JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE)).getFields().iterator().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) resourceField.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals("testSchema", annotation.getSchema()); - - sequenceGenerator.setSpecifiedSchema(null); - assertNull(annotation.getSchema()); - } - - // ********** utility ********** - - protected ICompilationUnit createTestEntityWithSequenceGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SEQUENCE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@SequenceGenerator(name=\"" + SEQUENCE_GENERATOR_NAME + "\")"); - } - }); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaVersionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaVersionMapping2_0Tests.java deleted file mode 100644 index 5fd0a4ff32..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaVersionMapping2_0Tests.java +++ /dev/null @@ -1,352 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaVersionMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - } - }); - } - - public GenericJavaVersionMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToElementCollectionMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - resourceField.addAnnotation(Access2_0Annotation.ANNOTATION_NAME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); - - assertNull(resourceField.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(Access2_0Annotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java deleted file mode 100644 index afbf7de334..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class Generic2_0OrmContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(Generic2_0OrmContextModelTests.class.getPackage().getName()); - suite.addTestSuite(GenericOrmAssociationOverride2_0Tests.class); - suite.addTestSuite(GenericOrmCascade2_0Tests.class); - suite.addTestSuite(GenericOrmCollectionTable2_0Tests.class); - suite.addTestSuite(GenericOrmElementCollectionMapping2_0Tests.class); - suite.addTestSuite(GenericOrmEntity2_0Tests.class); - suite.addTestSuite(GenericOrmEmbeddedMapping2_0Tests.class); - suite.addTestSuite(GenericOrmManyToManyMapping2_0Tests.class); - suite.addTestSuite(GenericOrmManyToOneMapping2_0Tests.class); - suite.addTestSuite(GenericOrmOneToManyMapping2_0Tests.class); - suite.addTestSuite(GenericOrmOneToOneMapping2_0Tests.class); - suite.addTestSuite(GenericOrmPersistentAttribute2_0Tests.class); - suite.addTestSuite(GenericOrmPersistentType2_0Tests.class); - suite.addTestSuite(GenericOrmSequenceGenerator2_0Tests.class); - return suite; - } - - private Generic2_0OrmContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java deleted file mode 100644 index 3f9f71532c..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java +++ /dev/null @@ -1,534 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AssociationOverride; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.JoinTable; -import org.eclipse.jpt.jpa.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualJoinTable; -import org.eclipse.jpt.jpa.core.context.VirtualJoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.orm.OrmJoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.jpa2.context.OverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmAssociationOverride2_0Tests extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - sb.append(CR); - sb.append(" private java.util.Collection<AnnotationTestTypeChild> address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public GenericOrmAssociationOverride2_0Tests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride ormVirtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormVirtualAssociationOverride.getName()); - - ormVirtualAssociationOverride.convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - - assertEquals("address", ormAssociationOverride.getName()); - assertEquals("address", xmlAssociationOverride.getName()); - assertTrue(overrideContainer.getOverrides().iterator().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - //set name to null in the resource model - xmlAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(overrideContainer.getSpecifiedOverrides().iterator().hasNext()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - - assertEquals("address", specifiedAssociationOverride.getName()); - assertEquals("address", xmlAssociationOverride.getName()); - assertTrue(overrideContainer.getOverrides().iterator().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the context model, verify resource model modified - specifiedAssociationOverride.setName("foo"); - assertEquals("foo", specifiedAssociationOverride.getName()); - assertEquals("foo", xmlAssociationOverride.getName()); - - //set name to null in the context model - specifiedAssociationOverride.setName(null); - assertNull(specifiedAssociationOverride.getName()); - xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - assertNull(xmlAssociationOverride.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - OrmAssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - OrmJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - - JoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - JoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - JoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - AssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, xmlAssociationOverride.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - OrmAssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - OrmJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, xmlAssociationOverride.getJoinColumns().size()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - OrmAssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - OrmJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - ListIterator<OrmJoinColumn> joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - xmlAssociationOverride.getJoinColumns().add(0, OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinColumns().add(1, OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinColumns().add(2, OrmFactory.eINSTANCE.createXmlJoinColumn()); - - xmlAssociationOverride.getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinColumns().get(2).setName("BAZ"); - - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(2, 0); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(0, 1); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(0); - joinColumns = joiningStrategy.getSpecifiedJoinColumns().iterator(); - assertEquals("address_id", joinColumns.next().getName()); - - xmlAssociationOverride.getJoinColumns().remove(0); - assertFalse(joiningStrategy.getSpecifiedJoinColumns().iterator().hasNext()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals("AnnotationTestTypeChild", ormEntity.getName()); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertTrue(associationOverride.isVirtual()); - } - - - public void testSetJoinTableName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - OrmVirtualAssociationOverride virtualOverride = overrideContainer.getVirtualOverrides().iterator().next(); - OrmAssociationOverride associationOverride = virtualOverride.convertToSpecified(); - ((OverrideRelationship2_0) associationOverride.getRelationship()).setStrategyToJoinTable(); - JoinTableRelationshipStrategy joiningStrategy = ((OverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - - JoinTable joinTable = joiningStrategy.getJoinTable(); - joinTable.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinTable().getName()); - } - - public void testUpdateJoinTable() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - OrmVirtualAssociationOverride virtualOverride = overrideContainer.getVirtualOverrides().iterator().next(); - OrmAssociationOverride associationOverride = virtualOverride.convertToSpecified(); - ((OrmOverrideRelationship2_0) associationOverride.getRelationship()).setStrategyToJoinTable(); - OrmJoinTableRelationshipStrategy joiningStrategy = ((OrmOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - xmlAssociationOverride.getJoinTable().setName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", joiningStrategy.getJoinTable().getSpecifiedName()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinTable().getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinTable().getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinTable().getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinTable().getJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().move(2, 0); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().move(0, 1); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().remove(1); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().remove(1); - joinColumns = joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().remove(0); - assertFalse(joiningStrategy.getJoinTable().getSpecifiedJoinColumns().iterator().hasNext()); - } - - public void testDefaultJoinTableName() throws Exception { - createTestMappedSuperclassManyToMany(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - VirtualJoinTableRelationshipStrategy joiningStrategy = ((VirtualOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - - VirtualJoinTable joinTable = joiningStrategy.getJoinTable(); - - assertEquals("AnnotationTestTypeChild_AnnotationTestTypeChild", joinTable.getName()); - - - ormEntity.getTable().setSpecifiedName("FOO"); - assertEquals("FOO_FOO", joinTable.getName()); - - PersistentType mappedSuperclass = ormPersistentType.getSuperPersistentType(); - ((OrmReadOnlyPersistentAttribute) mappedSuperclass.getAttributeNamed("address")).convertToSpecified(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) mappedSuperclass.getAttributeNamed("address").getMapping(); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("BAR"); - assertEquals("BAR", manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java deleted file mode 100644 index ccec4fbb81..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmCascade2_0Tests extends Generic2_0ContextModelTestCase -{ - public GenericOrmCascade2_0Tests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateCascadeDetach() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isDetach()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isDetach()); - assertNotNull(oneToOne.getCascade()); - - //set detach in the resource model, verify context model updated - oneToOne.getCascade().setCascadeDetach(true); - assertEquals(true, cascade.isDetach()); - assertEquals(true, oneToOne.getCascade().isCascadeDetach()); - - //set detach to false in the resource model - oneToOne.getCascade().setCascadeDetach(false); - assertEquals(false, cascade.isDetach()); - assertEquals(false, oneToOne.getCascade().isCascadeDetach()); - } - - public void testModifyCascadeDetach() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isDetach()); - assertNull(oneToOne.getCascade()); - - //set detach in the context model, verify resource model updated - cascade.setDetach(true); - assertEquals(true, cascade.isDetach()); - assertEquals(true, oneToOne.getCascade().isCascadeDetach()); - - //set detach to false in the context model - cascade.setDetach(false); - assertEquals(false, cascade.isDetach()); - assertNull(oneToOne.getCascade()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java deleted file mode 100644 index f80cb1439a..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java +++ /dev/null @@ -1,753 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.UniqueConstraint; -import org.eclipse.jpt.jpa.core.context.java.JavaEntity; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.CollectionTable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaCollectionTable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmCollectionTable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlCollectionTable; -import org.eclipse.jpt.jpa.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlElementCollection_2_0; -import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmCollectionTable2_0Tests extends Generic2_0ContextModelTestCase -{ - public GenericOrmCollectionTable2_0Tests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityWithValidElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - sb.append(" private Collection<String> projects;").append(CR); - sb.append("@Id").append(CR); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = elementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - - - //set name in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setName("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedName()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getName()); - - //set name to null in the resource model - resourceElementCollection.getCollectionTable().setName(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable().getName()); - - resourceElementCollection.getCollectionTable().setName("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedName()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getName()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = elementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set name in the context model, verify resource model modified - ormCollectionTable.setSpecifiedName("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedName()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getName()); - - //set name to null in the context model - ormCollectionTable.setSpecifiedName(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testVirtualCollectionTable() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(TYPE_NAME + "_projects", virtualCollectionTable.getName()); - assertNull(virtualCollectionTable.getSpecifiedCatalog()); - assertNull(virtualCollectionTable.getSpecifiedSchema()); - assertEquals(0, virtualCollectionTable.getSpecifiedJoinColumnsSize()); - JoinColumn virtualJoinColumn = virtualCollectionTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_id", virtualJoinColumn.getDefaultName()); - assertEquals("id", virtualJoinColumn.getDefaultReferencedColumnName()); - - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) javaPersistentAttribute.getMapping(); - JavaCollectionTable2_0 javaCollectionTable = javaElementCollectionMapping.getCollectionTable(); - javaCollectionTable.setSpecifiedName("FOO"); - javaCollectionTable.setSpecifiedCatalog("CATALOG"); - javaCollectionTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaCollectionTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - - assertEquals("FOO", virtualCollectionTable.getSpecifiedName()); - assertEquals("CATALOG", virtualCollectionTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualCollectionTable.getSpecifiedSchema()); - assertEquals(1, virtualCollectionTable.getSpecifiedJoinColumnsSize()); - virtualJoinColumn = virtualCollectionTable.getSpecifiedJoinColumns().iterator().next(); - assertEquals("NAME", virtualJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", virtualJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "projects"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - assertEquals(TYPE_NAME + "_projects", ormCollectionTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).setSpecifiedName("Foo"); - assertEquals("Foo_projects", ormCollectionTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).setSpecifiedName("Bar"); - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove element collection mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("projects"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute2.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - assertTrue(ormPersistentAttribute2.isVirtual()); - assertEquals("JAVA_COLLECTION_TABLE", virtualCollectionTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - javaElementCollectionMapping.getCollectionTable().setSpecifiedName(null); - assertEquals("Bar_projects", virtualCollectionTable.getName()); - assertEquals("Bar_projects", virtualCollectionTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set schema in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setSchema("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getSchema()); - - //set Schema to null in the resource model - resourceElementCollection.getCollectionTable().setSchema(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable().getSchema()); - - resourceElementCollection.getCollectionTable().setSchema("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getSchema()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Schema in the context model, verify resource model modified - ormCollectionTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedSchema()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getSchema()); - - //set Schema to null in the context model - ormCollectionTable.setSpecifiedSchema(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Catalog in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setCatalog("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getCatalog()); - - //set Catalog to null in the resource model - resourceElementCollection.getCollectionTable().setCatalog(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable().getCatalog()); - - resourceElementCollection.getCollectionTable().setCatalog("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getCatalog()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Catalog in the context model, verify resource model modified - ormCollectionTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getCatalog()); - - //set Catalog to null in the context model - ormCollectionTable.setSpecifiedCatalog(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - OrmJoinColumn joinColumn = ormCollectionTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormCollectionTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormCollectionTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - ormCollectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormCollectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormCollectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals(3, resourceCollectionTable.getJoinColumns().size()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(2, resourceCollectionTable.getJoinColumns().size()); - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(1, resourceCollectionTable.getJoinColumns().size()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(0).getName()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, resourceCollectionTable.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - ormCollectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormCollectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormCollectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals(3, resourceCollectionTable.getJoinColumns().size()); - - - ormCollectionTable.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - - - ormCollectionTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - } - - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - resourceCollectionTable.getJoinColumns().get(0).setName("FOO"); - resourceCollectionTable.getJoinColumns().get(1).setName("BAR"); - resourceCollectionTable.getJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().move(2, 0); - joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().move(0, 1); - joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(1); - joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(1); - joinColumns = ormCollectionTable.getSpecifiedJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(0); - assertFalse(ormCollectionTable.getSpecifiedJoinColumns().iterator().hasNext()); - } - - public void testUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - assertEquals(0, ormCollectionTable.getUniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormCollectionTable.getUniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = resourceCollectionTable.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = resourceCollectionTable.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, resourceCollectionTable.getUniqueConstraints().size()); - - ormCollectionTable.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormCollectionTable.removeUniqueConstraint(1); - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormCollectionTable.removeUniqueConstraint(0); - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, resourceCollectionTable.getUniqueConstraints().size()); - - - ormCollectionTable.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormCollectionTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(1); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(1); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(0); - uniqueConstraints = ormCollectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.getAttributes().iterator().next(); - assertTrue(virtualAttribute.isVirtual()); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) virtualAttribute.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - - ListIterator<? extends UniqueConstraint> uniqueConstraints = virtualCollectionTable.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping2_0 = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributes().iterator().next().getMapping(); - JavaCollectionTable2_0 javaCollectionTable = javaElementCollectionMapping2_0.getCollectionTable(); - - javaCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = virtualCollectionTable.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - virtualAttribute.convertToSpecified(); - - virtualElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentType.getAttributes().iterator().next().getMapping(); - assertEquals(0, virtualElementCollectionMapping.getCollectionTable().getUniqueConstraintsSize()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java deleted file mode 100644 index afb0daa0cc..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java +++ /dev/null @@ -1,1711 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.Column; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmColumn; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlElementCollection; -import org.eclipse.jpt.jpa.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlElementCollection_2_0; -import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmElementCollectionMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public GenericOrmElementCollectionMapping2_0Tests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityWithElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection(targetClass=String.class, fetch=FetchType.EAGER)"); - sb.append(CR); - sb.append(" private java.util.Collection<Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE, 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(" @ElementCollection"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(" private java.util.Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithNonGenericElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericBasicElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<String> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map<String, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createSelfReferentialElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.List<Foo> elementCollection;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertEquals("oneToOneMapping", ormElementCollectionMapping.getName()); - assertEquals("oneToOneMapping", elementCollection.getName()); - - //set name in the resource model, verify context model updated - elementCollection.setName("newName"); - assertEquals("newName", ormElementCollectionMapping.getName()); - assertEquals("newName", elementCollection.getName()); - - //set name to null in the resource model - elementCollection.setName(null); - assertNull(ormElementCollectionMapping.getName()); - assertNull(elementCollection.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertEquals("oneToOneMapping", ormElementCollectionMapping.getName()); - assertEquals("oneToOneMapping", elementCollection.getName()); - - //set name in the context model, verify resource model updated - ormElementCollectionMapping.setName("newName"); - assertEquals("newName", ormElementCollectionMapping.getName()); - assertEquals("newName", elementCollection.getName()); - - //set name to null in the context model - ormElementCollectionMapping.setName(null); - assertNull(ormElementCollectionMapping.getName()); - assertNull(elementCollection.getName()); - } - - public void testMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormElementCollectionMapping.getName()); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", virtualElementCollectionMapping.getName()); - assertEquals(FetchType.EAGER, virtualElementCollectionMapping.getSpecifiedFetch()); - assertEquals("String", virtualElementCollectionMapping.getSpecifiedTargetClass()); - - ormPersistentAttribute = ormPersistentAttribute.convertToSpecified(); - OrmElementCollectionMapping2_0 specifiedElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", specifiedElementCollectionMapping.getName()); - assertEquals(null, specifiedElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, specifiedElementCollectionMapping.getDefaultFetch()); - assertEquals(null, specifiedElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals(PACKAGE_NAME + ".Address", specifiedElementCollectionMapping.getDefaultTargetClass()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.convertToSpecified(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormElementCollectionMapping.getName()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormElementCollectionMapping.getName()); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - - public void testMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the resource model, verify context model updated - elementCollection.setFetch(org.eclipse.jpt.jpa.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(org.eclipse.jpt.jpa.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the resource model - elementCollection.setFetch(null); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.FetchType.EAGER, elementCollection.getFetch()); - assertEquals(FetchType.EAGER, ormElementCollectionMapping.getSpecifiedFetch()); - - ormElementCollectionMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.FetchType.LAZY, elementCollection.getFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormElementCollectionMapping.setSpecifiedFetch(null); - assertNull(elementCollection.getFetch()); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedTargetClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the resource model, verify context model updated - elementCollection.setTargetClass("newTargetClass"); - assertEquals("newTargetClass", ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the resource model - elementCollection.setTargetClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - public void testModifySpecifiedTargetClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedTargetClass("newTargetClass"); - assertEquals("newTargetClass", ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the context model - ormElementCollectionMapping.setSpecifiedTargetClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - - public void testGetValueTypeEmbeddable() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeEntity() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeNone() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.NO_TYPE, elementCollectionMapping.getValueType()); - - elementCollectionMapping.setSpecifiedTargetClass("test.Address"); - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeBasic() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualElementCollectionMapping.getSpecifiedMapKey()); - assertNull(virtualElementCollectionMapping.getMapKey()); - assertFalse(virtualElementCollectionMapping.isPkMapKey()); - assertFalse(virtualElementCollectionMapping.isCustomMapKey()); - assertTrue(virtualElementCollectionMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setPkMapKey(true); - assertEquals(null, virtualElementCollectionMapping.getMapKey());//no primary key on an embeddable - assertTrue(virtualElementCollectionMapping.isPkMapKey()); - assertFalse(virtualElementCollectionMapping.isCustomMapKey()); - assertFalse(virtualElementCollectionMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setCustomMapKey(true); - javaElementCollectionMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualElementCollectionMapping.getSpecifiedMapKey()); - assertEquals("city", virtualElementCollectionMapping.getMapKey()); - assertFalse(virtualElementCollectionMapping.isPkMapKey()); - assertTrue(virtualElementCollectionMapping.isCustomMapKey()); - assertFalse(virtualElementCollectionMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany xmlOneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(xmlOneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", xmlOneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertTrue(ormOneToManyMapping.isPkMapKey()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = virtualElementCollectionMapping.getCandidateMapKeyNames().iterator(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = virtualElementCollectionMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - javaElementCollectionMapping.setSpecifiedTargetClass("test.Address"); - mapKeyNames = virtualElementCollectionMapping.getCandidateMapKeyNames().iterator(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - virtualElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = virtualElementCollectionMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - virtualElementCollectionMapping.setSpecifiedTargetClass("test.Address"); - mapKeyNames = virtualElementCollectionMapping.getCandidateMapKeyNames().iterator(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - virtualElementCollectionMapping.setSpecifiedTargetClass("String"); - mapKeyNames = virtualElementCollectionMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - elementCollection.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNotNull(elementCollection.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - elementCollection.getMapKeyClass().setClassName("String"); - assertEquals("String", ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", elementCollection.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - elementCollection.getMapKeyClass().setClassName(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass().getClassName()); - - elementCollection.getMapKeyClass().setClassName("String"); - elementCollection.setMapKeyClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", virtualElementCollectionMapping.getMapKeyClass()); - assertNull(virtualElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualElementCollectionMapping.getMapKeyClass()); - assertEquals("Integer", virtualElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", elementCollection.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormElementCollectionMapping.setSpecifiedMapKeyClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = (Orderable2_0) elementCollectionMapping.getOrderable(); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = (Orderable2_0) elementCollectionMapping.getOrderable(); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaElementCollectionMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 virtualCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute2.getMapping(); - orderable = (Orderable2_0) virtualCollectionMapping.getOrderable(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(false, orderable.isNoOrdering()); - assertEquals(TYPE_NAME + "_addresses", orderable.getOrderColumn().getTable()); - assertEquals("addresses_ORDER", orderable.getOrderColumn().getName()); - - ((Orderable2_0) javaElementCollectionMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_addresses", orderable.getOrderColumn().getTable()); - assertEquals("FOO", orderable.getOrderColumn().getName()); - } - - public void testVirtualValueColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attrubte in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getValueColumn(); - assertEquals("addresses", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getValueColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getValueColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getValueColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getValueColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getValueColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getValueColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmElementCollectionMapping2_0 addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - OrmColumn ormColumn = addressesVirtualMapping.getValueColumn(); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getValueColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getValueColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getValueColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getValueColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getValueColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getValueColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualValueColumnTable() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getValueColumn(); - - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //entity table should have no affect on the collection table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //set Column table element in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - assertEquals("JAVA_COLLECTION_TABLE", virtualColumn.getTable()); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesVirtualMapping.getValueColumn(); - assertNull(virtualColumn.getSpecifiedTable()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getDefaultTable()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - elementCollectionResource.getAttributeOverrides().get(0).setName("FOO"); - elementCollectionResource.getAttributeOverrides().get(1).setName("BAR"); - elementCollectionResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, elementCollectionResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", elementCollectionResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", elementCollectionResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", elementCollectionResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", elementCollectionResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - elementCollectionResource.getAttributeOverrides().get(0).setName("FOO"); - elementCollectionResource.getAttributeOverrides().get(1).setName("BAR"); - elementCollectionResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.getSpecifiedOverrides().iterator().hasNext()); - } - - public void testElementCollectionMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - - assertEquals("foo", ormElementCollectionMapping.getName()); - - - assertFalse(attributeOverrideContainer.getSpecifiedOverrides().iterator().hasNext()); - assertFalse(attributeOverrideContainer.getVirtualOverrides().iterator().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType persistentType3 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - ListIterator<? extends ReadOnlyAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - ReadOnlyAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - ListIterator<? extends ReadOnlyAttributeOverride> virtualOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - attributeOverride = virtualOverrides.next(); - assertEquals("state.name", attributeOverride.getName()); - attributeOverride = virtualOverrides.next(); - assertEquals("state.abbr", attributeOverride.getName()); - attributeOverride = virtualOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaElementCollectionMapping.getValueAttributeOverrideContainer().getSpecifiedOverrides().iterator().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType3.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", attributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, attributeOverride.getColumn().isInsertable()); - assertEquals(false, attributeOverride.getColumn().isUpdatable()); - assertEquals(true, attributeOverride.getColumn().isUnique()); - assertEquals(false, attributeOverride.getColumn().isNullable()); - assertEquals(5, attributeOverride.getColumn().getLength()); - assertEquals(6, attributeOverride.getColumn().getPrecision()); - assertEquals(7, attributeOverride.getColumn().getScale()); - - virtualOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - attributeOverride = virtualOverrides.next(); - assertEquals("state.name", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualOverrides.next(); - assertEquals("state.abbr", attributeOverride.getName()); - attributeOverride = virtualOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("addresses").convertToSpecified(); - elementCollectionMapping = (OrmElementCollectionMapping2_0) persistentType.getAttributeNamed("addresses").getMapping(); - attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(0, attributeOverrideContainer.getSpecifiedOverridesSize()); - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - VirtualAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualOverride.getColumn().getName()); - assertEquals(TYPE_NAME + "_addresses", virtualOverride.getColumn().getTable()); - assertEquals(null, virtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualOverride.getColumn().isInsertable()); - assertEquals(true, virtualOverride.getColumn().isUpdatable()); - assertEquals(false, virtualOverride.getColumn().isUnique()); - assertEquals(true, virtualOverride.getColumn().isNullable()); - assertEquals(255, virtualOverride.getColumn().getLength()); - assertEquals(0, virtualOverride.getColumn().getPrecision()); - assertEquals(0, virtualOverride.getColumn().getScale()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualOverride.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualOverride.getColumn().getDefaultTable()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals("city", attributeOverrideContainer.getSpecifiedOverrides().iterator().next().getName()); - virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmElementCollectionMapping2_0 addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //entity table should have no affect on the collection table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //set Column table element in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - assertEquals("JAVA_COLLECTION_TABLE", virtualColumn.getTable()); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertNull(virtualColumn.getSpecifiedTable()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getDefaultTable()); - } - - public void testSelfReferentialElementCollectionMapping() throws Exception { - createSelfReferentialElementCollection(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Foo"); - - ElementCollectionMapping2_0 mapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("elementCollection").getMapping(); - assertFalse(mapping.getAllOverridableAttributeMappingNames().iterator().hasNext()); - } - - public void testUpdateSpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - assertNull(elementCollectionResource.getMapKeyEnumerated()); - - //set enumerated in the resource model, verify context model updated - elementCollectionResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, elementCollectionResource.getMapKeyEnumerated()); - - elementCollectionResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, elementCollectionResource.getMapKeyEnumerated()); - - //set enumerated to null in the resource model - elementCollectionResource.setMapKeyEnumerated(null); - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - assertNull(elementCollectionResource.getMapKeyEnumerated()); - } - - public void testModifySpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - assertNull(elementCollectionResource.getMapKeyEnumerated()); - - //set enumerated in the context model, verify resource model updated - ormElementCollectionMapping.setMapKeyConverter(EnumeratedConverter.class); - ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.ORDINAL); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, elementCollectionResource.getMapKeyEnumerated()); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, elementCollectionResource.getMapKeyEnumerated()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormElementCollectionMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - //set enumerated to null in the context model - ormElementCollectionMapping.setMapKeyConverter(null); - assertNull(elementCollectionResource.getMapKeyEnumerated()); - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - } - - public void testUpdateSpecifiedTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - assertNull(elementCollectionResource.getMapKeyTemporal()); - - //set temporal in the resource model, verify context model updated - elementCollectionResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, elementCollectionResource.getMapKeyTemporal()); - - elementCollectionResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, elementCollectionResource.getMapKeyTemporal()); - - elementCollectionResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP, elementCollectionResource.getMapKeyTemporal()); - - //set temporal to null in the resource model - elementCollectionResource.setMapKeyTemporal(null); - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - assertNull(elementCollectionResource.getMapKeyTemporal()); - } - - public void testModifySpecifiedTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - assertNull(elementCollectionResource.getMapKeyTemporal()); - - //set temporal in the context model, verify resource model updated - ormElementCollectionMapping.setMapKeyConverter(TemporalConverter.class); - ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, elementCollectionResource.getMapKeyTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType()); - - ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, elementCollectionResource.getMapKeyTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormElementCollectionMapping.getMapKeyConverter()).getTemporalType()); - - //set temporal to null in the context model - ormElementCollectionMapping.setMapKeyConverter(null); - assertNull(elementCollectionResource.getMapKeyTemporal()); - assertNull(ormElementCollectionMapping.getMapKeyConverter().getType()); - } - - public void testAddSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - JoinColumn joinColumn = ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - - JoinColumn joinColumn2 = ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(1).getName()); - - JoinColumn joinColumn3 = ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(2).getName()); - - ListIterator<? extends JoinColumn> joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, elementCollectionResource.getMapKeyJoinColumns().size()); - - ormElementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(2, elementCollectionResource.getMapKeyJoinColumns().size()); - assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(1).getName()); - - ormElementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(1, elementCollectionResource.getMapKeyJoinColumns().size()); - assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - - ormElementCollectionMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(0, elementCollectionResource.getMapKeyJoinColumns().size()); - } - - public void testMoveSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - ormElementCollectionMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, elementCollectionResource.getMapKeyJoinColumns().size()); - - - ormElementCollectionMapping.moveSpecifiedMapKeyJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(2).getName()); - - - ormElementCollectionMapping.moveSpecifiedMapKeyJoinColumn(0, 1); - joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", elementCollectionResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAR", elementCollectionResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getMapKeyJoinColumns().get(2).getName()); - } - - public void testUpdateMapKeyJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - ElementCollectionMapping2_0 ormElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - elementCollectionResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - elementCollectionResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - elementCollectionResource.getMapKeyJoinColumns().get(0).setName("FOO"); - elementCollectionResource.getMapKeyJoinColumns().get(1).setName("BAR"); - elementCollectionResource.getMapKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<? extends JoinColumn> joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - elementCollectionResource.getMapKeyJoinColumns().move(2, 0); - joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - elementCollectionResource.getMapKeyJoinColumns().move(0, 1); - joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - elementCollectionResource.getMapKeyJoinColumns().remove(1); - joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - elementCollectionResource.getMapKeyJoinColumns().remove(1); - joinColumns = ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - elementCollectionResource.getMapKeyJoinColumns().remove(0); - assertFalse(ormElementCollectionMapping.getSpecifiedMapKeyJoinColumns().iterator().hasNext()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java deleted file mode 100644 index 0a82a030a7..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java +++ /dev/null @@ -1,1734 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AssociationOverride; -import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.AttributeOverride; -import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.Column; -import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.jpa.core.context.EmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn; -import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn; -import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTable; -import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.TransientMapping; -import org.eclipse.jpt.jpa.core.context.VersionMapping; -import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.VirtualJoinColumn; -import org.eclipse.jpt.jpa.core.context.VirtualJoinColumnRelationship; -import org.eclipse.jpt.jpa.core.context.VirtualJoinColumnRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.VirtualJoinTableRelationshipStrategy; -import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinTable; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaReadOnlyAssociationOverride; -import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.jpa2.context.EmbeddedMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ReadOnlyOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmEmbeddedMapping2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.jpa.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmEmbeddedMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - private static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - private static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - public GenericOrmEmbeddedMapping2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityEmbeddedMappingAttributeOverrides() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED, 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(" @Embedded"); - 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"); - } - }); - } - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createAddressEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Address {"); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Column(name=\"A_STATE\")").append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress2() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - private void createSelfReferentialEmbedded() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Foo embedded;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// OrmAttributeOverride attributeOverride = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEmbeddedMapping.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// ormEmbeddedMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedResource.getAttributeOverrides().size()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.getSpecifiedOverrides().iterator().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - - assertEquals("foo", ormEmbeddedMapping.getName()); - - - assertFalse(attributeOverrideContainer.getSpecifiedOverrides().iterator().hasNext()); - assertFalse(attributeOverrideContainer.getVirtualOverrides().iterator().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("address"); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - ListIterator<? extends ReadOnlyAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - ReadOnlyAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - ListIterator<? extends ReadOnlyAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaEmbeddedMapping javaEmbeddedMapping = (JavaEmbeddedMapping) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaEmbeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", attributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, attributeOverride.getColumn().isInsertable()); - assertEquals(false, attributeOverride.getColumn().isUpdatable()); - assertEquals(true, attributeOverride.getColumn().isUnique()); - assertEquals(false, attributeOverride.getColumn().isNullable()); - assertEquals(5, attributeOverride.getColumn().getLength()); - assertEquals(6, attributeOverride.getColumn().getPrecision()); - assertEquals(7, attributeOverride.getColumn().getScale()); - - virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").convertToSpecified(); - embeddedMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(4, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals(0, attributeOverrideContainer.getSpecifiedOverridesSize()); - virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - ReadOnlyAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - assertEquals("city", virtualOverride.getColumn().getName()); - assertEquals(TYPE_NAME, virtualOverride.getColumn().getTable()); - assertEquals(null, virtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualOverride.getColumn().isInsertable()); - assertEquals(true, virtualOverride.getColumn().isUpdatable()); - assertEquals(false, virtualOverride.getColumn().isUnique()); - assertEquals(true, virtualOverride.getColumn().isNullable()); - assertEquals(255, virtualOverride.getColumn().getLength()); - assertEquals(0, virtualOverride.getColumn().getPrecision()); - assertEquals(0, virtualOverride.getColumn().getScale()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, virtualOverride.getColumn().getDefaultTable()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - attributeOverrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - assertEquals(4, attributeOverrideContainer.getOverridesSize()); - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - assertEquals("id", attributeOverrideContainer.getSpecifiedOverrides().iterator().next().getName()); - virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - EmbeddedMapping virtualEmbeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = virtualEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals("address", virtualEmbeddedMapping.getName()); - - assertEquals(1, attributeOverrideContainer.getSpecifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends ReadOnlyAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.getSpecifiedOverrides().iterator(); - - ReadOnlyAttributeOverride override = specifiedAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, override.getName()); - ReadOnlyColumn column = override.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getSpecifiedName()); - - ListIterator<? extends ReadOnlyAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - override = virtualAttributeOverrides.next(); - assertEquals("id", override.getName()); - column = override.getColumn(); - assertEquals("id", column.getName()); - - override = virtualAttributeOverrides.next(); - assertEquals("state", override.getName()); - column = override.getColumn(); - assertEquals("A_STATE", column.getName()); - - override = virtualAttributeOverrides.next(); - assertEquals("zip", override.getName()); - column = override.getColumn(); - assertEquals("zip", column.getName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - EmbeddedMapping virtualEmbeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", virtualEmbeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(0, ormEmbeddedMapping.getAttributeOverrideContainer().getSpecifiedOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - - - public void testEmbeddedMorphToIdMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToEmbeddedIdMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedIdMapping) ormPersistentAttribute.getMapping()).getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.getSpecifiedAttributes().iterator().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().getSpecifiedOverrides().iterator().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - - OrmAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - ListIterator<OrmAssociationOverride> specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(associationOverride); - associationOverride.setName("FOO"); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(1, associationOverride); - associationOverride.setName("BAR"); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(0, associationOverride); - associationOverride.setName("BAZ"); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - embeddedResource.getAssociationOverrides().move(1, 0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - embeddedResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - VirtualJoinColumnRelationshipStrategy joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.getJoinColumnsSize()); - VirtualJoinColumn virtualJoinColumn = joiningStrategy.getJoinColumns().iterator().next(); - assertEquals("address_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - - JavaPersistentType javaEmbeddable = getPersistenceUnit().getSpecifiedClassRefs().iterator().next().getJavaPersistentType(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) javaEmbeddable.getAttributeNamed("address").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.getJoinColumnsSize()); - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - virtualJoinColumn = joiningStrategy.getJoinColumns().iterator().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.getJoinColumns().iterator().next().getName()); - - - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(associationOverride); - associationOverride.setName("FOO"); - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(0, associationOverride); - associationOverride.setName("BAR"); - - assertEquals(2, overrideContainer.getSpecifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(0, overrideContainer.getVirtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getOverridesSize()); - - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(associationOverride); - associationOverride.setName("bar"); - assertEquals(3, overrideContainer.getOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("address", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - OrmAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", embeddedResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - OrmAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals(1, embeddedResource.getAssociationOverrides().size()); - - Iterator<OrmAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("addresses", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - assertEquals(0, embeddedResource.getAssociationOverrides().size()); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator<? extends AssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("addresses", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", embeddedResource.getAssociationOverrides().get(1).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("addresses", associationOverrides.next().getName()); - - assertEquals("address", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(1).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(0, associationOverride); - associationOverride.setName("FOO"); - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(1, associationOverride); - associationOverride.setName("BAR"); - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(2, associationOverride); - associationOverride.setName("BAZ"); - - ListIterator<? extends AssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().move(2, 0); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().move(0, 1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(0); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - OrmAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideJoinTableDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME_ + "Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = CollectionTools.get(overrideContainer.getVirtualOverrides(), 1); - VirtualJoinTableRelationshipStrategy joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - ReadOnlyJoinTable joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals("AnnotationTestType_Address", joinTable.getName()); - assertEquals(1, joinTable.getJoinColumnsSize()); - ReadOnlyJoinColumn virtualJoinColumn = joinTable.getJoinColumns().iterator().next(); - assertEquals("AnnotationTestType_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.getInverseJoinColumnsSize()); - ReadOnlyJoinColumn virtualInverseJoinColumn = joinTable.getInverseJoinColumns().iterator().next(); - assertEquals("addresses_id", virtualInverseJoinColumn.getName()); - assertEquals("id", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualInverseJoinColumn.getTable()); - assertEquals(null, virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(true, virtualInverseJoinColumn.isInsertable()); - assertEquals(true, virtualInverseJoinColumn.isUpdatable()); - assertEquals(false, virtualInverseJoinColumn.isUnique()); - assertEquals(true, virtualInverseJoinColumn.isNullable()); - - JavaPersistentType javaEmbeddable = getPersistenceUnit().getSpecifiedClassRefs().iterator().next().getJavaPersistentType(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) javaEmbeddable.getAttributeNamed("addresses").getMapping(); - JoinTableRelationshipStrategy joinTableStrategy = oneToManyMapping.getRelationship().getJoinTableStrategy(); - joinTableStrategy.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = joinTableStrategy.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumn inverseJoinColumn = joinTableStrategy.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("MY_INVERSE_JOIN_COLUMN"); - inverseJoinColumn.setSpecifiedReferencedColumnName("MY_INVERSE_REFERENCE_COLUMN"); - inverseJoinColumn.setSpecifiedTable("INVERSE_BAR"); - inverseJoinColumn.setColumnDefinition("INVERSE_COLUMN_DEF"); - inverseJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUnique(Boolean.TRUE); - inverseJoinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = CollectionTools.get(overrideContainer.getVirtualOverrides(), 1); - joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals(1, joinTable.getJoinColumnsSize()); - virtualJoinColumn = joinTable.getJoinColumns().iterator().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.getInverseJoinColumnsSize()); - virtualInverseJoinColumn = joinTable.getInverseJoinColumns().iterator().next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - assertEquals("INVERSE_COLUMN_DEF", virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(false, virtualInverseJoinColumn.isInsertable()); - assertEquals(false, virtualInverseJoinColumn.isUpdatable()); - assertEquals(true, virtualInverseJoinColumn.isUnique()); - assertEquals(false, virtualInverseJoinColumn.isNullable()); - - - //add the java association override and make sure the settings are not used in determining the association override defaults in the specified orm embedded mapping - JavaEmbeddedMapping2_0 javaEmbeddedMapping = (JavaEmbeddedMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - ListIterator<JavaReadOnlyAssociationOverride> javaAssociationOverrides = javaEmbeddedMapping.getAssociationOverrideContainer().getOverrides().iterator(); - javaAssociationOverrides.next(); - JavaAssociationOverride javaAssociationOverride = ((JavaVirtualAssociationOverride) javaAssociationOverrides.next()).convertToSpecified(); - assertEquals("addresses", javaAssociationOverride.getName()); - JavaJoinTable javaJoinTable = ((JavaOverrideRelationship2_0) javaAssociationOverride.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("JAVA_FOO"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("JAVA_JOIN_COLUMN_NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("JAVA_JOIN_COLUMN_REFERENCED_NAME"); - JavaJoinColumn javaInverseJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - javaInverseJoinColumn.setSpecifiedName("JAVA_INVERSE_JOIN_COLUMN_NAME"); - javaInverseJoinColumn.setSpecifiedReferencedColumnName("JAVA_INVERSE_JOIN_COLUMN_REFERENCED_NAME"); - - - - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = CollectionTools.get(overrideContainer.getVirtualOverrides(), 1); - joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals(1, joinTable.getJoinColumnsSize()); - virtualJoinColumn = joinTable.getJoinColumns().iterator().next(); - - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.getInverseJoinColumnsSize()); - virtualInverseJoinColumn = joinTable.getInverseJoinColumns().iterator().next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - assertEquals("INVERSE_COLUMN_DEF", virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(false, virtualInverseJoinColumn.isInsertable()); - assertEquals(false, virtualInverseJoinColumn.isUpdatable()); - assertEquals(true, virtualInverseJoinColumn.isUnique()); - assertEquals(false, virtualInverseJoinColumn.isNullable()); - - - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - - ormPersistentAttribute.convertToVirtual(); - EmbeddedMapping2_0 virtualEmbeddedMapping = (EmbeddedMapping2_0) ormPersistentType.getAttributeNamed("myEmbedded").getMapping(); - overrideContainer = virtualEmbeddedMapping.getAssociationOverrideContainer(); - AssociationOverride associationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertEquals("addresses", associationOverride.getName()); - ReadOnlyJoinTableRelationshipStrategy strategy = ((ReadOnlyOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = strategy.getJoinTable(); - assertEquals("JAVA_FOO", joinTable.getName()); - assertEquals(2, joinTable.getJoinColumnsSize()); - ListIterator<? extends ReadOnlyJoinColumn> joinColumns = joinTable.getJoinColumns().iterator(); - virtualJoinColumn = joinColumns.next(); - assertEquals("JAVA_JOIN_COLUMN_NAME", virtualJoinColumn.getName()); - assertEquals("JAVA_JOIN_COLUMN_REFERENCED_NAME", virtualJoinColumn.getReferencedColumnName()); - assertEquals("JAVA_FOO", virtualJoinColumn.getTable()); - virtualJoinColumn = joinColumns.next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - - assertEquals(2, joinTable.getInverseJoinColumnsSize()); - ListIterator<? extends ReadOnlyJoinColumn> inverseJoinColumns = joinTable.getInverseJoinColumns().iterator(); - virtualInverseJoinColumn = inverseJoinColumns.next(); - assertEquals("JAVA_INVERSE_JOIN_COLUMN_NAME", virtualInverseJoinColumn.getName()); - assertEquals("JAVA_INVERSE_JOIN_COLUMN_REFERENCED_NAME", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("JAVA_FOO", virtualInverseJoinColumn.getTable()); - virtualInverseJoinColumn = inverseJoinColumns.next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress2(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - customerPersistentType.getAttributeNamed("address").convertToSpecified(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(5, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<? extends VirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.getVirtualOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - virtualAttributeOverride = (VirtualAttributeOverride) ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testSelfReferentialEmbeddedMapping() throws Exception { - createSelfReferentialEmbedded(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Foo"); - - EmbeddedMapping2_0 embeddedMapping = (EmbeddedMapping2_0) persistentType.getAttributeNamed("embedded").getMapping(); - assertFalse(embeddedMapping.getAllOverridableAttributeMappingNames().iterator().hasNext()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java deleted file mode 100644 index 559fef408e..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java +++ /dev/null @@ -1,1972 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AssociationOverride; -import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.AttributeOverride; -import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.InheritanceType; -import org.eclipse.jpt.jpa.core.context.JoinTable; -import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.jpa.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.jpa.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmNamedQuery2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOverrideRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity; -import org.eclipse.jpt.jpa.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.jpa.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlAssociationOverride_2_0; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmEntity2_0Tests extends Generic2_0ContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public GenericOrmEntity2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - private void createTestMappedSuperclassCustomerWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<Address> address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEntityLongTimeCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("LongTimeCustomer extends Customer "); - sb.append("{}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "LongTimeCustomer.java", sourceWriter); - } - - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - private LockModeType2_0 lockModeOf(XmlNamedQuery resourceQuery) { - return resourceQuery == null ? null : LockModeType2_0.fromOrmResourceModel(resourceQuery.getLockMode()); - } - - public void testAddNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - OrmNamedQuery2_0 namedQuery = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(0); - namedQuery.setName("FOO"); - namedQuery.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - XmlNamedQuery resourceQuery = entityResource.getNamedQueries().get(0); - assertEquals("FOO", resourceQuery.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(resourceQuery)); - - OrmNamedQuery2_0 namedQuery2 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.READ); - - resourceQuery = entityResource.getNamedQueries().get(0); - assertEquals("BAR", resourceQuery.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(resourceQuery)); - assertEquals("FOO", entityResource.getNamedQueries().get(1).getName()); - - OrmNamedQuery2_0 namedQuery3 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - namedQuery3.setSpecifiedLockMode(LockModeType2_0.WRITE); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - resourceQuery = entityResource.getNamedQueries().get(1); - assertEquals("BAZ", resourceQuery.getName()); - assertEquals(LockModeType2_0.WRITE, this.lockModeOf(resourceQuery)); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - ListIterator<OrmNamedQuery> namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedQuery(0).setName("FOO"); - OrmNamedQuery2_0 namedQuery1 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.READ); - - OrmNamedQuery2_0 namedQuery2 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(2); - namedQuery2.setName("BAZ"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(2, entityResource.getNamedQueries().size()); - XmlNamedQuery xmlQuery0 = entityResource.getNamedQueries().get(0); - assertEquals("BAR", xmlQuery0.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(xmlQuery0)); - - XmlNamedQuery xmlQuery1 = entityResource.getNamedQueries().get(1); - assertEquals("BAZ", xmlQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery1)); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(1, entityResource.getNamedQueries().size()); - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - xmlQuery0 = entityResource.getNamedQueries().get(0); - assertEquals("BAZ", xmlQuery0.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery0)); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(0, entityResource.getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedQuery(0).setName("FOO"); - OrmNamedQuery2_0 namedQuery1 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - ormEntity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - - ormEntity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator<OrmNamedQuery> namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - XmlNamedQuery xmlQuery0 = entityResource.getNamedQueries().get(0); - assertEquals("BAR", xmlQuery0.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery0)); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - - ormEntity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAZ", namedQueries.next().getName()); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - XmlNamedQuery xmlQuery1 = entityResource.getNamedQueries().get(1); - assertEquals("BAR", xmlQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery1)); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, ormEntity.getPersistenceUnit().getQueriesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().get(0).setName("FOO"); - entityResource.getNamedQueries().get(1).setName("BAR"); - XmlNamedQuery xmlQuery = entityResource.getNamedQueries().get(2); - xmlQuery.setName("BAZ"); - xmlQuery.setLockMode(org.eclipse.jpt.jpa.core.resource.orm.v2_0.LockModeType_2_0.OPTIMISTIC); - - ListIterator<OrmNamedQuery> namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - OrmNamedQuery2_0 namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, ormEntity.getPersistenceUnit().getQueriesSize()); - - entityResource.getNamedQueries().move(2, 0); - namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - assertEquals("BAR", namedQueries.next().getName()); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().move(0, 1); - namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, ormEntity.getPersistenceUnit().getQueriesSize()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.getQueryContainer().getNamedQueries().iterator(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, ormEntity.getPersistenceUnit().getQueriesSize()); - - entityResource.getNamedQueries().remove(0); - assertFalse(ormEntity.getQueryContainer().getNamedQueries().iterator().hasNext()); - assertEquals(0, ormEntity.getPersistenceUnit().getQueriesSize()); - } - - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAttributes = entity.getOverridableAttributeNames().iterator(); - assertFalse(overridableAttributes.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = entity.getOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAttributeNames = entity.getOverridableAttributeNames().iterator(); - assertFalse(overridableAttributeNames.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = entity.getOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAttributes = ormEntity.getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - OrmEntity abstractEntity = (OrmEntity) ormEntity.getParentEntity(); - overridableAttributes = abstractEntity.getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAssociations = ormEntity.getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - OrmEntity abstractEntity = (OrmEntity) ormEntity.getParentEntity(); - overridableAssociations = abstractEntity.getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } -//TODO -// public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); -// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// Iterator<PersistentAttribute> overridableAttributes = getJavaEntity().allOverridableAttributes(); -// assertEquals("id", overridableAttributes.next().getName()); -// assertEquals("name", overridableAttributes.next().getName()); -// assertEquals("foo", overridableAttributes.next().getName()); -// assertFalse(overridableAttributes.hasNext()); -// } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAttributeNames = ormEntity.getAllOverridableAttributeNames().iterator(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - - ListIterator<OrmAttributeOverride> specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAttributeOverrides.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().add(1, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("BAZ"); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().move(1, 0); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testDefaultAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) ormEntity.getPersistentType().getSuperPersistentType().getMapping(); - - mappedSuperclass.getPersistentType().getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - } - - public void testDefaultAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - OrmEntity superclass = (OrmEntity) ormEntity.getParentEntity(); - - superclass.getPersistentType().getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - virtualAttributeOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("BAR"); - - assertEquals(2, overrideContainer.getSpecifiedOverridesSize()); - } - - public void testDefaultAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(0, overrideContainer.getVirtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(3, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(3, overrideContainer.getOverridesSize()); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("bar"); - assertEquals(4, overrideContainer.getOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("id", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("name", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - ListIterator<OrmVirtualAttributeOverride> virtualAttributeOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getAttributeOverrides().size()); - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("foo", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - - Iterator<OrmAttributeOverride> attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - assertEquals("foo", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals(1, entityResource.getAttributeOverrides().size()); - - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - assertEquals(0, entityResource.getAttributeOverrides().size()); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals(3, entityResource.getAttributeOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("foo", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(2).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - assertEquals("foo", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("name", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().add(1, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().add(2, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(2, 0); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(0, 1); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - attributeOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - ListIterator<OrmVirtualAttributeOverride> virtualAttributeOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAssociationNames = entity.getOverridableAssociationNames().iterator(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAssociationNames = ormEntity.getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertEquals("address3", overridableAssociationNames.next()); - assertEquals("address4", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator<String> overridableAssociations = ormEntity.getAllOverridableAssociationNames().iterator(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmAssociationOverride> specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(0, xmlAssociationOverride); - xmlAssociationOverride.setName("FOO"); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(1, xmlAssociationOverride); - xmlAssociationOverride.setName("BAR"); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(0, xmlAssociationOverride); - xmlAssociationOverride.setName("BAZ"); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - entityResource.getAssociationOverrides().move(1, 0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testDefaultAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(FULLY_QUALIFIED_SUB_TYPE_NAME, entityResource.getClassName()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - - assertEquals(4, overrideContainer.getVirtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - -// -// //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); -// //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); -// //idMapping.getColumn().setSpecifiedName("FOO"); -// //idMapping.getColumn().setSpecifiedTable("BAR"); -// -// assertEquals(SUB_TYPE_NAME, entityResource.getName()); -// assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); -// assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.getVirtualOverridesSize()); - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - -// //idMapping.getColumn().setSpecifiedName(null); -// //idMapping.getColumn().setSpecifiedTable(null); -// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -// assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); -// assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.getVirtualOverrides().iterator().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, overrideContainer.getSpecifiedOverridesSize()); - - //add to the resource model and verify the context model is updated - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("BAR"); - - assertEquals(2, overrideContainer.getSpecifiedOverridesSize()); - } - - public void testDefaultAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(3, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(2, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(0, overrideContainer.getVirtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(4, overrideContainer.getOverridesSize()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - assertEquals(4, overrideContainer.getOverridesSize()); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("bar"); - assertEquals(5, overrideContainer.getOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("address", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address2", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, entityResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, entityResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(2, entityResource.getAssociationOverrides().size()); - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals(1, entityResource.getAssociationOverrides().size()); - - Iterator<OrmAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.getSpecifiedOverrides().iterator().next().convertToVirtual(); - assertEquals(0, entityResource.getAssociationOverrides().size()); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(2, entityResource.getAssociationOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator<OrmAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", entityResource.getAssociationOverrides().get(1).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - assertEquals("address", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address2", entityResource.getAssociationOverrides().get(1).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().add(1, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().add(2, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAssociationOverride> associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(2, 0); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(0, 1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - associationOverrides = overrideContainer.getSpecifiedOverrides().iterator(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.getVirtualOverrides().iterator().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.getSpecifiedOverrides().iterator().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAttributeOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<OrmVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - OrmAttributeOverride specifiedAttributeOverride = ((OrmVirtualAttributeOverride) ((OrmEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - public void testNestedVirtualAttributeOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAttributeOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<OrmVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - OrmAttributeOverride specifiedAttributeOverride = ((OrmVirtualAttributeOverride) ((OrmEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAssociationOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, attributeOverrideContainer.getVirtualOverridesSize()); - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = attributeOverrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testNestedVirtualAssociationOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAssociationOverrideContainer overrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, overrideContainer.getVirtualOverridesSize()); - ListIterator<OrmVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.getVirtualOverrides().iterator(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testSetSpecifiedCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, entityResource.getCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, entityResource.getCacheable()); - - cacheable.setSpecifiedCacheable(null); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - } - - public void testGetSpecifiedCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - - entityResource.setCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, entityResource.getCacheable()); - - entityResource.setCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, entityResource.getCacheable()); - - entityResource.setCacheable(null); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - } - - public void testIsDefaultCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - assertEquals(SharedCacheMode.UNSPECIFIED, persistenceUnit2_0.getSharedCacheMode()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromSuperType() throws Exception { - createTestEntity(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subOrmPersistentType.getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromJava() throws Exception { - createTestEntity(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subOrmPersistentType.getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - - Cacheable2_0 javaCacheable = ((CacheableHolder2_0) ormPersistentType.getJavaPersistentType().getMapping()).getCacheable(); - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - //This is a test for bug 301892 - public void testAssociationOverrideJoinTableUpdate() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity resourceEntity = getXmlEntityMappings().getEntities().get(0); - - XmlAssociationOverride_2_0 resourceAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - resourceEntity.getAssociationOverrides().add((XmlAssociationOverride) resourceAssociationOverride); - ((XmlAssociationOverride) resourceAssociationOverride).setName("a"); - - OrmAssociationOverride associationOverride = entity.getAssociationOverrideContainer().getSpecifiedOverrides().iterator().next(); - assertEquals("a", associationOverride.getName()); - - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - resourceAssociationOverride.setJoinTable(resourceJoinTable); - resourceJoinTable.setName("FOO"); - XmlJoinColumn resourceJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumn(); - resourceJoinTable.getInverseJoinColumns().add(resourceJoinColumn); - resourceJoinColumn.setName("BAR"); - - associationOverride = entity.getAssociationOverrideContainer().getSpecifiedOverrides().iterator().next(); - assertEquals("a", associationOverride.getName()); - JoinTable joinTable = ((OrmOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("BAR", joinTable.getInverseJoinColumns().iterator().next().getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java deleted file mode 100644 index 43ac4cf2c0..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java +++ /dev/null @@ -1,1197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.Column; -import org.eclipse.jpt.jpa.core.context.Entity; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.ManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn; -import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter; -import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ManyToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaManyToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmManyToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlManyToMany_2_0; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmManyToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmManyToManyMapping2_0Tests(String name) { - super(name); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<State> state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map<String, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, JPA2_0.MAP_KEY_ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" @MapKeyEnumerated(EnumType.STRING)").append(CR); - sb.append(" private java.util.Map<String, Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributes().iterator().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNotNull(manyToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKey().setName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey().getName()); - - manyToMany.getMapKey().setName("myMapKey"); - manyToMany.setMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualManyToManyMapping.getSpecifiedMapKey()); - assertNull(virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertTrue(virtualManyToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setPkMapKey(true); - assertEquals("id", virtualManyToManyMapping.getMapKey()); - assertTrue(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setCustomMapKey(true); - javaManyToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualManyToManyMapping.getSpecifiedMapKey()); - assertEquals("city", virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertTrue(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany xmlManyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(xmlManyToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", xmlManyToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setSpecifiedMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(xmlManyToMany.getMapKey().getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - - Iterator<String> mapKeyNames = virtualManyToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = virtualManyToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - javaManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualManyToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - virtualManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = virtualManyToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - virtualManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualManyToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - virtualManyToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = virtualManyToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNotNull(manyToMany.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKeyClass().setClassName("String"); - assertEquals("String", ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", manyToMany.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKeyClass().setClassName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass().getClassName()); - - manyToMany.getMapKeyClass().setClassName("String"); - manyToMany.setMapKeyClass(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping2_0 virtualManyToManyMapping = (ManyToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", virtualManyToManyMapping.getMapKeyClass()); - assertNull(virtualManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualManyToManyMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualManyToManyMapping.getMapKeyClass()); - assertEquals("Integer", virtualManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualManyToManyMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", manyToMany.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType printQueuePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - OrmPersistentAttribute jobsPersistentAttribute = printQueuePersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmManyToManyMapping jobsMapping = (OrmManyToManyMapping) jobsPersistentAttribute.getMapping(); - jobsMapping.getRelationship().setStrategyToMappedBy(); - jobsMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("queues"); - - OrmPersistentType printJobPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute queuesPersistentAttribute = printJobPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "queues"); - OrmManyToManyMapping queuesMapping = (OrmManyToManyMapping) queuesPersistentAttribute.getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - OrderColumn2_0 jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - OrderColumn2_0 queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - - jobsOrderable.setOrderColumnOrdering(true); - jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(null, jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderable.setOrderColumnOrdering(true); - queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(null, queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - jobsOrderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderColumn.setSpecifiedName("BAR"); - assertEquals("BAR", queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - assertEquals("MY_TABLE_PrintQueue", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printQueuePersistentType.getMapping()).getTable().setSpecifiedName("OTHER_TABLE"); - assertEquals("MY_TABLE_OTHER_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_OTHER_TABLE", queuesOrderColumn.getTable()); - - queuesMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_JOIN_TABLE", queuesOrderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType printQueuePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - OrmPersistentAttribute jobsPersistentAttribute = printQueuePersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmManyToManyMapping jobsMapping = (OrmManyToManyMapping) jobsPersistentAttribute.getMapping(); - - OrmPersistentType printJobPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute queuesPersistentAttribute = printJobPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "queues"); - OrmManyToManyMapping queuesMapping = (OrmManyToManyMapping) queuesPersistentAttribute.getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - JavaManyToManyMapping javaJobsManyToManyMapping = (JavaManyToManyMapping) jobsPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaJobsManyToManyMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - jobsPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute jobsPersistentAttribute2 = printQueuePersistentType.getAttributeNamed("jobs"); - ManyToManyMapping virtualJobsMapping = (ManyToManyMapping) jobsPersistentAttribute2.getMapping(); - jobsOrderable = ((Orderable2_0) virtualJobsMapping.getOrderable()); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(false, jobsOrderable.isNoOrdering()); - assertEquals("PrintJob_PrintQueue", jobsOrderable.getOrderColumn().getTable()); - assertEquals("jobs_ORDER", jobsOrderable.getOrderColumn().getName()); - queuesPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute queuesPersistentAttribute2 = printJobPersistentType.getAttributeNamed("queues"); - ManyToManyMapping virtualQueuesMapping = (ManyToManyMapping) queuesPersistentAttribute2.getMapping(); - queuesOrderable = ((Orderable2_0) virtualQueuesMapping.getOrderable()); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(false, queuesOrderable.isNoOrdering()); - assertEquals("PrintJob_PrintQueue", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - - ((Orderable2_0) javaJobsManyToManyMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals("PrintJob_PrintQueue", jobsOrderable.getOrderColumn().getTable()); - assertEquals("FOO", jobsOrderable.getOrderColumn().getName()); - assertEquals("PrintJob_PrintQueue", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - - JavaManyToManyMapping javaQueuesManyToManyMapping = (JavaManyToManyMapping) queuesPersistentAttribute.getJavaPersistentAttribute().getMapping(); - javaQueuesManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JOIN_TABLE"); - assertEquals("JOIN_TABLE", jobsOrderable.getOrderColumn().getTable()); - assertEquals("FOO", jobsOrderable.getOrderColumn().getName()); - assertEquals("JOIN_TABLE", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany(mappedBy=\"queues\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List<test.PrintJob> jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List<test.PrintQueue> queues;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - ManyToManyMapping2_0 addressesVirtualMapping = (ManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", ormColumn.getName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertTrue(ormColumn.isInsertable()); - assertTrue(ormColumn.isUpdatable()); - assertTrue(ormColumn.isNullable()); - assertFalse(ormColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getScale()); - - //set Column annotation in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaManyToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmManyToManyMapping2_0 addressesVirtualMapping = (OrmManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaManyToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - ManyToManyMapping2_0 addressesVirtualMapping = (ManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column column = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_Address", column.getTable()); - - //entity table changes the join table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE_Address", column.getTable()); - - //set Column table element in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - assertEquals("JAVA_JOIN_TABLE", column.getTable()); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", column.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - column = addressesVirtualMapping.getMapKeyColumn(); - assertNull(column.getSpecifiedTable()); - assertEquals("ORM_TABLE_Address", column.getDefaultTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - ManyToManyMapping2_0 virtualManyToManyMapping = (ManyToManyMapping2_0) virtualAttribute.getMapping(); - assertEquals("address", virtualManyToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualManyToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) virtualManyToManyMapping.getMapKeyConverter()).getEnumType()); - - Cascade2_0 cascade = (Cascade2_0) virtualManyToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(virtualManyToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - OrmReadOnlyPersistentAttribute ormPersistentAttribute= ormPersistentType.getSpecifiedAttributes().iterator().next(); - - ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch()); - assertEquals("test.Address", ormManyToManyMapping.getTargetEntity()); - assertNull(ormManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertTrue(ormManyToManyMapping.getMapKeyConverter() instanceof NullOrmConverter); - - Cascade2_0 cascade = (Cascade2_0) ormManyToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } - - public void testUpdateSpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - assertNull(manyToManyResource.getMapKeyEnumerated()); - - //set enumerated in the resource model, verify context model updated - manyToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, manyToManyResource.getMapKeyEnumerated()); - - manyToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, manyToManyResource.getMapKeyEnumerated()); - - //set enumerated to null in the resource model - manyToManyResource.setMapKeyEnumerated(null); - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - assertNull(manyToManyResource.getMapKeyEnumerated()); - } - - public void testModifySpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "ManyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - assertNull(manyToManyResource.getMapKeyEnumerated()); - - //set enumerated in the context model, verify resource model updated - ormManyToManyMapping.setMapKeyConverter(EnumeratedConverter.class); - ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.ORDINAL); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, manyToManyResource.getMapKeyEnumerated()); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, manyToManyResource.getMapKeyEnumerated()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormManyToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - //set enumerated to null in the context model - ormManyToManyMapping.setMapKeyConverter(null); - assertNull(manyToManyResource.getMapKeyEnumerated()); - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - } - - public void testUpdateSpecifiedTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "ManyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - assertNull(manyToManyResource.getMapKeyTemporal()); - - //set temporal in the resource model, verify context model updated - manyToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, manyToManyResource.getMapKeyTemporal()); - - manyToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, manyToManyResource.getMapKeyTemporal()); - - manyToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP, manyToManyResource.getMapKeyTemporal()); - - //set temporal to null in the resource model - manyToManyResource.setMapKeyTemporal(null); - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - assertNull(manyToManyResource.getMapKeyTemporal()); - } - - public void testModifySpecifiedTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "ManyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - assertNull(manyToManyResource.getMapKeyTemporal()); - - //set temporal in the context model, verify resource model updated - ormManyToManyMapping.setMapKeyConverter(TemporalConverter.class); - ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, manyToManyResource.getMapKeyTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType()); - - ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, manyToManyResource.getMapKeyTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormManyToManyMapping.getMapKeyConverter()).getTemporalType()); - - //set temporal to null in the context model - ormManyToManyMapping.setMapKeyConverter(null); - assertNull(manyToManyResource.getMapKeyTemporal()); - assertNull(ormManyToManyMapping.getMapKeyConverter().getType()); - } - - public void testAddSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - JoinColumn joinColumn = ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - - JoinColumn joinColumn2 = ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(1).getName()); - - JoinColumn joinColumn3 = ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(2).getName()); - - ListIterator<? extends JoinColumn> joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToManyResource.getMapKeyJoinColumns().size()); - - ormManyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(2, manyToManyResource.getMapKeyJoinColumns().size()); - assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(1).getName()); - - ormManyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(1, manyToManyResource.getMapKeyJoinColumns().size()); - assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - - ormManyToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(0, manyToManyResource.getMapKeyJoinColumns().size()); - } - - public void testMoveSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - ormManyToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToManyResource.getMapKeyJoinColumns().size()); - - - ormManyToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(2).getName()); - - - ormManyToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1); - joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", manyToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAR", manyToManyResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", manyToManyResource.getMapKeyJoinColumns().get(2).getName()); - } - - public void testUpdateMapKeyJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - ManyToManyMapping2_0 ormManyToManyMapping = (ManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany_2_0 manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - manyToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - manyToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - manyToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - manyToManyResource.getMapKeyJoinColumns().get(0).setName("FOO"); - manyToManyResource.getMapKeyJoinColumns().get(1).setName("BAR"); - manyToManyResource.getMapKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<? extends JoinColumn> joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - manyToManyResource.getMapKeyJoinColumns().move(2, 0); - joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - manyToManyResource.getMapKeyJoinColumns().move(0, 1); - joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - manyToManyResource.getMapKeyJoinColumns().remove(1); - joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - manyToManyResource.getMapKeyJoinColumns().remove(1); - joinColumns = ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - manyToManyResource.getMapKeyJoinColumns().remove(0); - assertFalse(ormManyToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java deleted file mode 100644 index d178847a00..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java +++ /dev/null @@ -1,673 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinTable; -import org.eclipse.jpt.jpa.core.context.ManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaEntity; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinTable; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.jpa.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaManyToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmDerivedIdentity2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmManyToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity; -import org.eclipse.jpt.jpa.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.jpa.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlDerivedId_2_0; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlMapsId_2_0; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmManyToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmManyToOneMapping2_0Tests(String name) { - super(name); - } - - - private void createTestEntityWithIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEntityWithManyToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId("foo"); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(Boolean.TRUE); - assertNotNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute contextAttribute = (OrmPersistentAttribute) contextType.getAttributeNamed("manyToOne"); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - - XmlManyToOne resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - resourceManyToOne.setMapsId("foo"); - assertNull(resourceManyToOne.getId()); - assertFalse(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceManyToOne.getMapsId()); - assertEquals("foo", ((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - XmlOneToOne resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - assertNull(resourceOneToOne.getId()); - assertFalse(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceOneToOne.getMapsId()); - assertEquals("foo", ((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - assertNull(resourceManyToOne.getId()); - assertFalse(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceManyToOne.getMapsId()); - assertEquals("foo", ((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidManyToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - JavaManyToOneMapping2_0 javaManyToOneMapping = ((JavaManyToOneMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping()); - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, virtualJoinTable.getSpecifiedName()); - - createTestTargetEntityAddress(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - assertEquals(TYPE_NAME + "_Address", virtualJoinTable.getName()); - assertNull(virtualJoinTable.getSpecifiedCatalog()); - assertNull(virtualJoinTable.getSpecifiedSchema()); - assertEquals(0, virtualJoinTable.getSpecifiedJoinColumnsSize()); - assertEquals(0, virtualJoinTable.getSpecifiedInverseJoinColumnsSize()); - JoinColumn virtualJoinColumn = virtualJoinTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_Address", virtualJoinColumn.getDefaultTable()); - assertEquals(TYPE_NAME + "_id", virtualJoinColumn.getDefaultName()); - assertEquals("id", virtualJoinColumn.getDefaultReferencedColumnName()); - JoinColumn virtualInverseJoinColumn = virtualJoinTable.getDefaultInverseJoinColumn(); - assertEquals(TYPE_NAME + "_Address", virtualInverseJoinColumn.getDefaultTable()); - assertEquals("address_id", virtualInverseJoinColumn.getDefaultName()); - assertEquals("id", virtualInverseJoinColumn.getDefaultReferencedColumnName()); - - JavaJoinTable javaJoinTable = ((JavaManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", virtualJoinTable.getSpecifiedName()); - assertEquals("CATALOG", virtualJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualJoinTable.getSpecifiedSchema()); - assertEquals(1, virtualJoinTable.getSpecifiedJoinColumnsSize()); - assertEquals(1, virtualJoinTable.getSpecifiedInverseJoinColumnsSize()); - virtualJoinColumn = virtualJoinTable.getSpecifiedJoinColumns().iterator().next(); - assertEquals("NAME", virtualJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", virtualJoinColumn.getSpecifiedReferencedColumnName()); - virtualInverseJoinColumn = virtualJoinTable.getSpecifiedInverseJoinColumns().iterator().next(); - assertEquals("INVERSE_NAME", virtualInverseJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", virtualInverseJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidManyToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - OrmManyToOneMapping2_0 ormManyToOneMapping = (OrmManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((ManyToOneRelationship2_0) ormManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - OrmJoinTable ormJoinTable = ((OrmManyToOneRelationship2_0) ormManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTestTargetEntityAddress(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - JavaManyToOneMapping2_0 javaManyToOneMapping = (JavaManyToOneMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("address").getMapping(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) virtualPersistentAttribute.getMapping(); - JoinTable virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertTrue(virtualPersistentAttribute.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", virtualJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().removeStrategy(); - virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", virtualJoinTable.getDefaultName()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmManyToOneRelationship2_0 rel = (OrmManyToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmManyToOneRelationship2_0 rel = (OrmManyToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - ManyToOneMapping virtualManyToOneMapping = (ManyToOneMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualManyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualManyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualManyToOneMapping.getSpecifiedTargetEntity()); - - JoinColumn virtualJoinColumn = virtualManyToOneMapping.getRelationship().getJoinColumnStrategy().getSpecifiedJoinColumns().iterator().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) virtualManyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute= ormPersistentType.getSpecifiedAttributes().iterator().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(true, ormManyToOneMapping.isDefaultOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - Cascade2_0 cascade = (Cascade2_0) ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java deleted file mode 100644 index ff0785e334..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java +++ /dev/null @@ -1,1486 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.Column; -import org.eclipse.jpt.jpa.core.context.Entity; -import org.eclipse.jpt.jpa.core.context.EnumType; -import org.eclipse.jpt.jpa.core.context.EnumeratedConverter; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.OneToManyMapping; -import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn; -import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.TemporalConverter; -import org.eclipse.jpt.jpa.core.context.TemporalType; -import org.eclipse.jpt.jpa.core.context.java.JavaEntity; -import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.NullOrmConverter; -import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrphanRemovalHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOneToManyMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOneToManyRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity; -import org.eclipse.jpt.jpa.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlOneToMany_2_0; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmOneToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmOneToManyMapping2_0Tests(String name) { - super(name); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<State> state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityWithValidOneToManyMapping() throws Exception { - this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map<String, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map<String, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, JPA2_0.MAP_KEY_ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" @MapKeyEnumerated(EnumType.STRING)").append(CR); - sb.append(" private java.util.Collection<Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.name"); - assertEquals("name", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributes().iterator().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.name"); - assertEquals("name", stateFooMapping.getName()); - } - private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) { - return ((OrmOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval(); - } - - public void testUpdateSpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToManyMapping); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToManyResource.getOrphanRemoval()); - - //set enumerated in the resource model, verify context model updated - oneToManyResource.setOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval()); - - oneToManyResource.setOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval()); - } - - public void testModifySpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToManyMapping); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToManyResource.getOrphanRemoval()); - - //set enumerated in the context model, verify resource model updated - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval()); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval()); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToManyMapping.getMapKey()); - assertFalse(oneToManyMapping.isPkMapKey()); - assertFalse(oneToManyMapping.isCustomMapKey()); - assertTrue(oneToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setPkMapKey(true); - assertEquals("id", oneToManyMapping.getMapKey()); - assertTrue(oneToManyMapping.isPkMapKey()); - assertFalse(oneToManyMapping.isCustomMapKey()); - assertFalse(oneToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setCustomMapKey(true); - javaOneToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("city", oneToManyMapping.getMapKey()); - assertFalse(oneToManyMapping.isPkMapKey()); - assertTrue(oneToManyMapping.isCustomMapKey()); - assertFalse(oneToManyMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = oneToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = oneToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = oneToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = oneToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = oneToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = oneToManyMapping.getCandidateMapKeyNames().iterator(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNotNull(oneToMany.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKeyClass().setClassName("String"); - assertEquals("String", ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", oneToMany.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKeyClass().setClassName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass().getClassName()); - - oneToMany.getMapKeyClass().setClassName("String"); - oneToMany.setMapKeyClass(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", oneToManyMapping.getMapKeyClass()); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", oneToManyMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", oneToManyMapping.getMapKeyClass()); - assertEquals("Integer", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", oneToMany.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmOneToManyMapping oneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - oneToManyMapping.getRelationship().setStrategyToMappedBy(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("queue"); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - OrmPersistentType printJobPersistentType = (OrmPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - - assertEquals("MY_TABLE", orderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("jobs"); - oneToManyMapping = (OneToManyMapping) ormPersistentAttribute2.getMapping(); - orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(false, orderable.isNoOrdering()); - assertEquals("PrintJob", orderable.getOrderColumn().getTable()); - assertEquals("jobs_ORDER", orderable.getOrderColumn().getName()); - - ((Orderable2_0) javaOneToManyMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals("PrintJob", orderable.getOrderColumn().getTable()); - assertEquals("FOO", orderable.getOrderColumn().getName()); - } - - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @OneToMany(mappedBy=\"queue\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List<PrintJob> jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private PrintQueue queue;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 virtualAddressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = virtualAddressesMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_Address", virtualColumn.getTable()); - assertNull(virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaOneToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getName()); - assertEquals("FOO_TABLE", virtualColumn.getTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertFalse(virtualColumn.isInsertable()); - assertFalse(virtualColumn.isUpdatable()); - assertFalse(virtualColumn.isNullable()); - assertTrue(virtualColumn.isUnique()); - assertEquals(45, virtualColumn.getLength()); - assertEquals(46, virtualColumn.getPrecision()); - assertEquals(47, virtualColumn.getScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmOneToManyMapping2_0 addressesVirtualMapping = (OrmOneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaOneToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - OneToManyMapping2_0 virtualAddressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = virtualAddressesMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_Address", virtualColumn.getTable()); - assertNull(virtualColumn.getSpecifiedTable()); - - //entity table changes the join table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE_Address", virtualColumn.getTable()); - - //set Column table element in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - assertEquals("JAVA_JOIN_TABLE", virtualColumn.getTable()); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - OneToManyMapping2_0 specifiedAddressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column specifiedColumn = specifiedAddressesMapping.getMapKeyColumn(); - assertNull(specifiedColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE_Address", specifiedColumn.getDefaultTable()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 contextMapping = (OrmOneToManyMapping2_0) contextAttribute.getMapping(); - OrmOneToManyRelationship2_0 rel = (OrmOneToManyRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 contextMapping = (OrmOneToManyMapping2_0) contextAttribute.getMapping(); - OrmOneToManyRelationship2_0 rel = (OrmOneToManyRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testTargetForeignKeyJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - OneToManyRelationship2_0 rr = (OneToManyRelationship2_0) javaOneToManyMapping.getRelationship(); - rr.setStrategyToJoinColumn(); - - JoinColumn joinColumn = rr.getJoinColumnStrategy().getJoinColumns().iterator().next(); - assertTrue(persistentAttribute.isVirtual()); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("Address", joinColumn.getDefaultTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - oneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - rr = (OneToManyRelationship2_0) oneToManyMapping.getRelationship(); - assertFalse(rr.strategyIsJoinColumn()); - - rr.setStrategyToJoinColumn(); - joinColumn = rr.getJoinColumnStrategy().getSpecifiedJoinColumns().iterator().next(); - assertFalse(persistentAttribute.isVirtual()); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - joinColumn.setSpecifiedName("FOO"); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - } - - //target foreign key case - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - OneToManyRelationship2_0 rr = (OneToManyRelationship2_0) javaOneToManyMapping.getRelationship(); - rr.setStrategyToJoinColumn(); - - assertTrue(persistentAttribute.isVirtual()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, Kind.TYPE); - JavaResourceField resourceField = resourceType.getFields().iterator().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) resourceField.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - oneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - rr = (OneToManyRelationship2_0) oneToManyMapping.getRelationship(); - assertFalse(rr.strategyIsJoinColumn()); - - rr.setStrategyToJoinColumn(); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - oneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("FOO", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - } - - //target foreign key case - public void testOrderColumnDefaultsJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - OneToManyRelationship2_0 rr = (OneToManyRelationship2_0) javaOneToManyMapping.getRelationship(); - rr.setStrategyToJoinColumn(); - ((Orderable2_0) javaOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals("Address", orderColumn.getTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - oneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - rr = (OneToManyRelationship2_0) oneToManyMapping.getRelationship(); - assertFalse(rr.strategyIsJoinColumn()); - - rr.setStrategyToJoinColumn(); - assertFalse(((Orderable2_0) oneToManyMapping.getOrderable()).isOrderColumnOrdering()); - ((Orderable2_0) oneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - OneToManyMapping2_0 virtualOneToManyMapping = (OneToManyMapping2_0) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualOneToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) virtualOneToManyMapping.getMapKeyConverter()).getEnumType()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(virtualOneToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertTrue(((OrphanRemovalHolder2_0) virtualOneToManyMapping).getOrphanRemoval().isOrphanRemoval()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch()); - assertEquals("test.Address", ormOneToManyMapping.getTargetEntity()); - assertNull(ormOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertTrue(ormOneToManyMapping.getMapKeyConverter() instanceof NullOrmConverter); - - Cascade2_0 cascade = (Cascade2_0) ormOneToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval()); - } - - public void testUpdateSpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - assertNull(oneToManyResource.getMapKeyEnumerated()); - - //set enumerated in the resource model, verify context model updated - oneToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, oneToManyResource.getMapKeyEnumerated()); - - oneToManyResource.setMapKeyEnumerated(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, oneToManyResource.getMapKeyEnumerated()); - - //set enumerated to null in the resource model - oneToManyResource.setMapKeyEnumerated(null); - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - assertNull(oneToManyResource.getMapKeyEnumerated()); - } - - public void testModifySpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - assertNull(oneToManyResource.getMapKeyEnumerated()); - - //set enumerated in the context model, verify resource model updated - ormOneToManyMapping.setMapKeyConverter(EnumeratedConverter.class); - ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.ORDINAL); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.ORDINAL, oneToManyResource.getMapKeyEnumerated()); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.EnumType.STRING, oneToManyResource.getMapKeyEnumerated()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormOneToManyMapping.getMapKeyConverter()).getSpecifiedEnumType()); - - //set enumerated to null in the context model - ormOneToManyMapping.setMapKeyConverter(null); - assertNull(oneToManyResource.getMapKeyEnumerated()); - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - } - - public void testUpdateSpecifiedTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - assertNull(oneToManyResource.getMapKeyTemporal()); - - //set temporal in the resource model, verify context model updated - oneToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, oneToManyResource.getMapKeyTemporal()); - - oneToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, oneToManyResource.getMapKeyTemporal()); - - oneToManyResource.setMapKeyTemporal(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIMESTAMP, oneToManyResource.getMapKeyTemporal()); - - //set temporal to null in the resource model - oneToManyResource.setMapKeyTemporal(null); - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - assertNull(oneToManyResource.getMapKeyTemporal()); - } - - public void testModifySpecifiedTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - assertNull(oneToManyResource.getMapKeyTemporal()); - - //set temporal in the context model, verify resource model updated - ormOneToManyMapping.setMapKeyConverter(TemporalConverter.class); - ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.DATE, oneToManyResource.getMapKeyTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType()); - - ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.jpa.core.resource.orm.TemporalType.TIME, oneToManyResource.getMapKeyTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormOneToManyMapping.getMapKeyConverter()).getTemporalType()); - - //set temporal to null in the context model - ormOneToManyMapping.setMapKeyConverter(null); - assertNull(oneToManyResource.getMapKeyTemporal()); - assertNull(ormOneToManyMapping.getMapKeyConverter().getType()); - } - - public void testAddSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - JoinColumn joinColumn = ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - - JoinColumn joinColumn2 = ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(1).getName()); - - JoinColumn joinColumn3 = ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(2).getName()); - - ListIterator<? extends JoinColumn> joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToManyResource.getMapKeyJoinColumns().size()); - - ormOneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(2, oneToManyResource.getMapKeyJoinColumns().size()); - assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(1).getName()); - - ormOneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(1, oneToManyResource.getMapKeyJoinColumns().size()); - assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - - ormOneToManyMapping.removeSpecifiedMapKeyJoinColumn(0); - assertEquals(0, oneToManyResource.getMapKeyJoinColumns().size()); - } - - public void testMoveSpecifiedMapKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(0).setSpecifiedName("FOO"); - ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(1).setSpecifiedName("BAR"); - ormOneToManyMapping.addSpecifiedMapKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToManyResource.getMapKeyJoinColumns().size()); - - - ormOneToManyMapping.moveSpecifiedMapKeyJoinColumn(2, 0); - ListIterator<? extends JoinColumn> joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(2).getName()); - - - ormOneToManyMapping.moveSpecifiedMapKeyJoinColumn(0, 1); - joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToManyResource.getMapKeyJoinColumns().get(0).getName()); - assertEquals("BAR", oneToManyResource.getMapKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToManyResource.getMapKeyJoinColumns().get(2).getName()); - } - - public void testUpdateMapKeyJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OneToManyMapping2_0 ormOneToManyMapping = (OneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany_2_0 oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - oneToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - oneToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - oneToManyResource.getMapKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - oneToManyResource.getMapKeyJoinColumns().get(0).setName("FOO"); - oneToManyResource.getMapKeyJoinColumns().get(1).setName("BAR"); - oneToManyResource.getMapKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<? extends JoinColumn> joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - oneToManyResource.getMapKeyJoinColumns().move(2, 0); - joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - oneToManyResource.getMapKeyJoinColumns().move(0, 1); - joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - oneToManyResource.getMapKeyJoinColumns().remove(1); - joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - oneToManyResource.getMapKeyJoinColumns().remove(1); - joinColumns = ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - oneToManyResource.getMapKeyJoinColumns().remove(0); - assertFalse(ormOneToManyMapping.getSpecifiedMapKeyJoinColumns().iterator().hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java deleted file mode 100644 index d90195fd20..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java +++ /dev/null @@ -1,990 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.JoinColumn; -import org.eclipse.jpt.jpa.core.context.JoinTable; -import org.eclipse.jpt.jpa.core.context.OneToOneMapping; -import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaEntity; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.jpa.core.context.java.JavaJoinTable; -import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; -import org.eclipse.jpt.jpa.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.OrphanRemovalHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaOneToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmDerivedIdentity2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOneToOneRelationship2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; -import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity; -import org.eclipse.jpt.jpa.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.jpa.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlDerivedId_2_0; -import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlMapsId_2_0; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmOneToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmOneToOneMapping2_0Tests(String name) { - super(name); - } - - - private void createTestEntityWithIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection<State> state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private void createTestEntityWithOneToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : ormPersistentType.getAttributes()) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedIdAttributeName(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(Boolean.TRUE); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId("foo"); - assertNotNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(null); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute contextAttribute = (OrmPersistentAttribute) contextType.getAttributeNamed("oneToOne"); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - - XmlOneToOne resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - resourceOneToOne.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceOneToOne.getId()); - assertTrue(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceOneToOne.getMapsId()); - assertNull(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - XmlManyToOne resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - assertEquals(Boolean.TRUE, resourceManyToOne.getId()); - assertTrue(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceManyToOne.getMapsId()); - assertNull(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - assertEquals(Boolean.TRUE, resourceOneToOne.getId()); - assertTrue(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceOneToOne.getMapsId()); - assertNull(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedIdAttributeName()); - - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributes().iterator().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().getCandidateMappedByAttributeNames().iterator(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToOneMapping2_0 oneToOneMapping) { - return ((OrmOrphanRemovalHolder2_0) oneToOneMapping).getOrphanRemoval(); - } - - public void testUpdateSpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToOneMapping); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToOneResource.getOrphanRemoval()); - - //set enumerated in the resource model, verify context model updated - oneToOneResource.setOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.TRUE, oneToOneResource.getOrphanRemoval()); - - oneToOneResource.setOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.FALSE, oneToOneResource.getOrphanRemoval()); - } - - public void testModifySpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToOneMapping); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToOneResource.getOrphanRemoval()); - - //set enumerated in the context model, verify resource model updated - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneResource.getOrphanRemoval()); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneResource.getOrphanRemoval()); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidOneToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - JavaOneToOneMapping2_0 javaOneToOneMapping = ((JavaOneToOneMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping()); - JavaOneToOneMapping2_0 virtualOneToOneMapping = (JavaOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, virtualJoinTable.getSpecifiedName()); - - createTestTargetEntityAddress(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals(TYPE_NAME + "_Address", virtualJoinTable.getDefaultName()); - assertNull(virtualJoinTable.getSpecifiedCatalog()); - assertNull(virtualJoinTable.getSpecifiedSchema()); - assertEquals(0, virtualJoinTable.getSpecifiedJoinColumnsSize()); - assertEquals(0, virtualJoinTable.getSpecifiedInverseJoinColumnsSize()); - JoinColumn ormJoinColumn = virtualJoinTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_Address", ormJoinColumn.getDefaultTable()); - assertEquals(TYPE_NAME + "_id", ormJoinColumn.getDefaultName()); - assertEquals("id", ormJoinColumn.getDefaultReferencedColumnName()); - JoinColumn inverseOrmJoinColumn = virtualJoinTable.getDefaultInverseJoinColumn(); - assertEquals(TYPE_NAME + "_Address", inverseOrmJoinColumn.getDefaultTable()); - assertEquals("address_id", inverseOrmJoinColumn.getDefaultName()); - assertEquals("id", inverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaJoinTable javaJoinTable = ((JavaOneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", virtualJoinTable.getSpecifiedName()); - assertEquals("CATALOG", virtualJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualJoinTable.getSpecifiedSchema()); - assertEquals(1, virtualJoinTable.getSpecifiedJoinColumnsSize()); - assertEquals(1, virtualJoinTable.getSpecifiedInverseJoinColumnsSize()); - ormJoinColumn = virtualJoinTable.getSpecifiedJoinColumns().iterator().next(); - assertEquals("NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - inverseOrmJoinColumn = virtualJoinTable.getSpecifiedInverseJoinColumns().iterator().next(); - assertEquals("INVERSE_NAME", inverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", inverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidOneToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((OneToOneRelationship2_0) ormOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - OrmJoinTable ormJoinTable = ((OrmOneToOneRelationship2_0) ormOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTestTargetEntityAddress(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - JavaOneToOneMapping2_0 javaOneToOneMapping = (JavaOneToOneMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("address").getMapping(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.getAttributeNamed("address"); - OneToOneMapping2_0 virtualOneToOneMapping = (OneToOneMapping2_0) virtualAttribute.getMapping(); - JoinTable virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertTrue(virtualAttribute.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", virtualJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().removeStrategy(); - virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("BAR_FOO", virtualJoinTable.getName()); - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", virtualJoinTable.getDefaultName()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmOneToOneRelationship2_0 rel = (OrmOneToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmOneToOneRelationship2_0 rel = (OrmOneToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getPrimaryKeyJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - - OneToOneMapping2_0 virtualOneToOneMapping = (OneToOneMapping2_0) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualOneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualOneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToOneMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - JoinColumn virtualJoinColumn = - virtualOneToOneMapping.getRelationship().getJoinColumnStrategy().getSpecifiedJoinColumns().iterator().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(((OrphanRemovalHolder2_0) virtualOneToOneMapping).getOrphanRemoval().isOrphanRemoval()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - - OneToOneMapping2_0 ormOneToOneMapping = (OneToOneMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java deleted file mode 100644 index d0bf3e8f57..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java +++ /dev/null @@ -1,565 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AccessType; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmPersistentAttribute2_0Tests - extends Generic2_0ContextModelTestCase -{ - - public GenericOrmPersistentAttribute2_0Tests(String name) { - super(name); - } - - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityIdMappingPropertyAccess() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(" private Address address;"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.getVirtualAttributesSize()); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.getVirtualAttributesSize()); - assertEquals(2, ormPersistentType.getSpecifiedAttributesSize()); - Iterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.getSpecifiedAttributes().iterator(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedWithAccess() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = CollectionTools.get(ormPersistentType.getVirtualAttributes(), 1); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertEquals(null, ormPersistentAttribute.getJavaPersistentAttribute().getSpecifiedAccess()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.getVirtualAttributesSize()); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertEquals(null, specifiedOrmPersistentAttribute.getSpecifiedAccess()); - assertEquals(AccessType.PROPERTY, specifiedOrmPersistentAttribute.getAccess()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.getVirtualAttributesSize()); - assertEquals(2, ormPersistentType.getSpecifiedAttributesSize()); - Iterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.getSpecifiedAttributes().iterator(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, specifiedOrmPersistentAttribute.getAccess()); - assertEquals(null, specifiedOrmPersistentAttribute.getSpecifiedAccess()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, specifiedOrmPersistentAttribute.getSpecifiedAccess()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.getVirtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertTrue(ormPersistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - ormPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmOneToOneMapping); - - - ormPersistentAttribute = ormPersistentType.getVirtualAttributes().iterator().next(); - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.getVirtualAttributesSize()); - assertEquals(2, ormPersistentType.getSpecifiedAttributesSize()); - Iterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.getSpecifiedAttributes().iterator(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - - ormPersistentType.getVirtualAttributes().iterator().next().convertToSpecified(); - ormPersistentType.getVirtualAttributes().iterator().next().convertToSpecified(); - - assertEquals(0, ormPersistentType.getVirtualAttributesSize()); - assertEquals(2, ormPersistentType.getSpecifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.getVirtualAttributesSize()); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - assertEquals(0, ormPersistentType.getSpecifiedAttributesSize()); - - Iterator<OrmReadOnlyPersistentAttribute> virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.getVirtualAttributesSize()); - - ormPersistentType.getVirtualAttributes().iterator().next().convertToSpecified(); - ormPersistentType.getVirtualAttributes().iterator().next().convertToSpecified(); - - - ormPersistentType.getSpecifiedAttributes().iterator().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.getVirtualAttributesSize()); - assertEquals(2, ormPersistentType.getSpecifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.getVirtualAttributesSize()); - assertEquals(1, ormPersistentType.getSpecifiedAttributesSize()); - - assertEquals("id", ormPersistentType.getVirtualAttributes().iterator().next().getName()); - assertEquals("name", ormPersistentType.getSpecifiedAttributes().iterator().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } - - public void testGetJavaPersistentAttribute() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - //virtual orm attribute, access type matches java : FIELD, name matches java - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - JavaResourceAttribute javaResourceAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute(); - assertTrue(javaResourceAttribute.getKind() == Kind.FIELD); - assertEquals("id", javaResourceAttribute.getName()); - assertEquals(javaPersistentType.getJavaResourceType().getFields().iterator().next(), javaResourceAttribute); - - - //specified orm attribute, access type matches java : FIELD, name matches java - //javaPersistentAttribute should be == to java context model object - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - - - //virtual orm attribute, java access type FIELD, orm access type PROPERTY, name matches java - //verify both the property java resource attribute and the field java resource attribute are used in orm - //because the field is annotated and property is specified - ((OrmPersistentAttribute) ormPersistentAttribute).convertToVirtual(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - ListIterator<OrmReadOnlyPersistentAttribute> attributes = ormPersistentType.getAttributes().iterator(); - OrmReadOnlyPersistentAttribute idFieldAttribute = attributes.next(); - OrmReadOnlyPersistentAttribute idPropertyAttribute = attributes.next(); - assertEquals(ormPersistentAttribute, idFieldAttribute); - assertNotSame(ormPersistentAttribute, idPropertyAttribute); - ormPersistentAttribute = idPropertyAttribute; - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.FIELD, idFieldAttribute.getJavaPersistentAttribute().getAccess()); - javaResourceAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute(); - assertEquals("id", javaResourceAttribute.getName()); - assertEquals(javaPersistentType.getJavaResourceType().getMethods().iterator().next(), javaResourceAttribute); - - - ormPersistentType.setSpecifiedAccess(null);//default access will be field - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmPersistentAttribute ormPersistentAttribute2 = ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute2.getMapping().setName("id2"); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName(null); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName("id"); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - } - - public void testGetJavaPersistentAttributeMixedAccess() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ListIterator<OrmReadOnlyPersistentAttribute> attributes = ormPersistentType.getAttributes().iterator(); - OrmReadOnlyPersistentAttribute ormFieldAttribute = attributes.next(); - OrmReadOnlyPersistentAttribute ormPropertyAttribute = attributes.next(); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertEquals(AccessType.FIELD, ormFieldAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, ormPropertyAttribute.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getOwningPersistentType().getAccess()); - assertTrue(ormFieldAttribute.isVirtual()); - assertTrue(ormPropertyAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPropertyAttribute.getJavaPersistentAttribute()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormFieldAttribute.getMappingKey()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPropertyAttribute.getMappingKey()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - - ormPropertyAttribute.convertToSpecified(); - ormPropertyAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPropertyAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPropertyAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPropertyAttribute.getJavaPersistentAttribute()); - assertTrue(ormPropertyAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.METHOD); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - - ((OrmPersistentAttribute) ormPropertyAttribute).setSpecifiedAccess(AccessType.FIELD); - ormPropertyAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPropertyAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPropertyAttribute.getAccess()); - assertEquals(javaPersistentAttribute, ormPropertyAttribute.getJavaPersistentAttribute()); - assertTrue(ormPropertyAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.FIELD); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - } - - public void testGetAccess() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.FIELD); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.FIELD); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - } - - public void testGetAccessPropertyInJava() throws Exception { - createTestEntityIdMappingPropertyAccess(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.METHOD); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.METHOD); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.METHOD); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.METHOD); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.METHOD); - } - - public void testGetAccessPropertyInJava2() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.METHOD); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.METHOD); - - - OrmReadOnlyPersistentAttribute nameOrmPersistentAttribute = ormPersistentType.getAttributeNamed("name"); - JavaPersistentAttribute nameJavaPersistentAttribute = javaPersistentType.getAttributeNamed("name"); - - assertTrue(nameOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getAccess()); - assertTrue(nameOrmPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.FIELD); - assertEquals(AccessType.FIELD, nameJavaPersistentAttribute.getAccess()); - assertTrue(nameJavaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.METHOD); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.METHOD); - - nameOrmPersistentAttribute.convertToSpecified(); - nameOrmPersistentAttribute = ormPersistentType.getAttributeNamed("name"); - assertFalse(nameOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertTrue(nameOrmPersistentAttribute.getJavaPersistentAttribute().getResourceAttribute().getKind() == Kind.FIELD); - assertEquals(AccessType.FIELD, nameJavaPersistentAttribute.getAccess()); - assertTrue(nameJavaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - assertEquals(nameJavaPersistentAttribute, nameOrmPersistentAttribute.getJavaPersistentAttribute()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourceAttribute().getKind() == Kind.METHOD); - - assertFalse(nameOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, nameOrmPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.FIELD, nameJavaPersistentAttribute.getAccess()); - assertTrue(nameJavaPersistentAttribute.getResourceAttribute().getKind() == Kind.FIELD); - - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java deleted file mode 100644 index a32aa28c65..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AccessType; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmPersistentType2_0Tests - extends Generic2_0ContextModelTestCase -{ - - public GenericOrmPersistentType2_0Tests(String name) { - super(name); - } - - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityFieldSpecifiedPropertyAnnotated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestEntityPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - public void testGetAccessWithJavaAnnotations() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - assertEquals(null, javaPersistentType.getSpecifiedAccess()); - - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentAttribute.convertToSpecified(); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - assertEquals(null, javaPersistentType.getSpecifiedAccess()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testGetAccessWithJavaAnnotationsProperty() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.PROPERTY, ormPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getSpecifiedAccess()); - - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentAttribute.convertToSpecified(); - assertEquals(AccessType.PROPERTY, ormPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getSpecifiedAccess()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testVirtualAttributes() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<OrmReadOnlyPersistentAttribute> virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - } - - public void testVirtualAttributes2() throws Exception { - createTestEntityPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<OrmReadOnlyPersistentAttribute> virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - } - - public void testVirtualAttributes3() throws Exception { - createTestEntityFieldSpecifiedPropertyAnnotated(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<OrmReadOnlyPersistentAttribute> virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - assertEquals(AccessType.PROPERTY, virtualAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - - virtualAttribute.convertToSpecified(); - - virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - - OrmPersistentAttribute specifiedAttribute = ormPersistentType.getSpecifiedAttributes().iterator().next(); - assertEquals("id", specifiedAttribute.getName()); - assertEquals(AccessType.PROPERTY, specifiedAttribute.getSpecifiedAccess()); - - - virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - virtualAttributes.next(); - virtualAttributes.next().convertToSpecified(); - virtualAttributes = ormPersistentType.getVirtualAttributes().iterator(); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - } - - public void testGetDefaultAccess() throws Exception { - createTestEntityPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - javaPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - javaPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java deleted file mode 100644 index 527e131e50..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm; - -import org.eclipse.jpt.jpa.core.jpa2.context.SequenceGenerator2_0; -import org.eclipse.jpt.jpa.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -/** - * Generic2_0OrmSequenceGenerator2_0Tests - */ -@SuppressWarnings("nls") -public class GenericOrmSequenceGenerator2_0Tests - extends Generic2_0ContextModelTestCase -{ - - public GenericOrmSequenceGenerator2_0Tests(String name) { - super(name); - } - - // ********** catalog ********** - - public void testUpdateSpecifiedCatalog() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setCatalog("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedCatalog()); - assertEquals("FOO", sequenceGeneratorResource.getCatalog()); - - //set name to null in the resource model - sequenceGeneratorResource.setCatalog(null); - assertNull(sequenceGenerator.getSpecifiedCatalog()); - assertNull(sequenceGeneratorResource.getCatalog()); - } - - public void testModifySpecifiedCatalog() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedCatalog("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getCatalog()); - assertEquals("FOO", sequenceGenerator.getSpecifiedCatalog()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedCatalog(null); - assertNull(sequenceGeneratorResource.getCatalog()); - assertNull(sequenceGenerator.getSpecifiedCatalog()); - } - - // ********** schema ********** - - public void testUpdateSpecifiedSchema() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setSchema("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedSchema()); - assertEquals("FOO", sequenceGeneratorResource.getSchema()); - - //set name to null in the resource model - sequenceGeneratorResource.setSchema(null); - assertNull(sequenceGenerator.getSpecifiedSchema()); - assertNull(sequenceGeneratorResource.getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedSchema("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getSchema()); - assertEquals("FOO", sequenceGenerator.getSpecifiedSchema()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedSchema(null); - assertNull(sequenceGeneratorResource.getSchema()); - assertNull(sequenceGenerator.getSpecifiedSchema()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java deleted file mode 100644 index a913b9e229..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.persistence; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.connection.JpaConnection2_0; - -/** - * GenericConnection2_0Tests - */ -@SuppressWarnings("nls") -public class Generic2_0ConnectionTests extends Generic2_0PersistenceUnitTests -{ - private JpaConnection2_0 connection; - - public static final String DRIVER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_DRIVER; - public static final String DRIVER_TEST_VALUE = "test"; - public static final String DRIVER_TEST_VALUE_2 = "test_2"; - - public static final String URL_KEY = JpaConnection2_0.PERSISTENCE_JDBC_URL; - public static final String URL_TEST_VALUE = "test"; - public static final String URL_TEST_VALUE_2 = "test_2"; - - public static final String USER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_USER; - public static final String USER_TEST_VALUE = "test"; - public static final String USER_TEST_VALUE_2 = "test_2"; - - public static final String PASSWORD_KEY = JpaConnection2_0.PERSISTENCE_JDBC_PASSWORD; - public static final String PASSWORD_TEST_VALUE = "test"; - public static final String PASSWORD_TEST_VALUE_2 = "test_2"; - - // ********** constructors ********** - public Generic2_0ConnectionTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.connection = (JpaConnection2_0) this.subject.getConnection(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.connection.addPropertyChangeListener(JpaConnection2_0.DRIVER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(JpaConnection2_0.URL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(JpaConnection2_0.USER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(JpaConnection2_0.PASSWORD_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PersistenceUnit properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 4; // PersistenceUnit properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(DRIVER_KEY, DRIVER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(URL_KEY, URL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(USER_KEY, USER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(PASSWORD_KEY, PASSWORD_TEST_VALUE.toString()); - - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.connection; - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(JpaConnection2_0.DRIVER_PROPERTY)) - modelValue = this.connection.getDriver(); - else if (propertyName.equals(JpaConnection2_0.URL_PROPERTY)) - modelValue = this.connection.getUrl(); - else if (propertyName.equals(JpaConnection2_0.USER_PROPERTY)) - modelValue = this.connection.getUser(); - else if (propertyName.equals(JpaConnection2_0.PASSWORD_PROPERTY)) - modelValue = this.connection.getPassword(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(JpaConnection2_0.DRIVER_PROPERTY)) - this.connection.setDriver((String) newValue); - else if (propertyName.equals(JpaConnection2_0.URL_PROPERTY)) - this.connection.setUrl((String) newValue); - else if (propertyName.equals(JpaConnection2_0.USER_PROPERTY)) - this.connection.setUser((String) newValue); - else if (propertyName.equals(JpaConnection2_0.PASSWORD_PROPERTY)) - this.connection.setPassword((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - // ********** Driver tests ********** - public void testSetDriver() throws Exception { - this.verifyModelInitialized( - DRIVER_KEY, - DRIVER_TEST_VALUE); - this.verifySetProperty( - DRIVER_KEY, - DRIVER_TEST_VALUE, - DRIVER_TEST_VALUE_2); - } - - public void testAddRemoveDriver() throws Exception { - this.verifyAddRemoveProperty( - DRIVER_KEY, - DRIVER_TEST_VALUE, - DRIVER_TEST_VALUE_2); - } - - // ********** Url tests ********** - public void testSetUrl() throws Exception { - this.verifyModelInitialized( - URL_KEY, - URL_TEST_VALUE); - this.verifySetProperty( - URL_KEY, - URL_TEST_VALUE, - URL_TEST_VALUE_2); - } - - public void testAddRemoveUrl() throws Exception { - this.verifyAddRemoveProperty( - URL_KEY, - URL_TEST_VALUE, - URL_TEST_VALUE_2); - } - - // ********** User tests ********** - public void testSetUser() throws Exception { - this.verifyModelInitialized( - USER_KEY, - USER_TEST_VALUE); - this.verifySetProperty( - USER_KEY, - USER_TEST_VALUE, - USER_TEST_VALUE_2); - } - - public void testAddRemoveUser() throws Exception { - this.verifyAddRemoveProperty( - USER_KEY, - USER_TEST_VALUE, - USER_TEST_VALUE_2); - } - - // ********** Password tests ********** - public void testSetPassword() throws Exception { - this.verifyModelInitialized( - PASSWORD_KEY, - PASSWORD_TEST_VALUE); - this.verifySetProperty( - PASSWORD_KEY, - PASSWORD_TEST_VALUE, - PASSWORD_TEST_VALUE_2); - } - - public void testAddRemovePassword() throws Exception { - this.verifyAddRemoveProperty( - PASSWORD_KEY, - PASSWORD_TEST_VALUE, - PASSWORD_TEST_VALUE_2); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java deleted file mode 100644 index 10ea07e67f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java +++ /dev/null @@ -1,520 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.persistence; - -import java.util.ListIterator; - -import org.eclipse.jpt.common.utility.model.event.ListAddEvent; -import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.common.utility.model.event.ListClearEvent; -import org.eclipse.jpt.common.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.common.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.options.JpaOptions2_0; - -/** - * GenericOptions2_0Tests - */ -@SuppressWarnings("nls") -public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests -{ - private JpaOptions2_0 options; - private ListChangeEvent prePersistEvent; - private ListChangeEvent preUpdateEvent; - private ListChangeEvent preRemoveEvent; - - public static final String LOCK_TIMEOUT_KEY = JpaOptions2_0.PERSISTENCE_LOCK_TIMEOUT; - public static final Integer LOCK_TIMEOUT_TEST_VALUE = 100; - public static final Integer LOCK_TIMEOUT_TEST_VALUE_2 = 200; - - public static final String QUERY_TIMEOUT_KEY = JpaOptions2_0.PERSISTENCE_QUERY_TIMEOUT; - public static final Integer QUERY_TIMEOUT_TEST_VALUE = 100; - public static final Integer QUERY_TIMEOUT_TEST_VALUE_2 = 200; - - public static final String VALIDATION_GROUP_PRE_PERSIST_KEY = JpaOptions2_0.PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST; - public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE = "test_pre-persist_group"; - public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2 = "test_2_pre-persist_group"; - - public static final String VALIDATION_GROUP_PRE_UPDATE_KEY = JpaOptions2_0.PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE; - public static final String VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE = "test_pre-update_group"; - public static final String VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2 = "test_2_pre-update_group"; - - public static final String VALIDATION_GROUP_PRE_REMOVE_KEY = JpaOptions2_0.PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE; - public static final String VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE = "test_pre-remove_group"; - public static final String VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2 = "test_2_pre-remove_group"; - - // ********** constructors ********** - public Generic2_0OptionsTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = (JpaOptions2_0) this.subject.getOptions(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.options.addPropertyChangeListener(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, propertyChangeListener); - - ListChangeListener validationGroupListChangeListener = this.buildValidationGroupListChangeListener(); - this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST, validationGroupListChangeListener); - this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST, validationGroupListChangeListener); - this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST, validationGroupListChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PersistenceUnit properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 5; // PersistenceUnit properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty(LOCK_TIMEOUT_KEY, LOCK_TIMEOUT_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(QUERY_TIMEOUT_KEY, QUERY_TIMEOUT_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.options; - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY)) - modelValue = this.options.getLockTimeout(); - else if (propertyName.equals(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY)) - modelValue = this.options.getQueryTimeout(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) { - ListIterator<String> iterator = this.options.getValidationGroupPrePersists().iterator(); - modelValue = this.getFirstElement(iterator); - } - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) { - ListIterator<String> iterator = this.options.getValidationGroupPreUpdates().iterator(); - modelValue = this.getFirstElement(iterator); - } - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) { - ListIterator<String> iterator = this.options.getValidationGroupPreRemoves().iterator(); - modelValue = this.getFirstElement(iterator); - } - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY)) - this.options.setLockTimeout((Integer) newValue); - else if (propertyName.equals(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY)) - this.options.setQueryTimeout((Integer) newValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.addValidationGroupPrePersist((String) newValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.addValidationGroupPreUpdate((String) newValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.addValidationGroupPreRemove((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - // ********** LockTimeout tests ********** - public void testSetLockTimeout() throws Exception { - this.verifyModelInitialized( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE); - this.verifySetProperty( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE, - LOCK_TIMEOUT_TEST_VALUE_2); - } - - public void testAddRemoveLockTimeout() throws Exception { - this.verifyAddRemoveProperty( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE, - LOCK_TIMEOUT_TEST_VALUE_2); - } - - // ********** QueryTimeout tests ********** - public void testSetQueryTimeout() throws Exception { - this.verifyModelInitialized( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE); - this.verifySetProperty( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE, - QUERY_TIMEOUT_TEST_VALUE_2); - } - - public void testAddRemoveQueryTimeout() throws Exception { - this.verifyAddRemoveProperty( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE, - QUERY_TIMEOUT_TEST_VALUE_2); - } - - // ********** ValidationGroupPrePersist tests ********** - public void testSetValidationGroupPrePersist() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.verifySetValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPrePersist() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testAddValidationGroupPrePersistCompositeValue() throws Exception { - this.verifyAddCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPrePersistCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - // ********** ValidationGroupPreUpdate tests ********** - public void testSetValidationGroupPreUpdate() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.verifySetValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPreUpdate() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testAddValidationGroupPreUpdateCompositeValue() throws Exception { - this.verifyAddCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPreUpdateCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - // ********** ValidationGroupPreRemove tests ********** - public void testSetValidationGroupPreRemove() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - this.verifySetValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPreRemove() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testAddValidationGroupPreRemoveCompositeValue() throws Exception { - this.verifyAddCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPreRemoveCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - // ********** ValidationGroups list ********** - public void testValidationGroupsList() throws Exception { - this.verifyListEvents( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2, - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST); - - this.verifyListEvents( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2, - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST); - - this.verifyListEvents( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2, - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST); - } - - // ********** override ********** - - @Override - protected void clearEvent() { - super.clearEvent(); - this.prePersistEvent = null; - this.preUpdateEvent = null; - this.preRemoveEvent = null; - } - - // ****** convenience methods ******* - - // ********** verify ValidationGroup property ********** - protected void verifySetValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Replace - this.persistenceUnitSetProperty(key, testValue2, true); - this.propertiesTotal++; - this.verifyPutValidationGroupProperty(propertyName, testValue1); - } - - @SuppressWarnings("unused") - protected void verifyAddRemoveValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - assertTrue(this.validationGroupValueExists(propertyName, (String)testValue1)); - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(key, (String)testValue1); - assertFalse(this.validationGroupValueExists(propertyName, (String)testValue1)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(key, testValue1, true); - this.verifyPutValidationGroupProperty(propertyName, testValue1); - } - - protected void verifyAddCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - String stringTestValue1 = (String)testValue1; - String stringTestValue2 = (String)testValue2; - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertEquals(this.getValidationGroupSize(propertyName), 1); - this.addValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 2); - - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue2)); - - String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); - assertTrue(propertyValue.indexOf(stringTestValue1) != -1); - assertTrue(propertyValue.indexOf(stringTestValue2) != -1); - } - - protected void verifyRemoveCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - String stringTestValue1 = (String)testValue1; - String stringTestValue2 = (String)testValue2; - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertEquals(this.getValidationGroupSize(propertyName), 1); - this.addValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 2); - - this.removeValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 1); - assertFalse(this.validationGroupValueExists(propertyName, stringTestValue2)); - String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); - assertTrue(propertyValue.indexOf(stringTestValue1) != -1); - assertTrue(propertyValue.indexOf(stringTestValue2) == -1); - - this.removeValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 1); - - this.removeValidationGroupValue(propertyName, stringTestValue1); - assertEquals(this.getValidationGroupSize(propertyName), 0); - assertFalse(this.validationGroupValueExists(propertyName, stringTestValue1)); - - assertNull(this.getPersistenceUnit().getProperty(key)); - } - - protected void verifyListEvents(String propertyName, String testValue, String listName) throws Exception { - // add - this.clearEvent(); - this.addValidationGroupValue(propertyName, testValue); - - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event for the expected property - assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); - - // remove - this.clearEvent(); - - this.removeValidationGroupValue(propertyName, testValue); - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event for the expected property - assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); - } - - protected void verifyPutValidationGroupProperty(String propertyName, Object expectedValue) throws Exception { - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event value - assertTrue(this.validationGroupValueExists(propertyName, (String) expectedValue)); - return; - } - - // ********** internal method ********** - - private ListChangeListener buildValidationGroupListChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsRemoved(ListRemoveEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsReplaced(ListReplaceEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListMoveEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListClearEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - - Generic2_0OptionsTests.this.validationGroupChanged(e); - } - }; - } - - private void validationGroupChanged(ListChangeEvent e) { - String listName = e.getListName(); - - if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST)) - this.prePersistEvent = e; - else if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST)) - this.preUpdateEvent = e; - else if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST)) - this.preRemoveEvent = e; - else - this.throwUnsupportedOperationException(e); - } - - private void addValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.addValidationGroupPrePersist(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.addValidationGroupPreUpdate(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.addValidationGroupPreRemove(propertyValue); - else - this.throwMissingDefinition("addValidationGroupValue", propertyName); - } - - private void removeValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.removeValidationGroupPrePersist(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.removeValidationGroupPreUpdate(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.removeValidationGroupPreRemove(propertyValue); - else - this.throwMissingDefinition("removeValidationGroupValue", propertyName); - } - - private boolean validationGroupValueExists(String propertyName, String propertyValue) throws NoSuchFieldException { - boolean result = false; - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - result = this.options.validationGroupPrePersistExists(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - result = this.options.validationGroupPreUpdateExists(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - result = this.options.validationGroupPreRemoveExists(propertyValue); - else - this.throwMissingDefinition("verifyValidationGroupValueExists", propertyName); - return result; - } - - private int getValidationGroupSize(String propertyName) throws NoSuchFieldException { - int result = 0; - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - result = this.options.getValidationGroupPrePersistsSize(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - result = this.options.getValidationGroupPreUpdatesSize(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - result = this.options.getValidationGroupPreRemovesSize(); - else - this.throwMissingDefinition("verifyValidationGroupSize", propertyName); - return result; - } - - private ListChangeEvent getEventFor(String propertyName) throws NoSuchFieldException { - ListChangeEvent event = null; - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - event = this.prePersistEvent; - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - event = this.preUpdateEvent; - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - event = this.preRemoveEvent; - else - this.throwMissingDefinition("getEventFor", propertyName); - return event; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java deleted file mode 100644 index 9d8602147f..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.persistence; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class Generic2_0PersistenceContextModelTests - extends TestCase -{ - - public static Test suite() { - TestSuite suite = new TestSuite(Generic2_0ConnectionTests.class.getPackage().getName()); - suite.addTestSuite(Generic2_0OptionsTests.class); - return suite; - } - - private Generic2_0PersistenceContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java deleted file mode 100644 index b1158a47d4..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.persistence; - -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.jpa.core.JpaFacet; -import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.jpa.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.jpa.core.platform.GenericPlatform; -import org.eclipse.jpt.jpa.core.tests.internal.context.persistence.PersistenceUnitTestCase; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * GenericPersistenceUnit2_0Tests - */ -public abstract class Generic2_0PersistenceUnitTests extends PersistenceUnitTestCase -{ - protected PersistenceUnit2_0 subject; - - protected PropertyValueModel<PersistenceUnit2_0> subjectHolder; - - // ********** constructors ********** - protected Generic2_0PersistenceUnitTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject = this.getPersistenceUnit(); - this.subjectHolder = new SimplePropertyValueModel<PersistenceUnit2_0>(this.subject); - this.populatePu(); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_2_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_2_0); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - @Override - protected PersistenceUnit2_0 getPersistenceUnit() { - return (PersistenceUnit2_0) super.getPersistenceUnit(); - } -} |