View | Details | Raw Unified | Return to bug 392701 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/jpa/core/context/NamedNativeQuery.java (+10 lines)
Lines 24-29 Link Here
24
public interface NamedNativeQuery
24
public interface NamedNativeQuery
25
	extends Query
25
	extends Query
26
{
26
{
27
28
	// ********** query **********
29
30
	String QUERY_PROPERTY = "query"; //$NON-NLS-1$
31
32
	String getQuery();
33
34
	void setQuery(String query);
35
36
27
	// ********** result class **********
37
	// ********** result class **********
28
38
29
	String getResultClass();
39
	String getResultClass();
(-)src/org/eclipse/jpt/jpa/core/context/NamedQuery.java (-1 / +10 lines)
Lines 24-28 Link Here
24
public interface NamedQuery
24
public interface NamedQuery
25
	extends Query
25
	extends Query
26
{
26
{
27
	// nothing yet
27
28
	// ********** query **********
29
30
	String QUERY_PROPERTY = "query"; //$NON-NLS-1$
31
32
	String getQuery();
33
34
	void setQuery(String query);
35
36
28
}
37
}
(-)src/org/eclipse/jpt/jpa/core/context/Query.java (-9 lines)
Lines 48-62 Link Here
48
			NamedNativeQuery.class
48
			NamedNativeQuery.class
49
		);
49
		);
50
50
51
	// ********** query **********
52
53
	String QUERY_PROPERTY = "query"; //$NON-NLS-1$
54
55
	String getQuery();
56
57
	void setQuery(String query);
58
59
60
	// ********** hints **********
51
	// ********** hints **********
61
52
62
	String HINTS_LIST = "hints"; //$NON-NLS-1$
53
	String HINTS_LIST = "hints"; //$NON-NLS-1$
(-)src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java (-46 lines)
Lines 43-50 Link Here
43
43
44
	protected String name;
44
	protected String name;
45
45
46
	protected String query;
47
48
	protected final ContextListContainer<JavaQueryHint, QueryHintAnnotation> hintContainer;
46
	protected final ContextListContainer<JavaQueryHint, QueryHintAnnotation> hintContainer;
49
47
50
48
Lines 52-58 Link Here
52
		super(parent);
50
		super(parent);
53
		this.queryAnnotation = queryAnnotation;
51
		this.queryAnnotation = queryAnnotation;
54
		this.name = queryAnnotation.getName();
52
		this.name = queryAnnotation.getName();
55
		this.query = queryAnnotation.getQuery();
56
		this.hintContainer = this.buildHintContainer();
53
		this.hintContainer = this.buildHintContainer();
57
	}
54
	}
58
55
Lines 63-69 Link Here
63
	public void synchronizeWithResourceModel() {
60
	public void synchronizeWithResourceModel() {
64
		super.synchronizeWithResourceModel();
61
		super.synchronizeWithResourceModel();
65
		this.setName_(this.queryAnnotation.getName());
62
		this.setName_(this.queryAnnotation.getName());
66
		this.setQuery_(this.queryAnnotation.getQuery());
67
		this.syncHints();
63
		this.syncHints();
68
	}
64
	}
69
65
Lines 89-112 Link Here
89
		String old = this.name;
85
		String old = this.name;
90
		this.name = name;
86
		this.name = name;
91
		this.firePropertyChanged(NAME_PROPERTY, old, name);
87
		this.firePropertyChanged(NAME_PROPERTY, old, name);
92
	}
93
94
95
	// ********** query **********
96
97
	public String getQuery() {
98
		return this.query;
99
	}
100
101
	public void setQuery(String query) {
102
		this.queryAnnotation.setQuery(query);
103
		this.setQuery_(query);
104
	}
105
106
	protected void setQuery_(String query) {
107
		String old = this.query;
108
		this.query = query;
109
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
110
	}
88
	}
111
89
112
90
Lines 198-204 Link Here
198
	public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
176
	public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
199
		super.validate(messages, reporter);
177
		super.validate(messages, reporter);
200
		this.validateName(messages);
178
		this.validateName(messages);
201
		this.validateQuery(queryHelper, messages, reporter);
202
	}
179
	}
203
180
204
	protected void validateName(List<IMessage> messages) {
181
	protected void validateName(List<IMessage> messages) {
Lines 215-238 Link Here
215
		}
192
		}
216
	}
193
	}
217
194
218
	public void validateQuery(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
219
		if (StringTools.isBlank(this.query)){
220
			messages.add(
221
				DefaultJpaValidationMessages.buildMessage(
222
					IMessage.HIGH_SEVERITY,
223
					JpaValidationMessages.QUERY_STATEMENT_UNDEFINED,
224
					new String[] {this.name},
225
					this,
226
					this.getNameTextRange()
227
				)
228
			);
229
		} else {
230
			this.validateQuery_(queryHelper, messages, reporter);
231
		}
232
	}
233
234
	protected abstract void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter);
235
236
	public TextRange getValidationTextRange() {
195
	public TextRange getValidationTextRange() {
237
		TextRange textRange = this.queryAnnotation.getTextRange();
196
		TextRange textRange = this.queryAnnotation.getTextRange();
238
		return (textRange != null) ? textRange : this.getParent().getValidationTextRange();
197
		return (textRange != null) ? textRange : this.getParent().getValidationTextRange();
Lines 240-249 Link Here
240
199
241
	public TextRange getNameTextRange() {
200
	public TextRange getNameTextRange() {
242
		return this.getValidationTextRange(this.queryAnnotation.getNameTextRange());
201
		return this.getValidationTextRange(this.queryAnnotation.getNameTextRange());
243
	}
244
245
	public List<TextRange> getQueryTextRanges() {
246
		return this.queryAnnotation.getQueryTextRanges();
247
	}
202
	}
248
203
249
	public boolean isEquivalentTo(JpaNamedContextNode node) {
204
	public boolean isEquivalentTo(JpaNamedContextNode node) {
Lines 254-260 Link Here
254
209
255
	protected boolean isEquivalentTo(Query other) {
210
	protected boolean isEquivalentTo(Query other) {
256
		return ObjectTools.equals(this.name, other.getName()) &&
211
		return ObjectTools.equals(this.name, other.getName()) &&
257
				ObjectTools.equals(this.query, other.getQuery()) &&
258
				this.hintsAreEquivalentTo(other);
212
				this.hintsAreEquivalentTo(other);
259
	}
213
	}
260
214
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java (-3 / +54 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 10-22 Link Here
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
11
11
12
import java.util.List;
12
import java.util.List;
13
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.utility.internal.ObjectTools;
14
import org.eclipse.jpt.common.utility.internal.ObjectTools;
15
import org.eclipse.jpt.common.utility.internal.StringTools;
14
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
16
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
15
import org.eclipse.jpt.jpa.core.context.Query;
17
import org.eclipse.jpt.jpa.core.context.Query;
16
import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery;
18
import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery;
17
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
19
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
18
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
20
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
19
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
21
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
22
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
23
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
20
import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
24
import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
21
import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueryAnnotation;
25
import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueryAnnotation;
22
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
26
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
Lines 29-34 Link Here
29
	extends AbstractJavaQuery<NamedNativeQueryAnnotation>
33
	extends AbstractJavaQuery<NamedNativeQueryAnnotation>
30
	implements JavaNamedNativeQuery
34
	implements JavaNamedNativeQuery
31
{
35
{
36
	protected String query;
37
32
	protected String resultClass;
38
	protected String resultClass;
33
	protected String fullyQualifiedResultClass;
39
	protected String fullyQualifiedResultClass;
34
40
Lines 37-42 Link Here
37
43
38
	public GenericJavaNamedNativeQuery(JavaQueryContainer parent, NamedNativeQueryAnnotation queryAnnotation) {
44
	public GenericJavaNamedNativeQuery(JavaQueryContainer parent, NamedNativeQueryAnnotation queryAnnotation) {
39
		super(parent, queryAnnotation);
45
		super(parent, queryAnnotation);
46
		this.query = queryAnnotation.getQuery();
40
		this.resultClass = queryAnnotation.getResultClass();
47
		this.resultClass = queryAnnotation.getResultClass();
41
		this.resultSetMapping = queryAnnotation.getResultSetMapping();
48
		this.resultSetMapping = queryAnnotation.getResultSetMapping();
42
	}
49
	}
Lines 47-52 Link Here
47
	@Override
54
	@Override
48
	public void synchronizeWithResourceModel() {
55
	public void synchronizeWithResourceModel() {
49
		super.synchronizeWithResourceModel();
56
		super.synchronizeWithResourceModel();
57
		this.setQuery_(this.queryAnnotation.getQuery());
50
		this.setResultClass_(this.queryAnnotation.getResultClass());
58
		this.setResultClass_(this.queryAnnotation.getResultClass());
51
		this.setResultSetMapping_(this.queryAnnotation.getResultSetMapping());
59
		this.setResultSetMapping_(this.queryAnnotation.getResultSetMapping());
52
	}
60
	}
Lines 56-61 Link Here
56
		super.update();
64
		super.update();
57
		this.setFullyQualifiedResultClass(this.buildFullyQualifiedResultClass());
65
		this.setFullyQualifiedResultClass(this.buildFullyQualifiedResultClass());
58
	}
66
	}
67
68
	// ********** query **********
69
70
	public String getQuery() {
71
		return this.query;
72
	}
73
74
	public void setQuery(String query) {
75
		this.queryAnnotation.setQuery(query);
76
		this.setQuery_(query);
77
	}
78
79
	protected void setQuery_(String query) {
80
		String old = this.query;
81
		this.query = query;
82
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
83
	}
84
59
85
60
	// ********** result class **********
86
	// ********** result class **********
61
87
Lines 122-130 Link Here
122
148
123
	// ********** validation **********
149
	// ********** validation **********
124
150
125
	@Override
151
	public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
152
		super.validate(messages, reporter);
153
		this.validateQuery(queryHelper, messages, reporter);
154
	}
155
156
	public void validateQuery(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
157
		if (StringTools.isBlank(this.query)){
158
			messages.add(
159
				DefaultJpaValidationMessages.buildMessage(
160
					IMessage.HIGH_SEVERITY,
161
					JpaValidationMessages.QUERY_STATEMENT_UNDEFINED,
162
					new String[] {this.name},
163
					this,
164
					this.getNameTextRange()
165
				)
166
			);
167
		} else {
168
			this.validateQuery_(queryHelper, messages, reporter);
169
		}
170
	}
171
126
	protected void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
172
	protected void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
127
		// nothing yet
173
		// nothing yet
174
	}
175
176
	public List<TextRange> getQueryTextRanges() {
177
		return this.queryAnnotation.getQueryTextRanges();
128
	}
178
	}
129
179
130
	@Override
180
	@Override
Lines 134-140 Link Here
134
	}
184
	}
135
	
185
	
136
	protected boolean isEquivalentTo(NamedNativeQuery other) {
186
	protected boolean isEquivalentTo(NamedNativeQuery other) {
137
		return ObjectTools.equals(this.resultClass, other.getResultClass()) &&
187
		return 	ObjectTools.equals(this.query, other.getQuery()) &&
188
				ObjectTools.equals(this.resultClass, other.getResultClass()) &&
138
				ObjectTools.equals(this.resultSetMapping, other.getResultSetMapping());
189
				ObjectTools.equals(this.resultSetMapping, other.getResultSetMapping());
139
	}
190
	}
140
191
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java (-12 / +73 lines)
Lines 10-20 Link Here
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
10
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
11
11
12
import java.util.List;
12
import java.util.List;
13
import org.eclipse.jpt.common.core.utility.TextRange;
14
import org.eclipse.jpt.common.utility.internal.ObjectTools;
15
import org.eclipse.jpt.common.utility.internal.StringTools;
16
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
13
import org.eclipse.jpt.jpa.core.context.NamedQuery;
17
import org.eclipse.jpt.jpa.core.context.NamedQuery;
14
import org.eclipse.jpt.jpa.core.context.Query;
18
import org.eclipse.jpt.jpa.core.context.Query;
15
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
19
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
16
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
20
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
17
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
21
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
22
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
23
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
18
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
24
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
19
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
25
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
20
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
26
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
Lines 31-42 Link Here
31
	extends AbstractJavaQuery<NamedQueryAnnotation>
37
	extends AbstractJavaQuery<NamedQueryAnnotation>
32
	implements JavaNamedQuery2_0
38
	implements JavaNamedQuery2_0
33
{
39
{
40
	protected String query;
41
34
	protected LockModeType2_0 specifiedLockMode;
42
	protected LockModeType2_0 specifiedLockMode;
35
	protected LockModeType2_0 defaultLockMode;
43
	protected LockModeType2_0 defaultLockMode;
36
44
37
	public GenericJavaNamedQuery(JavaQueryContainer parent, NamedQueryAnnotation queryAnnotation) {
45
	public GenericJavaNamedQuery(JavaQueryContainer parent, NamedQueryAnnotation queryAnnotation) {
38
		super(parent, queryAnnotation);
46
		super(parent, queryAnnotation);
39
		this.specifiedLockMode = this.buildSpecifiedLockMode();
47
		this.specifiedLockMode = this.buildSpecifiedLockMode();
48
		this.query = queryAnnotation.getQuery();
40
	}
49
	}
41
50
42
	// ********** synchronize/update **********
51
	// ********** synchronize/update **********
Lines 44-49 Link Here
44
	@Override
53
	@Override
45
	public void synchronizeWithResourceModel() {
54
	public void synchronizeWithResourceModel() {
46
		super.synchronizeWithResourceModel();
55
		super.synchronizeWithResourceModel();
56
		this.setQuery_(this.queryAnnotation.getQuery());
47
		this.setSpecifiedLockMode_(this.buildSpecifiedLockMode());
57
		this.setSpecifiedLockMode_(this.buildSpecifiedLockMode());
48
	}
58
	}
49
59
Lines 52-57 Link Here
52
		super.update();
62
		super.update();
53
		this.setDefaultLockMode(this.buildDefaultLockMode());
63
		this.setDefaultLockMode(this.buildDefaultLockMode());
54
	}
64
	}
65
66
67
	// ********** query **********
68
69
	public String getQuery() {
70
		return this.query;
71
	}
72
73
	public void setQuery(String query) {
74
		this.queryAnnotation.setQuery(query);
75
		this.setQuery_(query);
76
		this.query = queryAnnotation.getQuery();
77
}
78
79
	protected void setQuery_(String query) {
80
		String old = this.query;
81
		this.query = query;
82
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
83
	}
84
85
55
	// ********** lock mode **********
86
	// ********** lock mode **********
56
87
57
	public LockModeType2_0 getLockMode() {
88
	public LockModeType2_0 getLockMode() {
Lines 95-101 Link Here
95
			return LockModeType2_0.NONE;
126
			return LockModeType2_0.NONE;
96
		}
127
		}
97
		return null;
128
		return null;
98
	}
129
}
130
99
131
100
	// ********** metadata conversion *********
132
	// ********** metadata conversion *********
101
133
Lines 109-125 Link Here
109
141
110
	// ********** validation **********
142
	// ********** validation **********
111
143
112
	@Override
144
	public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
145
		super.validate(messages, reporter);
146
		this.validateQuery(queryHelper, messages, reporter);
147
	}
148
149
	public void validateQuery(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
150
		if (StringTools.isBlank(this.query)){
151
			messages.add(
152
					DefaultJpaValidationMessages.buildMessage(
153
							IMessage.HIGH_SEVERITY,
154
							JpaValidationMessages.QUERY_STATEMENT_UNDEFINED,
155
							new String[] {this.name},
156
							this,
157
							this.getNameTextRange()
158
							)
159
					);
160
		} else {
161
			this.validateQuery_(queryHelper, messages, reporter);
162
		}
163
	}
164
113
	protected void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
165
	protected void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
114
		queryHelper.validate(
166
		queryHelper.validate(
115
			this,
167
				this,
116
			this.query,
168
				this.query,
117
			this.query,
169
				this.query,
118
			this.queryAnnotation.getQueryTextRanges(),
170
				this.queryAnnotation.getQueryTextRanges(),
119
			1,
171
				1,
120
			JpaJpqlQueryHelper.EscapeType.JAVA,
172
				JpaJpqlQueryHelper.EscapeType.JAVA,
121
			messages
173
				messages
122
		);
174
				);
175
	}
176
177
	public List<TextRange> getQueryTextRanges() {
178
		return this.queryAnnotation.getQueryTextRanges();
179
	}
180
181
	protected boolean isEquivalentTo(NamedNativeQuery other) {
182
		return 	ObjectTools.equals(this.query, other.getQuery());
123
	}
183
	}
124
184
125
	@Override
185
	@Override
Lines 129-135 Link Here
129
	}
189
	}
130
190
131
	protected boolean isEquivalentTo(NamedQuery other) {
191
	protected boolean isEquivalentTo(NamedQuery other) {
132
		boolean queriesEquivalent = super.isEquivalentTo(other);
192
		boolean queriesEquivalent = super.isEquivalentTo(other) && 
193
				ObjectTools.equals(this.query, other.getQuery());
133
		if (this.isJpa2_0Compatible()) {
194
		if (this.isJpa2_0Compatible()) {
134
			return queriesEquivalent && this.isEquivalentTo((NamedQuery2_0) other); 
195
			return queriesEquivalent && this.isEquivalentTo((NamedQuery2_0) other); 
135
		}
196
		}
Lines 145-148 Link Here
145
	public Class<NamedQuery> getType() {
206
	public Class<NamedQuery> getType() {
146
		return NamedQuery.class;
207
		return NamedQuery.class;
147
	}
208
	}
148
}
209
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/Generic2_1JpaAnnotationDefinitionProvider.java (-1 / +7 lines)
Lines 33-38 Link Here
33
import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.SequenceGenerator2_0AnnotationDefinition;
33
import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.SequenceGenerator2_0AnnotationDefinition;
34
import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.StaticMetamodelAnnotationDefinition;
34
import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.StaticMetamodelAnnotationDefinition;
35
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.Converter2_1AnnotationDefinition;
35
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.Converter2_1AnnotationDefinition;
36
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.NamedStoredProcedureQueries2_1AnnotationDefinition;
37
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.NamedStoredProcedureQuery2_1AnnoationDefinition;
38
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.StoredProcedureParameter2_1AnnotationDefinition;
36
import org.eclipse.jpt.jpa.core.internal.resource.java.AssociationOverridesAnnotationDefinition;
39
import org.eclipse.jpt.jpa.core.internal.resource.java.AssociationOverridesAnnotationDefinition;
37
import org.eclipse.jpt.jpa.core.internal.resource.java.AttributeOverrideAnnotationDefinition;
40
import org.eclipse.jpt.jpa.core.internal.resource.java.AttributeOverrideAnnotationDefinition;
38
import org.eclipse.jpt.jpa.core.internal.resource.java.AttributeOverridesAnnotationDefinition;
41
import org.eclipse.jpt.jpa.core.internal.resource.java.AttributeOverridesAnnotationDefinition;
Lines 148-154 Link Here
148
		TableGeneratorAnnotationDefinition.instance(),
151
		TableGeneratorAnnotationDefinition.instance(),
149
		TemporalAnnotationDefinition.instance(),
152
		TemporalAnnotationDefinition.instance(),
150
		TransientAnnotationDefinition.instance(),
153
		TransientAnnotationDefinition.instance(),
151
		VersionAnnotationDefinition.instance()
154
		VersionAnnotationDefinition.instance(),
155
		NamedStoredProcedureQueries2_1AnnotationDefinition.instance(),
156
		StoredProcedureParameter2_1AnnotationDefinition.instance()
152
	};
157
	};
153
158
154
	@Override
159
	@Override
Lines 165-169 Link Here
165
		NamedNativeQueryAnnotationDefinition.instance(),
170
		NamedNativeQueryAnnotationDefinition.instance(),
166
		PrimaryKeyJoinColumnAnnotationDefinition.instance(),
171
		PrimaryKeyJoinColumnAnnotationDefinition.instance(),
167
		SecondaryTableAnnotationDefinition.instance(),
172
		SecondaryTableAnnotationDefinition.instance(),
173
		NamedStoredProcedureQuery2_1AnnoationDefinition.instance()
168
	};
174
	};
169
}
175
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationDefinition.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java;
11
12
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryNamedAnnotation;
14
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceNamedAnnotation;
15
import org.eclipse.jpt.common.core.resource.java.Annotation;
16
import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
17
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
18
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
19
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
20
21
/**
22
 * javax.persistence.NamedStoredProcedureQueries
23
 */
24
public final class NamedStoredProcedureQueries2_1AnnotationDefinition
25
	implements AnnotationDefinition
26
{
27
	// singleton
28
	private static final AnnotationDefinition INSTANCE = new NamedStoredProcedureQueries2_1AnnotationDefinition();
29
30
	/**
31
	 * Return the singleton.
32
	 */
33
	public static AnnotationDefinition instance() {
34
		return INSTANCE;
35
	}
36
37
	/**
38
	 * Ensure single instance.
39
	 */
40
	private NamedStoredProcedureQueries2_1AnnotationDefinition() {
41
		super();
42
	}
43
44
	public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
45
		return new SourceNamedAnnotation(parent, annotatedElement, getAnnotationName());
46
	}
47
48
	public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
49
		throw new UnsupportedOperationException();
50
	}
51
52
	public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
53
		return new BinaryNamedAnnotation(parent, jdtAnnotation, getAnnotationName());
54
	}
55
56
	public String getAnnotationName() {
57
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERIES;
58
	}
59
60
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnoationDefinition.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java;
11
12
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
14
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
15
import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
16
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
17
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.binary.BinaryNamedStoredProcedureQuery2_1Annotation;
18
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.source.SourceNamedStoredProcedureQuery2_1Annotation;
19
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
20
21
/**
22
 * javax.persistence.NamedStoredProcedureQuery
23
 */
24
public final class NamedStoredProcedureQuery2_1AnnoationDefinition
25
	implements NestableAnnotationDefinition
26
{
27
	// singleton
28
	private static final NestableAnnotationDefinition INSTANCE = new NamedStoredProcedureQuery2_1AnnoationDefinition();
29
30
	/**
31
	 * Return the singleton.
32
	 */
33
	public static NestableAnnotationDefinition instance() {
34
		return INSTANCE;
35
	}
36
37
	/**
38
	 * Ensure single instance.
39
	 */
40
	private NamedStoredProcedureQuery2_1AnnoationDefinition() {
41
		super();
42
	}
43
44
	public NestableAnnotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement, int index) {
45
		return SourceNamedStoredProcedureQuery2_1Annotation.buildSourceNamedStoredProcedureQuery2_1Annotation(parent, annotatedElement, index);
46
	}
47
48
	public NestableAnnotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation, int index) {
49
		return new BinaryNamedStoredProcedureQuery2_1Annotation(parent, jdtAnnotation);
50
	}
51
52
	public String getNestableAnnotationName() {
53
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY;
54
	}
55
56
	public String getContainerAnnotationName() {
57
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERIES;
58
	}
59
60
	public String getElementName() {
61
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERIES__VALUE;
62
	}
63
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/StoredProcedureParameter2_1AnnotationDefinition.java (+48 lines)
Added Link Here
1
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java;
2
3
import org.eclipse.jdt.core.IAnnotation;
4
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryNamedAnnotation;
5
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceNamedAnnotation;
6
import org.eclipse.jpt.common.core.resource.java.Annotation;
7
import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
8
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
9
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
10
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
11
12
public final class StoredProcedureParameter2_1AnnotationDefinition
13
	implements AnnotationDefinition
14
{
15
	// singleton
16
	private static final AnnotationDefinition INSTANCE = new StoredProcedureParameter2_1AnnotationDefinition();
17
18
	/**
19
	 * Return the singleton.
20
	 */
21
	public static AnnotationDefinition instance() {
22
		return INSTANCE;
23
	}
24
25
	/**
26
	 * Ensure single instance.
27
	 */
28
	private StoredProcedureParameter2_1AnnotationDefinition() {
29
		super();
30
	}
31
32
	public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
33
		return new SourceNamedAnnotation(parent, annotatedElement, getAnnotationName());
34
	}
35
36
	public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
37
		throw new UnsupportedOperationException();
38
	}
39
40
	public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
41
		return new BinaryNamedAnnotation(parent, jdtAnnotation, getAnnotationName());
42
	}
43
44
	public String getAnnotationName() {
45
		return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER;
46
	}
47
48
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryNamedStoredProcedureQuery2_1Annotation.java (+251 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.binary;
11
12
import java.util.Vector;
13
import org.eclipse.jdt.core.IAnnotation;
14
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
15
import org.eclipse.jpt.common.core.utility.TextRange;
16
import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneListIterable;
17
import org.eclipse.jpt.common.utility.iterable.ListIterable;
18
import org.eclipse.jpt.jpa.core.internal.resource.java.binary.BinaryQueryAnnotation;
19
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
20
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annoation;
21
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
22
23
/**
24
 * javax.persistence.NamedStoredProcedureQuery
25
 */
26
public final class BinaryNamedStoredProcedureQuery2_1Annotation
27
	extends BinaryQueryAnnotation
28
	implements NamedStoredProcedureQuery2_1Annoation
29
{
30
	private String procedureName;
31
	private final Vector<StoredProcedureParameter2_1Annotation> parameters;
32
	private final Vector<String> resultClasses;
33
	private final Vector<String> resultSetMappings;
34
35
36
	public BinaryNamedStoredProcedureQuery2_1Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
37
		super(parent, jdtAnnotation);
38
		this.procedureName = this.buildProcedureName();
39
		this.parameters = this.buildParameters();
40
		this.resultClasses = this.buildResultClasses();
41
		this.resultSetMappings = this.buildResultSetMappings();
42
	}
43
44
	@Override
45
	public void update() {
46
		super.update();
47
		this.setProcedureName_(this.buildProcedureName());
48
		this.updateParameters();
49
		this.updateResultClasses();
50
		this.updateResultSetMappings();
51
	}
52
	
53
	public String getAnnotationName() {
54
		return ANNOTATION_NAME;
55
	}
56
	
57
	// ********** BinaryNamedStoredProcedureQueryAnnotation implementation **********
58
59
	@Override
60
	public String getNameElementName() {
61
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__NAME;
62
	}
63
	
64
	@Override
65
	public String getHintsElementName() {
66
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__HINTS;
67
	}
68
69
	// ********** NamedStoredProcedureQueryAnnotation implementation **********
70
	
71
	//****** procedure name ******
72
	public String getProcedureName() {
73
		return this.procedureName;
74
	}
75
76
	public void setProcedureName(String procedureName) {
77
		throw new UnsupportedOperationException();
78
	}
79
80
	private void setProcedureName_(String procedureName) {
81
		String old = this.procedureName;
82
		this.procedureName = procedureName;
83
		this.firePropertyChanged(PROCEDURE_NAME_PROPERTY, old, procedureName);
84
	}
85
86
	private String buildProcedureName() {
87
		return (String) this.getJdtMemberValue(this.getProcedureNameElementName());
88
	}
89
90
	public String getProcedureNameElementName() {
91
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PROCEDURE_NAME;
92
	}
93
94
	public TextRange getProcedureNameTextRange() {
95
		throw new UnsupportedOperationException();
96
	}
97
98
	// ********* parameters ***********
99
	public ListIterable<StoredProcedureParameter2_1Annotation> getParameters() {
100
		return new LiveCloneListIterable<StoredProcedureParameter2_1Annotation>(this.parameters);
101
	}
102
103
	public int getParametersSize() {
104
		return this.parameters.size();
105
	}
106
107
	public StoredProcedureParameter2_1Annotation parameterAt(int index) {
108
		return this.parameters.get(index);
109
	}
110
111
	public StoredProcedureParameter2_1Annotation addParameter(int index) {
112
		throw new UnsupportedOperationException();
113
	}
114
115
	public void moveParameter(int targetIndex, int sourceIndex) {
116
		throw new UnsupportedOperationException();
117
	}
118
119
	public void removeParameter(int index) {
120
		throw new UnsupportedOperationException();
121
	}
122
	
123
	private Vector<StoredProcedureParameter2_1Annotation> buildParameters() {
124
		Object[] jdtParameters = this.getJdtMemberValues(this.getParametersElementName());
125
		Vector<StoredProcedureParameter2_1Annotation> result = new Vector<StoredProcedureParameter2_1Annotation>(jdtParameters.length);
126
		for (Object jdtParameter : jdtParameters) {
127
			result.add(new BinaryStoredProcedureParameter2_1Annotation(this, (IAnnotation) jdtParameter));
128
		}
129
		return result;
130
	}
131
132
	private String getParametersElementName() {
133
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PARAMETERS;
134
	}
135
136
	// TODO
137
	private void updateParameters() {
138
		throw new UnsupportedOperationException();
139
	}
140
141
	// *********** result classes **********
142
	public ListIterable<String> getResultClasses() {
143
		return new LiveCloneListIterable<String>(this.resultClasses);
144
	}
145
146
	public int getResultClassesSize() {
147
		return this.resultClasses.size();
148
	}
149
150
	public String resultClassAt(int index) {
151
		return this.resultClasses.elementAt(index);
152
	}
153
154
	public void addResultClass(String resultClass) {
155
		throw new UnsupportedOperationException();
156
	}
157
158
	public void addResultClass(int index, String resultClass) {
159
		throw new UnsupportedOperationException();
160
	}
161
162
	public void moveResultClass(int targetIndex, int sourceIndex) {
163
		throw new UnsupportedOperationException();
164
	}
165
166
	public boolean resultClassTouches(int pos) {
167
		throw new UnsupportedOperationException();
168
	}
169
170
	public void removeResultClass(String resultClass) {
171
		throw new UnsupportedOperationException();
172
	}
173
174
	public void removeResultClass(int index) {
175
		throw new UnsupportedOperationException();
176
	}
177
178
	private Vector<String> buildResultClasses() {
179
		Object[] jdtResultClasses = this.getJdtMemberValues(this.getResultClassesElementName());
180
		Vector<String> result = new Vector<String>(jdtResultClasses.length);
181
		for (Object resultClass : jdtResultClasses) {
182
			result.add((String) resultClass);
183
		}
184
		return result;
185
	}
186
	
187
	private String getResultClassesElementName() {
188
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES;
189
	}
190
	
191
	//TODO
192
	private void updateResultClasses() {
193
		throw new UnsupportedOperationException();
194
	}
195
196
	// *********** result set mappings **********
197
	public ListIterable<String> getResultSetMappings() {
198
		return new LiveCloneListIterable<String>(this.resultSetMappings);
199
	}
200
201
	public int getResultSetMappingsSize() {
202
		return this.resultSetMappings.size();
203
	}
204
205
	public String resultSetMappingAt(int index) {
206
		return this.resultSetMappings.elementAt(index);
207
	}
208
209
	public void addResultSetMapping(String resultSetMapping) {
210
		throw new UnsupportedOperationException();
211
	}
212
213
	public void addResultSetMapping(int index, String resultSetMapping) {
214
		throw new UnsupportedOperationException();
215
	}
216
217
	public void moveResultSetMapping(int targetIndex, int sourceIndex) {
218
		throw new UnsupportedOperationException();
219
	}
220
221
	public boolean resultSetMappingTouches(int pos) {
222
		throw new UnsupportedOperationException();
223
	}
224
225
	public void removeResultSetMapping(String resultSetMapping) {
226
		throw new UnsupportedOperationException();
227
	}
228
229
	public void removeResultSetMapping(int index) {
230
		throw new UnsupportedOperationException();
231
	}
232
233
	private Vector<String> buildResultSetMappings() {
234
		Object[] jdtResultSetMappings = this.getJdtMemberValues(this.getResultSetMappingsElementName());
235
		Vector<String> result = new Vector<String>(jdtResultSetMappings.length);
236
		for (Object resultSetMapping : jdtResultSetMappings) {
237
			result.add((String) resultSetMapping);
238
		}
239
		return result;
240
	}
241
	
242
	private String getResultSetMappingsElementName() {
243
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS;
244
	}
245
246
	//TODO
247
	private void updateResultSetMappings() {
248
		throw new UnsupportedOperationException();
249
	}
250
251
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryStoredProcedureParameter2_1Annotation.java (+142 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.binary;
11
12
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation;
14
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
15
import org.eclipse.jpt.common.core.utility.TextRange;
16
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
17
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.ParameterMode2_1;
18
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
19
20
/**
21
 * javax.persistence.StoredProcedureParameter
22
 */
23
public final class BinaryStoredProcedureParameter2_1Annotation 
24
	extends BinaryAnnotation
25
	implements StoredProcedureParameter2_1Annotation
26
{
27
	private String name;
28
	private ParameterMode2_1 mode;
29
	private String type;
30
31
32
	public BinaryStoredProcedureParameter2_1Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
33
		super(parent, jdtAnnotation);
34
		this.name = this.buildName();
35
		this.mode = this.buildMode();
36
		this.type = this.buildType();
37
	}
38
39
	public String getAnnotationName() {
40
		return ANNOTATION_NAME;
41
	}
42
43
	@Override
44
	public void update() {
45
		super.update();
46
		this.setName_(this.buildName());
47
		this.setMode_(this.buildMode());
48
		this.setType_(this.buildType());
49
	}
50
	
51
52
	// ********** BinaryStoredProcedureParameterAnnotation implementation **********
53
54
	String getNameElementName() {
55
		return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__NAME;
56
	}
57
58
	String getModeElementName() {
59
		return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__MODE;
60
	}
61
62
	String getTypeElementName() {
63
		return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__TYPE;
64
	}
65
66
	// ********** StoredProcedureParameterAnnotation implementation **********
67
68
	// ***** name
69
	public String getName() {
70
		return this.name;
71
	}
72
73
	public void setName(String name) {
74
		throw new UnsupportedOperationException();
75
	}
76
77
	private void setName_(String name) {
78
		String old = this.name;
79
		this.name = name;
80
		this.firePropertyChanged(NAME_PROPERTY, old, name);
81
	}
82
83
	private String buildName() {
84
		return (String) this.getJdtMemberValue(this.getNameElementName());
85
	}
86
87
	public TextRange getNameTextRange() {
88
		throw new UnsupportedOperationException();
89
	}
90
	
91
	// ***** mode
92
	public ParameterMode2_1 getMode() {
93
		return this.mode;
94
	}
95
96
	public void setMode(ParameterMode2_1 mode) {
97
		throw new UnsupportedOperationException();
98
	}
99
100
	private void setMode_(ParameterMode2_1 mode) {
101
		ParameterMode2_1 old = this.mode;
102
		this.mode = mode;
103
		this.firePropertyChanged(MODE_PROPERTY, old, mode);
104
	}
105
106
	private ParameterMode2_1 buildMode() {
107
		return ParameterMode2_1.fromJavaAnnotationValue(this.getJdtMemberValue(this.getModeElementName()));
108
	}
109
110
	public TextRange getModeTextRange() {
111
		throw new UnsupportedOperationException();
112
	}
113
114
	// ***** type
115
	public String getType() {
116
		return this.type;
117
	}
118
119
	public void setType(String type) {
120
		throw new UnsupportedOperationException();
121
	}
122
123
	private void setType_(String type) {
124
		String old = this.type;
125
		this.type = type;
126
		this.firePropertyChanged(TYPE_PROPERTY, old, type);
127
	}
128
129
	private String buildType() {
130
		return (String) this.getJdtMemberValue(this.getTypeElementName());
131
	}
132
133
	public TextRange getTypeTextRange() {
134
		throw new UnsupportedOperationException();
135
	}
136
137
	// ***** fully-qualified type name
138
	public String getFullyQualifiedTypeName()  {
139
		return this.type;
140
	}
141
142
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceNamedStoredProcedureQuery2_1Annotation.java (+475 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.source;
11
12
import java.util.Arrays;
13
import java.util.Vector;
14
import org.eclipse.jdt.core.dom.Annotation;
15
import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
16
import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter;
17
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
18
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
19
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
20
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
21
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
22
import org.eclipse.jpt.common.core.utility.TextRange;
23
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
24
import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
25
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
26
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
27
import org.eclipse.jpt.common.core.utility.jdt.ExpressionConverter;
28
import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
29
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
30
import org.eclipse.jpt.common.utility.internal.collection.ListTools;
31
import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneListIterable;
32
import org.eclipse.jpt.common.utility.iterable.ListIterable;
33
import org.eclipse.jpt.jpa.core.internal.resource.java.source.SourceQueryAnnotation;
34
import org.eclipse.jpt.jpa.core.internal.resource.java.source.SourceQueryHintAnnotation;
35
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
36
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annoation;
37
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
38
import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
39
40
/**
41
 * <code>javax.persistence.NamedStoredProcedureQuery</code>
42
 */
43
public final class SourceNamedStoredProcedureQuery2_1Annotation
44
	extends SourceQueryAnnotation
45
	implements NamedStoredProcedureQuery2_1Annoation
46
{
47
	private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
48
	private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES);
49
50
	DeclarationAnnotationElementAdapter<String> procedureNameDeclarationAdapter;
51
	AnnotationElementAdapter<String> procedureNameAdapter;
52
	String procedureName;
53
	TextRange procedureNameTextRange;
54
	
55
	final StoredProcedureParameterAnnotationContainer storedProcedureParametersContainer = new StoredProcedureParameterAnnotationContainer();
56
	
57
	private DeclarationAnnotationElementAdapter<String[]> resultClassesDeclarationAdapter;
58
	private AnnotationElementAdapter<String[]> resultClassesAdapter;
59
	private final Vector<String> resultClasses = new Vector<String>();
60
	private TextRange resultClassesTextRange;
61
	
62
	/**
63
	 * TODO: Need to handle fullyQualifiedResultClassName/fqResultClassNameStale for each of the result classes
64
	    private final Vector<String> fullyQualifiedResultClassNames = new Vector<String>();
65
		// we need a flag since the f-q name can be null
66
		private boolean fqResultClassNameStale = true;
67
	 */
68
69
	private DeclarationAnnotationElementAdapter<String[]> resultSetMappingsDeclarationAdapter;
70
	private AnnotationElementAdapter<String[]> resultSetMappingsAdapter;
71
	private final Vector<String> resultSetMappings = new Vector<String>();
72
	private TextRange resultSetMappingsTextRange;
73
74
	public static SourceNamedStoredProcedureQuery2_1Annotation buildSourceNamedStoredProcedureQuery2_1Annotation(
75
			JavaResourceAnnotatedElement parent, 
76
			AnnotatedElement element, 
77
			int index)
78
	{
79
		IndexedDeclarationAnnotationAdapter idaa = buildNamedStoredProcedureQuery2_1DeclarationAnnotationAdapter(index);
80
		IndexedAnnotationAdapter iaa = buildNamedStoredProcedureQuery2_1AnnotationAdapter(element, idaa);
81
		return new SourceNamedStoredProcedureQuery2_1Annotation(
82
			parent,
83
			element,
84
			idaa,
85
			iaa);
86
	}
87
88
	private SourceNamedStoredProcedureQuery2_1Annotation(
89
			JavaResourceAnnotatedElement parent,
90
			AnnotatedElement element,
91
			IndexedDeclarationAnnotationAdapter daa,
92
			IndexedAnnotationAdapter annotationAdapter)
93
	{
94
		super(parent, element, daa, annotationAdapter);
95
		this.procedureNameDeclarationAdapter = this.buildProcedureNameDeclarationAdapter();
96
		this.procedureNameAdapter = this.buildProcedureNameAdapter();
97
		this.resultClassesDeclarationAdapter = this.buildResultClassesDeclarationAdapter();
98
		this.resultClassesAdapter = this.buildResultClassesAdapter();
99
		this.resultSetMappingsDeclarationAdapter = this.buildResultSetMappingsDeclarationAdapter();
100
		this.resultSetMappingsAdapter = this.buildResultSetMappingsAdapter();
101
	}
102
103
	public String getAnnotationName() {
104
		return ANNOTATION_NAME;
105
	}
106
107
	@Override
108
	public void initialize(Annotation astAnnotation) {
109
		super.initialize(astAnnotation);
110
		
111
		this.procedureName = this.buildProcedureName(astAnnotation);
112
		this.procedureNameTextRange = this.buildProcedureNameTextRange(astAnnotation);
113
114
		this.storedProcedureParametersContainer.initializeFromContainerAnnotation(astAnnotation);
115
		
116
		this.initializeResultClasses(astAnnotation);
117
		this.resultClassesTextRange = this.buildResultClassesTextRange(astAnnotation);
118
119
		this.initializeResultSetMappings(astAnnotation);
120
		this.resultSetMappingsTextRange = this.buildResultSetMappingsTextRange(astAnnotation);
121
	}
122
123
	@Override
124
	public void synchronizeWith(Annotation astAnnotation) {
125
		super.synchronizeWith(astAnnotation);
126
		
127
		this.syncProcedureName(this.buildProcedureName(astAnnotation));
128
		this.procedureNameTextRange = this.buildProcedureNameTextRange(astAnnotation);
129
130
		this.storedProcedureParametersContainer.synchronize(astAnnotation);
131
		
132
		this.syncResultClasses(astAnnotation);
133
		this.resultClassesTextRange = this.buildResultClassesTextRange(astAnnotation);
134
		
135
		this.syncResultSetMappings(astAnnotation);
136
		this.resultSetMappingsTextRange = this.buildResultSetMappingsTextRange(astAnnotation);
137
	
138
	}
139
140
	// ********** AbstractNamedStoredProcedureQuery2_1Annotation implementation **********
141
142
	@Override
143
	public String getNameElementName() {
144
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__NAME;
145
	}
146
147
	@Override
148
	public String getHintsElementName() {
149
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__HINTS;
150
	}
151
152
	@Override
153
	public QueryHintAnnotation buildHint(int index) {
154
		return SourceQueryHintAnnotation.buildNamedStoredProcedureQuery2_1QueryHint(this, this.annotatedElement, this.daa, index);
155
	}
156
157
158
	// ********** NamedStoredProcedureQuery2_1Annotation implementation **********
159
	
160
	String getProcedureNameElementName() {
161
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PROCEDURE_NAME;
162
	}
163
	
164
	String getParametersElementName() {
165
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PARAMETERS;
166
	}
167
	
168
	public StoredProcedureParameter2_1Annotation buildParameter(int index) {
169
		return SourceStoredProcedureParameter2_1Annotation.buildNamedStoredProcedureQuery2_1Parameter(this, this.annotatedElement, this.daa, index);
170
	}
171
172
	String getResultClassesElementName() {
173
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES;
174
	}
175
176
	String getResultSetMappingsElementName() {
177
		return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS;
178
	}
179
180
	// ***** procedure name
181
	public String getProcedureName() {
182
		return this.procedureName;
183
	}
184
185
	public void setProcedureName(String procedureName) {
186
		if (this.attributeValueHasChanged(this.procedureName, procedureName)) {
187
			this.procedureName = procedureName;
188
			this.procedureNameAdapter.setValue(procedureName);
189
		}
190
	}
191
192
	private void syncProcedureName(String procedureName) {
193
		String old = this.procedureName;
194
		this.procedureName = procedureName;
195
		this.firePropertyChanged(PROCEDURE_NAME_PROPERTY, old, procedureName);
196
	}
197
198
	private String buildProcedureName(Annotation astAnnotation) {
199
		return this.procedureNameAdapter.getValue(astAnnotation);
200
	}
201
202
	public TextRange getProcedureNameTextRange() {
203
		return this.procedureNameTextRange;
204
	}
205
206
	private TextRange buildProcedureNameTextRange(Annotation astAnnotation) {
207
		return this.getElementTextRange(this.procedureNameDeclarationAdapter, astAnnotation);
208
	}
209
210
	private DeclarationAnnotationElementAdapter<String> buildProcedureNameDeclarationAdapter() {
211
		return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getProcedureNameElementName());
212
	}
213
214
	private AnnotationElementAdapter<String> buildProcedureNameAdapter() {
215
		return this.buildStringElementAdapter(this.procedureNameDeclarationAdapter);
216
	}
217
218
219
	// ***** parameters
220
	public ListIterable<StoredProcedureParameter2_1Annotation> getParameters() {
221
		return this.storedProcedureParametersContainer.getNestedAnnotations();
222
	}
223
224
	public int getParametersSize() {
225
		return this.storedProcedureParametersContainer.getNestedAnnotationsSize();
226
	}
227
228
	public StoredProcedureParameter2_1Annotation parameterAt(int index) {
229
		return this.storedProcedureParametersContainer.getNestedAnnotation(index);
230
	}
231
232
	public StoredProcedureParameter2_1Annotation addParameter(int index) {
233
		return this.storedProcedureParametersContainer.addNestedAnnotation(index);
234
	}
235
236
	public void moveParameter(int targetIndex, int sourceIndex) {
237
		this.storedProcedureParametersContainer.moveNestedAnnotation(targetIndex, sourceIndex);
238
	}
239
240
	public void removeParameter(int index) {
241
		this.storedProcedureParametersContainer.removeNestedAnnotation(index);
242
	}
243
244
245
	// ***** result classes
246
	public ListIterable<String> getResultClasses() {
247
		return new LiveCloneListIterable<String>(this.resultClasses);
248
	}
249
250
	public int getResultClassesSize() {
251
		return this.resultClasses.size();
252
	}
253
254
	public String resultClassAt(int index) {
255
		return this.resultClasses.elementAt(index);
256
	}
257
258
	public void addResultClass(String resultClass) {
259
		this.addResultClass(this.resultClasses.size(), resultClass);
260
	}
261
262
	public void addResultClass(int index, String resultClass) {
263
		this.resultClasses.add(index, resultClass);
264
		this.writeResultClasses();
265
	}
266
267
	public void moveResultClass(int targetIndex, int sourceIndex) {
268
		ListTools.move(this.resultClasses, targetIndex, sourceIndex);
269
		this.writeResultClasses();
270
	}
271
272
	public void removeResultClass(String resultClass) {
273
		this.resultClasses.remove(resultClass);
274
		this.writeResultClasses();
275
	}
276
277
	public void removeResultClass(int index) {
278
		this.resultClasses.remove(index);
279
		this.writeResultClasses();
280
	}
281
282
	private void writeResultClasses() {
283
		this.resultClassesAdapter.setValue(this.resultClasses.toArray(new String[this.resultClasses.size()]));
284
	}
285
286
	private void initializeResultClasses(Annotation astAnnotation) {
287
		String[] astResultClasses = this.resultClassesAdapter.getValue(astAnnotation);
288
		for (int i = 0; i < astResultClasses.length; i++) {
289
			this.resultClasses.add(astResultClasses[i]);
290
		}
291
	}
292
293
	private void syncResultClasses(Annotation astAnnotation) {
294
		String[] javaResultClasses = this.resultClassesAdapter.getValue(astAnnotation);
295
		this.synchronizeList(Arrays.asList(javaResultClasses), this.resultClasses, RESULT_CLASSES_LIST);
296
	}
297
298
	private TextRange buildResultClassesTextRange(Annotation astAnnotation) {
299
		return this.getElementTextRange(this.resultClassesDeclarationAdapter, astAnnotation);
300
	}
301
302
	public boolean resultClassesTouches(int pos) {
303
		return this.textRangeTouches(this.resultClassesTextRange, pos);
304
	}
305
306
	private DeclarationAnnotationElementAdapter<String[]> buildResultClassesDeclarationAdapter() {
307
		return buildResultClassesArrayAnnotationElementAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES);
308
	}
309
310
	private AnnotationElementAdapter<String[]> buildResultClassesAdapter() {
311
		return this.buildAnnotationElementAdapter(this.resultClassesDeclarationAdapter);
312
	}
313
314
315
	// ***** result set mappings
316
	public ListIterable<String> getResultSetMappings() {
317
		return new LiveCloneListIterable<String>(this.resultSetMappings);
318
	}
319
320
	public int getResultSetMappingsSize() {
321
		return this.resultSetMappings.size();
322
	}
323
324
	public String resultSetMappingAt(int index) {
325
		return this.resultSetMappings.elementAt(index);
326
	}
327
328
	public void addResultSetMapping(String resultClass) {
329
		this.addResultSetMapping(this.resultSetMappings.size(), resultClass);
330
	}
331
332
	public void addResultSetMapping(int index, String resultClass) {
333
		this.resultSetMappings.add(index, resultClass);
334
		this.writeResultSetMappings();
335
	}
336
337
	public void moveResultSetMapping(int targetIndex, int sourceIndex) {
338
		ListTools.move(this.resultSetMappings, targetIndex, sourceIndex);
339
		this.writeResultSetMappings();
340
	}
341
342
	public void removeResultSetMapping(String resultSetMapping) {
343
		this.resultSetMappings.remove(resultSetMapping);
344
		this.writeResultSetMappings();
345
	}
346
347
	public void removeResultSetMapping(int index) {
348
		this.resultSetMappings.remove(index);
349
		this.writeResultSetMappings();
350
	}
351
352
	private void writeResultSetMappings() {
353
		this.resultSetMappingsAdapter.setValue(this.resultSetMappings.toArray(new String[this.resultSetMappings.size()]));
354
	}
355
356
	private void initializeResultSetMappings(Annotation astAnnotation) {
357
		String[] astResultClasses = this.resultSetMappingsAdapter.getValue(astAnnotation);
358
		for (int i = 0; i < astResultClasses.length; i++) {
359
			this.resultSetMappings.add(astResultClasses[i]);
360
		}
361
	}
362
363
	private void syncResultSetMappings(Annotation astAnnotation) {
364
		String[] javaResultClasses = this.resultSetMappingsAdapter.getValue(astAnnotation);
365
		this.synchronizeList(Arrays.asList(javaResultClasses), this.resultSetMappings, RESULT_SET_MAPPINGS_LIST);
366
	}
367
368
	private TextRange buildResultSetMappingsTextRange(Annotation astAnnotation) {
369
		return this.getElementTextRange(this.resultSetMappingsDeclarationAdapter, astAnnotation);
370
	}
371
372
	public boolean resultSetMappingsTouches(int pos) {
373
		return this.textRangeTouches(this.resultSetMappingsTextRange, pos);
374
	}
375
376
	private DeclarationAnnotationElementAdapter<String[]> buildResultSetMappingsDeclarationAdapter() {
377
		return buildResultSetMappingsArrayAnnotationElementAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS);
378
	}
379
380
	private AnnotationElementAdapter<String[]> buildResultSetMappingsAdapter() {
381
		return this.buildAnnotationElementAdapter(this.resultSetMappingsDeclarationAdapter);
382
	}
383
	
384
	// **********
385
	private AnnotationElementAdapter<String[]> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String[]> daea) {
386
		return new AnnotatedElementAnnotationElementAdapter<String[]>(this.annotatedElement, daea);
387
	}
388
389
	private static DeclarationAnnotationElementAdapter<String[]> buildResultClassesArrayAnnotationElementAdapter(
390
			DeclarationAnnotationAdapter annotationAdapter,
391
			String elementName)
392
	{
393
		return buildArrayAnnotationElementAdapter(
394
				annotationAdapter,
395
				elementName,
396
				AnnotationStringArrayExpressionConverter.forTypes());
397
	}
398
	
399
	private static DeclarationAnnotationElementAdapter<String[]> buildResultSetMappingsArrayAnnotationElementAdapter(
400
			DeclarationAnnotationAdapter annotationAdapter,
401
			String elementName)
402
	{
403
		return buildArrayAnnotationElementAdapter(
404
				annotationAdapter,
405
				elementName,
406
				AnnotationStringArrayExpressionConverter.forStrings());
407
	}
408
409
	private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(
410
			DeclarationAnnotationAdapter annotationAdapter,
411
			String elementName,
412
			ExpressionConverter<String[]> converter)
413
	{
414
		return new ConversionDeclarationAnnotationElementAdapter<String[]>(
415
				annotationAdapter,
416
				elementName,
417
				converter);
418
	}
419
420
421
	// ********** stored procedure parameter container **********
422
	/**
423
	 * adapt the AnnotationContainer interface to the xml schema's xmlns
424
	 */
425
	class StoredProcedureParameterAnnotationContainer
426
		extends AnnotationContainer<StoredProcedureParameter2_1Annotation>
427
	{
428
		@Override
429
		protected String getNestedAnnotationsListName() {
430
			return PARAMETERS_LIST;
431
		}
432
		@Override
433
		protected String getElementName() {
434
			return SourceNamedStoredProcedureQuery2_1Annotation.this.getParametersElementName();
435
		}
436
		@Override
437
		protected String getNestedAnnotationName() {
438
			return StoredProcedureParameter2_1Annotation.ANNOTATION_NAME;
439
		}
440
		@Override
441
		protected StoredProcedureParameter2_1Annotation buildNestedAnnotation(int index) {
442
			return SourceNamedStoredProcedureQuery2_1Annotation.this.buildParameter(index);
443
		}
444
	}
445
446
	// ********** misc **********
447
448
	@Override
449
	public boolean isUnset() {
450
		return super.isUnset() &&
451
				(this.procedureName == null) &&
452
				(this.storedProcedureParametersContainer.isEmpty()) &&
453
				(this.resultClasses.isEmpty()) &&
454
				(this.resultSetMappings.isEmpty());
455
	}
456
457
	// ********** static methods **********
458
459
	private static IndexedAnnotationAdapter buildNamedStoredProcedureQuery2_1AnnotationAdapter(
460
			AnnotatedElement annotatedElement,
461
			IndexedDeclarationAnnotationAdapter idaa)
462
	{
463
		return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
464
	}
465
466
	private static IndexedDeclarationAnnotationAdapter buildNamedStoredProcedureQuery2_1DeclarationAnnotationAdapter(int index) 
467
	{
468
		return new CombinationIndexedDeclarationAnnotationAdapter(
469
				DECLARATION_ANNOTATION_ADAPTER,
470
				CONTAINER_DECLARATION_ANNOTATION_ADAPTER,
471
				index,
472
				ANNOTATION_NAME);
473
	}
474
475
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceStoredProcedureParameter2_1Annotation.java (+319 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.source;
11
12
import org.eclipse.jdt.core.dom.Annotation;
13
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation;
14
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
15
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
16
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
17
import org.eclipse.jpt.common.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter;
18
import org.eclipse.jpt.common.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter;
19
import org.eclipse.jpt.common.core.internal.utility.jdt.TypeStringExpressionConverter;
20
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
21
import org.eclipse.jpt.common.core.utility.TextRange;
22
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
23
import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
24
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
25
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
26
import org.eclipse.jpt.common.core.utility.jdt.ExpressionConverter;
27
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
28
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
29
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.ParameterMode2_1;
30
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
31
32
/**
33
 * <code>javax.persistence.StoredProcedureParameter</code>
34
 */
35
public final class SourceStoredProcedureParameter2_1Annotation 
36
	extends SourceAnnotation
37
	implements StoredProcedureParameter2_1Annotation
38
{
39
	private DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter;
40
	private AnnotationElementAdapter<String> nameAdapter;
41
	private String name;
42
	private TextRange nameTextRange;
43
44
	private DeclarationAnnotationElementAdapter<String> modeDeclarationAdapter;
45
	private AnnotationElementAdapter<String> modeAdapter;
46
	private ParameterMode2_1 mode;
47
	private TextRange modeTextRange;
48
49
	private DeclarationAnnotationElementAdapter<String> typeDeclarationAdapter;
50
	private AnnotationElementAdapter<String> typeAdapter;
51
	private String type;
52
	private TextRange typeTextRange;
53
54
	private String fullyQualifiedTypeName;
55
	// we need a flag since the f-q name can be null
56
	private boolean fqTypeNameStale = true;
57
	
58
	public static SourceStoredProcedureParameter2_1Annotation buildNamedStoredProcedureQuery2_1Parameter(
59
			JavaResourceNode parent,
60
			AnnotatedElement element,
61
			DeclarationAnnotationAdapter namedStoredProcedureQueryAdapter,
62
			int index)
63
	{
64
		return buildNestedSourceStoredProcedureParameter2_1Annotation(
65
				parent,
66
				element,
67
				buildStoredProcedureParameter2_1AnnotationAdapter(namedStoredProcedureQueryAdapter,
68
				index));
69
	}
70
71
	
72
	public static SourceStoredProcedureParameter2_1Annotation buildNestedSourceStoredProcedureParameter2_1Annotation(
73
			JavaResourceNode parent, 
74
			AnnotatedElement element, 
75
			IndexedDeclarationAnnotationAdapter idaa) 
76
	{
77
		return new SourceStoredProcedureParameter2_1Annotation(
78
				parent,
79
				element,
80
				idaa);
81
	}
82
83
	private SourceStoredProcedureParameter2_1Annotation(
84
			JavaResourceNode parent,
85
			AnnotatedElement element,
86
			IndexedDeclarationAnnotationAdapter idaa)
87
	{
88
		super(parent, element, idaa, new ElementIndexedAnnotationAdapter(element, idaa));
89
		this.nameDeclarationAdapter = this.buildNameDeclarationAdapter();
90
		this.nameAdapter = this.buildNameAdapter();
91
		this.modeDeclarationAdapter = this.buildModeDeclarationAdapter();
92
		this.modeAdapter = this.buildModeAdapter();
93
		this.typeDeclarationAdapter = this.buildTypeDeclarationAdapter();
94
		this.typeAdapter = this.buildTypeAdapter();
95
	}
96
97
	public String getAnnotationName() {
98
		return ANNOTATION_NAME;
99
	}
100
101
	@Override
102
	public void initialize(Annotation astAnnotation) {
103
		super.initialize(astAnnotation);
104
		this.name = this.buildName(astAnnotation);
105
		this.nameTextRange = this.buildNameTextRange(astAnnotation);
106
107
		this.mode = this.buildMode(astAnnotation);
108
		this.modeTextRange = this.buildModeTextRange(astAnnotation);
109
110
		this.type = this.buildType(astAnnotation);
111
		this.typeTextRange = this.buildTypeTextRange(astAnnotation);
112
	}
113
114
	@Override
115
	public void synchronizeWith(Annotation astAnnotation) {
116
		super.synchronizeWith(astAnnotation);
117
		this.syncName(this.buildName(astAnnotation));
118
		this.nameTextRange = this.buildNameTextRange(astAnnotation);
119
120
		this.syncMode(this.buildMode(astAnnotation));
121
		this.modeTextRange = this.buildModeTextRange(astAnnotation);
122
123
		this.syncType(this.buildType(astAnnotation));
124
		this.typeTextRange = this.buildTypeTextRange(astAnnotation);
125
	}
126
127
128
	// ********** StoredProcedureParameterAnnotation implementation **********
129
130
	// ***** name
131
	public String getName() {
132
		return this.name;
133
	}
134
135
	public void setName(String name) {
136
		if (this.attributeValueHasChanged(this.name, name)) {
137
			this.name = name;
138
			this.nameAdapter.setValue(name);
139
		}
140
	}
141
142
	private void syncName(String astName) {
143
		String old = this.name;
144
		this.name = astName;
145
		this.firePropertyChanged(NAME_PROPERTY, old, astName);
146
	}
147
148
	private String buildName(Annotation astAnnotation) {
149
		return this.nameAdapter.getValue(astAnnotation);
150
	}
151
152
	public TextRange getNameTextRange() {
153
		return this.nameTextRange;
154
	}
155
156
	private TextRange buildNameTextRange(Annotation astAnnotation) {
157
		return this.getElementTextRange(this.nameDeclarationAdapter, astAnnotation);
158
	}
159
160
	private DeclarationAnnotationElementAdapter<String> buildNameDeclarationAdapter() {
161
		return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__NAME);
162
	}
163
164
	private AnnotationElementAdapter<String> buildNameAdapter() {
165
		return this.buildStringElementAdapter(this.nameDeclarationAdapter);
166
	}
167
168
	// ***** mode
169
	public ParameterMode2_1 getMode() {
170
		return this.mode;
171
	}
172
173
	public void setMode(ParameterMode2_1 mode) {
174
		if (this.attributeValueHasChanged(this.mode, mode)) {
175
			this.mode = mode;
176
			this.modeAdapter.setValue(ParameterMode2_1.toJavaAnnotationValue(mode));
177
		}
178
	}
179
180
	private void syncMode(ParameterMode2_1 astValue) {
181
		ParameterMode2_1 old = this.mode;
182
		this.mode = astValue;
183
		this.firePropertyChanged(MODE_PROPERTY, old, astValue);
184
	}
185
186
	private ParameterMode2_1 buildMode(Annotation astAnnotation) {
187
		return ParameterMode2_1.fromJavaAnnotationValue(this.modeAdapter.getValue(astAnnotation));
188
	}
189
190
	public TextRange getModeTextRange() {
191
		return this.modeTextRange;
192
	}
193
194
	private TextRange buildModeTextRange(Annotation astAnnotation) {
195
		return this.getElementTextRange(this.modeDeclarationAdapter, astAnnotation);
196
	}
197
198
	private DeclarationAnnotationElementAdapter<String> buildModeDeclarationAdapter() {
199
		return new EnumDeclarationAnnotationElementAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__MODE);
200
	}
201
202
	private AnnotationElementAdapter<String> buildModeAdapter() {
203
		return this.buildStringElementAdapter(this.modeDeclarationAdapter);
204
	}
205
	
206
	// ***** type
207
	public String getType() {
208
		return this.type;
209
	}
210
211
	public void setType(String type) {
212
		if (this.attributeValueHasChanged(this.type, type)) {
213
			this.type = type;
214
			this.fqTypeNameStale = true;
215
			this.typeAdapter.setValue(type);
216
		}
217
	}
218
	
219
	private void syncType(String astType) {
220
		if (this.attributeValueHasChanged(this.type, astType)) {
221
			this.syncType_(astType);
222
		}
223
	}
224
225
	private void syncType_(String astType) {
226
		String old = this.type;
227
		this.type = astType;
228
		this.fqTypeNameStale = true;
229
		this.firePropertyChanged(TYPE_PROPERTY, old, astType);
230
	}
231
232
	private String buildType(Annotation astAnnotation) {
233
		return this.typeAdapter.getValue(astAnnotation);
234
	}
235
236
	public TextRange getTypeTextRange() {
237
		return this.typeTextRange;
238
	}
239
240
	private TextRange buildTypeTextRange(Annotation astAnnotation) {
241
		return this.getElementTextRange(this.typeDeclarationAdapter, astAnnotation);
242
	}
243
244
	private DeclarationAnnotationElementAdapter<String> buildTypeDeclarationAdapter() {
245
		return buildTypeDeclarationAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__TYPE);
246
	}
247
248
	private static DeclarationAnnotationElementAdapter<String> buildTypeDeclarationAdapter(
249
			DeclarationAnnotationAdapter annotationAdapter,
250
			String elementName)
251
	{
252
		return buildAnnotationElementAdapter(
253
				annotationAdapter, 
254
				elementName, 
255
				TypeStringExpressionConverter.instance());
256
	}
257
258
	private static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(
259
			DeclarationAnnotationAdapter annotationAdapter,
260
			String elementName,
261
			ExpressionConverter<String> converter)
262
	{
263
		return new ConversionDeclarationAnnotationElementAdapter<String>(
264
				annotationAdapter,
265
				elementName,
266
				converter);
267
	}
268
269
	private AnnotationElementAdapter<String> buildTypeAdapter() {
270
		return this.buildStringElementAdapter(this.typeDeclarationAdapter);
271
	}
272
	
273
	// ***** fully-qualified type name
274
	public String getFullyQualifiedTypeName()  {
275
		if (this.fqTypeNameStale) {
276
			this.fullyQualifiedTypeName = this.buildFullyQualifiedTypeName();
277
			this.fqTypeNameStale = false;
278
		}
279
		return this.fullyQualifiedTypeName;
280
	}
281
282
	private String buildFullyQualifiedTypeName() {
283
		return (this.type == null) ? null : this.buildFullyQualifiedTypeName_();
284
	}
285
286
	private String buildFullyQualifiedTypeName_() {
287
		return ASTTools.resolveFullyQualifiedName(this.typeAdapter.getExpression(this.buildASTRoot()));
288
	}
289
290
291
	// ********** misc **********
292
293
	@Override
294
	public boolean isUnset() {
295
		return super.isUnset() &&
296
				(this.name == null) &&
297
				(this.mode == null) &&
298
				(this.type == null);
299
	}
300
301
	@Override
302
	public void toString(StringBuilder sb) {
303
		sb.append(this.name);
304
	}
305
306
307
	// ********** static methods **********
308
	private static IndexedDeclarationAnnotationAdapter buildStoredProcedureParameter2_1AnnotationAdapter(
309
			DeclarationAnnotationAdapter namedStoredProcedureQuery2_1Adapter,
310
			int index)
311
	{
312
		return new NestedIndexedDeclarationAnnotationAdapter(
313
				namedStoredProcedureQuery2_1Adapter,
314
				JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PARAMETERS,
315
				index,
316
				ANNOTATION_NAME);
317
	}
318
319
}
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java (-9 / +35 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-14 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
10
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
11
11
12
import java.util.List;
12
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
14
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
14
import org.eclipse.jpt.common.core.utility.TextRange;
15
import org.eclipse.jpt.common.core.utility.TextRange;
Lines 22-33 Link Here
22
	extends BinaryQueryAnnotation
23
	extends BinaryQueryAnnotation
23
	implements NamedNativeQueryAnnotation
24
	implements NamedNativeQueryAnnotation
24
{
25
{
26
	private String query;
25
	private String resultClass;
27
	private String resultClass;
26
	private String resultSetMapping;
28
	private String resultSetMapping;
27
29
28
30
29
	public BinaryNamedNativeQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
31
	public BinaryNamedNativeQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
30
		super(parent, jdtAnnotation);
32
		super(parent, jdtAnnotation);
33
		this.query = this.buildQuery();
31
		this.resultClass = this.buildResultClass();
34
		this.resultClass = this.buildResultClass();
32
		this.resultSetMapping = this.buildResultSetMapping();
35
		this.resultSetMapping = this.buildResultSetMapping();
33
	}
36
	}
Lines 39-69 Link Here
39
	@Override
42
	@Override
40
	public void update() {
43
	public void update() {
41
		super.update();
44
		super.update();
45
		this.setQuery_(this.buildQuery());
42
		this.setResultClass_(this.buildResultClass());
46
		this.setResultClass_(this.buildResultClass());
43
		this.setResultSetMapping_(this.buildResultSetMapping());
47
		this.setResultSetMapping_(this.buildResultSetMapping());
44
	}
48
	}
45
49
46
50
47
	// ********** BinaryBaseNamedQueryAnnotation implementation **********
51
	// ********** BinaryNamedNativeQueryAnnotation implementation **********
48
52
49
	@Override
53
	@Override
50
	String getNameElementName() {
54
	public String getNameElementName() {
51
		return JPA.NAMED_NATIVE_QUERY__NAME;
55
		return JPA.NAMED_NATIVE_QUERY__NAME;
52
	}
56
	}
53
57
54
	@Override
58
	@Override
55
	String getQueryElementName() {
59
	public String getHintsElementName() {
56
		return JPA.NAMED_NATIVE_QUERY__QUERY;
57
	}
58
59
	@Override
60
	String getHintsElementName() {
61
		return JPA.NAMED_NATIVE_QUERY__HINTS;
60
		return JPA.NAMED_NATIVE_QUERY__HINTS;
62
	}
61
	}
63
62
64
63
65
	// ********** NamedNativeQueryAnnotation implementation **********
64
	// ********** NamedNativeQueryAnnotation implementation **********
66
65
66
	String getQueryElementName() {
67
		return JPA.NAMED_NATIVE_QUERY__QUERY;
68
	}
69
70
	// ***** query
71
	public String getQuery() {
72
		return this.query;
73
	}
74
75
	public void setQuery(String query) {
76
		throw new UnsupportedOperationException();
77
	}
78
79
	private void setQuery_(String query) {
80
		String old = this.query;
81
		this.query = query;
82
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
83
	}
84
85
	private String buildQuery() {
86
		return (String) this.getJdtMemberValue(this.getQueryElementName());
87
	}
88
89
	public List<TextRange> getQueryTextRanges() {
90
		throw new UnsupportedOperationException();
91
	}
92
67
	// ***** result class
93
	// ***** result class
68
	public String getResultClass() {
94
	public String getResultClass() {
69
		return this.resultClass;
95
		return this.resultClass;
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java (-5 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2009, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-16 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
10
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
11
11
12
import java.util.List;
12
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
14
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
15
import org.eclipse.jpt.common.core.utility.TextRange;
14
import org.eclipse.jpt.jpa.core.resource.java.JPA;
16
import org.eclipse.jpt.jpa.core.resource.java.JPA;
15
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
17
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
16
18
Lines 21-50 Link Here
21
	extends BinaryQueryAnnotation
23
	extends BinaryQueryAnnotation
22
	implements NamedQueryAnnotation
24
	implements NamedQueryAnnotation
23
{
25
{
26
	private String query;
27
	
24
	public BinaryNamedQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
28
	public BinaryNamedQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
25
		super(parent, jdtAnnotation);
29
		super(parent, jdtAnnotation);
30
		this.query = this.buildQuery();
26
	}
31
	}
27
32
28
	public String getAnnotationName() {
33
	public String getAnnotationName() {
29
		return ANNOTATION_NAME;
34
		return ANNOTATION_NAME;
30
	}
35
	}
31
36
37
	@Override
38
	public void update() {
39
		super.update();
40
		this.setQuery_(this.buildQuery());
41
	}
32
42
33
	// ********** BinaryBaseNamedQueryAnnotation implementation **********
43
44
	// ********** BinaryNamedQueryAnnotation implementation **********
34
45
35
	@Override
46
	@Override
36
	String getNameElementName() {
47
	public String getNameElementName() {
37
		return JPA.NAMED_QUERY__NAME;
48
		return JPA.NAMED_QUERY__NAME;
38
	}
49
	}
39
50
40
	@Override
41
	String getQueryElementName() {
51
	String getQueryElementName() {
42
		return JPA.NAMED_QUERY__QUERY;
52
		return JPA.NAMED_QUERY__QUERY;
43
	}
53
	}
44
54
45
	@Override
55
	@Override
46
	String getHintsElementName() {
56
	public String getHintsElementName() {
47
		return JPA.NAMED_QUERY__HINTS;
57
		return JPA.NAMED_QUERY__HINTS;
48
	}
58
	}
49
59
60
61
	// ********** NamedNativeQueryAnnotation implementation **********
62
63
	// ***** query
64
	public String getQuery() {
65
		return this.query;
66
	}
67
68
	public void setQuery(String query) {
69
		throw new UnsupportedOperationException();
70
	}
71
72
	private void setQuery_(String query) {
73
		String old = this.query;
74
		this.query = query;
75
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
76
	}
77
78
	private String buildQuery() {
79
		return (String) this.getJdtMemberValue(this.getQueryElementName());
80
	}
81
82
	public List<TextRange> getQueryTextRanges() {
83
		throw new UnsupportedOperationException();
84
	}
85
50
}
86
}
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryQueryAnnotation.java (-33 / +5 lines)
Lines 9-15 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
10
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
11
11
12
import java.util.List;
13
import java.util.Vector;
12
import java.util.Vector;
14
import org.eclipse.jdt.core.IAnnotation;
13
import org.eclipse.jdt.core.IAnnotation;
15
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation;
14
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation;
Lines 23-42 Link Here
23
/**
22
/**
24
 * javax.persistence.NamedQuery
23
 * javax.persistence.NamedQuery
25
 * javax.persistence.NamedNativeQuery
24
 * javax.persistence.NamedNativeQuery
25
 * javax.persistence.NamedStoredProcedureQuery
26
 */
26
 */
27
abstract class BinaryQueryAnnotation
27
public abstract class BinaryQueryAnnotation
28
	extends BinaryAnnotation
28
	extends BinaryAnnotation
29
	implements QueryAnnotation
29
	implements QueryAnnotation
30
{
30
{
31
	String name;
31
	String name;
32
	String query;
33
	final Vector<QueryHintAnnotation> hints;
32
	final Vector<QueryHintAnnotation> hints;
34
33
35
34
36
	BinaryQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
35
	protected BinaryQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
37
		super(parent, jdtAnnotation);
36
		super(parent, jdtAnnotation);
38
		this.name = this.buildName();
37
		this.name = this.buildName();
39
		this.query = this.buildQuery();
40
		this.hints = this.buildHints();
38
		this.hints = this.buildHints();
41
	}
39
	}
42
40
Lines 44-50 Link Here
44
	public void update() {
42
	public void update() {
45
		super.update();
43
		super.update();
46
		this.setName_(this.buildName());
44
		this.setName_(this.buildName());
47
		this.setQuery_(this.buildQuery());
48
		this.updateHints();
45
		this.updateHints();
49
	}
46
	}
50
47
Lines 75-108 Link Here
75
		return (String) this.getJdtMemberValue(this.getNameElementName());
72
		return (String) this.getJdtMemberValue(this.getNameElementName());
76
	}
73
	}
77
74
78
	abstract String getNameElementName();
75
	public abstract String getNameElementName();
79
76
80
	public TextRange getNameTextRange() {
77
	public TextRange getNameTextRange() {
81
		throw new UnsupportedOperationException();
82
	}
83
84
	// ***** query
85
	public String getQuery() {
86
		return this.query;
87
	}
88
89
	public void setQuery(String query) {
90
		throw new UnsupportedOperationException();
91
	}
92
93
	private void setQuery_(String query) {
94
		String old = this.query;
95
		this.query = query;
96
		this.firePropertyChanged(QUERY_PROPERTY, old, query);
97
	}
98
99
	private String buildQuery() {
100
		return (String) this.getJdtMemberValue(this.getQueryElementName());
101
	}
102
103
	abstract String getQueryElementName();
104
105
	public List<TextRange> getQueryTextRanges() {
106
		throw new UnsupportedOperationException();
78
		throw new UnsupportedOperationException();
107
	}
79
	}
108
80
Lines 141-147 Link Here
141
		return result;
113
		return result;
142
	}
114
	}
143
115
144
	abstract String getHintsElementName();
116
	public abstract String getHintsElementName();
145
117
146
	// TODO
118
	// TODO
147
	private void updateHints() {
119
	private void updateHints() {
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java (-10 / +62 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-14 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
10
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
11
11
12
import java.util.List;
12
import org.eclipse.jdt.core.dom.Annotation;
13
import org.eclipse.jdt.core.dom.Annotation;
13
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
14
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
14
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
15
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
Lines 37-42 Link Here
37
{
38
{
38
	private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
39
	private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
39
	private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.NAMED_NATIVE_QUERIES);
40
	private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.NAMED_NATIVE_QUERIES);
41
42
	DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
43
	AnnotationElementAdapter<String> queryAdapter;
44
	String query;
45
	List<TextRange> queryTextRanges;
40
46
41
	private DeclarationAnnotationElementAdapter<String> resultClassDeclarationAdapter;
47
	private DeclarationAnnotationElementAdapter<String> resultClassDeclarationAdapter;
42
	private AnnotationElementAdapter<String> resultClassAdapter;
48
	private AnnotationElementAdapter<String> resultClassAdapter;
Lines 71-76 Link Here
71
			IndexedDeclarationAnnotationAdapter daa,
77
			IndexedDeclarationAnnotationAdapter daa,
72
			IndexedAnnotationAdapter annotationAdapter) {
78
			IndexedAnnotationAdapter annotationAdapter) {
73
		super(parent, element, daa, annotationAdapter);
79
		super(parent, element, daa, annotationAdapter);
80
		this.queryDeclarationAdapter = this.buildQueryDeclarationAdapter();
81
		this.queryAdapter = this.buildQueryAdapter();
74
		this.resultClassDeclarationAdapter = this.buildResultClassDeclarationAdapter();
82
		this.resultClassDeclarationAdapter = this.buildResultClassDeclarationAdapter();
75
		this.resultClassAdapter = this.buildResultClassAdapter();
83
		this.resultClassAdapter = this.buildResultClassAdapter();
76
		this.resultSetMappingDeclarationAdapter = this.buildResultSetMappingAdapter(daa);
84
		this.resultSetMappingDeclarationAdapter = this.buildResultSetMappingAdapter(daa);
Lines 84-89 Link Here
84
	@Override
92
	@Override
85
	public void initialize(Annotation astAnnotation) {
93
	public void initialize(Annotation astAnnotation) {
86
		super.initialize(astAnnotation);
94
		super.initialize(astAnnotation);
95
		
96
		this.query = this.buildQuery(astAnnotation);
97
		this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
87
98
88
		this.resultClass = this.buildResultClass(astAnnotation);
99
		this.resultClass = this.buildResultClass(astAnnotation);
89
		this.resultClassTextRange = this.buildResultClassTextRange(astAnnotation);
100
		this.resultClassTextRange = this.buildResultClassTextRange(astAnnotation);
Lines 95-100 Link Here
95
	@Override
106
	@Override
96
	public void synchronizeWith(Annotation astAnnotation) {
107
	public void synchronizeWith(Annotation astAnnotation) {
97
		super.synchronizeWith(astAnnotation);
108
		super.synchronizeWith(astAnnotation);
109
		
110
		this.syncQuery(this.buildQuery(astAnnotation));
111
		this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
98
112
99
		this.syncResultClass(this.buildResultClass(astAnnotation));
113
		this.syncResultClass(this.buildResultClass(astAnnotation));
100
		this.resultClassTextRange = this.buildResultClassTextRange(astAnnotation);
114
		this.resultClassTextRange = this.buildResultClassTextRange(astAnnotation);
Lines 104-133 Link Here
104
	}
118
	}
105
119
106
120
107
	// ********** AbstractBaseNamedQueryAnnotation implementation **********
121
	// ********** AbstractNamedNativeQueryAnnotation implementation **********
108
122
109
	@Override
123
	@Override
110
	String getNameElementName() {
124
	public String getNameElementName() {
111
		return JPA.NAMED_NATIVE_QUERY__NAME;
125
		return JPA.NAMED_NATIVE_QUERY__NAME;
112
	}
126
	}
113
127
114
	@Override
128
	@Override
115
	String getQueryElementName() {
129
	public String getHintsElementName() {
116
		return JPA.NAMED_NATIVE_QUERY__QUERY;
117
	}
118
119
	@Override
120
	String getHintsElementName() {
121
		return JPA.NAMED_NATIVE_QUERY__HINTS;
130
		return JPA.NAMED_NATIVE_QUERY__HINTS;
122
	}
131
	}
123
132
124
	@Override
133
	@Override
125
	QueryHintAnnotation buildHint(int index) {
134
	public QueryHintAnnotation buildHint(int index) {
126
		return SourceQueryHintAnnotation.buildNamedNativeQueryQueryHint(this, this.annotatedElement, this.daa, index);
135
		return SourceQueryHintAnnotation.buildNamedNativeQueryQueryHint(this, this.annotatedElement, this.daa, index);
127
	}
136
	}
128
137
129
138
130
	// ********** NamedNativeQueryAnnotation implementation **********
139
	// ********** NamedNativeQueryAnnotation implementation **********
140
141
	String getQueryElementName() {
142
		return JPA.NAMED_NATIVE_QUERY__QUERY;
143
	}
144
	
145
	// ***** query
146
	public String getQuery() {
147
		return this.query;
148
	}
149
150
	public void setQuery(String query) {
151
		if (this.attributeValueHasChanged(this.query, query)) {
152
			this.query = query;
153
			this.queryAdapter.setValue(query);
154
		}
155
	}
156
157
	private void syncQuery(String annotationQuery) {
158
		String old = this.query;
159
		this.query = annotationQuery;
160
		this.firePropertyChanged(QUERY_PROPERTY, old, annotationQuery);
161
	}
162
163
	private String buildQuery(Annotation astAnnotation) {
164
		return this.queryAdapter.getValue(astAnnotation);
165
	}
166
167
	public List<TextRange> getQueryTextRanges() {
168
		return this.queryTextRanges;
169
	}
170
171
	private List<TextRange> buildQueryTextRanges(Annotation astAnnotation) {
172
		return this.getElementTextRanges(this.queryDeclarationAdapter, astAnnotation);
173
	}
174
175
	private DeclarationAnnotationElementAdapter<String> buildQueryDeclarationAdapter() {
176
		return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getQueryElementName());
177
	}
178
179
	private AnnotationElementAdapter<String> buildQueryAdapter() {
180
		return this.buildStringElementAdapter(this.queryDeclarationAdapter);
181
	}
131
182
132
	// ***** result class
183
	// ***** result class
133
	public String getResultClass() {
184
	public String getResultClass() {
Lines 236-241 Link Here
236
	@Override
287
	@Override
237
	public boolean isUnset() {
288
	public boolean isUnset() {
238
		return super.isUnset() &&
289
		return super.isUnset() &&
290
				(this.query == null) &&
239
				(this.resultClass == null) &&
291
				(this.resultClass == null) &&
240
				(this.resultSetMapping == null);
292
				(this.resultSetMapping == null);
241
	}
293
	}
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedQueryAnnotation.java (-6 / +80 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-21 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
10
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
11
11
12
import java.util.List;
13
import org.eclipse.jdt.core.dom.Annotation;
12
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
14
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
15
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
13
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
16
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
14
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
17
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
15
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
18
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
19
import org.eclipse.jpt.common.core.utility.TextRange;
16
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
20
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
17
import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
21
import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
22
import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
18
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
23
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
24
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
19
import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
25
import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
20
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
26
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
21
import org.eclipse.jpt.jpa.core.resource.java.JPA;
27
import org.eclipse.jpt.jpa.core.resource.java.JPA;
Lines 32-70 Link Here
32
	private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
38
	private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
33
	private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.NAMED_QUERIES);
39
	private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.NAMED_QUERIES);
34
40
41
	DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
42
	AnnotationElementAdapter<String> queryAdapter;
43
	String query;
44
	List<TextRange> queryTextRanges;
35
	
45
	
36
	protected SourceNamedQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
46
	protected SourceNamedQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
37
		super(parent, element, daa, annotationAdapter);
47
		super(parent, element, daa, annotationAdapter);
48
		this.queryDeclarationAdapter = this.buildQueryDeclarationAdapter();
49
		this.queryAdapter = this.buildQueryAdapter();
38
	}
50
	}
39
40
51
41
	public String getAnnotationName() {
52
	public String getAnnotationName() {
42
		return ANNOTATION_NAME;
53
		return ANNOTATION_NAME;
43
	}
54
	}
44
55
56
	@Override
57
	public void initialize(Annotation astAnnotation) {
58
		super.initialize(astAnnotation);
59
		
60
		this.query = this.buildQuery(astAnnotation);
61
		this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
62
	}
63
64
	@Override
65
	public void synchronizeWith(Annotation astAnnotation) {
66
		super.synchronizeWith(astAnnotation);
67
		
68
		this.syncQuery(this.buildQuery(astAnnotation));
69
		this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
70
	}
45
71
46
	// ********** AbstractBaseNamedQueryAnnotation implementation **********
72
	// ********** AbstractBaseNamedQueryAnnotation implementation **********
47
73
48
	@Override
74
	@Override
49
	String getNameElementName() {
75
	public String getNameElementName() {
50
		return JPA.NAMED_QUERY__NAME;
76
		return JPA.NAMED_QUERY__NAME;
51
	}
77
	}
52
78
53
	@Override
54
	String getQueryElementName() {
79
	String getQueryElementName() {
55
		return JPA.NAMED_QUERY__QUERY;
80
		return JPA.NAMED_QUERY__QUERY;
56
	}
81
	}
57
82
58
	@Override
83
	@Override
59
	String getHintsElementName() {
84
	public String getHintsElementName() {
60
		return JPA.NAMED_QUERY__HINTS;
85
		return JPA.NAMED_QUERY__HINTS;
61
	}
86
	}
62
87
63
	@Override
88
	@Override
64
	QueryHintAnnotation buildHint(int index) {
89
	public QueryHintAnnotation buildHint(int index) {
65
		return SourceQueryHintAnnotation.buildNamedQueryQueryHint(this, this.annotatedElement, this.daa, index);
90
		return SourceQueryHintAnnotation.buildNamedQueryQueryHint(this, this.annotatedElement, this.daa, index);
66
	}
91
	}
67
92
93
	// ***** query
94
	public String getQuery() {
95
		return this.query;
96
	}
97
98
	public void setQuery(String query) {
99
		if (this.attributeValueHasChanged(this.query, query)) {
100
			this.query = query;
101
			this.queryAdapter.setValue(query);
102
		}
103
	}
104
105
	private void syncQuery(String annotationQuery) {
106
		String old = this.query;
107
		this.query = annotationQuery;
108
		this.firePropertyChanged(QUERY_PROPERTY, old, annotationQuery);
109
	}
110
111
	private String buildQuery(Annotation astAnnotation) {
112
		return this.queryAdapter.getValue(astAnnotation);
113
	}
114
115
	public List<TextRange> getQueryTextRanges() {
116
		return this.queryTextRanges;
117
	}
118
119
	private List<TextRange> buildQueryTextRanges(Annotation astAnnotation) {
120
		return this.getElementTextRanges(this.queryDeclarationAdapter, astAnnotation);
121
	}
122
123
	private DeclarationAnnotationElementAdapter<String> buildQueryDeclarationAdapter() {
124
		return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getQueryElementName());
125
	}
126
127
	private AnnotationElementAdapter<String> buildQueryAdapter() {
128
		return this.buildStringElementAdapter(this.queryDeclarationAdapter);
129
	}
130
	
131
	// ********** misc **********
132
133
	@Override
134
	public boolean isUnset() {
135
		return super.isUnset() &&
136
				(this.query == null);
137
	}
138
139
140
	// ********** static methods **********
141
68
	protected static IndexedAnnotationAdapter buildNamedQueryAnnotationAdapter(AnnotatedElement annotatedElement, IndexedDeclarationAnnotationAdapter idaa) {
142
	protected static IndexedAnnotationAdapter buildNamedQueryAnnotationAdapter(AnnotatedElement annotatedElement, IndexedDeclarationAnnotationAdapter idaa) {
69
		return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
143
		return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
70
	}
144
	}
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java (-58 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-15 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
10
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
11
11
12
import java.util.List;
13
import org.eclipse.jdt.core.dom.Annotation;
12
import org.eclipse.jdt.core.dom.Annotation;
14
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation;
13
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation;
15
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
14
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
Lines 28-36 Link Here
28
 * <ul>
27
 * <ul>
29
 * <li><code>javax.persistence.NamedQuery</code>
28
 * <li><code>javax.persistence.NamedQuery</code>
30
 * <li><code>javax.persistence.NamedNativeQuery</code>
29
 * <li><code>javax.persistence.NamedNativeQuery</code>
30
 * <li><code>javax.persistence.NamedStoredProcedureQuery</code>
31
 * </ul>
31
 * </ul>
32
 */
32
 */
33
abstract class SourceQueryAnnotation
33
public abstract class SourceQueryAnnotation
34
	extends SourceAnnotation
34
	extends SourceAnnotation
35
	implements QueryAnnotation
35
	implements QueryAnnotation
36
{
36
{
Lines 39-58 Link Here
39
	String name;
39
	String name;
40
	TextRange nameTextRange;
40
	TextRange nameTextRange;
41
41
42
	DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
43
	AnnotationElementAdapter<String> queryAdapter;
44
	String query;
45
	List<TextRange> queryTextRanges;
46
47
	final QueryHintsAnnotationContainer hintsContainer = new QueryHintsAnnotationContainer();
42
	final QueryHintsAnnotationContainer hintsContainer = new QueryHintsAnnotationContainer();
48
43
49
44
50
	SourceQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
45
	protected SourceQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
51
		super(parent, element, daa, annotationAdapter);
46
		super(parent, element, daa, annotationAdapter);
52
		this.nameDeclarationAdapter = this.buildNameDeclarationAdapter();
47
		this.nameDeclarationAdapter = this.buildNameDeclarationAdapter();
53
		this.nameAdapter = this.buildNameAdapter();
48
		this.nameAdapter = this.buildNameAdapter();
54
		this.queryDeclarationAdapter = this.buildQueryDeclarationAdapter();
49
55
		this.queryAdapter = this.buildQueryAdapter();
56
	}
50
	}
57
51
58
	@Override
52
	@Override
Lines 60-67 Link Here
60
		super.initialize(astAnnotation);
54
		super.initialize(astAnnotation);
61
		this.name = this.buildName(astAnnotation);
55
		this.name = this.buildName(astAnnotation);
62
		this.nameTextRange = this.buildNameTextRange(astAnnotation);
56
		this.nameTextRange = this.buildNameTextRange(astAnnotation);
63
		this.query = this.buildQuery(astAnnotation);
64
		this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
65
		this.hintsContainer.initializeFromContainerAnnotation(astAnnotation);
57
		this.hintsContainer.initializeFromContainerAnnotation(astAnnotation);
66
	}
58
	}
67
59
Lines 70-77 Link Here
70
		super.synchronizeWith(astAnnotation);
62
		super.synchronizeWith(astAnnotation);
71
		this.syncName(this.buildName(astAnnotation));
63
		this.syncName(this.buildName(astAnnotation));
72
		this.nameTextRange = this.buildNameTextRange(astAnnotation);
64
		this.nameTextRange = this.buildNameTextRange(astAnnotation);
73
		this.syncQuery(this.buildQuery(astAnnotation));
74
		this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
75
		this.hintsContainer.synchronize(astAnnotation);
65
		this.hintsContainer.synchronize(astAnnotation);
76
	}
66
	}
77
67
Lines 116-162 Link Here
116
		return this.buildStringElementAdapter(this.nameDeclarationAdapter);
106
		return this.buildStringElementAdapter(this.nameDeclarationAdapter);
117
	}
107
	}
118
108
119
	abstract String getNameElementName();
109
	public abstract String getNameElementName();
120
110
121
	// ***** query
122
	public String getQuery() {
123
		return this.query;
124
	}
125
126
	public void setQuery(String query) {
127
		if (this.attributeValueHasChanged(this.query, query)) {
128
			this.query = query;
129
			this.queryAdapter.setValue(query);
130
		}
131
	}
132
133
	private void syncQuery(String annotationQuery) {
134
		String old = this.query;
135
		this.query = annotationQuery;
136
		this.firePropertyChanged(QUERY_PROPERTY, old, annotationQuery);
137
	}
138
139
	private String buildQuery(Annotation astAnnotation) {
140
		return this.queryAdapter.getValue(astAnnotation);
141
	}
142
143
	public List<TextRange> getQueryTextRanges() {
144
		return this.queryTextRanges;
145
	}
146
147
	private List<TextRange> buildQueryTextRanges(Annotation astAnnotation) {
148
		return this.getElementTextRanges(this.queryDeclarationAdapter, astAnnotation);
149
	}
150
151
	private DeclarationAnnotationElementAdapter<String> buildQueryDeclarationAdapter() {
152
		return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getQueryElementName());
153
	}
154
155
	private AnnotationElementAdapter<String> buildQueryAdapter() {
156
		return this.buildStringElementAdapter(this.queryDeclarationAdapter);
157
	}
158
159
	abstract String getQueryElementName();
160
111
161
	// ***** hints
112
	// ***** hints
162
113
Lines 184-192 Link Here
184
		this.hintsContainer.removeNestedAnnotation(index);
135
		this.hintsContainer.removeNestedAnnotation(index);
185
	}
136
	}
186
137
187
	abstract QueryHintAnnotation buildHint(int index);
138
	public abstract QueryHintAnnotation buildHint(int index);
188
139
189
	abstract String getHintsElementName();
140
	public abstract String getHintsElementName();
190
141
191
142
192
	// ********** misc **********
143
	// ********** misc **********
Lines 195-201 Link Here
195
	public boolean isUnset() {
146
	public boolean isUnset() {
196
		return super.isUnset() &&
147
		return super.isUnset() &&
197
				(this.name == null) &&
148
				(this.name == null) &&
198
				(this.query == null) &&
199
				this.hintsContainer.isEmpty();
149
				this.hintsContainer.isEmpty();
200
	}
150
	}
201
151
(-)src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryHintAnnotation.java (-1 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 21-26 Link Here
21
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
21
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
22
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
22
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
23
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
23
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
24
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
24
import org.eclipse.jpt.jpa.core.resource.java.JPA;
25
import org.eclipse.jpt.jpa.core.resource.java.JPA;
25
import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
26
import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
26
27
Lines 48-53 Link Here
48
49
49
	static SourceQueryHintAnnotation buildNamedNativeQueryQueryHint(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) {
50
	static SourceQueryHintAnnotation buildNamedNativeQueryQueryHint(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) {
50
		return buildNestedSourceQueryHintAnnotation(parent, element, buildNamedNativeQueryQueryHintAnnotationAdapter(namedNativeQueryAdapter, index));
51
		return buildNestedSourceQueryHintAnnotation(parent, element, buildNamedNativeQueryQueryHintAnnotationAdapter(namedNativeQueryAdapter, index));
52
	}
53
	
54
	public static SourceQueryHintAnnotation buildNamedStoredProcedureQuery2_1QueryHint(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter namedStoredProcedureQuery2_1Adapter, int index) {
55
		return buildNestedSourceQueryHintAnnotation(parent, element, buildNamedStoredProcedureQuery2_1QueryHintAnnotationAdapter(namedStoredProcedureQuery2_1Adapter, index));
51
	}
56
	}
52
	
57
	
53
	public static SourceQueryHintAnnotation buildNestedSourceQueryHintAnnotation(
58
	public static SourceQueryHintAnnotation buildNestedSourceQueryHintAnnotation(
Lines 193-196 Link Here
193
	private static IndexedDeclarationAnnotationAdapter buildNamedNativeQueryQueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) {
198
	private static IndexedDeclarationAnnotationAdapter buildNamedNativeQueryQueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) {
194
		return new NestedIndexedDeclarationAnnotationAdapter(namedNativeQueryAdapter, JPA.NAMED_NATIVE_QUERY__HINTS, index, ANNOTATION_NAME);
199
		return new NestedIndexedDeclarationAnnotationAdapter(namedNativeQueryAdapter, JPA.NAMED_NATIVE_QUERY__HINTS, index, ANNOTATION_NAME);
195
	}
200
	}
201
	private static IndexedDeclarationAnnotationAdapter buildNamedStoredProcedureQuery2_1QueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedStoredProcedureQuery2_1Adapter, int index) {
202
		return new NestedIndexedDeclarationAnnotationAdapter(namedStoredProcedureQuery2_1Adapter, JPA2_1.NAMED_STORED_PROCEDURE_QUERY__HINTS, index, ANNOTATION_NAME);
203
	}
196
}
204
}
(-)src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/JPA2_1.java (-1 / +23 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2012 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 36-40 Link Here
36
	// JPA 2.1 annotations
36
	// JPA 2.1 annotations
37
	String CONVERTER = PACKAGE_ + "Converter";
37
	String CONVERTER = PACKAGE_ + "Converter";
38
		String CONVERTER__AUTO_APPLY = "autoApply";
38
		String CONVERTER__AUTO_APPLY = "autoApply";
39
		
40
	String NAMED_STORED_PROCEDURE_QUERIES = PACKAGE_ + "NamedStoredProcedureQueries";
41
		String NAMED_STORED_PROCEDURE_QUERIES__VALUE = "value";
42
	String NAMED_STORED_PROCEDURE_QUERY =PACKAGE_ + "NamedStoredProcedureQuery";
43
		String NAMED_STORED_PROCEDURE_QUERY__NAME = "name";
44
		String NAMED_STORED_PROCEDURE_QUERY__PROCEDURE_NAME= "procedureName";
45
		String NAMED_STORED_PROCEDURE_QUERY__PARAMETERS = "parameters";
46
		String NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES = "resultClasses";
47
		String NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS= "resultSetMappings";
48
		String NAMED_STORED_PROCEDURE_QUERY__HINTS = "hints";
49
	String NAMED_STORED_PROCEDURE_PARAMETER = PACKAGE_ + "StoredProcedureParameter";
50
		String NAMED_STORED_PROCEDURE_PARAMETER__NAME = "name";
51
		String NAMED_STORED_PROCEDURE_PARAMETER__MODE = "mode";
52
		String NAMED_STORED_PROCEDURE_PARAMETER__TYPE = "type";
53
		
54
	// JPA 2.1 enums
55
	String PARAMETER_MODE = PACKAGE_ + "ParameterMode";
56
		String PARAMETER_MODE_ = PARAMETER_MODE + '.';
57
		String PARAMETER_MODE__IN = PARAMETER_MODE_ + "IN";
58
		String PARAMETER_MODE__INOUT = PARAMETER_MODE_ + "INOUT";
59
		String PARAMETER_MODE__OUT = PARAMETER_MODE_ + "OUT";
60
		String PARAMETER_MODE__REF_CURSOR= PARAMETER_MODE_ + "REF_CURSOR";
39
61
40
}
62
}
(-)src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/NamedStoredProcedureQuery2_1Annoation.java (+171 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.jpa2_1.resource.java;
11
12
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.utility.iterable.ListIterable;
14
import org.eclipse.jpt.jpa.core.resource.java.QueryAnnotation;
15
16
/**
17
 * Corresponds to the JPA annotation
18
 * <code>javax.persistence.NamedStoredProcedureQuery</code>
19
 * <p>
20
 * Provisional API: This interface is part of an interim API that is still
21
 * under development and expected to change significantly before reaching
22
 * stability. It is available at this early stage to solicit feedback from
23
 * pioneering adopters on the understanding that any code that uses this API
24
 * will almost certainly be broken (repeatedly) as the API evolves.
25
 * 
26
 * @version 3.3
27
 * @since 3.3
28
 */
29
public interface NamedStoredProcedureQuery2_1Annoation
30
	extends QueryAnnotation
31
{
32
	String ANNOTATION_NAME = JPA2_1.NAMED_STORED_PROCEDURE_QUERY;
33
34
35
	// ********** procedure name **********
36
37
	/**
38
	 * Corresponds to the 'procedureName' element of the *NamedStoredProcedureQuery annotation.
39
	 * Return null if the element does not exist in Java.
40
	 */
41
	String getProcedureName();
42
		String PROCEDURE_NAME_PROPERTY = "procedureName"; //$NON-NLS-1$
43
44
	/**
45
	 * Corresponds to the 'procedureName' element of the *NamedStoredProcedureQuery annotation.
46
	 * Set to null to remove the element.
47
	 */
48
	void setProcedureName(String procedureName);
49
50
	/**
51
	 * Return the {@link TextRange} for the 'procedureName' element. If element
52
	 * does not exist return the {@link TextRange} for the *NamedStoredProcedureQuery annotation.
53
	 */
54
	TextRange getProcedureNameTextRange();
55
56
57
	// ********** parameters **********
58
59
	/**
60
	 * Corresponds to the 'parameters' element of the *NamedStoredProcedureQuery annotation.
61
	 * Return an empty iterator if the element does not exist in Java.
62
	 */
63
	ListIterable<StoredProcedureParameter2_1Annotation> getParameters();
64
		String PARAMETERS_LIST = "parameters"; //$NON-NLS-1$
65
66
	/**
67
	 * Corresponds to the 'parameters' element of the *NamedStoredProcedureQuery annotation.
68
	 */
69
	int getParametersSize();
70
71
	/**
72
	 * Corresponds to the 'parameters' element of the *NamedStoredProcedureQuery annotation.
73
	 */
74
	StoredProcedureParameter2_1Annotation parameterAt(int index);
75
76
	/**
77
	 * Corresponds to the 'parameters' element of the *NamedStoredProcedureQuery annotation.
78
	 */
79
	StoredProcedureParameter2_1Annotation addParameter(int index);
80
81
	/**
82
	 * Corresponds to the 'parameters' element of the *NamedStoredProcedureQuery annotation.
83
	 */
84
	void moveParameter(int targetIndex, int sourceIndex);
85
86
	/**
87
	 * Corresponds to the 'parameters' element of the *NamedStoredProcedureQuery annotation.
88
	 */
89
	void removeParameter(int index);
90
91
92
	// ********** result classes **********
93
94
	/**
95
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
96
	 * Return an empty iterator if the element does not exist in Java.
97
	 */
98
	ListIterable<String> getResultClasses();
99
		String RESULT_CLASSES_LIST = "resultClasses"; //$NON-NLS-1$
100
101
	/**
102
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
103
	 */
104
	int getResultClassesSize();
105
106
	/**
107
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
108
	 */
109
	String resultClassAt(int index);
110
111
	/**
112
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
113
	 */
114
	void addResultClass(String resultClass);
115
116
	/**
117
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
118
	 */
119
	void moveResultClass(int targetIndex, int sourceIndex);
120
121
	/**
122
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
123
	 */
124
	void removeResultClass(String resultClass);
125
126
	/**
127
	 * Corresponds to the 'resultClasses' element of the *NamedStoredProcedureQuery annotation.
128
	 */
129
	void removeResultClass(int index);
130
131
	
132
	// ********** result set mappings **********
133
134
	/**
135
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
136
	 * Return an empty iterator if the element does not exist in Java.
137
	 */
138
	ListIterable<String> getResultSetMappings();
139
		String RESULT_SET_MAPPINGS_LIST = "resultSetMappings"; //$NON-NLS-1$
140
141
	/**
142
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
143
	 */
144
	int getResultSetMappingsSize();
145
146
	/**
147
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
148
	 */
149
	String resultSetMappingAt(int index);
150
151
	/**
152
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
153
	 */
154
	void addResultSetMapping(String resultSetMapping);
155
156
	/**
157
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
158
	 */
159
	void moveResultSetMapping(int targetIndex, int sourceIndex);
160
161
	/**
162
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
163
	 */
164
	void removeResultSetMapping(String resultSetMapping);
165
166
	/**
167
	 * Corresponds to the 'resultSetMappings' element of the *NamedStoredProcedureQuery annotation.
168
	 */
169
	void removeResultSetMapping(int index);
170
171
}
(-)src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/ParameterMode2_1.java (+67 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.jpa2_1.resource.java;
11
12
13
/**
14
 * Corresponds to the JPA 2.1 enum
15
 * javax.persistence.ParameterMode
16
 * <p>
17
 * Provisional API: This interface is part of an interim API that is still
18
 * under development and expected to change significantly before reaching
19
 * stability. It is available at this early stage to solicit feedback from
20
 * pioneering adopters on the understanding that any code that uses this API
21
 * will almost certainly be broken (repeatedly) as the API evolves.
22
 * 
23
 * @version 3.3
24
 * @since 3.3
25
 */
26
public enum ParameterMode2_1
27
{
28
	
29
	IN(JPA2_1.PARAMETER_MODE__IN),
30
	INOUT(JPA2_1.PARAMETER_MODE__INOUT),
31
	OUT(JPA2_1.PARAMETER_MODE__OUT),
32
	REF_CURSOR(JPA2_1.PARAMETER_MODE__REF_CURSOR);
33
34
35
	private String javaAnnotationValue;
36
37
	ParameterMode2_1(String javaAnnotationValue) {
38
		if (javaAnnotationValue == null) {
39
			throw new NullPointerException();
40
		}
41
		this.javaAnnotationValue = javaAnnotationValue;
42
	}
43
44
	public String getJavaAnnotationValue() {
45
		return this.javaAnnotationValue;
46
	}
47
48
49
	// ********** static methods **********
50
51
	public static ParameterMode2_1 fromJavaAnnotationValue(Object javaAnnotationValue) {
52
		return (javaAnnotationValue == null) ? null : fromJavaAnnotationValue_(javaAnnotationValue);
53
	}
54
55
	private static ParameterMode2_1 fromJavaAnnotationValue_(Object javaAnnotationValue) {
56
		for (ParameterMode2_1 parameterMode : ParameterMode2_1.values()) {
57
			if (parameterMode.getJavaAnnotationValue().equals(javaAnnotationValue)) {
58
				return parameterMode;
59
			}
60
		}
61
		return null;
62
	}
63
64
	public static String toJavaAnnotationValue(ParameterMode2_1 parameterMode) {
65
		return (parameterMode == null) ? null : parameterMode.getJavaAnnotationValue();
66
	}
67
}
(-)src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/StoredProcedureParameter2_1Annotation.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.jpa2_1.resource.java;
11
12
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
13
import org.eclipse.jpt.common.core.utility.TextRange;
14
15
/**
16
 * Corresponds to the JPA annotation
17
 * <code>javax.persistence.StoredProcedureParameter</code>
18
 * <p>
19
 * Provisional API: This interface is part of an interim API that is still
20
 * under development and expected to change significantly before reaching
21
 * stability. It is available at this early stage to solicit feedback from
22
 * pioneering adopters on the understanding that any code that uses this API
23
 * will almost certainly be broken (repeatedly) as the API evolves.
24
 * 
25
 * @version 3.3
26
 * @since 3.3
27
 */
28
public interface StoredProcedureParameter2_1Annotation
29
	extends NestableAnnotation
30
{
31
	String ANNOTATION_NAME = JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER;
32
33
	// ********* name **********
34
	/**
35
	 * Corresponds to the 'name' element of the StoredProcedureParameter annotation.
36
	 * Return null if the element does not exist in the annotation
37
	 */
38
	String getName();
39
		String NAME_PROPERTY = "name"; //$NON-NLS-1$
40
	
41
	/**
42
	 * Corresponds to the 'name' element of the StoredProcedureParameter annotation.
43
	 * Setting to null will remove the element.
44
	 */
45
	void setName(String name);
46
		
47
	/**
48
	 * Return the {@link TextRange} for the 'name' element. If the element 
49
	 * does not exist return the {@link TextRange} for the StoredProcedureParameter annotation.
50
	 */
51
	TextRange getNameTextRange();
52
53
	// *********** mode *************
54
55
	/**
56
	 * Corresponds to the 'mode' element of the StoredProcedureParameter annotation.
57
	 * Return null if the element does not exist in the annotation
58
	 */
59
	ParameterMode2_1 getMode();
60
		String MODE_PROPERTY = "mode"; //$NON-NLS-1$
61
	
62
	/**
63
	 * Corresponds to the 'mode' element of the StoredProcedureParameter annotation.
64
	 * Setting to null will remove the element.
65
	 */
66
	void setMode(ParameterMode2_1 mode);
67
68
	/**
69
	 * Return the {@link TextRange} for the 'mode' element. If the element 
70
	 * does not exist return the {@link TextRange} for the StoredProcedureParameter annotation.
71
	 */
72
	TextRange getModeTextRange();
73
	
74
	// ********** type ***********
75
76
	/**
77
	 * Corresponds to the 'type' element of the StoredProcedureParameter annotation.
78
	 * Return null if the element does not exist in the annotation
79
	 */
80
	String getType();
81
		String TYPE_PROPERTY = "type"; //$NON-NLS-1$
82
	
83
	/**
84
	 * Corresponds to the 'type' element of the StoredProcedureParameter annotation.
85
	 * Setting to null will remove the element.
86
	 */
87
	void setType(String type);
88
89
	/**
90
	 * Return the {@link TextRange} for the 'type' element. If the element 
91
	 * does not exist return the {@link TextRange} for the StoredProcedureParameter annotation.
92
	 */
93
	TextRange getTypeTextRange();
94
95
	/**
96
	 * Return the named native query's fully-qualified type name as
97
	 * resolved by the AST's bindings.
98
	 * <pre>
99
	 *     &#64;NamedStoredProcedureQuery(type=Employee.class)
100
	 * </pre>
101
	 * will return <code>"model.Employee"</code> if there is an import for
102
	 * <code>model.Employee</code>.
103
	 */
104
	String getFullyQualifiedTypeName();
105
}
(-)src/org/eclipse/jpt/jpa/core/resource/java/NamedNativeQueryAnnotation.java (-1 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-14 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.resource.java;
10
package org.eclipse.jpt.jpa.core.resource.java;
11
11
12
import java.util.List;
12
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.core.utility.TextRange;
13
14
14
15
Lines 31-36 Link Here
31
	String ANNOTATION_NAME = JPA.NAMED_NATIVE_QUERY;
32
	String ANNOTATION_NAME = JPA.NAMED_NATIVE_QUERY;
32
33
33
34
35
	// ********** query **********
36
37
	/**
38
	 * Corresponds to the 'query' element of the *Query annotation.
39
	 * Return null if the element does not exist in Java.
40
	 */
41
	String getQuery();
42
		String QUERY_PROPERTY = "query"; //$NON-NLS-1$
43
44
	/**
45
	 * Corresponds to the 'query' element of the *Query annotation.
46
	 * Set to null to remove the element.
47
	 */
48
	void setQuery(String query);
49
50
	/**
51
	 * Return the {@link TextRange} for the 'query' element. If element
52
	 * does not exist return the {@link TextRange} for the *Query annotation.
53
	 */
54
	List<TextRange> getQueryTextRanges();
55
56
34
	// ********** result class **********
57
	// ********** result class **********
35
58
36
	/**
59
	/**
(-)src/org/eclipse/jpt/jpa/core/resource/java/NamedQueryAnnotation.java (-1 / +26 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 8-13 Link Here
8
 *     Oracle - initial API and implementation
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.resource.java;
10
package org.eclipse.jpt.jpa.core.resource.java;
11
12
import java.util.List;
13
import org.eclipse.jpt.common.core.utility.TextRange;
11
14
12
/**
15
/**
13
 * Corresponds to the JPA annotation
16
 * Corresponds to the JPA annotation
Lines 26-29 Link Here
26
	extends QueryAnnotation
29
	extends QueryAnnotation
27
{
30
{
28
	String ANNOTATION_NAME = JPA.NAMED_QUERY;
31
	String ANNOTATION_NAME = JPA.NAMED_QUERY;
32
33
	// ********** query **********
34
35
	/**
36
	 * Corresponds to the 'query' element of the *Query annotation.
37
	 * Return null if the element does not exist in Java.
38
	 */
39
	String getQuery();
40
		String QUERY_PROPERTY = "query"; //$NON-NLS-1$
41
42
	/**
43
	 * Corresponds to the 'query' element of the *Query annotation.
44
	 * Set to null to remove the element.
45
	 */
46
	void setQuery(String query);
47
48
	/**
49
	 * Return the {@link TextRange} for the 'query' element. If element
50
	 * does not exist return the {@link TextRange} for the *Query annotation.
51
	 */
52
	List<TextRange> getQueryTextRanges();
53
29
}
54
}
(-)src/org/eclipse/jpt/jpa/core/resource/java/QueryAnnotation.java (-24 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2012 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
Lines 9-15 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.resource.java;
10
package org.eclipse.jpt.jpa.core.resource.java;
11
11
12
import java.util.List;
13
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
12
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
14
import org.eclipse.jpt.common.core.utility.TextRange;
13
import org.eclipse.jpt.common.core.utility.TextRange;
15
import org.eclipse.jpt.common.utility.iterable.ListIterable;
14
import org.eclipse.jpt.common.utility.iterable.ListIterable;
Lines 51-78 Link Here
51
	 * does not exist return the {@link TextRange} for the *Query annotation.
50
	 * does not exist return the {@link TextRange} for the *Query annotation.
52
	 */
51
	 */
53
	TextRange getNameTextRange();
52
	TextRange getNameTextRange();
54
55
56
	// ********** query **********
57
58
	/**
59
	 * Corresponds to the 'query' element of the *Query annotation.
60
	 * Return null if the element does not exist in Java.
61
	 */
62
	String getQuery();
63
		String QUERY_PROPERTY = "query"; //$NON-NLS-1$
64
65
	/**
66
	 * Corresponds to the 'query' element of the *Query annotation.
67
	 * Set to null to remove the element.
68
	 */
69
	void setQuery(String query);
70
71
	/**
72
	 * Return the {@link TextRange} for the 'query' element. If element
73
	 * does not exist return the {@link TextRange} for the *Query annotation.
74
	 */
75
	List<TextRange> getQueryTextRanges();
76
53
77
54
78
	// ********** hints **********
55
	// ********** hints **********
(-)src/org/eclipse/jpt/jpa/ui/internal/details/NamedNativeQueryPropertyComposite.java (-2 / +2 lines)
Lines 13-20 Link Here
13
import org.eclipse.jpt.common.ui.internal.widgets.ClassChooserPane;
13
import org.eclipse.jpt.common.ui.internal.widgets.ClassChooserPane;
14
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
14
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
15
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
15
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
16
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
17
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
16
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
17
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
18
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
18
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
19
import org.eclipse.jpt.jpa.core.context.Query;
19
import org.eclipse.jpt.jpa.core.context.Query;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
Lines 121-127 Link Here
121
	}
121
	}
122
122
123
	private ModifiablePropertyValueModel<String> buildQueryHolder() {
123
	private ModifiablePropertyValueModel<String> buildQueryHolder() {
124
		return new PropertyAspectAdapter<NamedNativeQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
124
		return new PropertyAspectAdapter<NamedNativeQuery, String>(getSubjectHolder(), NamedNativeQuery.QUERY_PROPERTY) {
125
			@Override
125
			@Override
126
			protected String buildValue_() {
126
			protected String buildValue_() {
127
				return this.subject.getQuery();
127
				return this.subject.getQuery();
(-)src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java (-1 / +1 lines)
Lines 83-89 Link Here
83
	}
83
	}
84
84
85
	protected ModifiablePropertyValueModel<String> buildQueryHolder() {
85
	protected ModifiablePropertyValueModel<String> buildQueryHolder() {
86
		return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
86
		return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), NamedQuery.QUERY_PROPERTY) {
87
			@Override
87
			@Override
88
			protected String buildValue_() {
88
			protected String buildValue_() {
89
				return this.subject.getQuery();
89
				return this.subject.getQuery();
(-)src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java (-1 / +2 lines)
Lines 16-21 Link Here
16
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
16
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
17
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
17
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
18
import org.eclipse.jpt.jpa.core.JpaPreferences;
18
import org.eclipse.jpt.jpa.core.JpaPreferences;
19
import org.eclipse.jpt.jpa.core.context.NamedQuery;
19
import org.eclipse.jpt.jpa.core.context.Query;
20
import org.eclipse.jpt.jpa.core.context.Query;
20
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
21
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
21
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
22
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
Lines 91-97 Link Here
91
	}
92
	}
92
93
93
	protected ModifiablePropertyValueModel<String> buildQueryHolder() {
94
	protected ModifiablePropertyValueModel<String> buildQueryHolder() {
94
		return new PropertyAspectAdapter<NamedQuery2_0, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
95
		return new PropertyAspectAdapter<NamedQuery2_0, String>(getSubjectHolder(), NamedQuery.QUERY_PROPERTY) {
95
			@Override
96
			@Override
96
			protected String buildValue_() {
97
			protected String buildValue_() {
97
				return this.subject.getQuery();
98
				return this.subject.getQuery();
(-)src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResource2_1Tests.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.tests.internal.jpa2_1.resource.java;
11
12
import junit.framework.Test;
13
import junit.framework.TestSuite;
14
15
public class JavaResource2_1Tests
16
{
17
18
	public static Test suite() {
19
		TestSuite suite = new TestSuite(JavaResource2_1Tests.class.getPackage().getName());
20
		
21
		suite.addTestSuite(NamedStoredProcedureQuery2_1AnnoationTests.class);
22
		suite.addTestSuite(NamedStoredProcedureQueries2_1AnnotationTests.class);
23
		suite.addTestSuite(StoredProcedureParameter2_1AnnotationTests.class);
24
			
25
		return suite;
26
	}
27
28
	private JavaResource2_1Tests() {
29
		super();
30
		throw new UnsupportedOperationException();
31
	}
32
33
}
(-)src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResourceModel2_1TestCase.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.tests.internal.jpa2_1.resource.java;
11
12
import org.eclipse.jpt.common.core.AnnotationProvider;
13
import org.eclipse.jpt.jpa.core.internal.JpaAnnotationProvider;
14
import org.eclipse.jpt.jpa.core.internal.jpa2_1.Generic2_1JpaAnnotationDefinitionProvider;
15
import org.eclipse.jpt.jpa.core.tests.internal.resource.java.JpaJavaResourceModelTestCase;
16
17
public class JavaResourceModel2_1TestCase
18
	extends JpaJavaResourceModelTestCase
19
{
20
	
21
	
22
	public JavaResourceModel2_1TestCase(String name) {
23
		super(name);
24
	}
25
26
	@Override
27
	protected AnnotationProvider buildAnnotationProvider() {
28
		return new JpaAnnotationProvider(
29
			Generic2_1JpaAnnotationDefinitionProvider.instance());
30
	}
31
32
}
(-)src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationTests.java (+369 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.tests.internal.jpa2_1.resource.java;
11
12
import java.util.Iterator;
13
import java.util.ListIterator;
14
import org.eclipse.jdt.core.ICompilationUnit;
15
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
16
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
17
import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
18
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
19
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annoation;
20
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
21
import org.eclipse.jpt.jpa.core.resource.java.JPA;
22
import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
23
24
public class NamedStoredProcedureQueries2_1AnnotationTests
25
	extends JavaResourceModel2_1TestCase
26
{
27
28
	private static final String QUERY_NAME = "myQuery";
29
	private static final String QUERY_PROCEDURE_NAME = "myProcedure";
30
	
31
	public NamedStoredProcedureQueries2_1AnnotationTests(String name) {
32
		super(name);
33
	}
34
	
35
	private ICompilationUnit createTestNamedStoredProcedureQueries() throws Exception {
36
		return this.createTestType(new DefaultAnnotationWriter() {
37
			@Override
38
			public Iterator<String> imports() {
39
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
40
			}
41
			@Override
42
			public void appendTypeAnnotationTo(StringBuilder sb) {
43
				sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery)");
44
			}
45
		});
46
	}
47
	
48
	private ICompilationUnit createTestNamedStoredProcedureQueryWithName() throws Exception {
49
		return createTestQueryWithStringElement("name", QUERY_NAME);
50
	}
51
	
52
	private ICompilationUnit createTestNamedStoredProcedureQueryWithProcedureName() throws Exception {
53
		return createTestQueryWithStringElement("procedureName", QUERY_PROCEDURE_NAME);
54
	}
55
	
56
	private ICompilationUnit createTestQueryWithStringElement(final String elementName, final String value) throws Exception {
57
		return this.createTestType(new DefaultAnnotationWriter() {
58
			@Override
59
			public Iterator<String> imports() {
60
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
61
			}
62
			@Override
63
			public void appendTypeAnnotationTo(StringBuilder sb) {
64
				sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(" + elementName + " = \"" + value + "\"))");
65
			}
66
		});
67
	}
68
69
	private ICompilationUnit createTestNamedStoredProcedureQueryWithParameters() throws Exception {
70
		return this.createTestType(new DefaultAnnotationWriter() {
71
			@Override
72
			public Iterator<String> imports() {
73
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER, JPA2_1.PARAMETER_MODE);
74
			}
75
			@Override
76
			public void appendTypeAnnotationTo(StringBuilder sb) {
77
				sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\", " +
78
						"mode=ParameterMode.IN, type=Integer.class), @StoredProcedureParameter}))");
79
			}
80
		});
81
	}
82
	
83
	private ICompilationUnit createTestNamedStoredProcedureQueryWithResultClasses() throws Exception {
84
		return this.createTestType(new DefaultAnnotationWriter() {
85
			@Override
86
			public Iterator<String> imports() {
87
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
88
			}
89
			@Override
90
			public void appendTypeAnnotationTo(StringBuilder sb) {
91
				sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(resultClasses={Employee.class, Address.class})");
92
			}
93
		});
94
	}
95
	
96
	private ICompilationUnit createTestNamedStoredProcedureQueryWithResultSetMappings() throws Exception {
97
		return this.createTestType(new DefaultAnnotationWriter() {
98
			@Override
99
			public Iterator<String> imports() {
100
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
101
			}
102
			@Override
103
			public void appendTypeAnnotationTo(StringBuilder sb) {
104
				sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(resultSetMappings={\"EmployeeResultSetMapping\", \"AddressResultSetMapping\"})");
105
			}
106
		});
107
	}
108
	
109
	private ICompilationUnit createTestNamedStoredProcedureQueryWithHints() throws Exception {
110
		return this.createTestType(new DefaultAnnotationWriter() {
111
			@Override
112
			public Iterator<String> imports() {
113
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA.QUERY_HINT);
114
			}
115
			@Override
116
			public void appendTypeAnnotationTo(StringBuilder sb) {
117
				sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint}))");
118
			}
119
		});
120
	}
121
122
	private ICompilationUnit createTestNamedStoredProcedureQuery() throws Exception {
123
		return this.createTestType(new DefaultAnnotationWriter() {
124
			@Override
125
			public Iterator<String> imports() {
126
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA.QUERY_HINT);
127
			}
128
			@Override
129
			public void appendTypeAnnotationTo(StringBuilder sb) {
130
				sb.append("@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"))");
131
			}
132
		});
133
	}
134
135
	public void testNamedStoredProcedureQuery() throws Exception {
136
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
137
		JavaResourceType resourceType = buildJavaResourceType(cu);
138
		
139
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
140
		assertNotNull(namedQuery);
141
	}
142
143
	// ******** name *********
144
	
145
	public void testGetName() throws Exception {
146
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
147
		JavaResourceType resourceType = buildJavaResourceType(cu);
148
		
149
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
150
		assertEquals(QUERY_NAME, namedQuery.getName());
151
	}
152
153
	public void testSetName() throws Exception {
154
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
155
		JavaResourceType resourceType = buildJavaResourceType(cu);
156
		
157
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
158
		assertEquals(QUERY_NAME, namedQuery.getName());
159
		
160
		namedQuery.setName("foo");
161
		assertEquals("foo", namedQuery.getName());
162
		
163
		assertSourceContains("@NamedStoredProcedureQuery(name = \"foo\")", cu);
164
		
165
		namedQuery.setName(null);
166
		assertNull(namedQuery.getName());
167
		
168
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
169
	}
170
171
	// ********** procedure name ************
172
	
173
	public void testGetProcedureName() throws Exception {
174
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithProcedureName();
175
		JavaResourceType resourceType = buildJavaResourceType(cu);
176
		
177
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
178
		assertEquals(QUERY_PROCEDURE_NAME, namedQuery.getProcedureName());
179
	}
180
181
	public void testSetProcedureName() throws Exception {
182
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithProcedureName();
183
		JavaResourceType resourceType = buildJavaResourceType(cu);
184
		
185
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
186
		assertEquals(QUERY_PROCEDURE_NAME, namedQuery.getProcedureName());
187
		
188
		namedQuery.setProcedureName("foo");
189
		assertEquals("foo", namedQuery.getProcedureName());
190
		
191
		assertSourceContains("@NamedStoredProcedureQuery(procedureName = \"foo\")", cu);
192
		
193
		namedQuery.setProcedureName(null);
194
		assertNull(namedQuery.getProcedureName());
195
		
196
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
197
	}
198
199
	// *********** parameters *********
200
	
201
	public void testParameters1() throws Exception {
202
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
203
		JavaResourceType resourceType = buildJavaResourceType(cu);
204
		
205
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
206
		
207
		assertEquals(0, namedQuery.getParametersSize());
208
	}
209
	
210
	public void testParameters2() throws Exception {
211
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
212
		JavaResourceType resourceType = buildJavaResourceType(cu);
213
		
214
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
215
		
216
		assertEquals(2, namedQuery.getParametersSize());
217
		
218
		ListIterator<StoredProcedureParameter2_1Annotation> iterator = namedQuery.getParameters().iterator();
219
		assertEquals("BAR", iterator.next().getName());
220
		assertNull(iterator.next().getName());
221
	}
222
223
	// *********** result classes *******
224
	
225
	public void testResultClasses1() throws Exception {
226
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
227
		JavaResourceType resourceType = buildJavaResourceType(cu);
228
		
229
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
230
		
231
		assertEquals(0, namedQuery.getResultClassesSize());
232
	}
233
	
234
	public void testResultClasses2() throws Exception {
235
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
236
		JavaResourceType resourceType = buildJavaResourceType(cu);
237
		
238
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
239
		
240
		assertEquals(2, namedQuery.getResultClassesSize());
241
		
242
		ListIterator<String> iterator = namedQuery.getResultClasses().iterator();
243
		assertEquals("Employee", iterator.next());
244
		assertEquals("Address", iterator.next());
245
	
246
	}
247
	
248
	// ********** result set mappings ********
249
	
250
	public void testResultSetMappings1() throws Exception {
251
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
252
		JavaResourceType resourceType = buildJavaResourceType(cu);
253
		
254
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
255
		
256
		assertEquals(0, namedQuery.getResultSetMappingsSize());
257
	}
258
	
259
	public void testResultSetMappings2() throws Exception {
260
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
261
		JavaResourceType resourceType = buildJavaResourceType(cu);
262
		
263
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
264
		
265
		assertEquals(2, namedQuery.getResultSetMappingsSize());
266
		
267
		ListIterator<String> iterator = namedQuery.getResultSetMappings().iterator();
268
		assertEquals("EmployeeResultSetMapping", iterator.next());
269
		assertEquals("AddressResultSetMapping", iterator.next());
270
	
271
	}
272
273
	// *********** hints ********
274
	
275
	public void testHints1() throws Exception {
276
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
277
		JavaResourceType resourceType = buildJavaResourceType(cu);
278
		
279
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
280
		
281
		assertEquals(0, namedQuery.getHintsSize());
282
	}
283
	
284
	public void testHints2() throws Exception {
285
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
286
		JavaResourceType resourceType = buildJavaResourceType(cu);
287
		
288
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
289
		
290
		assertEquals(2, namedQuery.getHintsSize());
291
		
292
		ListIterator<QueryHintAnnotation> iterator = namedQuery.getHints().iterator();
293
		assertEquals("BAR", iterator.next().getName());
294
		assertNull(iterator.next().getName());
295
	}
296
	
297
	// ********** other tests ********
298
	
299
	public void testAddNamedQueryCopyExisting() throws Exception {
300
		ICompilationUnit cu = createTestNamedStoredProcedureQuery();
301
		JavaResourceType resourceType = buildJavaResourceType(cu);
302
		
303
		String expected1 = "@NamedStoredProcedureQueries({";
304
		String expected2 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),";
305
		String expected3 = "@NamedStoredProcedureQuery(name = \"BAR\") })";
306
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.addAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
307
		namedQuery.setName("BAR");
308
		assertSourceContains(expected1, cu);
309
		assertSourceContains(expected2, cu);
310
		assertSourceContains(expected3, cu);
311
		
312
		assertNull(resourceType.getAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
313
		assertNotNull(resourceType.getContainerAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES));
314
		assertNotNull(resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
315
		assertEquals(2, resourceType.getAnnotationsSize(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
316
	}
317
	
318
	public void testAddNamedQueryToBeginningOfList() throws Exception {
319
		ICompilationUnit cu = createTestNamedStoredProcedureQuery();
320
		JavaResourceType resourceType = buildJavaResourceType(cu);
321
		
322
		String expected1 = "@NamedStoredProcedureQueries({";
323
		String expected2 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),";
324
		String expected3 = "@NamedStoredProcedureQuery(name = \"BAR\") })";
325
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.addAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
326
		namedQuery.setName("BAR");
327
		assertSourceContains(expected1, cu);
328
		assertSourceContains(expected2, cu);
329
		assertSourceContains(expected3, cu);
330
		
331
		expected2 = "@NamedStoredProcedureQuery(name = \"BAZ\"),";
332
		expected3 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")), @NamedStoredProcedureQuery(name = \"BAR\") })";
333
		namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.addAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
334
		namedQuery.setName("BAZ");
335
		assertSourceContains(expected1, cu);
336
		assertSourceContains(expected2, cu);
337
		assertSourceContains(expected3, cu);
338
339
		Iterator<NestableAnnotation> namedQueries = resourceType.getAnnotations(JPA2_1.NAMED_STORED_PROCEDURE_QUERY).iterator();
340
		assertEquals("BAZ", ((NamedStoredProcedureQuery2_1Annoation) namedQueries.next()).getName());
341
		assertEquals("foo", ((NamedStoredProcedureQuery2_1Annoation) namedQueries.next()).getName());
342
		assertEquals("BAR", ((NamedStoredProcedureQuery2_1Annoation) namedQueries.next()).getName());
343
344
		assertNull(resourceType.getAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
345
		assertNotNull(resourceType.getContainerAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES));
346
		assertNotNull(resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
347
		assertEquals(3, resourceType.getAnnotationsSize(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
348
	}
349
350
	public void testRemoveNamedQueryCopyExisting() throws Exception {
351
		ICompilationUnit cu = createTestNamedStoredProcedureQuery();
352
		JavaResourceType resourceType = buildJavaResourceType(cu);
353
		
354
		String expected1 = "@NamedStoredProcedureQueries({";
355
		String expected2 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),";
356
		String expected3 = "@NamedStoredProcedureQuery(name = \"BAR\") })";
357
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.addAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
358
		namedQuery.setName("BAR");
359
		assertSourceContains(expected1, cu);
360
		assertSourceContains(expected2, cu);
361
		assertSourceContains(expected3, cu);
362
		
363
		expected1 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"))";
364
		resourceType.removeAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
365
		assertSourceContains(expected1, cu);
366
		assertSourceDoesNotContain("@NamedStoredProcedureQueries", cu);
367
	}
368
369
}
(-)src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnoationTests.java (+722 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.tests.internal.jpa2_1.resource.java;
11
12
import java.util.Iterator;
13
import java.util.ListIterator;
14
import org.eclipse.jdt.core.ICompilationUnit;
15
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
16
import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
17
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
18
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annoation;
19
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
20
import org.eclipse.jpt.jpa.core.resource.java.JPA;
21
import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
22
23
public class NamedStoredProcedureQuery2_1AnnoationTests
24
	extends JavaResourceModel2_1TestCase
25
{
26
27
	private static final String QUERY_NAME = "myQuery";
28
	private static final String PROCEDURE_NAME = "myProcedure";
29
30
	public NamedStoredProcedureQuery2_1AnnoationTests(String name) {
31
		super(name);
32
		}
33
	
34
	private ICompilationUnit createTestNamedStoredProcedureQuery() throws Exception {
35
		return this.createTestType(new DefaultAnnotationWriter() {
36
			@Override
37
			public Iterator<String> imports() {
38
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
39
			}
40
			@Override
41
			public void appendTypeAnnotationTo(StringBuilder sb) {
42
				sb.append("@NamedStoredProcedureQuery");
43
			}
44
		});
45
	}
46
	
47
	private ICompilationUnit createTestNamedStoredProcedureQueryWithName() throws Exception {
48
		return createTestNamedStoredProcedureQueryWithStringElement("name", QUERY_NAME);
49
	}
50
	
51
	private ICompilationUnit createTestNamedNativeQueryWithProcedureName() throws Exception {
52
		return createTestNamedStoredProcedureQueryWithStringElement("procedureName", PROCEDURE_NAME);
53
	}
54
	
55
56
	private ICompilationUnit createTestNamedStoredProcedureQueryWithStringElement(final String elementName, final String value) throws Exception {
57
		return this.createTestType(new DefaultAnnotationWriter() {
58
			@Override
59
			public Iterator<String> imports() {
60
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
61
			}
62
			@Override
63
			public void appendTypeAnnotationTo(StringBuilder sb) {
64
				sb.append("@NamedStoredProcedureQuery(" + elementName + " = \"" + value + "\")");
65
			}
66
		});
67
	}
68
69
	private ICompilationUnit createTestNamedStoredProcedureQueryWithParameters() throws Exception {
70
		return this.createTestType(new DefaultAnnotationWriter() {
71
			@Override
72
			public Iterator<String> imports() {
73
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER, JPA2_1.PARAMETER_MODE);
74
			}
75
			@Override
76
			public void appendTypeAnnotationTo(StringBuilder sb) {
77
				sb.append("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\", " +
78
						"mode=ParameterMode.IN, type=Integer.class), @StoredProcedureParameter})");
79
			}
80
		});
81
	}
82
83
	private ICompilationUnit createTestNamedStoredProcedureQueryWithResultClasses() throws Exception {
84
		return this.createTestType(new DefaultAnnotationWriter() {
85
			@Override
86
			public Iterator<String> imports() {
87
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
88
			}
89
			@Override
90
			public void appendTypeAnnotationTo(StringBuilder sb) {
91
				sb.append("@NamedStoredProcedureQuery(resultClasses = { Employee.class, Address.class })");
92
			}
93
		});
94
	}
95
	
96
	private ICompilationUnit createTestNamedStoredProcedureQueryWithResultSetMappings() throws Exception {
97
		return this.createTestType(new DefaultAnnotationWriter() {
98
			@Override
99
			public Iterator<String> imports() {
100
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
101
			}
102
			@Override
103
			public void appendTypeAnnotationTo(StringBuilder sb) {
104
				sb.append("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"AddrRSMapping\" })");
105
			}
106
		});
107
	}
108
109
	private ICompilationUnit createTestNamedStoredProcedureQueryWithHints() throws Exception {
110
		return this.createTestType(new DefaultAnnotationWriter() {
111
			@Override
112
			public Iterator<String> imports() {
113
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA.QUERY_HINT);
114
			}
115
			@Override
116
			public void appendTypeAnnotationTo(StringBuilder sb) {
117
				sb.append("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint})");
118
			}
119
		});
120
	}
121
122
	public void testNamedStoredProcedureQuery() throws Exception {
123
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
124
		JavaResourceType resourceType = buildJavaResourceType(cu);
125
		
126
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
127
		assertNotNull(namedQuery);
128
	}
129
130
	// ************ name ***********
131
	
132
	public void testGetName() throws Exception {
133
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
134
		JavaResourceType resourceType = buildJavaResourceType(cu);
135
		
136
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
137
		assertEquals(QUERY_NAME, namedQuery.getName());
138
	}
139
140
	public void testSetName() throws Exception {
141
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
142
		JavaResourceType resourceType = buildJavaResourceType(cu);
143
		
144
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
145
		assertEquals(QUERY_NAME, namedQuery.getName());
146
		
147
		namedQuery.setName("foo");
148
		assertEquals("foo", namedQuery.getName());
149
		
150
		assertSourceContains("@NamedStoredProcedureQuery(name = \"foo\")", cu);
151
		
152
		namedQuery.setName(null);
153
		assertNull(namedQuery.getName());
154
		
155
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
156
	}
157
158
	// ************ procedure name ***************
159
	
160
	public void testGetProcedureName() throws Exception {
161
		ICompilationUnit cu = this.createTestNamedNativeQueryWithProcedureName();
162
		JavaResourceType resourceType = buildJavaResourceType(cu);
163
		
164
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
165
		assertEquals(PROCEDURE_NAME, namedQuery.getProcedureName());
166
	}
167
168
	public void testSetProcedureName() throws Exception {
169
		ICompilationUnit cu = this.createTestNamedNativeQueryWithProcedureName();
170
		JavaResourceType resourceType = buildJavaResourceType(cu);
171
		
172
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
173
		assertEquals(PROCEDURE_NAME, namedQuery.getProcedureName());
174
		
175
		namedQuery.setProcedureName("foo");
176
		assertEquals("foo", namedQuery.getProcedureName());
177
		
178
		assertSourceContains("@NamedStoredProcedureQuery(procedureName = \"foo\")", cu);
179
		
180
		namedQuery.setProcedureName(null);
181
		assertNull(namedQuery.getProcedureName());
182
		
183
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
184
	}
185
	
186
	// ************ parameters *********
187
	
188
	public void testParameters1() throws Exception {
189
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
190
		JavaResourceType resourceType = buildJavaResourceType(cu);
191
		
192
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
193
		
194
		assertEquals(0, namedQuery.getParametersSize());
195
	}
196
	
197
	public void testParameters2() throws Exception {
198
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
199
		JavaResourceType resourceType = buildJavaResourceType(cu);
200
		
201
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
202
		
203
		namedQuery.addParameter(0);
204
		namedQuery.addParameter(1);
205
		
206
		assertEquals(2, namedQuery.getParametersSize());
207
	}
208
	
209
	public void testParameters3() throws Exception {
210
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
211
		JavaResourceType resourceType = buildJavaResourceType(cu);
212
		
213
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
214
		
215
		assertEquals(2, namedQuery.getParametersSize());
216
		
217
		ListIterator<StoredProcedureParameter2_1Annotation> iterator = namedQuery.getParameters().iterator();
218
		assertEquals("BAR", iterator.next().getName());
219
		assertNull(iterator.next().getName());
220
	}
221
	
222
	public void testAddParameter() throws Exception {
223
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
224
		JavaResourceType resourceType = buildJavaResourceType(cu);
225
		
226
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
227
		
228
		namedQuery.addParameter(0).setName("FOO");
229
		namedQuery.addParameter(1);
230
		namedQuery.addParameter(0).setName("BAR");
231
232
		assertEquals("BAR", namedQuery.parameterAt(0).getName());
233
		assertEquals("FOO", namedQuery.parameterAt(1).getName());
234
		assertNull(namedQuery.parameterAt(2).getName());
235
		assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\")," +
236
				"@StoredProcedureParameter(name = \"FOO\"), @StoredProcedureParameter})", cu);
237
	}
238
	
239
	public void testRemoveParameter() throws Exception {
240
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
241
		JavaResourceType resourceType = buildJavaResourceType(cu);
242
		
243
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
244
245
		namedQuery.addParameter(0).setName("BAZ");
246
		
247
		assertEquals("BAZ", namedQuery.parameterAt(0).getName());
248
		assertEquals("BAR", namedQuery.parameterAt(1).getName());
249
		assertNull(namedQuery.parameterAt(2).getName());
250
		assertEquals(3, namedQuery.getParametersSize());
251
		
252
		namedQuery.removeParameter(2);
253
		assertEquals("BAZ", namedQuery.parameterAt(0).getName());
254
		assertEquals("BAR", namedQuery.parameterAt(1).getName());
255
		assertEquals(2, namedQuery.getParametersSize());
256
		assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAZ\"), " +
257
				"@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class)})", cu);
258
		
259
		namedQuery.removeParameter(0);
260
		assertEquals("BAR", namedQuery.parameterAt(0).getName());
261
		assertEquals(1, namedQuery.getParametersSize());
262
		assertSourceContains("@NamedStoredProcedureQuery(parameters = " +
263
				"@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class))", cu);
264
		
265
		namedQuery.removeParameter(0);
266
		assertEquals(0, namedQuery.getParametersSize());
267
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
268
	}
269
	
270
	public void testMoveParameter1() throws Exception {
271
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
272
		JavaResourceType resourceType = buildJavaResourceType(cu);
273
		
274
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
275
		
276
		namedQuery.addParameter(0).setName("BAZ");
277
		
278
		assertEquals("BAZ", namedQuery.parameterAt(0).getName());
279
		assertEquals("BAR", namedQuery.parameterAt(1).getName());
280
		assertNull(namedQuery.parameterAt(2).getName());
281
		assertEquals(3, namedQuery.getParametersSize());
282
	
283
		namedQuery.moveParameter(2, 0);
284
		
285
		assertEquals("BAR", namedQuery.parameterAt(0).getName());
286
		assertNull(namedQuery.parameterAt(1).getName());
287
		assertEquals("BAZ", namedQuery.parameterAt(2).getName());
288
		assertEquals(3, namedQuery.getParametersSize());
289
		assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class), " +
290
				"@StoredProcedureParameter, @StoredProcedureParameter(name = \"BAZ\")})", cu);
291
	}
292
	
293
	public void testMoveParameter2() throws Exception {
294
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
295
		JavaResourceType resourceType = buildJavaResourceType(cu);
296
		
297
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
298
		namedQuery.addParameter(0).setName("BAZ");
299
		
300
		assertEquals("BAZ", namedQuery.parameterAt(0).getName());
301
		assertEquals("BAR", namedQuery.parameterAt(1).getName());
302
		assertNull(namedQuery.parameterAt(2).getName());
303
		assertEquals(3, namedQuery.getParametersSize());
304
	
305
		namedQuery.moveParameter(0, 2);
306
		
307
		assertNull(namedQuery.parameterAt(0).getName());
308
		assertEquals("BAZ", namedQuery.parameterAt(1).getName());
309
		assertEquals("BAR", namedQuery.parameterAt(2).getName());
310
		assertEquals(3, namedQuery.getParametersSize());
311
		assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter, @StoredProcedureParameter(name = \"BAZ\"), " +
312
				"@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class)})", cu);
313
	}
314
	
315
	// ************ result classes *********
316
	
317
	public void testResultClasses1() throws Exception {
318
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
319
		JavaResourceType resourceType = buildJavaResourceType(cu);
320
		
321
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
322
		
323
		assertEquals(0, namedQuery.getResultClassesSize());
324
	}
325
	
326
	public void testResultClasses2() throws Exception {
327
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
328
		JavaResourceType resourceType = buildJavaResourceType(cu);
329
		
330
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
331
		
332
		assertEquals(2, namedQuery.getResultClassesSize());
333
		
334
		ListIterator<String> iterator = namedQuery.getResultClasses().iterator();
335
		assertEquals("Employee", iterator.next());
336
		assertEquals("Address", iterator.next());
337
	}
338
	
339
	public void testAddResultClass() throws Exception {
340
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
341
		JavaResourceType resourceType = buildJavaResourceType(cu);
342
		
343
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
344
		
345
		namedQuery.addResultClass("Project");
346
		namedQuery.addResultClass("Phone");
347
		
348
		assertEquals(2, namedQuery.getResultClassesSize());
349
350
		assertEquals("Project", namedQuery.resultClassAt(0));
351
		assertEquals("Phone", namedQuery.resultClassAt(1));
352
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Project.class, Phone.class })", cu);
353
	}
354
	
355
	public void testRemoveResultClass1() throws Exception {
356
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
357
		JavaResourceType resourceType = buildJavaResourceType(cu);
358
		
359
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
360
361
		namedQuery.addResultClass("Project");
362
		
363
		assertEquals("Employee", namedQuery.resultClassAt(0));
364
		assertEquals("Address", namedQuery.resultClassAt(1));
365
		assertEquals("Project", namedQuery.resultClassAt(2));
366
		assertEquals(3, namedQuery.getResultClassesSize());
367
		
368
		namedQuery.removeResultClass(1);
369
		assertEquals("Employee", namedQuery.resultClassAt(0));
370
		assertEquals("Project", namedQuery.resultClassAt(1));
371
		assertEquals(2, namedQuery.getResultClassesSize());
372
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Employee.class, Project.class })", cu);
373
		
374
		namedQuery.removeResultClass(0);
375
		assertEquals("Project", namedQuery.resultClassAt(0));
376
		assertEquals(1, namedQuery.getResultClassesSize());
377
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = Project.class)", cu);
378
		
379
		namedQuery.removeResultClass(0);
380
		assertEquals(0, namedQuery.getResultClassesSize());
381
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
382
	}
383
	
384
	public void testRemoveResultClass2() throws Exception {
385
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
386
		JavaResourceType resourceType = buildJavaResourceType(cu);
387
		
388
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
389
390
		namedQuery.addResultClass("Project");
391
		
392
		assertEquals("Employee", namedQuery.resultClassAt(0));
393
		assertEquals("Address", namedQuery.resultClassAt(1));
394
		assertEquals("Project", namedQuery.resultClassAt(2));
395
		assertEquals(3, namedQuery.getResultClassesSize());
396
		
397
		namedQuery.removeResultClass("Address");
398
		assertEquals("Employee", namedQuery.resultClassAt(0));
399
		assertEquals("Project", namedQuery.resultClassAt(1));
400
		assertEquals(2, namedQuery.getResultClassesSize());
401
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Employee.class, Project.class })", cu);
402
		
403
		namedQuery.removeResultClass("Employee");
404
		assertEquals("Project", namedQuery.resultClassAt(0));
405
		assertEquals(1, namedQuery.getResultClassesSize());
406
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = Project.class)", cu);
407
		
408
		namedQuery.removeResultClass("Project");
409
		assertEquals(0, namedQuery.getResultClassesSize());
410
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
411
	}
412
	
413
	public void testMoveResultClass1() throws Exception {
414
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
415
		JavaResourceType resourceType = buildJavaResourceType(cu);
416
		
417
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
418
		
419
		namedQuery.addResultClass("Project");
420
		
421
		assertEquals("Employee", namedQuery.resultClassAt(0));
422
		assertEquals("Address", namedQuery.resultClassAt(1));
423
		assertEquals("Project", namedQuery.resultClassAt(2));
424
		assertEquals(3, namedQuery.getResultClassesSize());
425
	
426
		namedQuery.moveResultClass(2, 0);
427
		
428
		assertEquals("Address", namedQuery.resultClassAt(0));
429
		assertEquals("Project", namedQuery.resultClassAt(1));
430
		assertEquals("Employee", namedQuery.resultClassAt(2));
431
		assertEquals(3, namedQuery.getResultClassesSize());
432
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Address.class, Project.class, Employee.class })", cu);
433
	}
434
	
435
	public void testMoveResultClass2() throws Exception {
436
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
437
		JavaResourceType resourceType = buildJavaResourceType(cu);
438
		
439
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
440
		namedQuery.addResultClass("Project");
441
		
442
		assertEquals("Employee", namedQuery.resultClassAt(0));
443
		assertEquals("Address", namedQuery.resultClassAt(1));
444
		assertEquals("Project", namedQuery.resultClassAt(2));
445
		assertEquals(3, namedQuery.getResultClassesSize());
446
	
447
		namedQuery.moveResultClass(0, 2);
448
		
449
		assertEquals("Project", namedQuery.resultClassAt(0));
450
		assertEquals("Employee", namedQuery.resultClassAt(1));
451
		assertEquals("Address", namedQuery.resultClassAt(2));
452
		assertEquals(3, namedQuery.getResultClassesSize());
453
		assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Project.class, Employee.class, Address.class })", cu);
454
	}
455
	
456
	
457
	// ************ result set mappings *********
458
	
459
	public void testResultSetMappings1() throws Exception {
460
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
461
		JavaResourceType resourceType = buildJavaResourceType(cu);
462
		
463
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
464
		
465
		assertEquals(0, namedQuery.getResultSetMappingsSize());
466
	}
467
	
468
	public void testResultSetMappings2() throws Exception {
469
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
470
		JavaResourceType resourceType = buildJavaResourceType(cu);
471
		
472
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
473
		
474
		assertEquals(2, namedQuery.getResultSetMappingsSize());
475
		
476
		ListIterator<String> iterator = namedQuery.getResultSetMappings().iterator();
477
		assertEquals("EmpRSMapping", iterator.next());
478
		assertEquals("AddrRSMapping", iterator.next());
479
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"AddrRSMapping\" })", cu);
480
	}
481
	
482
	public void testAddResultSetMapping() throws Exception {
483
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
484
		JavaResourceType resourceType = buildJavaResourceType(cu);
485
		
486
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
487
		
488
		namedQuery.addResultSetMapping("ProjRSMapping");
489
		namedQuery.addResultSetMapping("PhRSMapping");
490
		
491
		assertEquals(2, namedQuery.getResultSetMappingsSize());
492
493
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
494
		assertEquals("PhRSMapping", namedQuery.resultSetMappingAt(1));
495
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"ProjRSMapping\", \"PhRSMapping\" })", cu);
496
	}
497
	
498
	public void testRemoveResultSetMapping1() throws Exception {
499
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
500
		JavaResourceType resourceType = buildJavaResourceType(cu);
501
		
502
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
503
		
504
		namedQuery.addResultSetMapping("ProjRSMapping");
505
		
506
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
507
		assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
508
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
509
		assertEquals(3, namedQuery.getResultSetMappingsSize());
510
		
511
		namedQuery.removeResultSetMapping(1);
512
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
513
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(1));
514
		assertEquals(2, namedQuery.getResultSetMappingsSize());
515
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"ProjRSMapping\" })", cu);
516
		
517
		namedQuery.removeResultSetMapping(0);
518
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
519
		assertEquals(1, namedQuery.getResultSetMappingsSize());
520
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = \"ProjRSMapping\")", cu);
521
		
522
		namedQuery.removeResultSetMapping(0);
523
		assertEquals(0, namedQuery.getResultSetMappingsSize());
524
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
525
	}
526
	
527
	public void testRemoveResultSetMapping2() throws Exception {
528
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
529
		JavaResourceType resourceType = buildJavaResourceType(cu);
530
		
531
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
532
		
533
		namedQuery.addResultSetMapping("ProjRSMapping");
534
		
535
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
536
		assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
537
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
538
		assertEquals(3, namedQuery.getResultSetMappingsSize());
539
		
540
		namedQuery.removeResultSetMapping("AddrRSMapping");
541
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
542
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(1));
543
		assertEquals(2, namedQuery.getResultSetMappingsSize());
544
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"ProjRSMapping\" })", cu);
545
		
546
		namedQuery.removeResultSetMapping("EmpRSMapping");
547
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
548
		assertEquals(1, namedQuery.getResultSetMappingsSize());
549
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = \"ProjRSMapping\")", cu);
550
		
551
		namedQuery.removeResultSetMapping("ProjRSMapping");
552
		assertEquals(0, namedQuery.getResultSetMappingsSize());
553
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
554
	}
555
	public void testMoveResultSetMapping1() throws Exception {
556
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
557
		JavaResourceType resourceType = buildJavaResourceType(cu);
558
		
559
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
560
		
561
		namedQuery.addResultSetMapping("ProjRSMapping");
562
		
563
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
564
		assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
565
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
566
		assertEquals(3, namedQuery.getResultSetMappingsSize());
567
	
568
		namedQuery.moveResultSetMapping(2, 0);
569
		
570
		assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(0));
571
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(1));
572
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(2));
573
		assertEquals(3, namedQuery.getResultSetMappingsSize());
574
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"AddrRSMapping\", \"ProjRSMapping\", \"EmpRSMapping\" })", cu);
575
	}
576
	
577
	public void testMoveResultSetMapping2() throws Exception {
578
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
579
		JavaResourceType resourceType = buildJavaResourceType(cu);
580
		
581
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
582
		namedQuery.addResultSetMapping("ProjRSMapping");
583
		
584
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
585
		assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
586
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
587
		assertEquals(3, namedQuery.getResultSetMappingsSize());
588
	
589
		namedQuery.moveResultSetMapping(0, 2);
590
		
591
		assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
592
		assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(1));
593
		assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(2));
594
		assertEquals(3, namedQuery.getResultSetMappingsSize());
595
		assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"ProjRSMapping\", \"EmpRSMapping\", \"AddrRSMapping\" })", cu);
596
		}
597
598
	// *********** hints ************
599
	
600
	public void testHints1() throws Exception {
601
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
602
		JavaResourceType resourceType = buildJavaResourceType(cu);
603
		
604
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
605
		
606
		assertEquals(0, namedQuery.getHintsSize());
607
	}
608
	
609
	public void testHints2() throws Exception {
610
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
611
		JavaResourceType resourceType = buildJavaResourceType(cu);
612
		
613
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
614
		
615
		namedQuery.addHint(0);
616
		namedQuery.addHint(1);
617
		
618
		assertEquals(2, namedQuery.getHintsSize());
619
	}
620
	
621
	public void testHints3() throws Exception {
622
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
623
		JavaResourceType resourceType = buildJavaResourceType(cu);
624
		
625
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
626
		
627
		assertEquals(2, namedQuery.getHintsSize());
628
		
629
		ListIterator<QueryHintAnnotation> iterator = namedQuery.getHints().iterator();
630
		assertEquals("BAR", iterator.next().getName());
631
		assertNull(iterator.next().getName());
632
	}
633
	
634
	public void testAddHint() throws Exception {
635
		ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
636
		JavaResourceType resourceType = buildJavaResourceType(cu);
637
		
638
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
639
		
640
		namedQuery.addHint(0).setName("FOO");
641
		namedQuery.addHint(1);
642
		namedQuery.addHint(0).setName("BAR");
643
644
		assertEquals("BAR", namedQuery.hintAt(0).getName());
645
		assertEquals("FOO", namedQuery.hintAt(1).getName());
646
		assertNull(namedQuery.hintAt(2).getName());
647
		assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\"),@QueryHint(name = \"FOO\"), @QueryHint})", cu);
648
	}
649
	
650
	public void testRemoveHint() throws Exception {
651
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
652
		JavaResourceType resourceType = buildJavaResourceType(cu);
653
		
654
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
655
		namedQuery.addHint(0).setName("BAZ");
656
		
657
		assertEquals("BAZ", namedQuery.hintAt(0).getName());
658
		assertEquals("BAR", namedQuery.hintAt(1).getName());
659
		assertNull(namedQuery.hintAt(2).getName());
660
		assertEquals(3, namedQuery.getHintsSize());
661
		
662
		namedQuery.removeHint(2);
663
		assertEquals("BAZ", namedQuery.hintAt(0).getName());
664
		assertEquals("BAR", namedQuery.hintAt(1).getName());
665
		assertEquals(2, namedQuery.getHintsSize());
666
		assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu);
667
		
668
		namedQuery.removeHint(0);
669
		assertEquals("BAR", namedQuery.hintAt(0).getName());
670
		assertEquals(1, namedQuery.getHintsSize());
671
		assertSourceContains("@NamedStoredProcedureQuery(hints = @QueryHint(name = \"BAR\", value = \"FOO\"))", cu);
672
		
673
	
674
		namedQuery.removeHint(0);
675
		assertEquals(0, namedQuery.getHintsSize());
676
		assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
677
	}
678
	
679
	public void testMoveHint1() throws Exception {
680
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
681
		JavaResourceType resourceType = buildJavaResourceType(cu);
682
		
683
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
684
		
685
		namedQuery.addHint(0).setName("BAZ");
686
		
687
		assertEquals("BAZ", namedQuery.hintAt(0).getName());
688
		assertEquals("BAR", namedQuery.hintAt(1).getName());
689
		assertNull(namedQuery.hintAt(2).getName());
690
		assertEquals(3, namedQuery.getHintsSize());
691
	
692
		namedQuery.moveHint(2, 0);
693
		
694
		assertEquals("BAR", namedQuery.hintAt(0).getName());
695
		assertNull(namedQuery.hintAt(1).getName());
696
		assertEquals("BAZ", namedQuery.hintAt(2).getName());
697
		assertEquals(3, namedQuery.getHintsSize());
698
		assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint, @QueryHint(name = \"BAZ\")})", cu);
699
	}
700
	
701
	public void testMoveHint2() throws Exception {
702
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
703
		JavaResourceType resourceType = buildJavaResourceType(cu);
704
		
705
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
706
		namedQuery.addHint(0).setName("BAZ");
707
		
708
		assertEquals("BAZ", namedQuery.hintAt(0).getName());
709
		assertEquals("BAR", namedQuery.hintAt(1).getName());
710
		assertNull(namedQuery.hintAt(2).getName());
711
		assertEquals(3, namedQuery.getHintsSize());
712
	
713
		namedQuery.moveHint(0, 2);
714
		
715
		assertNull(namedQuery.hintAt(0).getName());
716
		assertEquals("BAZ", namedQuery.hintAt(1).getName());
717
		assertEquals("BAR", namedQuery.hintAt(2).getName());
718
		assertEquals(3, namedQuery.getHintsSize());
719
		assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint, @QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu);
720
	}
721
	
722
}
(-)src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/StoredProcedureParameter2_1AnnotationTests.java (+153 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6
 * 
7
 * Contributors:
8
 *     Oracle - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.tests.internal.jpa2_1.resource.java;
11
12
import java.util.Iterator;
13
import org.eclipse.jdt.core.ICompilationUnit;
14
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
15
import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
16
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
17
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annoation;
18
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.ParameterMode2_1;
19
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
20
21
public class StoredProcedureParameter2_1AnnotationTests
22
	extends JavaResourceModel2_1TestCase
23
{
24
25
	public StoredProcedureParameter2_1AnnotationTests(String name) {
26
		super(name);
27
	}
28
	
29
	private ICompilationUnit createTestNamedStoredProcedureQueryWithParameters() throws Exception {
30
		return this.createTestType(new DefaultAnnotationWriter() {
31
			@Override
32
			public Iterator<String> imports() {
33
				return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER, JPA2_1.PARAMETER_MODE);
34
			}
35
			@Override
36
			public void appendTypeAnnotationTo(StringBuilder sb) {
37
				sb.append("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN, type = MyType.class), @StoredProcedureParameter})");
38
			}
39
		});
40
	}
41
42
	public void testNamedStoredProcedureQueryWithParameters() throws Exception {
43
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
44
		JavaResourceType resourceType = buildJavaResourceType(cu); 
45
		
46
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
47
		assertEquals(2, namedQuery.getParametersSize());
48
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
49
		assertEquals("MyParameter", parameter.getName());
50
		parameter = namedQuery.parameterAt(1);
51
		assertNull(parameter.getName());
52
	}
53
	
54
	// ******** name *********
55
	
56
	public void testGetName() throws Exception {
57
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
58
		JavaResourceType resourceType = buildJavaResourceType(cu); 
59
		
60
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
61
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
62
		assertEquals("MyParameter", parameter.getName());
63
	}
64
65
	public void testSetName() throws Exception {
66
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
67
		JavaResourceType resourceType = buildJavaResourceType(cu); 
68
		
69
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
70
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
71
		assertEquals("MyParameter", parameter.getName());
72
		
73
		parameter.setName("foo");
74
		assertEquals("foo", parameter.getName());
75
		
76
		assertSourceContains("@StoredProcedureParameter(name = \"foo\", mode = ParameterMode.IN, type = MyType.class)", cu);
77
	}
78
	
79
	// ******* mode *********
80
	
81
	public void testGetMode() throws Exception {
82
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
83
		JavaResourceType resourceType = buildJavaResourceType(cu); 
84
		
85
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
86
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
87
		assertEquals(ParameterMode2_1.IN, parameter.getMode());
88
	}
89
90
	public void testSetMode() throws Exception {
91
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
92
		JavaResourceType resourceType = buildJavaResourceType(cu); 
93
		
94
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
95
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
96
		assertEquals(ParameterMode2_1.IN, parameter.getMode());
97
		
98
		parameter.setMode(ParameterMode2_1.INOUT);
99
		assertEquals(ParameterMode2_1.INOUT, parameter.getMode());
100
		assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = INOUT, type = MyType.class)", cu);
101
	
102
		parameter.setMode(null);
103
		assertNull(parameter.getMode());
104
		assertSourceDoesNotContain("mode", cu);
105
		assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", type = MyType.class)", cu);
106
	}
107
108
	// ******* type *********
109
	public void testGetType() throws Exception {
110
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
111
		JavaResourceType resourceType = buildJavaResourceType(cu);
112
		
113
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
114
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
115
116
		assertEquals("MyType", parameter.getType());
117
	}
118
119
	public void testSetType() throws Exception {
120
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
121
		JavaResourceType resourceType = buildJavaResourceType(cu);
122
		
123
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
124
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
125
126
		assertEquals("MyType", parameter.getType());
127
		
128
		parameter.setType("Foo");
129
		assertEquals("Foo", parameter.getType());	
130
		assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN, type = Foo.class", cu);
131
		
132
		parameter.setType(null);
133
		assertNull(parameter.getType());
134
		assertSourceDoesNotContain("type", cu);
135
		assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN", cu);
136
	}
137
138
	public void testGetFullyQualifiedClass() throws Exception {
139
		ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
140
		JavaResourceType resourceType = buildJavaResourceType(cu);
141
142
		NamedStoredProcedureQuery2_1Annoation namedQuery = (NamedStoredProcedureQuery2_1Annoation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
143
		StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
144
145
		assertNotNull(parameter.getType());
146
		assertEquals("MyType", parameter.getFullyQualifiedTypeName());
147
148
		parameter.setType(TYPE_NAME);		
149
		
150
		assertEquals(FULLY_QUALIFIED_TYPE_NAME, parameter.getFullyQualifiedTypeName());				
151
		assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN, type = " + TYPE_NAME + ".class)", cu);
152
	}
153
}

Return to bug 392701