Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2007-05-14 17:44:39 +0000
committerpfullbright2007-05-14 17:44:39 +0000
commitd73676bafc439be4ae1c2d635a64d787e04af63b (patch)
tree89a88003abdb3a094d238a2983ffefea065a305b
parentae0d57869b3b35ad744674879c71cff004e72f49 (diff)
downloadwebtools.dali-d73676bafc439be4ae1c2d635a64d787e04af63b.tar.gz
webtools.dali-d73676bafc439be4ae1c2d635a64d787e04af63b.tar.xz
webtools.dali-d73676bafc439be4ae1c2d635a64d787e04af63b.zip
Added some more "mappedBy" validation
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaJoinTable.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinTable.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IMultiRelationshipMapping.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java4
12 files changed, 136 insertions, 10 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
index 9ee7de3dec..1837212afe 100644
--- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
@@ -34,6 +34,8 @@ PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME=Attribute \"{0}\" in class \"{1}\" cannot b
PERSISTENT_ATTRIBUTE_INVALID_MAPPING=Attribute \"{0}\" has invalid mapping type in this context
MAPPING_UNRESOLVED_MAPPED_BY=Cannot resolve attribute named \"{0}\"
MAPPING_INVALID_MAPPED_BY=Attribute named \"{0}\" has invalid mapping for this relationship
+MAPPING_MAPPED_BY_WITH_JOIN_TABLE=Cannot specify join table if this attribute is mapped by another attribute
+MAPPING_MAPPED_BY_ON_BOTH_SIDES=Relationship must have an owner
TABLE_UNRESOLVED_SCHEMA=Schema \"{0}\" cannot be resolved for table \"{1}\"
TABLE_UNRESOLVED_NAME=Table \"{0}\" cannot be resolved
SECONDARY_TABLE_UNRESOLVED_SCHEMA=Schema \"{0}\" cannot be resolved for secondary table \"{1}\"
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaJoinTable.java
index ab752491cd..eaa452075a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaJoinTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaJoinTable.java
@@ -522,6 +522,10 @@ public class JavaJoinTable extends AbstractJavaTable implements IJoinTable
super.refreshDefaults(defaultsContext);
this.setDefaultName((String) defaultsContext.getDefault(BaseJpaPlatform.DEFAULT_JOIN_TABLE_NAME_KEY));
}
+
+ public boolean isSpecified() {
+ return getMember().containsAnnotation(DECLARATION_ANNOTATION_ADAPTER);
+ }
/**
* here we just worry about getting the join column lists the same size;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java
index ea097b43a8..41445b8d15 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java
@@ -317,6 +317,10 @@ public abstract class JavaMultiRelationshipMapping
}
return msgs;
}
+
+ public boolean isJoinTableSpecified() {
+ return getJavaJoinTable().isSpecified();
+ }
/**
* Returns the value of the '<em><b>Order By</b></em>' containment reference.
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinTable.java
index 2f899d7b22..97a3f7fdc0 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinTable.java
@@ -500,6 +500,10 @@ public class XmlJoinTable extends AbstractXmlTable implements IJoinTable
super.refreshDefaults(defaultsContext);
setDefaultName((String) defaultsContext.getDefault(BaseJpaPlatform.DEFAULT_JOIN_TABLE_NAME_KEY));
}
+
+ public boolean isSpecified() {
+ return node != null;
+ }
public IRelationshipMapping relationshipMapping() {
return (IRelationshipMapping) this.eContainer();
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 4be98d0f93..aa74f208a6 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
@@ -261,6 +261,11 @@ public abstract class XmlMultiRelationshipMappingInternal
}
return msgs;
}
+
+ public boolean isJoinTableSpecified() {
+ XmlJoinTable joinTable = getJoinTableForXml();
+ return joinTable != null && joinTable.isSpecified();
+ }
/**
* Returns the value of the '<em><b>Order By</b></em>' containment reference.
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IMultiRelationshipMapping.java
index eda92d59f2..62e8531cd2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IMultiRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IMultiRelationshipMapping.java
@@ -73,6 +73,13 @@ public interface IMultiRelationshipMapping extends INonOwningMapping
* @generated
*/
IJoinTable getJoinTable();
+
+ /**
+ * All multi-relationship mappings have a join table, even if it has to be
+ * calculated from default settings. However, it is important to note
+ * whether the table *is* default or whether it is specified.
+ */
+ boolean isJoinTableSpecified();
/**
* Returns the value of the '<em><b>Order By</b></em>' containment reference.
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java
index 3f15be3430..11df39b4fc 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java
@@ -56,7 +56,7 @@ public interface INonOwningMapping extends IRelationshipMapping
* @generated
*/
void setMappedBy(String value);
-
+
Iterator<String> candidateMappedByAttributeNames();
boolean mappedByIsValid(IAttributeMapping mappedByMapping);
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java
index 3e9991ec68..091ec3a072 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java
@@ -15,6 +15,7 @@ import org.eclipse.jpt.core.internal.content.java.mappings.JavaMultiRelationship
import org.eclipse.jpt.core.internal.mappings.IEntity;
import org.eclipse.jpt.core.internal.mappings.IJoinColumn;
import org.eclipse.jpt.core.internal.mappings.IJoinTable;
+import org.eclipse.jpt.core.internal.mappings.INonOwningMapping;
import org.eclipse.jpt.core.internal.mappings.ITable;
import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
@@ -70,22 +71,20 @@ public abstract class JavaMultiRelationshipMappingContext extends JavaRelationsh
public void addToMessages(List<IMessage> messages) {
super.addToMessages(messages);
+ JavaMultiRelationshipMapping mapping = getMapping();
+ if (getMapping().isJoinTableSpecified()) {
+ addJoinTableMessages(messages);
+ }
if (getMapping().getMappedBy() != null) {
addMappedByMessages(messages);
}
- else {
- addJoinTableMessages(messages);
- }
}
protected void addJoinTableMessages(List<IMessage> messages) {
- if (getMapping().getMappedBy() != null) {
- //do not add joinTable problems for the non-owning side, this is defined
- //by the side that specifies mappedBy
- return;
- }
- IJoinTable joinTable = getMapping().getJoinTable();
+ JavaMultiRelationshipMapping mapping = getMapping();
+ IJoinTable joinTable = mapping.getJoinTable();
+
boolean doContinue = joinTable.isConnected();
String schema = joinTable.getSchema();
@@ -163,6 +162,17 @@ public abstract class JavaMultiRelationshipMappingContext extends JavaRelationsh
protected void addMappedByMessages(List<IMessage> messages) {
JavaMultiRelationshipMapping mapping = getMapping();
String mappedBy = mapping.getMappedBy();
+
+ if (mapping.isJoinTableSpecified()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.MAPPING_MAPPED_BY_WITH_JOIN_TABLE,
+ mapping.getJoinTable(), mapping.getJoinTable().validationTextRange())
+ );
+
+ }
+
IEntity targetEntity = mapping.getResolvedTargetEntity();
if (targetEntity == null) {
@@ -191,6 +201,24 @@ public abstract class JavaMultiRelationshipMappingContext extends JavaRelationsh
new String[] {mappedBy},
mapping, mapping.mappedByTextRange())
);
+ return;
+ }
+
+ INonOwningMapping mappedByMapping;
+ try {
+ mappedByMapping = (INonOwningMapping) attribute.getMapping();
+ } catch (ClassCastException cce) {
+ // there is no error then
+ return;
+ }
+
+ if (mappedByMapping.getMappedBy() != null) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES,
+ mapping, mapping.mappedByTextRange())
+ );
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java
index 86f924fb36..29330a802b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java
@@ -12,6 +12,7 @@ import java.util.List;
import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.content.java.mappings.JavaOneToOne;
import org.eclipse.jpt.core.internal.mappings.IEntity;
+import org.eclipse.jpt.core.internal.mappings.INonOwningMapping;
import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -65,6 +66,24 @@ public class JavaOneToOneContext extends JavaSingleRelationshipMappingContext
new String[] {mappedBy},
mapping, mapping.mappedByTextRange())
);
+ return;
+ }
+
+ INonOwningMapping mappedByMapping;
+ try {
+ mappedByMapping = (INonOwningMapping) attribute.getMapping();
+ } catch (ClassCastException cce) {
+ // there is no error then
+ return;
+ }
+
+ if (mappedByMapping.getMappedBy() != null) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES,
+ mapping, mapping.mappedByTextRange())
+ );
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java
index 51d03f8e6d..a559a6575e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java
@@ -13,6 +13,7 @@ import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.content.orm.XmlMultiRelationshipMapping;
import org.eclipse.jpt.core.internal.content.orm.XmlMultiRelationshipMappingInternal;
import org.eclipse.jpt.core.internal.mappings.IEntity;
+import org.eclipse.jpt.core.internal.mappings.INonOwningMapping;
import org.eclipse.jpt.core.internal.mappings.ITable;
import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
@@ -80,6 +81,17 @@ public abstract class XmlMultiRelationshipMappingContext
protected void addMappedByMessages(List<IMessage> messages) {
XmlMultiRelationshipMapping mapping = multiRelationshipMapping();
String mappedBy = mapping.getMappedBy();
+
+ if (mapping.isJoinTableSpecified()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.MAPPING_MAPPED_BY_WITH_JOIN_TABLE,
+ mapping.getJoinTable(), mapping.getJoinTable().validationTextRange())
+ );
+
+ }
+
IEntity targetEntity = mapping.getResolvedTargetEntity();
if (targetEntity == null) {
@@ -108,6 +120,24 @@ public abstract class XmlMultiRelationshipMappingContext
new String[] {mappedBy},
mapping, mapping.mappedByTextRange())
);
+ return;
+ }
+
+ INonOwningMapping mappedByMapping;
+ try {
+ mappedByMapping = (INonOwningMapping) attribute.getMapping();
+ } catch (ClassCastException cce) {
+ // there is no error then
+ return;
+ }
+
+ if (mappedByMapping.getMappedBy() != null) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES,
+ mapping, mapping.mappedByTextRange())
+ );
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java
index 75c506ce95..33e786ec51 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java
@@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.content.orm.XmlOneToOne;
import org.eclipse.jpt.core.internal.mappings.IEntity;
+import org.eclipse.jpt.core.internal.mappings.INonOwningMapping;
import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -67,6 +68,24 @@ public class XmlOneToOneContext
new String[] {mappedBy},
mapping, mapping.mappedByTextRange())
);
+ return;
+ }
+
+ INonOwningMapping mappedByMapping;
+ try {
+ mappedByMapping = (INonOwningMapping) attribute.getMapping();
+ } catch (ClassCastException cce) {
+ // there is no error then
+ return;
+ }
+
+ if (mappedByMapping.getMappedBy() != null) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES,
+ mapping, mapping.mappedByTextRange())
+ );
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java
index b42ab33678..f223d6e84a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java
@@ -64,6 +64,10 @@ public interface IJpaValidationMessages
public static final String MAPPING_INVALID_MAPPED_BY = "MAPPING_INVALID_MAPPED_BY";
+ public static final String MAPPING_MAPPED_BY_WITH_JOIN_TABLE = "MAPPING_MAPPED_BY_WITH_JOIN_TABLE";
+
+ public static final String MAPPING_MAPPED_BY_ON_BOTH_SIDES = "MAPPING_MAPPED_BY_ON_BOTH_SIDES";
+
public static final String TABLE_UNRESOLVED_SCHEMA = "TABLE_UNRESOLVED_SCHEMA";
public static final String TABLE_UNRESOLVED_NAME = "TABLE_UNRESOLVED_NAME";

Back to the top