Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMapping.java')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMapping.java166
1 files changed, 166 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMapping.java
new file mode 100644
index 0000000000..0505f203d9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMapping.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.context.java;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.IMappingKeys;
+import org.eclipse.jpt.core.internal.context.base.IColumn;
+import org.eclipse.jpt.core.internal.context.base.IColumnMapping;
+import org.eclipse.jpt.core.internal.context.base.ITypeMapping;
+import org.eclipse.jpt.core.internal.context.base.TemporalType;
+import org.eclipse.jpt.core.internal.resource.java.Column;
+import org.eclipse.jpt.core.internal.resource.java.JPA;
+import org.eclipse.jpt.core.internal.resource.java.JavaPersistentAttributeResource;
+import org.eclipse.jpt.core.internal.resource.java.Temporal;
+import org.eclipse.jpt.core.internal.resource.java.Version;
+import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages;
+import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
+import org.eclipse.jpt.utility.internal.Filter;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+
+
+public class JavaVersionMapping extends JavaAttributeMapping implements IJavaVersionMapping
+{
+ protected final IJavaColumn column;
+
+ protected TemporalType temporal;
+
+ public JavaVersionMapping(IJavaPersistentAttribute parent) {
+ super(parent);
+ this.column = createJavaColumn();
+ }
+
+ protected IJavaColumn createJavaColumn() {
+ return jpaFactory().createJavaColumn(this, this);
+ }
+
+ @Override
+ public void initializeFromResource(JavaPersistentAttributeResource persistentAttributeResource) {
+ super.initializeFromResource(persistentAttributeResource);
+ this.column.initializeFromResource(this.columnResource());
+ this.temporal = this.temporal(this.temporalResource());
+ }
+
+ protected Temporal temporalResource() {
+ return (Temporal) this.persistentAttributeResource.nonNullAnnotation(Temporal.ANNOTATION_NAME);
+ }
+
+ public Column columnResource() {
+ return (Column) this.persistentAttributeResource.nonNullAnnotation(Column.ANNOTATION_NAME);
+ }
+
+ //************** IJavaAttributeMapping implementation ***************
+
+ public String getKey() {
+ return IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY;
+ }
+
+ public String annotationName() {
+ return Version.ANNOTATION_NAME;
+ }
+
+ public Iterator<String> correspondingAnnotationNames() {
+ return new ArrayIterator<String>(
+ JPA.COLUMN,
+ JPA.TEMPORAL);
+ }
+
+ //************** INamedColumn.Owner implementation ***************
+
+ public String defaultColumnName() {
+ return attributeName();
+ }
+
+ public String defaultTableName() {
+ return typeMapping().getTableName();
+ }
+
+ //************** IVersionMapping implementation ***************
+
+ public IJavaColumn getColumn() {
+ return this.column;
+ }
+
+ public TemporalType getTemporal() {
+ return this.temporal;
+ }
+
+ public void setTemporal(TemporalType newTemporal) {
+ TemporalType oldTemporal = this.temporal;
+ this.temporal = newTemporal;
+ this.temporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal));
+ firePropertyChanged(IColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal);
+ }
+
+ @Override
+ public void update(JavaPersistentAttributeResource persistentAttributeResource) {
+ super.update(persistentAttributeResource);
+ this.column.update(this.columnResource());
+ this.setTemporal(this.temporal(this.temporalResource()));
+ }
+
+ protected TemporalType temporal(Temporal temporal) {
+ return TemporalType.fromJavaResourceModel(temporal.getValue());
+ }
+
+ @Override
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ Iterator<String> result = super.candidateValuesFor(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ result = this.getColumn().candidateValuesFor(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ return null;
+ }
+
+ //*********** Validation ******************************
+
+ public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) {
+ super.addToMessages(messages, astRoot);
+
+ addColumnMessages(messages, astRoot);
+ }
+
+ protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) {
+ ITypeMapping typeMapping = this.typeMapping();
+ IJavaColumn column = this.getColumn();
+ String table = column.getTable();
+ boolean doContinue = entityOwned() && column.isConnected();
+
+ if (doContinue && this.typeMapping().tableNameIsInvalid(table)) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.COLUMN_UNRESOLVED_TABLE,
+ new String[] {table, column.getName()},
+ column, column.tableTextRange(astRoot))
+ );
+ doContinue = false;
+ }
+
+ if (doContinue && ! column.isResolved()) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.COLUMN_UNRESOLVED_NAME,
+ new String[] {column.getName()},
+ column, column.nameTextRange(astRoot))
+ );
+ }
+ }
+
+}

Back to the top