Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2007-05-31 01:39:42 +0000
committerkmoore2007-05-31 01:39:42 +0000
commitb669034ccf21a13df55fe3b6eddceec1335f2ab8 (patch)
tree04d6ab572d2dee9185b059c2362a678efaef00c6
parent4e971d70f8cf08abc84eb89d80541f5d84f5fe15 (diff)
downloadwebtools.dali-b669034ccf21a13df55fe3b6eddceec1335f2ab8.tar.gz
webtools.dali-b669034ccf21a13df55fe3b6eddceec1335f2ab8.tar.xz
webtools.dali-b669034ccf21a13df55fe3b6eddceec1335f2ab8.zip
188937 - default target entity for one-to-many in xml is wrong
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaRelationshipMapping.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRelationshipMapping.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlRelationshipMappingContext.java2
4 files changed, 60 insertions, 2 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaRelationshipMapping.java
index f875b9acbe..9deacff895 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaRelationshipMapping.java
@@ -674,7 +674,7 @@ public abstract class JavaRelationshipMapping extends JavaAttributeMapping
* return whether the specified non-array type is one of the container
* types allowed by the JPA spec
*/
- protected static boolean typeNamedIsContainer(String typeName) {
+ public static boolean typeNamedIsContainer(String typeName) {
return CollectionTools.contains(CONTAINER_TYPE_NAMES, typeName);
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java
index a7c3849405..a93d5d6186 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java
@@ -16,8 +16,11 @@ import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.Signature;
import org.eclipse.jpt.core.internal.ITextRange;
import org.eclipse.jpt.core.internal.ITypeMapping;
+import org.eclipse.jpt.core.internal.content.java.mappings.JavaRelationshipMapping;
import org.eclipse.jpt.core.internal.content.orm.resource.OrmXmlMapper;
import org.eclipse.jpt.core.internal.emfutility.DOMUtilities;
import org.eclipse.jpt.core.internal.mappings.DefaultLazyFetchType;
@@ -813,4 +816,31 @@ public abstract class XmlMultiRelationshipMappingInternal
setOrderBy(targetEntity.primaryKeyAttributeName() + " ASC");
}
}
+
+ //TODO copied from JavaMultiRelationshipMapping
+ /**
+ * extract the element type from the specified container signature and
+ * convert it into a reference entity type name;
+ * return null if the type is not a valid reference entity type (e.g. it's
+ * another container or an array or a primitive or other Basic type)
+ */
+ @Override
+ public String javaDefaultTargetEntity(String signature) {
+ String typeName = super.javaDefaultTargetEntity(signature);
+ return JavaRelationshipMapping.typeNamedIsContainer(typeName) ? this.javaDefaultTargetEntityFromContainer(signature) : null;
+ }
+
+ protected String javaDefaultTargetEntityFromContainer(String signature) {
+ String[] parmSignatures = Signature.getTypeArguments(signature);
+ if ((parmSignatures == null) || (parmSignatures.length != 1)) {
+ return null;
+ }
+ IType iType = getPersistentType().findJdtType();
+ if (iType == null) {
+ return null;
+ }
+ String elementSignature = parmSignatures[0];
+ String elementTypeName = buildReferenceEntityTypeName(elementSignature, iType);
+ return JavaRelationshipMapping.typeNamedIsContainer(elementTypeName) ? null : elementTypeName;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRelationshipMapping.java
index 85d4996e0a..de47356025 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRelationshipMapping.java
@@ -14,8 +14,11 @@ import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.Signature;
import org.eclipse.jpt.core.internal.IPersistentType;
import org.eclipse.jpt.core.internal.ITypeMapping;
+import org.eclipse.jpt.core.internal.jdtutility.JDTTools;
import org.eclipse.jpt.core.internal.mappings.ICascade;
import org.eclipse.jpt.core.internal.mappings.IEntity;
import org.eclipse.jpt.core.internal.mappings.IRelationshipMapping;
@@ -551,4 +554,29 @@ public abstract class XmlRelationshipMapping extends XmlAttributeMapping
}
setResolvedTargetEntity(null);
}
+
+ /**
+ * the default 'targetEntity' is calculated from the attribute type;
+ * return null if the attribute type cannot possibly be an entity
+ */
+ public String javaDefaultTargetEntity() {
+ return this.javaDefaultTargetEntity(this.getPersistentAttribute().getAttribute().typeSignature());
+ }
+
+ protected String javaDefaultTargetEntity(String signature) {
+ IType iType = getPersistentType().findJdtType();
+ if (iType != null) {
+ return buildReferenceEntityTypeName(signature, iType);
+ }
+ return null;
+ }
+
+ // TODO Embeddable???
+ public static String buildReferenceEntityTypeName(String signature, IType jdtType) {
+ if (Signature.getArrayCount(signature) > 0) {
+ return null; // arrays cannot be entities
+ }
+ return JDTTools.resolve(Signature.toString(signature), jdtType);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlRelationshipMappingContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlRelationshipMappingContext.java
index 120116297b..8c4eea914b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlRelationshipMappingContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlRelationshipMappingContext.java
@@ -71,7 +71,7 @@ public abstract class XmlRelationshipMappingContext extends XmlAttributeContext
if (attribute != null) {
IType iType = relationshipMapping().getPersistentType().findJdtType();
if (iType != null) {
- return JavaRelationshipMapping.buildReferenceEntityTypeName(attribute.typeSignature(), iType);
+ return relationshipMapping().javaDefaultTargetEntity();
}
}
}

Back to the top