Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNan Li2013-07-29 16:51:10 +0000
committerNan Li2013-07-29 16:51:10 +0000
commit39b8f4d3ba75265be7a1f360a230a08262880084 (patch)
treef54397b6a8801b4c6b00d4e864d5339ac5b2f2dd
parent1914bc6ba6ec36ea50843142c5dd0801ab6933ec (diff)
downloadwebtools.dali-39b8f4d3ba75265be7a1f360a230a08262880084.tar.gz
webtools.dali-39b8f4d3ba75265be7a1f360a230a08262880084.tar.xz
webtools.dali-39b8f4d3ba75265be7a1f360a230a08262880084.zip
410505 - Invalid validation with pk join column of an entity that is inv201307311924
an inheritance hierarchy
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java40
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java30
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java84
9 files changed, 145 insertions, 106 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties
index 13f8f623ae..eda9209d10 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties
@@ -58,12 +58,13 @@ ENTITY_NAME_MISSING=The given name of the entity \"{0}\" is empty
ENTITY_NO_PK=The entity has no primary key attribute defined
ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED=A primary key attribute should only be defined on the root entity or a mapped superclass
ENTITY_NON_ROOT_ID_CLASS_SPECIFIED=An ID class should only be defined on the root entity or a mapped superclass
-TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is annotated, but not listed in the persistence.xml file
-TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is managed, but is not listed in the persistence.xml file
-PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate class \"{0}\" found in mapping files. This configuration is not supported by the tooling and may result in invalid error messages.
MANAGED_TYPE_UNRESOLVED_CLASS=Class \"{0}\" cannot be resolved
MANAGED_TYPE_UNSPECIFIED_CLASS=Unspecified class
+ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED=Root entity should not have primary key join column defined
+PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate class \"{0}\" found in mapping files. This configuration is not supported by the tooling and may result in invalid error messages.
TARGET_NOT_AN_EMBEDDABLE={0} is not mapped as an embeddable
+TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is annotated, but not listed in the persistence.xml file
+TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is managed, but is not listed in the persistence.xml file
TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR=The Java class for mapped type \"{0}\" must define a non-private zero-argument constructor
TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR=The Java class for mapped type \"{0}\" has a private zero-argument constructor; it must be public or protected
TYPE_MAPPING_FINAL_CLASS=The Java class for mapped type \"{0}\" is final
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties
index 57d8fb42d6..b7c0b5fdf3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties
@@ -53,12 +53,13 @@ ENTITY_NAME_MISSING=Entity name is empty
ENTITY_NO_PK=Entity has no primary key
ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED=Primary key attribute should only be defined on the root entity or a mapped superclass
ENTITY_NON_ROOT_ID_CLASS_SPECIFIED=ID class should only be defined on the root entity or a mapped superclass
-TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is annotated, but is not listed in the persistence.xml file
-TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is managed, but is not listed in the persistence.xml file
-PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate ORM class
MANAGED_TYPE_UNRESOLVED_CLASS=Class in orm.xml cannot be resolved to a java class
MANAGED_TYPE_UNSPECIFIED_CLASS=Class is unspecified in orm.xml
+PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate ORM class
+ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED=Root entity should not have primary key join column defined
TARGET_NOT_AN_EMBEDDABLE=Target type of an embedded mapping is not an embeddable
+TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is annotated, but is not listed in the persistence.xml file
+TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is managed, but is not listed in the persistence.xml file
TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR=Mapped Java class has no no-arg constructor
TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR=Mapped Java class has a private no-arg constructor
TYPE_MAPPING_FINAL_CLASS=Mapped Java class is final
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
index e2e85ffdcc..c7494d58d2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
@@ -80,13 +80,13 @@ import org.eclipse.jpt.jpa.core.internal.jpa1.context.AssociationOverrideValidat
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideColumnValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.DiscriminatorColumnValidator;
+import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityPrimaryKeyJoinColumnValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericEntityPrimaryKeyValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.JoinTableTableDescriptionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.MappedSuperclassOverrideDescriptionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.SecondaryTableValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.TableValidator;
-import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.JavaEntityPrimaryKeyJoinColumnValidator;
import org.eclipse.jpt.jpa.core.internal.resource.java.NullPrimaryKeyJoinColumnAnnotation;
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAssociationOverrideContainer2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAttributeOverrideContainer2_0;
@@ -539,16 +539,15 @@ public abstract class AbstractJavaEntity
}
public void convertDefaultPrimaryKeyJoinColumnsToSpecified() {
- if (this.defaultPrimaryKeyJoinColumn == null) {
- throw new IllegalStateException("default PK join column is null"); //$NON-NLS-1$
- }
- // Add a PK join column by creating a specified one using the default one
- String columnName = this.defaultPrimaryKeyJoinColumn.getDefaultName();
- String referencedColumnName = this.defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName();
-
- SpecifiedPrimaryKeyJoinColumn pkJoinColumn = this.addSpecifiedPrimaryKeyJoinColumn(0);
- pkJoinColumn.setSpecifiedName(columnName);
- pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ // This is for root entities which have no default PK join column
+ SpecifiedPrimaryKeyJoinColumn pkJoinColumn = this.addSpecifiedPrimaryKeyJoinColumn(0);
+ // Add a PK join column by creating a specified one using the default one
+ if (this.defaultPrimaryKeyJoinColumn != null) {
+ String columnName = this.defaultPrimaryKeyJoinColumn.getDefaultName();
+ String referencedColumnName = this.defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName();
+ pkJoinColumn.setSpecifiedName(columnName);
+ pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ }
}
public void clearSpecifiedPrimaryKeyJoinColumns() {
@@ -648,7 +647,7 @@ public abstract class AbstractJavaEntity
}
protected boolean buildsDefaultPrimaryKeyJoinColumn() {
- return ! this.hasSpecifiedPrimaryKeyJoinColumns();
+ return ! this.isRootEntity() && ! this.hasSpecifiedPrimaryKeyJoinColumns();
}
protected JavaSpecifiedPrimaryKeyJoinColumn buildDefaultPrimaryKeyJoinColumn() {
@@ -1252,9 +1251,7 @@ public abstract class AbstractJavaEntity
secondaryTable.validate(messages, reporter);
}
this.validateInheritance(messages, reporter);
- for (JavaSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getPrimaryKeyJoinColumns()) {
- pkJoinColumn.validate(messages, reporter);
- }
+ this.validatePrimaryKeyJoinColumns(messages, reporter);
this.generatorContainer.validate(messages, reporter);
this.queryContainer.validate(messages, reporter);
this.attributeOverrideContainer.validate(messages, reporter);
@@ -1263,6 +1260,24 @@ public abstract class AbstractJavaEntity
this.idClassReference.validate(messages, reporter);
}
+ protected void validatePrimaryKeyJoinColumns(List<IMessage> messages, IReporter reporter) {
+ if (this.getPrimaryKeyJoinColumnsSize() > 0) {
+ if (this.getParentEntity() == null) {
+ messages.add(
+ this.buildValidationMessage(
+ this.getMappingAnnotation().getNameTextRange(),
+ JptJpaCoreValidationMessages.ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED,
+ this.getPersistentType().getName()
+ )
+ );
+ } else {
+ for (JavaSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getPrimaryKeyJoinColumns()) {
+ pkJoinColumn.validate(messages, reporter);
+ }
+ }
+ }
+ }
+
@Override
public boolean validatesAgainstDatabase() {
return super.validatesAgainstDatabase() && ! this.isAbstractTablePerClass();
@@ -1619,7 +1634,7 @@ public abstract class AbstractJavaEntity
}
public JpaValidator buildColumnValidator(NamedColumn column) {
- return new JavaEntityPrimaryKeyJoinColumnValidator((BaseJoinColumn) column, this, AbstractJavaEntity.this);
+ return new EntityPrimaryKeyJoinColumnValidator((BaseJoinColumn) column, this);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java
index 78b146a829..a1ae765a77 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java
@@ -799,6 +799,11 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
}
public void convertDefaultPrimaryKeyJoinColumnsToSpecified() {
+ // This is necessary for root entities which have no default PK join column
+ if (this.getPrimaryKeyJoinColumnsSize() == 0) {
+ this.addSpecifiedPrimaryKeyJoinColumn();
+ }
+
for (PrimaryKeyJoinColumn defaultJoinColumn : this.getDefaultPrimaryKeyJoinColumns()) {
String columnName = defaultJoinColumn.getName();
String referencedColumnName = defaultJoinColumn.getReferencedColumnName();
@@ -903,7 +908,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
if (this.javaPrimaryKeyJoinColumnsWillBeDefaults()) {
// specified => java
this.initializeVirtualPrimaryKeyJoinColumns();
- } else {
+ } else if (this.getParentEntity() != null) {
// specified => default
this.addDefaultPrimaryKeyJoinColumn();
}
@@ -1710,9 +1715,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
secondaryTable.validate(messages, reporter);
}
this.validateInheritance(messages, reporter);
- for (OrmSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getSpecifiedPrimaryKeyJoinColumns()) {
- pkJoinColumn.validate(messages, reporter);
- }
+ this.validatePrimaryKeyJoinColumns(messages, reporter);
this.attributeOverrideContainer.validate(messages, reporter);
this.associationOverrideContainer.validate(messages, reporter);
this.generatorContainer.validate(messages, reporter);
@@ -1721,6 +1724,25 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
this.idClassReference.validate(messages, reporter);
}
+ protected void validatePrimaryKeyJoinColumns(List<IMessage> messages, IReporter reporter) {
+ if (this.getPrimaryKeyJoinColumnsSize() > 0) {
+ if (this.getParentEntity() == null) {
+ messages.add(
+ this.buildValidationMessage(
+ this.getNameTextRange(),
+ JptJpaCoreValidationMessages.ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED,
+ this.getPersistentType().getName()
+ )
+ );
+ } else {
+ for (OrmSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getSpecifiedPrimaryKeyJoinColumns()) {
+ pkJoinColumn.validate(messages, reporter);
+ }
+ }
+ }
+
+ }
+
protected void validateEntityName(List<IMessage> messages) {
if (StringTools.isBlank(this.getName())){
messages.add(
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java
deleted file mode 100644
index c2e3236172..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 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.internal.jpa1.context.java;
-
-import java.util.List;
-import org.eclipse.jpt.jpa.core.context.BaseJoinColumn;
-import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaEntity;
-import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityPrimaryKeyJoinColumnValidator;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-
-public class JavaEntityPrimaryKeyJoinColumnValidator
- extends EntityPrimaryKeyJoinColumnValidator
-{
- protected final AbstractJavaEntity entity;
-
- public JavaEntityPrimaryKeyJoinColumnValidator(
- BaseJoinColumn column,
- BaseJoinColumn.ParentAdapter parentAdapter,
- AbstractJavaEntity entity) {
- super(column, parentAdapter);
- this.entity = entity;
- }
-
- @Override
- protected void validateJoinColumnName(List<IMessage> messages) {
- // Based on the spec., the PrimaryKeyJoinColumn annotation is really only meaningful when
- // applying on an entity subclass so we only validate it when an entity is a descendant or an entity
- // has specified primary key join columns
- if (this.entity.isDescendant() || this.entity.getSpecifiedPrimaryKeyJoinColumnsSize() > 0) {
- super.validateJoinColumnName(messages);
- }
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java
index e64f4de492..7272c06594 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java
@@ -72,6 +72,7 @@ public class JptJpaCoreValidationMessages {
public static ValidationMessage TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML;
public static ValidationMessage MANAGED_TYPE_UNRESOLVED_CLASS;
public static ValidationMessage MANAGED_TYPE_UNSPECIFIED_CLASS;
+ public static ValidationMessage ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED;
public static ValidationMessage TARGET_NOT_AN_EMBEDDABLE;
public static ValidationMessage TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR;
public static ValidationMessage TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java
index 3379774ee5..70dbc2b4e5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java
@@ -117,10 +117,11 @@ public class JpaProblemSeveritiesPage
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ENTITY_NO_PK);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED); //3.0 M7
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ENTITY_NON_ROOT_ID_CLASS_SPECIFIED); //3.0 M7
- this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
- this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.MANAGED_TYPE_UNRESOLVED_CLASS);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.MANAGED_TYPE_UNSPECIFIED_CLASS);
+ this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED);
+ this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
+ this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MAPPING_FINAL_CLASS);
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java
index 5749a5f356..7c4e60eb35 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java
@@ -20,9 +20,7 @@ import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AccessType;
-import org.eclipse.jpt.jpa.core.context.SpecifiedAssociationOverride;
import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer;
-import org.eclipse.jpt.jpa.core.context.SpecifiedAttributeOverride;
import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer;
import org.eclipse.jpt.jpa.core.context.BasicMapping;
import org.eclipse.jpt.jpa.core.context.DiscriminatorType;
@@ -30,30 +28,32 @@ import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.IdMapping;
import org.eclipse.jpt.jpa.core.context.InheritanceType;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
+import org.eclipse.jpt.jpa.core.context.JoinColumnRelationship;
+import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
import org.eclipse.jpt.jpa.core.context.NamedQuery;
import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.SpecifiedAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.SpecifiedAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumn;
-import org.eclipse.jpt.jpa.core.context.JoinColumn;
-import org.eclipse.jpt.jpa.core.context.JoinColumnRelationship;
-import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy;
-import org.eclipse.jpt.jpa.core.context.Table;
import org.eclipse.jpt.jpa.core.context.SpecifiedSecondaryTable;
import org.eclipse.jpt.jpa.core.context.SpecifiedTable;
+import org.eclipse.jpt.jpa.core.context.Table;
import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride;
import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride;
-import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedAssociationOverride;
import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer;
-import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedAttributeOverride;
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.JavaIdMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery;
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedAttributeOverride;
import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedPrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedSecondaryTable;
import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride;
@@ -1453,7 +1453,9 @@ public class JavaEntityTests extends ContextModelTestCase
}
public void testPrimaryKeyJoinColumnsSize() throws Exception {
- createTestEntityWithSecondaryTable();
+ createTestEntity();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
//just the default pkJoinColumn, so 1
@@ -1468,7 +1470,9 @@ public class JavaEntityTests extends ContextModelTestCase
}
public void testGetDefaultPrimaryKeyJoinColumn() throws Exception {
- createTestEntityWithSecondaryTable();
+ createTestEntity();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
assertNotNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn());
@@ -1650,7 +1654,9 @@ public class JavaEntityTests extends ContextModelTestCase
}
public void testPrimaryKeyJoinColumnIsVirtual() throws Exception {
- createTestEntityWithSecondaryTable();
+ createTestEntity();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isVirtual());
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java
index 1450205638..dc6bc04414 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java
@@ -11,8 +11,8 @@ package org.eclipse.jpt.jpa.core.tests.internal.context.java;
import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.AstNodeType;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.jpa.core.MappingKeys;
@@ -47,13 +47,39 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
});
}
+ private ICompilationUnit createTestSubEntity() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return IteratorTools.iterator(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 createTestEntityWithPrimaryKeyJoinColumn() throws Exception {
- return this.createTestType(new DefaultAnnotationWriter() {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
return IteratorTools.iterator(JPA.ENTITY, JPA.ID, JPA.PRIMARY_KEY_JOIN_COLUMN);
}
@Override
+ public void appendExtendsImplementsTo(StringBuilder sb) {
+ sb.append("extends " + TYPE_NAME + " ");
+ }
+ @Override
public void appendTypeAnnotationTo(StringBuilder sb) {
sb.append("@Entity").append(CR);
sb.append("@PrimaryKeyJoinColumn(name=\"" + PRIMARY_KEY_JOIN_COLUMN_NAME + "\")");
@@ -72,13 +98,13 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetSpecifiedName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getSpecifiedName());
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
pkJoinColumnResource.setName("FOO");
@@ -89,6 +115,8 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetDefaultNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception {
createTestEntity();
+ createTestSubEntity();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
SpecifiedPrimaryKeyJoinColumn pkJoinColumn = getJavaEntity().getDefaultPrimaryKeyJoinColumn();
@@ -97,7 +125,7 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetDefaultName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn());
@@ -113,7 +141,7 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getName());
@@ -121,14 +149,14 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testSetSpecifiedName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
specifiedPkJoinColumn.setSpecifiedName("foo");
assertEquals("foo", specifiedPkJoinColumn.getSpecifiedName());
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation columnAnnotation = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
assertEquals("foo", columnAnnotation.getName());
@@ -141,12 +169,12 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetColumnDefinition() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
-
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertNull(specifiedPkJoinColumn.getColumnDefinition());
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
column.setColumnDefinition(COLUMN_DEFINITION);
getJpaProject().synchronizeContextModel();
@@ -166,12 +194,12 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testSetColumnDefinition() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
specifiedPkJoinColumn.setColumnDefinition("foo");
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
assertEquals("foo", column.getColumnDefinition());
@@ -183,12 +211,12 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetSpecifiedReferencedColumnName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName());
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
pkJoinColumnResource.setReferencedColumnName("FOO");
@@ -199,15 +227,17 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetDefaultReferencedColumnNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception {
createTestEntity();
+ createTestSubEntity();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
-
+
SpecifiedPrimaryKeyJoinColumn pkJoinColumn = getJavaEntity().getDefaultPrimaryKeyJoinColumn();
assertEquals("id", pkJoinColumn.getDefaultReferencedColumnName());
}
public void testGetDefaultReferencedColumnName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn());
@@ -224,9 +254,9 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testGetReferencedColumnName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
pkJoinColumnResource.setReferencedColumnName("FOO");
@@ -238,14 +268,14 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testSetSpecifiedReferencedColumnName() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
specifiedPkJoinColumn.setSpecifiedReferencedColumnName("foo");
assertEquals("foo", specifiedPkJoinColumn.getSpecifiedReferencedColumnName());
- JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
+ JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(PACKAGE_NAME + ".AnnotationTestTypeChild", AstNodeType.TYPE);
PrimaryKeyJoinColumnAnnotation columnAnnotation = (PrimaryKeyJoinColumnAnnotation) resourceType.getAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN);
assertEquals("foo", columnAnnotation.getReferencedColumnName());
@@ -258,9 +288,11 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
}
public void testIsVirtual() throws Exception {
+ createTestEntity();
createTestEntityWithPrimaryKeyJoinColumn();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
-
+
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertFalse(specifiedPkJoinColumn.isVirtual());
@@ -271,7 +303,7 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testIsReferencedColumnResolved() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertFalse(((Boolean) ObjectTools.execute(specifiedPkJoinColumn, "referencedColumnIsResolved")).booleanValue());
@@ -279,7 +311,7 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testDbColumn() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertFalse(specifiedPkJoinColumn.isResolved());
@@ -287,7 +319,7 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testDbReferencedColumn() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertFalse(((Boolean) ObjectTools.execute(specifiedPkJoinColumn, "referencedColumnIsResolved")).booleanValue());
@@ -295,7 +327,7 @@ public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase
public void testDbTable() throws Exception {
createTestEntityWithPrimaryKeyJoinColumn();
- addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
SpecifiedPrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().getSpecifiedPrimaryKeyJoinColumns().iterator().next();
assertNull(specifiedPkJoinColumn.getDbTable());

Back to the top