Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-02-24 17:37:26 -0500
committerkmoore2011-02-24 17:37:26 -0500
commit80617f83784aa681fe4086db5ba05fdba32c2a05 (patch)
treecacd517ce26eb36a5ec404e9bed34acf6a1aa6a4
parentdf05f9612ad07fc0902d191a0568042011330131 (diff)
downloadwebtools.dali-80617f83784aa681fe4086db5ba05fdba32c2a05.tar.gz
webtools.dali-80617f83784aa681fe4086db5ba05fdba32c2a05.tar.xz
webtools.dali-80617f83784aa681fe4086db5ba05fdba32c2a05.zip
bug 336006 - Need validation for temporal type mappings - patch from Nan
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_validation.properties3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TemporalConverter.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/orm/XmlId.java6
8 files changed, 108 insertions, 9 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_validation.properties
index 54193cd3a7..18bfa346a4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_validation.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_validation.properties
@@ -71,10 +71,13 @@ ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED=No discriminator value should
ENTITY_NAME_MISSING=The given name of the entity \"{0}\" is empty
ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED=No discriminator column should be defined for non-root entity \"{0}\"
ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED=No discriminator column should be defined for entity \"{0}\" using table-per-concrete-class inheritance
+PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE=The element collection value for a Temporal type must be of type java.util.Date, java.util.Calendar or java.util.GregorianCalendar
PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME=Unspecified name
PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME=Attribute \"{0}\" in class \"{1}\" cannot be resolved
PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED=Attribute \"{0}\" is inherited; referring to inherited attributes in the orm.xml may not be supported by all persistence providers
PERSISTENT_ATTRIBUTE_INVALID_MAPPING=Attribute \"{0}\" has invalid mapping type in this context
+PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE=The persistent field or property for a Temporal type must be of type java.util.Date, java.util.Calendar or java.util.GregorianCalendar
+PERSISTENT_ATTRIBUTE_INVALID_VERSION_MAPPING_TYPE=The persistent field or property for a Version mapping must be of type int, Integer, short, Short, long, Long or Timestamp to ensure application portability to other JPA providers
PERSISTENT_ATTRIBUTE_FINAL_FIELD=The java field for attribute \"{0}\" is final
PERSISTENT_ATTRIBUTE_FINAL_GETTER=The get method for attribute \"{0}\" is final
PERSISTENT_ATTRIBUTE_PUBLIC_FIELD=The java field for attribute \"{0}\" is public
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TemporalConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TemporalConverter.java
index 7a651dc6fa..b00639b466 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TemporalConverter.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TemporalConverter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 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.
@@ -24,6 +24,8 @@ package org.eclipse.jpt.jpa.core.context;
public interface TemporalConverter
extends Converter
{
+ static final String[] TEMPORAL_MAPPING_SUPPORTED_TYPES = {"java.util.Date", "java.util.Calendar", "java.util.GregorianCalendar"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
TemporalType getTemporalType();
void setTemporalType(TemporalType temporalType);
String TEMPORAL_TYPE_PROPERTY = "temporalType"; //$NON-NLS-1$
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java
index a48e67aeb5..7552b4963a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 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.
@@ -9,14 +9,22 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
+import java.util.List;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.jpa.core.context.Converter;
import org.eclipse.jpt.jpa.core.context.TemporalConverter;
import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaTemporalConverter;
+import org.eclipse.jpt.jpa.core.internal.jpa2.context.java.AbstractJavaElementCollectionMapping2_0;
+import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
+import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
+import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
import org.eclipse.jpt.jpa.core.resource.java.TemporalAnnotation;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class GenericJavaTemporalConverter
extends AbstractJavaConverter
@@ -87,6 +95,43 @@ public class GenericJavaTemporalConverter
// ********** validation **********
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ this.validateAttributeTypeWithTemporal(messages, reporter, astRoot);
+ }
+
+ protected void validateAttributeTypeWithTemporal(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ if (this.getAttributeMapping().getKey() == MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY) {
+ String typeName = ((AbstractJavaElementCollectionMapping2_0) this.getAttributeMapping()).getFullyQualifiedTargetClass();
+ if (!ArrayTools.contains(TEMPORAL_MAPPING_SUPPORTED_TYPES, typeName)) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE,
+ new String[] {},
+ this,
+ this.getValidationTextRange(astRoot)
+ )
+ );
+ }
+ } else {
+ String typeName = this.getAttributeMapping().getPersistentAttribute().getTypeName();
+ if (!ArrayTools.contains(TEMPORAL_MAPPING_SUPPORTED_TYPES, typeName)) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE,
+ new String[] {},
+ this,
+ this.getValidationTextRange(astRoot)
+ )
+ );
+ }
+
+ }
+ }
public TextRange getValidationTextRange(CompilationUnit astRoot) {
return this.temporalAnnotation.getTextRange(astRoot);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java
index c95d8743e9..977da242f7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 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.
@@ -9,16 +9,24 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm;
+import java.util.List;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.jpa.core.context.Converter;
import org.eclipse.jpt.jpa.core.context.TemporalConverter;
import org.eclipse.jpt.jpa.core.context.TemporalType;
import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmTemporalConverter;
+import org.eclipse.jpt.jpa.core.internal.jpa2.context.orm.AbstractOrmElementCollectionMapping2_0;
+import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
+import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
+import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class GenericOrmTemporalConverter
extends AbstractOrmConverter
@@ -82,6 +90,44 @@ public class GenericOrmTemporalConverter
// ********** validation **********
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter) {
+ super.validate(messages, reporter);
+ this.validateAttributeTypeWithTemporal(messages, reporter);
+ }
+
+ protected void validateAttributeTypeWithTemporal(List<IMessage> messages, IReporter reporter) {
+ if (this.getAttributeMapping().getKey() == MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY) {
+ @SuppressWarnings("rawtypes")
+ String typeName = ((AbstractOrmElementCollectionMapping2_0) this.getAttributeMapping()).getTargetClass();
+ if (!ArrayTools.contains(TEMPORAL_MAPPING_SUPPORTED_TYPES, typeName)) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE,
+ new String[] {},
+ this,
+ this.getValidationTextRange()
+ )
+ );
+ }
+ } else {
+ String typeName = this.getAttributeMapping().getPersistentAttribute().getTypeName();
+ if (!ArrayTools.contains(TEMPORAL_MAPPING_SUPPORTED_TYPES, typeName)) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE,
+ new String[] {},
+ this,
+ this.getValidationTextRange()
+ )
+ );
+ }
+
+ }
+ }
public TextRange getValidationTextRange() {
return this.getXmlConvertibleMapping().getTemporalTextRange();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java
index 072f3a4ffb..c1edb0eda8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java
@@ -1227,12 +1227,12 @@ public abstract class AbstractJavaElementCollectionMapping2_0
}
protected void validateValue(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ this.converter.validate(messages, reporter, astRoot);
//TODO should we handle validation when the type is embeddable,
//but a value column is specified, or things like that if that is invalid?
switch (this.valueType) {
case BASIC_TYPE :
this.valueColumn.validate(messages, reporter, astRoot);
- this.converter.validate(messages, reporter, astRoot);
break;
case EMBEDDABLE_TYPE :
this.valueAttributeOverrideContainer.validate(messages, reporter, astRoot);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java
index 1ff7dd5687..93d88459b7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java
@@ -1336,12 +1336,12 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen
}
public void validateValue(List<IMessage> messages, IReporter reporter) {
+ this.converter.validate(messages, reporter);
//TODO should we handle validation when the type is embeddable,
//but a value column is specified, or things like that if that is invalid?
switch (this.valueType) {
case BASIC_TYPE :
this.valueColumn.validate(messages, reporter);
- this.converter.validate(messages, reporter);
break;
case EMBEDDABLE_TYPE :
this.valueAttributeOverrideContainer.validate(messages, reporter);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java
index 3491371224..7406c7f95f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 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.
@@ -77,6 +77,7 @@ public interface JpaValidationMessages {
public static final String ENTITY_NAME_MISSING = "ENTITY_NAME_MISSING";
public static final String ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED = "ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED";
public static final String ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED = "ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED";
+ public static final String PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE = "PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE";
public static final String PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME = "PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME";
public static final String PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME = "PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME";
public static final String PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED = "PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED";
@@ -84,6 +85,8 @@ public interface JpaValidationMessages {
public static final String PERSISTENT_ATTRIBUTE_FINAL_GETTER = "PERSISTENT_ATTRIBUTE_FINAL_GETTER";
public static final String PERSISTENT_ATTRIBUTE_PUBLIC_FIELD = "PERSISTENT_ATTRIBUTE_PUBLIC_FIELD";
public static final String PERSISTENT_ATTRIBUTE_INVALID_MAPPING = "PERSISTENT_ATTRIBUTE_INVALID_MAPPING";
+ public static final String PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE = "PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE";
+ public static final String PERSISTENT_ATTRIBUTE_INVALID_VERSION_MAPPING_TYPE = "PERSISTENT_ATTRIBUTE_INVALID_VERSION_MAPPING_TYPE";
public static final String MAPPING_UNRESOLVED_MAPPED_BY = "MAPPING_UNRESOLVED_MAPPED_BY";
public static final String MAPPING_INVALID_MAPPED_BY = "MAPPING_INVALID_MAPPED_BY";
public static final String MAPPING_MAPPED_BY_ON_BOTH_SIDES = "MAPPING_MAPPED_BY_ON_BOTH_SIDES";
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/orm/XmlId.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/orm/XmlId.java
index 1f668cab3e..7877c89fed 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/orm/XmlId.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/orm/XmlId.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 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.
@@ -746,7 +746,7 @@ public class XmlId extends AbstractXmlAttributeMapping implements ColumnMapping,
}
public TextRange getEnumeratedTextRange() {
- return getAttributeTextRange(JPA.ENUMERATED);
+ throw new UnsupportedOperationException("enumerated not supported by id mappings");
}
public TextRange getLobTextRange() {
@@ -754,7 +754,7 @@ public class XmlId extends AbstractXmlAttributeMapping implements ColumnMapping,
}
public TextRange getTemporalTextRange() {
- throw new UnsupportedOperationException("temporal not supported by id mappings");
+ return getAttributeTextRange(JPA.TEMPORAL);
}
public String getMappingKey() {

Back to the top