Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2007-05-08 20:12:02 +0000
committerkmoore2007-05-08 20:12:02 +0000
commitcb6517d2cbf9c42f9f21023c75c2be14edd60288 (patch)
tree6a2e50cfeb85412deef9af02aa0d6513ba281c43 /jpa
parente9ce8f955ec84c29a1bc93863b080ee098ff4959 (diff)
downloadwebtools.dali-cb6517d2cbf9c42f9f21023c75c2be14edd60288.tar.gz
webtools.dali-cb6517d2cbf9c42f9f21023c75c2be14edd60288.tar.xz
webtools.dali-cb6517d2cbf9c42f9f21023c75c2be14edd60288.zip
186017 - secondary table joinColumn defaults and validation
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/OneToOneTranslator.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaEntityContext.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PrimaryKeyJoinColumnContext.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/SecondaryTableContext.java107
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java9
8 files changed, 220 insertions, 13 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 016b9cf873..fe1597cfb4 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
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}\"
+SECONDARY_TABLE_UNRESOLVED_NAME=Secondary table \"{0}\" cannot be resolved
JOIN_TABLE_UNRESOLVED_SCHEMA=Schema \"{0}\" cannot be resolved for join table \"{1}\"
VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA=In virtual attribute \"{0}\", schema \"{1}\" cannot be resolved for join table \"{2}\"
JOIN_TABLE_UNRESOLVED_NAME=Join table \"{0}\" cannot be resolved
@@ -54,3 +56,5 @@ JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME=Referenced column \"{0}\" in join
VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME=In virtual attribute \"{0}\", referenced column \"{1}\" in join column \"{2}\" cannot be resolved
VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME=In virtual association override \"{0}\", referenced column \"{1}\" in join column \"{2}\" cannot be resolved
GENERATED_VALUE_UNRESOLVED_GENERATOR=No generator named \"{0}\" is defined in persistence unit
+PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME=Primary key join column \"{0}\" cannot be resolved
+PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME=Referenced Column \"{0}\" in primary key join column \"{1}\" cannot be resolved
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java
index 9ff3bd86c4..4018777447 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java
@@ -77,6 +77,7 @@ public class JavaSecondaryTable extends AbstractJavaTable
public JavaSecondaryTable(Owner owner, Member member, IndexedDeclarationAnnotationAdapter idaa) {
super(owner, member, idaa);
this.annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa);
+ this.getDefaultPrimaryKeyJoinColumns().add(this.createPrimaryKeyJoinColumn(0));
}
/**
@@ -331,6 +332,55 @@ public class JavaSecondaryTable extends AbstractJavaTable
return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
}
+
+ @Override
+ protected void updateFromJava(CompilationUnit astRoot) {
+ super.updateFromJava(astRoot);
+ this.updateSpecifiedPrimaryKeyJoinColumnsFromJava(astRoot);
+ }
+ /**
+ * here we just worry about getting the join column lists the same size;
+ * then we delegate to the join columns to synch themselves up
+ */
+ private void updateSpecifiedPrimaryKeyJoinColumnsFromJava(CompilationUnit astRoot) {
+ // synchronize the model join columns with the Java source
+ List<IPrimaryKeyJoinColumn> joinColumns = getSpecifiedPrimaryKeyJoinColumns();
+ int persSize = joinColumns.size();
+ int javaSize = 0;
+ boolean allJavaAnnotationsFound = false;
+ for (int i = 0; i < persSize; i++) {
+ JavaPrimaryKeyJoinColumn joinColumn = (JavaPrimaryKeyJoinColumn) joinColumns.get(i);
+ if (joinColumn.annotation(astRoot) == null) {
+ allJavaAnnotationsFound = true;
+ break; // no need to go any further
+ }
+ joinColumn.updateFromJava(astRoot);
+ javaSize++;
+ }
+ if (allJavaAnnotationsFound) {
+ // remove any model join columns beyond those that correspond to the Java annotations
+ while (persSize > javaSize) {
+ persSize--;
+ joinColumns.remove(persSize);
+ }
+ }
+ else {
+ // add new model join columns until they match the Java annotations
+ while (!allJavaAnnotationsFound) {
+ JavaPrimaryKeyJoinColumn joinColumn = this.createJavaPrimaryKeyJoinColumn(javaSize);
+ if (joinColumn.annotation(astRoot) == null) {
+ allJavaAnnotationsFound = true;
+ }
+ else {
+ getSpecifiedPrimaryKeyJoinColumns().add(joinColumn);
+ joinColumn.updateFromJava(astRoot);
+ javaSize++;
+ }
+ }
+ }
+ }
+
+
/**
* allow owners to verify the annotation
*/
@@ -364,7 +414,7 @@ public class JavaSecondaryTable extends AbstractJavaTable
}
private JavaPrimaryKeyJoinColumn createJavaPrimaryKeyJoinColumn(int index) {
- return JavaPrimaryKeyJoinColumn.createSecondaryTableJoinColumn(this, buildPkJoinColumnOwner(), ((JavaTypeMapping) typeMapping()).getType(), index);
+ return JavaPrimaryKeyJoinColumn.createSecondaryTableJoinColumn(this, buildPkJoinColumnOwner(), this.getMember(), index);
}
protected IAbstractJoinColumn.Owner buildPkJoinColumnOwner() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/OneToOneTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/OneToOneTranslator.java
index 6e4efe0b58..b73ed4760e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/OneToOneTranslator.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/resource/OneToOneTranslator.java
@@ -32,6 +32,7 @@ public class OneToOneTranslator extends SingleRelationshipTranslator
createNameTranslator(),
createTargetEntityTranslator(),
createFetchTypeTranslator(),
+ createOptionalTranslator(),
createMappedByTranslator(),
createPlaceHolderTranslator(ONE_TO_ONE__PRIMARY_KEY_JOIN_COLUMNS),
createJoinColumnsTranslator(),
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaEntityContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaEntityContext.java
index 668c1c5a5c..bbd678acfe 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaEntityContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaEntityContext.java
@@ -36,7 +36,7 @@ public class JavaEntityContext extends JavaTypeContext
{
private TableContext tableContext;
- private Collection<TableContext> secondaryTableContexts;
+ private Collection<SecondaryTableContext> secondaryTableContexts;
private Collection<AttributeOverrideContext> attributeOverrideContexts;
@@ -81,10 +81,10 @@ public class JavaEntityContext extends JavaTypeContext
return contexts;
}
- protected Collection<TableContext> buildSecondaryTableContexts() {
- Collection<TableContext> contexts = new ArrayList<TableContext>();
+ protected Collection<SecondaryTableContext> buildSecondaryTableContexts() {
+ Collection<SecondaryTableContext> contexts = new ArrayList<SecondaryTableContext>();
for (ISecondaryTable secondaryTable : getEntity().getSecondaryTables()) {
- contexts.add(new TableContext(this, secondaryTable));
+ contexts.add(new SecondaryTableContext(this, secondaryTable));
}
return contexts;
@@ -124,7 +124,7 @@ public class JavaEntityContext extends JavaTypeContext
}
refreshDefaultAttributeOverrides();
refreshDefaultAssociationOverrides();
- for (TableContext context : this.secondaryTableContexts) {
+ for (SecondaryTableContext context : this.secondaryTableContexts) {
context.refreshDefaults(defaultsContext);
}
for (AttributeOverrideContext context : this.attributeOverrideContexts) {
@@ -220,6 +220,10 @@ public class JavaEntityContext extends JavaTypeContext
addTableMessages(messages);
addIdMessages(messages);
+ for (SecondaryTableContext context : secondaryTableContexts) {
+ context.addToMessages(messages);
+ }
+
for (AttributeOverrideContext aoContext : attributeOverrideContexts) {
aoContext.addToMessages(messages);
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PrimaryKeyJoinColumnContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PrimaryKeyJoinColumnContext.java
index 002d7c576e..bb824fb6c7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PrimaryKeyJoinColumnContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PrimaryKeyJoinColumnContext.java
@@ -8,8 +8,12 @@
*******************************************************************************/
package org.eclipse.jpt.core.internal.platform;
+import java.util.List;
import org.eclipse.jpt.core.internal.mappings.IEntity;
import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn;
+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;
public class PrimaryKeyJoinColumnContext extends AbstractJoinColumnContext<IPrimaryKeyJoinColumn>
{
@@ -18,7 +22,7 @@ public class PrimaryKeyJoinColumnContext extends AbstractJoinColumnContext<IPrim
super(parentContext, column);
}
-
+ //TODO This default is different for oneToOne mappings, we don't yet support pkJoinColumns there
protected String buildDefaultReferencedColumnName() {
return this.buildDefaultName();
}
@@ -33,5 +37,29 @@ public class PrimaryKeyJoinColumnContext extends AbstractJoinColumnContext<IPrim
return pkColumnName;
}
-
+ @Override
+ public void addToMessages(List<IMessage> messages) {
+ super.addToMessages(messages);
+
+ boolean doContinue = column.isConnected();
+ if (doContinue && ! column.isResolved()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME,
+ new String[] {column.getName()},
+ column, column.getNameTextRange())
+ );
+ }
+
+ if (doContinue && ! column.isReferencedColumnResolved()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME,
+ new String[] {column.getReferencedColumnName(), column.getName()},
+ column, column.getReferencedColumnNameTextRange())
+ );
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/SecondaryTableContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/SecondaryTableContext.java
new file mode 100644
index 0000000000..80f4eed606
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/SecondaryTableContext.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.core.internal.platform;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.jpt.core.internal.IPersistentType;
+import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn;
+import org.eclipse.jpt.core.internal.mappings.ISecondaryTable;
+import org.eclipse.jpt.core.internal.mappings.ITable;
+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;
+
+public class SecondaryTableContext extends BaseContext
+{
+ private ISecondaryTable secondaryTable;
+
+ private Collection<PrimaryKeyJoinColumnContext> pkJoinColumnContexts;
+
+ public SecondaryTableContext(IContext parentContext, ISecondaryTable secondaryTable) {
+ super(parentContext);
+ this.secondaryTable = secondaryTable;
+ this.pkJoinColumnContexts = buildPkJoinColumnContexts();
+ }
+
+ protected Collection<PrimaryKeyJoinColumnContext> buildPkJoinColumnContexts() {
+ Collection<PrimaryKeyJoinColumnContext> contexts = new ArrayList<PrimaryKeyJoinColumnContext>();
+ for (IPrimaryKeyJoinColumn pkJoinColumn : getSecondaryTable().getPrimaryKeyJoinColumns()) {
+ contexts.add(new PrimaryKeyJoinColumnContext(this, pkJoinColumn));
+ }
+
+ return contexts;
+ }
+
+ @Override
+ protected void initialize() {}
+
+ public ISecondaryTable getSecondaryTable() {
+ return this.secondaryTable;
+ }
+
+ public void refreshDefaults(DefaultsContext defaultsContext) {
+ this.secondaryTable.refreshDefaults(defaultsContext);
+ for (PrimaryKeyJoinColumnContext context : this.pkJoinColumnContexts) {
+ context.refreshDefaults(defaultsContext);
+ }
+ }
+
+ public DefaultsContext wrapDefaultsContext(final DefaultsContext defaultsContext) {
+ return new DefaultsContext() {
+ public Object getDefault(String key) {
+// if (key.equals(BaseJpaPlatform.DEFAULT_COLUMN_TABLE_KEY)) {
+// return getTable().getName();
+// }
+ return defaultsContext.getDefault(key);
+ }
+
+ public IPersistentType persistentType(String fullyQualifiedTypeName) {
+ return defaultsContext.persistentType(fullyQualifiedTypeName);
+ }
+ };
+ }
+
+ @Override
+ public void addToMessages(List<IMessage> messages) {
+ super.addToMessages(messages);
+ addTableMessages(messages);
+ for (PrimaryKeyJoinColumnContext context : this.pkJoinColumnContexts) {
+ context.addToMessages(messages);
+ }
+ }
+
+ protected void addTableMessages(List<IMessage> messages) {
+ boolean doContinue = secondaryTable.isConnected();
+ String schema = secondaryTable.getSchema();
+
+ if (doContinue && ! secondaryTable.hasResolvedSchema()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA,
+ new String[] {schema, secondaryTable.getName()},
+ secondaryTable, secondaryTable.getSchemaTextRange())
+ );
+ doContinue = false;
+ }
+
+ if (doContinue && ! secondaryTable.isResolved()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME,
+ new String[] {secondaryTable.getName()},
+ secondaryTable, secondaryTable.getNameTextRange())
+ );
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java
index a48af7dc02..46d09dc266 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java
@@ -35,7 +35,7 @@ public class XmlEntityContext extends XmlTypeContext
{
private TableContext tableContext;
- private Collection<TableContext> secondaryTableContexts;
+ private Collection<SecondaryTableContext> secondaryTableContexts;
private JavaTable javaTable;
@@ -70,10 +70,10 @@ public class XmlEntityContext extends XmlTypeContext
return contexts;
}
- protected Collection<TableContext> buildSecondaryTableContexts() {
- Collection<TableContext> contexts = new ArrayList<TableContext>();
+ protected Collection<SecondaryTableContext> buildSecondaryTableContexts() {
+ Collection<SecondaryTableContext> contexts = new ArrayList<SecondaryTableContext>();
for (ISecondaryTable secondaryTable : getEntity().getSecondaryTables()) {
- contexts.add(new TableContext(this, secondaryTable));
+ contexts.add(new SecondaryTableContext(this, secondaryTable));
}
return contexts;
@@ -127,7 +127,7 @@ public class XmlEntityContext extends XmlTypeContext
refreshDefaultAttributeOverrides();
refreshDefaultAssociationOverrides();
refreshDefaultSecondaryTables();
- for (TableContext context : this.secondaryTableContexts) {
+ for (SecondaryTableContext context : this.secondaryTableContexts) {
context.refreshDefaults(parentDefaults);
}
for (AttributeOverrideContext context : this.attributeOverrideContexts) {
@@ -324,6 +324,10 @@ public class XmlEntityContext extends XmlTypeContext
tableContext.addToMessages(messages);
addIdMessages(messages);
+ for (SecondaryTableContext context : secondaryTableContexts) {
+ context.addToMessages(messages);
+ }
+
for (AttributeOverrideContext aoContext : attributeOverrideContexts) {
aoContext.addToMessages(messages);
}
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 ea0781e7eb..9b6dd5bbc4 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 TABLE_UNRESOLVED_NAME = "TABLE_UNRESOLVED_NAME";
+ public static final String SECONDARY_TABLE_UNRESOLVED_SCHEMA = "SECONDARY_TABLE_UNRESOLVED_SCHEMA";
+
+ public static final String SECONDARY_TABLE_UNRESOLVED_NAME = "SECONDARY_TABLE_UNRESOLVED_NAME";
+
public static final String JOIN_TABLE_UNRESOLVED_SCHEMA = "JOIN_TABLE_UNRESOLVED_SCHEMA";
public static final String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA = "VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA";
@@ -103,4 +107,9 @@ public interface IJpaValidationMessages
public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME";
public static final String GENERATED_VALUE_UNRESOLVED_GENERATOR = "GENERATED_VALUE_UNRESOLVED_GENERATOR";
+
+ public static final String PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME = "PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME";
+
+ public static final String PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME = "PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME";
+
} \ No newline at end of file

Back to the top