Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a12eeeaa59039f9dffe8893c9104ea76cf0a742d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*******************************************************************************
 * Copyright (c) 2006, 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.content.java.mappings;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.ITextRange;
import org.eclipse.jpt.core.internal.ITypeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
import org.eclipse.jpt.core.internal.content.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.jdtutility.AnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.Attribute;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.jdtutility.MemberAnnotationAdapter;
import org.eclipse.jpt.core.internal.mappings.INamedColumn;
import org.eclipse.jpt.core.internal.platform.DefaultsContext;
import org.eclipse.jpt.db.internal.Table;

/**
 * <!-- begin-user-doc -->
 * A representation of the model object '<em><b>Java Attribute Mapping</b></em>'.
 * <!-- end-user-doc -->
 *
 *
 * @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getJavaAttributeMapping()
 * @model kind="class" abstract="true"
 * @generated
 */
public abstract class JavaAttributeMapping extends JavaEObject
	implements IJavaAttributeMapping
{
	private final Attribute attribute;

	// TODO remove?
	private final AnnotationAdapter annotationAdapter;

	protected JavaAttributeMapping() {
		throw new UnsupportedOperationException("Use JavaAttributeMapping(Attribute) instead");
	}

	protected JavaAttributeMapping(Attribute attribute) {
		super();
		this.attribute = attribute;
		this.annotationAdapter = this.buildAnnotationAdapter(this.declarationAnnotationAdapter());
	}

	/**
	 * Return the declaration adapter for the mapping's annotation.
	 */
	protected abstract DeclarationAnnotationAdapter declarationAnnotationAdapter();

	/**
	 * Build and return an adapter for the mapping's annotation.
	 */
	protected AnnotationAdapter buildAnnotationAdapter(DeclarationAnnotationAdapter daa) {
		return new MemberAnnotationAdapter(this.attribute, daa);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return JpaJavaMappingsPackage.Literals.JAVA_ATTRIBUTE_MAPPING;
	}

	public void initialize() {
		this.updateFromJava(this.attribute.astRoot());
	}

	public JavaPersistentAttribute getPersistentAttribute() {
		return (JavaPersistentAttribute) this.eContainer();
	}

	/**
	 * the persistent attribute can tell whether there is a "specified" mapping
	 * or a "default" one
	 */
	public boolean isDefault() {
		return this.getPersistentAttribute().mappingIsDefault();
	}

	public ITypeMapping typeMapping() {
		return this.getPersistentAttribute().typeMapping();
	}

	public Attribute getAttribute() {
		return this.attribute;
	}

	public ITextRange validationTextRange() {
		ITextRange textRange = attribute.annotationTextRange(this.declarationAnnotationAdapter());
		return (textRange == null) ? this.getPersistentAttribute().validationTextRange() : textRange;
	}

	protected ITextRange elementTextRange(DeclarationAnnotationElementAdapter<?> elementAdapter) {
		return this.elementTextRange(this.attribute.annotationElementTextRange(elementAdapter));
	}

	protected IType jdtType() {
		return this.typeMapping().getPersistentType().findJdtType();
	}

	public void updateFromJava(CompilationUnit astRoot) {
	// do nothing - override as appropriate
	}

	protected INamedColumn.Owner buildColumnOwner() {
		return new ColumnOwner();
	}

	public void refreshDefaults(DefaultsContext defaultsContext) {
	// do nothing - override as appropriate
	}

	public String primaryKeyColumnName() {
		return null;
	}

	protected boolean elementTouches(DeclarationAnnotationElementAdapter<?> elementAdapter, int pos) {
		return this.elementTouches(this.attribute.annotationElementTextRange(elementAdapter), pos);
	}

	protected boolean elementTouches(DeclarationAnnotationElementAdapter<?> elementAdapter, int pos, CompilationUnit astRoot) {
		return this.elementTouches(this.attribute.annotationElementTextRange(elementAdapter, astRoot), pos);
	}

	public boolean isOverridableAttributeMapping() {
		return false;
	}

	public boolean isOverridableAssociationMapping() {
		return false;
	}

	public boolean isIdMapping() {
		return false;
	}


	/**
	 * mapping implementation of column owner
	 */
	protected class ColumnOwner implements INamedColumn.Owner
	{
		public ITypeMapping getTypeMapping() {
			return JavaAttributeMapping.this.typeMapping();
		}

		public ITextRange validationTextRange() {
			return JavaAttributeMapping.this.validationTextRange();
		}

		public Table dbTable(String tableName) {
			return this.getTypeMapping().dbTable(tableName);
		}
	}
}

Back to the top