Skip to main content
summaryrefslogtreecommitdiffstats
blob: 83558cd2ba88fc3956bd73e2d288553e641ff870 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*******************************************************************************
 * Copyright (c) 2007, 2008 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.resource.java;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter;
import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation;
import org.eclipse.jpt.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.Member;

public abstract class BaseColumnImpl extends AbstractNamedColumn implements BaseColumnAnnotation
{
	// hold this so we can get the 'table' text range
	private final DeclarationAnnotationElementAdapter<String> tableDeclarationAdapter;
	
	// hold this so we can get the 'unique' text range
	private final DeclarationAnnotationElementAdapter<Boolean> uniqueDeclarationAdapter;
	
	// hold this so we can get the 'nullable' text range
	private final DeclarationAnnotationElementAdapter<Boolean> nullableDeclarationAdapter;
	
	// hold this so we can get the 'insertable' text range
	private final DeclarationAnnotationElementAdapter<Boolean> insertableDeclarationAdapter;
	
	// hold this so we can get the 'updatable' text range
	private final DeclarationAnnotationElementAdapter<Boolean> updatableDeclarationAdapter;

	private final AnnotationElementAdapter<String> tableAdapter;

	private final AnnotationElementAdapter<Boolean> uniqueAdapter;

	private final AnnotationElementAdapter<Boolean> nullableAdapter;

	private final AnnotationElementAdapter<Boolean> insertableAdapter;

	private final AnnotationElementAdapter<Boolean> updatableAdapter;

	private String table;
	private Boolean unique;
	private Boolean nullable;
	private Boolean insertable;
	private Boolean updatable;
	

	public BaseColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) {
		this(parent, member, daa, new MemberAnnotationAdapter(member, daa));
	}
	
	public BaseColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
		super(parent, member, daa, annotationAdapter);
		this.tableDeclarationAdapter = this.buildStringElementAdapter(this.tableElementName());
		this.tableAdapter = this.buildShortCircuitElementAdapter(this.tableDeclarationAdapter);
		this.uniqueDeclarationAdapter = this.buildBooleanElementAdapter(this.uniqueElementName());
		this.uniqueAdapter = this.buildShortCircuitBooleanElementAdapter(this.uniqueDeclarationAdapter);
		this.nullableDeclarationAdapter = this.buildBooleanElementAdapter(this.nullableElementName());
		this.nullableAdapter = this.buildShortCircuitBooleanElementAdapter(this.nullableDeclarationAdapter);
		this.insertableDeclarationAdapter = this.buildBooleanElementAdapter(this.insertableElementName());
		this.insertableAdapter = this.buildShortCircuitBooleanElementAdapter(this.insertableDeclarationAdapter);
		this.updatableDeclarationAdapter = this.buildBooleanElementAdapter(this.updatableElementName());
		this.updatableAdapter = this.buildShortCircuitBooleanElementAdapter(this.updatableDeclarationAdapter);
	}
	
	@Override
	public void initialize(CompilationUnit astRoot) {
		super.initialize(astRoot);
		this.table = this.table(astRoot);
		this.unique = this.unique(astRoot);
		this.nullable = this.nullable(astRoot);
		this.insertable = this.insertable(astRoot);
		this.updatable = this.updatable(astRoot);
	}
	
	protected abstract String tableElementName();

	protected abstract String uniqueElementName();

	protected abstract String nullableElementName();

	protected abstract String insertableElementName();

	protected abstract String updatableElementName();

	@Override
	public void initializeFrom(NestableAnnotation oldAnnotation) {
		super.initializeFrom(oldAnnotation);
		BaseColumnAnnotation oldColumn = (BaseColumnAnnotation) oldAnnotation;
		setTable(oldColumn.getTable());
		setUnique(oldColumn.getUnique());
		setNullable(oldColumn.getNullable());
		setInsertable(oldColumn.getInsertable());
		setUpdatable(oldColumn.getUpdatable());
	}

	//************* AbstractColumn implementation *************
	public String getTable() {
		return this.table;
	}

	public void setTable(String newTable) {
		if (attributeValueHasNotChanged(this.table, newTable)) {
			return;
		}
		String oldTable = this.table;
		this.table = newTable;
		this.tableAdapter.setValue(newTable);
		firePropertyChanged(TABLE_PROPERTY, oldTable, newTable);
	}
	
	public Boolean getUnique() {
		return this.unique;
	}

	public void setUnique(Boolean newUnique) {
		if (attributeValueHasNotChanged(this.unique, newUnique)) {
			return;
		}
		Boolean oldUnique = this.unique;
		this.unique = newUnique;
		this.uniqueAdapter.setValue(newUnique);
		firePropertyChanged(UNIQUE_PROPERTY, oldUnique, newUnique);
	}

	public Boolean getNullable() {
		return this.nullable;
	}

	public void setNullable(Boolean newNullable) {
		if (attributeValueHasNotChanged(this.nullable, newNullable)) {
			return;
		}
		Boolean oldNullable = this.nullable;
		this.nullable = newNullable;
		this.nullableAdapter.setValue(newNullable);
		firePropertyChanged(NULLABLE_PROPERTY, oldNullable, newNullable);
	}

	public Boolean getInsertable() {
		return this.insertable;
	}

	public void setInsertable(Boolean newInsertable) {
		if (attributeValueHasNotChanged(this.insertable, newInsertable)) {
			return;
		}
		Boolean oldInsertable = this.insertable;
		this.insertable = newInsertable;
		this.insertableAdapter.setValue(newInsertable);
		firePropertyChanged(INSERTABLE_PROPERTY, oldInsertable, newInsertable);
	}

	public Boolean getUpdatable() {
		return this.updatable;
	}

	public void setUpdatable(Boolean newUpdatable) {
		if (attributeValueHasNotChanged(this.updatable, newUpdatable)) {
			return;
		}
		Boolean oldUpdatable = this.updatable;
		this.updatable = newUpdatable;
		this.updatableAdapter.setValue(newUpdatable);
		firePropertyChanged(UPDATABLE_PROPERTY, oldUpdatable, newUpdatable);
	}

	public TextRange getNullableTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.nullableDeclarationAdapter, astRoot);
	}
	
	public TextRange getInsertableTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.insertableDeclarationAdapter, astRoot);
	}
	
	public TextRange getUniqueTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.uniqueDeclarationAdapter, astRoot);
	}
	
	public TextRange getUpdatableTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.updatableDeclarationAdapter, astRoot);
	}
	
	public TextRange getTableTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.tableDeclarationAdapter, astRoot);
	}
	
	public boolean tableTouches(int pos, CompilationUnit astRoot) {
		return this.elementTouches(this.tableDeclarationAdapter, pos, astRoot);
	}


	@Override
	public void update(CompilationUnit astRoot) {
		super.update(astRoot);
		this.setTable(this.table(astRoot));
		this.setUnique(this.unique(astRoot));
		this.setNullable(this.nullable(astRoot));
		this.setInsertable(this.insertable(astRoot));
		this.setUpdatable(this.updatable(astRoot));
	}
	
	protected String table(CompilationUnit astRoot) {
		return this.tableAdapter.getValue(astRoot);
	}
	
	protected Boolean unique(CompilationUnit astRoot) {
		return this.uniqueAdapter.getValue(astRoot);
	}
	
	protected Boolean nullable(CompilationUnit astRoot) {
		return this.nullableAdapter.getValue(astRoot);
	}
	
	protected Boolean insertable(CompilationUnit astRoot) {
		return this.insertableAdapter.getValue(astRoot);
	}
	
	protected Boolean updatable(CompilationUnit astRoot) {
		return this.updatableAdapter.getValue(astRoot);
	}

}

Back to the top