Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 337930 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+2 lines)
Lines 25-30 Link Here
25
 org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)",
25
 org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)",
26
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
26
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
27
 org.eclipse.jst.j2ee.core;bundle-version="[1.1.200,2.0.0)",
27
 org.eclipse.jst.j2ee.core;bundle-version="[1.1.200,2.0.0)",
28
 org.eclipse.persistence.utils.jpa.query;bundle-version="1.0.0",
28
 org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
29
 org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
29
 org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)",
30
 org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)",
30
 org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
31
 org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
Lines 62-67 Link Here
62
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java;x-internal:=true,
63
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java;x-internal:=true,
63
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.binary;x-internal:=true,
64
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.binary;x-internal:=true,
64
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.source;x-internal:=true,
65
 org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.source;x-internal:=true,
66
 org.eclipse.jpt.jpa.core.internal.jpql;x-friends:="org.eclipse.jpt.jpa.ui",
65
 org.eclipse.jpt.jpa.core.internal.libprov;x-internal:=true,
67
 org.eclipse.jpt.jpa.core.internal.libprov;x-internal:=true,
66
 org.eclipse.jpt.jpa.core.internal.libval;x-internal:=true,
68
 org.eclipse.jpt.jpa.core.internal.libval;x-internal:=true,
67
 org.eclipse.jpt.jpa.core.internal.operations;x-internal:=true,
69
 org.eclipse.jpt.jpa.core.internal.operations;x-internal:=true,
(-)property_files/jpa_jpql_validation.properties (+481 lines)
Added Link Here
1
################################################################################
2
# Copyright (c) 2011 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
11
// AbsExpression - Grammar
12
ABS_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
13
ABS_EXPRESSION_MISSING_EXPRESSION = The encapsulated expression must be provided for an ABS expression.
14
ABS_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the ABS expression.
15
ABS_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the ABS expression.
16
// AbsExpression - Semantic
17
ABS_EXPRESSION_INVALID_NUMERIC_EXPRESSION = The encapsulated expression is not a valid numeric expression.
18
19
// AbstractFromClause - Grammar
20
ABSTRACT_FROM_CLAUSE_IDENTIFICATION_VARIABLE_DECLARATION_ENDS_WITH_COMMA = The FROM clause cannot end with a comma.
21
ABSTRACT_FROM_CLAUSE_IDENTIFICATION_VARIABLE_DECLARATION_IS_MISSING_COMMA = The FROM clause has ''{0}'' and ''{1}'' that are not separated by a comma.
22
ABSTRACT_FROM_CLAUSE_MISSING_IDENTIFICATION_VARIABLE_DECLARATION = The FROM clause must defined at least one identification variable declaration.
23
ABSTRACT_FROM_CLAUSE_WRONG_ORDER_OF_IDENTIFICATION_VARIABLE_DECLARATION = The identification variable ''{0}'' is declared after its usage. Identification variables are evaluated from left to right.
24
25
// AbstractPathExpression - Grammar
26
ABSTRACT_PATH_EXPRESSION_CANNOT_END_WITH_COMMA = A path expression cannot end with a comma.
27
ABSTRACT_PATH_EXPRESSION_MISSING_IDENTIFICATION_VARIABLE = A path expression must start with an identification variable.
28
29
// AbstractSchemaName - Grammar
30
ABSTRACT_SCHEMA_NAME_INVALID = The abstract schema type ''{0}'' is unknown.
31
ABSTRACT_SCHEMA_NAME_NOT_RESOLVABLE = ''{0}'' cannot be resolved to a type.
32
// AbstractSchemaName - Semantic
33
PATH_EXPRESSION_NOT_RELATIONSHIP_MAPPING = The derived path ''{0}'' does not represent an association field.
34
35
// AbstractSelectClause - Grammar
36
ABSTRACT_SELECT_CLAUSE_SELECT_EXPRESSION_ENDS_WITH_COMMA = The select expression cannot end with a comma.
37
ABSTRACT_SELECT_CLAUSE_SELECT_EXPRESSION_IS_MISSING_COMMA = The SELECT clause has ''{0}'' and ''{1}'' that are not separated by a comma.
38
ABSTRACT_SELECT_CLAUSE_SELECT_EXPRESSION_MALFORMED = The select expression is malformed.
39
ABSTRACT_SELECT_CLAUSE_SELECT_MISSING_EXPRESSION = The select expression is missing from the SELECT clause.
40
41
// AbstractSelectStatement - Grammar
42
ABSTRACT_SELECT_STATEMENT_FROM_CLAUSE_MSSING = A select statement must have a FROM clause.
43
44
// AdditionExpression - Semantic
45
ADDITION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the addition is not a valid arithmetic expression.
46
ADDITION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the addition is not a valid arithmetic expression.
47
48
// AllOrAnyExpression - Grammar
49
ALL_OR_ANY_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
50
ALL_OR_ANY_EXPRESSION_MISSING_EXPRESSION = The subquery must be provided for an {0} expression.
51
ALL_OR_ANY_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the {0} expression.
52
ALL_OR_ANY_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the {0} expression.
53
ALL_OR_ANY_EXPRESSION_NOT_PART_OF_COMPARISON_EXPRESSION = The {0} expression must be part of a comparison expression.
54
55
// ArithmeticFactor - Grammar
56
ARITHMETIC_FACTOR_MISSING_EXPRESSION = An arithmetic factor must be followed by an expression.
57
// ArithmeticFactor - Semantic
58
ARITHMETIC_FACTOR_INVALID_EXPRESSION = The expression must be an arithmetic expression.
59
60
// ArithmeticExpression - Grammar
61
ARITHMETIC_EXPRESSION_INVALID_LEFT_EXPRESSION = The left expression is not an arithmetic expression.
62
ARITHMETIC_EXPRESSION_INVALID_RIGHT_EXPRESSION = The right expression is not an arithmetic expression.
63
ARITHMETIC_EXPRESSION_MISSING_LEFT_EXPRESSION = The left expression is missing from the arithmetic expression.
64
ARITHMETIC_EXPRESSION_MISSING_RIGHT_EXPRESSION = The right expression is missing from the arithmetic expression.
65
66
// AvgFunction - Grammar
67
AVG_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
68
AVG_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the AVG expression.
69
AVG_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for an AVG expression.
70
AVG_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the AVG expression.
71
// AvgFunction - Semantic
72
AVG_FUNCTION_INVALID_NUMERIC_EXPRESSION = The encapsulated expression is not a valid numeric expression.
73
74
// BetweenExpression - Grammar
75
BETWEEN_EXPRESSION_MISSING_EXPRESSION = The result expression is missing from the BETWEEN expression.
76
BETWEEN_EXPRESSION_MISSING_LOWER_BOUND_EXPRESSION = The lower bound expression is missing from the BETWEEN expression.
77
BETWEEN_EXPRESSION_MISSING_AND = The identifier AND is missing from the BETWEEN expression.
78
BETWEEN_EXPRESSION_MISSING_UPPER_BOUND_EXPRESSION = The upper bound expression is missing from the BETWEEN expression.
79
// BetweenExpression - Semantic
80
BETWEEN_EXPRESSION_WRONG_TYPE = The expression's type and the lower and upper bound expressions' type have to be the same type.
81
82
// CaseExpression - Grammar
83
CASE_EXPRESSION_MISSING_ELSE_EXPRESSION = A CASE expression must have an ELSE expression.
84
CASE_EXPRESSION_MISSING_ELSE_IDENTIFIER = The identifier ELSE is missing from the CASE expression.
85
CASE_EXPRESSION_MISSING_END_IDENTIFIER = The identifier END is missing from the CASE expression.
86
CASE_EXPRESSION_MISSING_WHEN_CLAUSE = A CASE expression must define at least one WHEN clause.
87
CASE_EXPRESSION_WHEN_CLAUSES_END_WITH_COMMA = The WHEN clauses cannot end with a comma.
88
CASE_EXPRESSION_WHEN_CLAUSES_HAS_COMMA = Two WHEN clauses cannot be separated by a comma.
89
90
// CoalesceExpression - Grammar
91
COALESCE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
92
COALESCE_EXPRESSION_MISSING_EXPRESSION = The encapsulated expressions must be provided for a COALESCE expression.
93
COALESCE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the COALESCE expression.
94
COALESCE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the COALESCE expression.
95
96
// CollectionMemberExpression - Grammar
97
COLLECTION_MEMBER_EXPRESSION_MISSING_ENTITY_EXPRESSION = A collection member expression must define an entity expression.
98
COLLECTION_MEMBER_EXPRESSION_MISSING_COLLECTION_VALUED_PATH_EXPRESSION = A collection member expression must define a collection valued path expression.
99
// CollectionMemberExpression - Semantic
100
COLLECTION_MEMBER_EXPRESSION_EMBEDDABLE = An embeddable type is not supported.
101
102
// CollectionMemberDeclaration - Grammar
103
COLLECTION_MEMBER_DECLARATION_MISSING_COLLECTION_VALUED_PATH_EXPRESSION = The collection-valued path expression is missing from the collection member declaration.
104
COLLECTION_MEMBER_DECLARATION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the collection member declaration.
105
COLLECTION_MEMBER_DECLARATION_MISSING_IDENTIFICATION_VARIABLE = An identification variable must be specified for a collection member declaration.
106
COLLECTION_MEMBER_DECLARATION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the collection member declaration.
107
108
// CollectionValuedPathExpression - Semantic
109
COLLECTION_VALUED_PATH_EXPRESSION_NOT_RESOLVABLE" ,     "The collection-valued path ''{0}'' cannot be resolved to a valid association field.
110
COLLECTION_VALUED_PATH_EXPRESSION_NOT_COLLECTION_TYPE = The collection-valued path ''{0}'' must resolve to an association field.
111
112
// ComparisonExpression - Grammar
113
COMPARISON_EXPRESSION_MISSING_LEFT_EXPRESSION = A comparison expression must define the left side of the comparison.
114
COMPARISON_EXPRESSION_MISSING_RIGHT_EXPRESSION = A comparison expression must define the right side of the comparison.
115
// ComparisonExpression - Semantic
116
COMPARISON_EXPRESSION_WRONG_COMPARISON_TYPE = The left and right expressions' type must be of the same type.
117
118
// ConcatExpression - Grammar
119
CONCAT_EXPRESSION_INVALID_EXPRESSION = The expression ''{0}'' is not valid expression.
120
CONCAT_EXPRESSION_MISSING_EXPRESSION = The encapsulated expression is missing from the CONCAT expression.
121
CONCAT_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the CONCAT expression.
122
CONCAT_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the CONCAT expression.
123
// ConcatExpression - Semantic
124
CONCAT_EXPRESSION_EXPRESSION_WRONG_TYPE = The expression ''{0}'' is not a String.
125
126
// ConstructorExpression - Grammar
127
CONSTRUCTOR_EXPRESSION_CONSTRUCTOR_ITEM_ENDS_WITH_COMMA = The constructor items cannot end with a comma.
128
CONSTRUCTOR_EXPRESSION_CONSTRUCTOR_ITEM_IS_MISSING_COMMA = The constructor expression has two constructor items (''{0}'' and ''{1}'') that are not separated by a comma.
129
CONSTRUCTOR_EXPRESSION_MISSING_CONSTRUCTOR_ITEM = A constructor expression must define at least one constructor item.
130
CONSTRUCTOR_EXPRESSION_MISSING_CONSTRUCTOR_NAME = The fully qualified class name must be specified.
131
CONSTRUCTOR_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the constructor expression.
132
CONSTRUCTOR_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the constructor expression.
133
// ConstructorExpression - Semantic
134
CONSTRUCTOR_EXPRESSION_MISMATCHED_PARAMETER_TYPES = No constructors can be found that match the argument types.
135
CONSTRUCTOR_EXPRESSION_UNKNOWN_TYPE = ''{0}'' cannot be resolved to a type.
136
137
// CountFunction - Grammar
138
COUNT_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
139
COUNT_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a COUNT expression.
140
COUNT_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the COUNT expression.
141
COUNT_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the COUNT expression.
142
// CountFunction - Semantic
143
COUNT_FUNCTION_DISTINCT_EMBEDDABLE = The use of DISTINCT is not supported for arguments of embeddable types.
144
145
// DateTime - Grammar
146
DATE_TIME_JDBC_ESCAPE_FORMAT_INVALID_SPECIFICATION = The JDBC escape format does not start with either 'd', 't' or 'ts'.
147
DATE_TIME_JDBC_ESCAPE_FORMAT_MISSING_CLOSE_QUOTE = The JDBC escape format is missing the close quote.
148
DATE_TIME_JDBC_ESCAPE_FORMAT_MISSING_OPEN_QUOTE = The JDBC escape format is missing the open quote.
149
DATE_TIME_JDBC_ESCAPE_FORMAT_MISSING_RIGHT_CURLY_BRACE = The JDBC escape format is missing the right curly brace.
150
151
// DeleteClause - Grammar
152
DELETE_CLAUSE_FROM_MISSING = The identifier FROM is missing from the DELETE FROM clause.
153
DELETE_CLAUSE_MULTIPLE_RANGE_VARIABLE_DECLARATION = Only one entity abstract schema type can be defined.
154
DELETE_CLAUSE_RANGE_VARIABLE_DECLARATION_MALFORMED = The entity abstract schema type declaration is malformed.
155
DELETE_CLAUSE_RANGE_VARIABLE_DECLARATION_MISSING = A DELETE clause must define an entity abstract schema type.
156
157
// DivisionExpression - Semantic
158
DIVISION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the division is not a valid arithmetic expression.
159
DIVISION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the division is not a valid arithmetic expression.
160
161
// EclipseLinkQueryBuilder - Validation
162
ECLIPSE_LINK_QUERY_BUILDER_GRAMMAR_VALIDATOR_ERROR_MESSAGE = Syntax error parsing the query [{0}]. {1}
163
ECLIPSE_LINK_QUERY_BUILDER_SEMANTIC_VALIDATOR_ERROR_MESSAGE = Problem compiling the query [{0}]. {1}
164
165
// EncapsulatedIdentificationVariableExpression - Semantic
166
ENCAPSULATED_IDENTIFICATION_VARIABLE_EXPRESSION_NOT_MAP_VALUED = The {0} operator may only be applied to identification variables that correspond to map-valued associations or map-valued element collections.
167
168
// EmptyCollectionComparisonExpression - Grammar
169
EMPTY_COLLECTION_COMPARISON_EXPRESSION_MISSING_EXPRESSION = The collection valued path expression must be defined.
170
171
// EntityTypeLiteral - Semantic
172
ENTITY_TYPE_LITERAL_NOT_RESOLVABLE = ''{0}'' cannot be resolved to a type.
173
174
// EntryExpression - Grammar
175
ENTRY_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
176
ENTRY_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for an ENTRY expression.
177
ENTRY_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the ENTRY expression.
178
ENTRY_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the ENTRY expression.
179
180
// ExistsExpression - Grammar
181
EXISTS_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
182
EXISTS_EXPRESSION_MISSING_EXPRESSION = A subquery must be provided for an EXISTS expression.
183
EXISTS_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the EXISTS expression.
184
EXISTS_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the EXISTS expression.
185
186
// FuncExpression - Grammar
187
FUNC_EXPRESSION_MISSING_FUNCTION_NAME = The SQL function name must be specified.
188
FUNC_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the FUNC expression.
189
FUNC_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the FUNC expression.
190
191
// GroupByClause - Grammar
192
GROUP_BY_CLAUSE_GROUP_BY_ITEM_ENDS_WITH_COMMA = The select expression cannot end with a comma.
193
GROUP_BY_CLAUSE_GROUP_BY_ITEM_IS_MISSING_COMMA = The GROUP BY clause has ''{0}'' and ''{1}'' that are not separated by a comma.
194
GROUP_BY_CLAUSE_GROUP_BY_ITEM_MISSING = The grouping item is missing from the GROUP BY clause.
195
196
// HavingClause - Grammar
197
HAVING_CLAUSE_INVALID_CONDITIONAL_EXPRESSION = The expression is not a valid conditional expression.
198
HAVING_CLAUSE_MISSING_CONDITIONAL_EXPRESSION = The conditional expression is missing from the HAVING clause.
199
200
// IdentificationVariable - Grammar
201
IDENTIFICATION_VARIABLE_INVALID_DUPLICATE = The identification variable ''{0}'' cannot be declared more than once.
202
IDENTIFICATION_VARIABLE_INVALID_JAVA_IDENTIFIER = The identification variable ''{0}'' is not following the rules for a Java identifier.
203
IDENTIFICATION_VARIABLE_INVALID_RESERVED_WORD = The identification variable ''{0}'' cannot be a reserved word.
204
// IdentificationVariable - Semantic
205
IDENTIFICATION_VARIABLE_ENTITY_NAME = An identification variable must not have the same name as any entity in the same persistence unit.
206
IDENTIFICATION_VARIABLE_INVALID_NOT_DECLARED = The identification variable ''{0}'' is not defined in the FROM clause.
207
208
// IdentificationVariableDeclaration - Grammar
209
IDENTIFICATION_VARIABLE_DECLARATION_MISSING_RANGE_VARIABLE_DECLARATION = The range variable declaration must be specified.
210
211
// IndexExpression - Grammar
212
INDEX_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
213
INDEX_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for an INDEX expression.
214
INDEX_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the INDEX expression.
215
INDEX_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the INDEX expression.
216
// IndexExpression - Semantic
217
INDEX_EXPRESSION_WRONG_VARIABLE = The identification variable ''{0}'' does not represent an association or element collection.
218
219
// InExpression - Grammar
220
IN_EXPRESSION_IN_ITEM_ENDS_WITH_COMMA = The items cannot end with a comma.
221
IN_EXPRESSION_IN_ITEM_IS_MISSING_COMMA = The IN expression has ''{0}'' and ''{1}'' that are not separated by a comma.
222
IN_EXPRESSION_MALFORMED_EXPRESSION = The IN expression does not have a valid state field path expression or TYPE expession.
223
IN_EXPRESSION_MISSING_IN_ITEMS = A least one item must be defined for the IN expression.
224
IN_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the IN expression.
225
IN_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the IN expression.
226
IN_EXPRESSION_MISSING_EXPRESSION = A state field path expression or TYPE expression must be defined.
227
228
// InputParameter - Grammar
229
INPUT_PARAMETER_JAVA_IDENTIFIER = The named input parameter ''{0}'' is not following the rules for a Java identifier.
230
INPUT_PARAMETER_MISSING_PARAMETER = The parameter value is missing from the input parameter.
231
INPUT_PARAMETER_MIXTURE = Named and positional input parameters must not be mixed in a single query.
232
INPUT_PARAMETER_NOT_INTEGER = The positional input parameter ''{0}'' cannot use non-Integer characters.
233
INPUT_PARAMETER_SMALLER_THAN_ONE = The number used for the positional input parameter ''{0}'' must be greater than 0.
234
INPUT_PARAMETER_WRONG_CLAUSE_DECLARATION = Input parameters can only be used in the WHERE clause or HAVING clause of a query.
235
236
// Join - Grammar
237
JOIN_MISSING_IDENTIFICATION_VARIABLE = An identification variable must be defined for a JOIN expression.
238
JOIN_MISSING_JOIN_ASSOCIATION_PATH = The join association path is missing from the JOIN expression.
239
240
// JoinFetch - Grammar
241
JOIN_FETCH_MISSING_JOIN_ASSOCIATION_PATH = The join association path is missing from the JOIN FETCH expression.
242
JOIN_FETCH_WRONG_CLAUSE_DECLARATION = JOIN FETCH expressions cannot be used in a FROM clause of a subquery.
243
244
// JPQLExpression - Grammar
245
JPQL_EXPRESSION_INVALID_QUERY = The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM.
246
JPQL_EXPRESSION_UNKNOWN_ENDING = The query contains a malformed ending.
247
248
// KeyExpression - Grammar
249
KEY_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
250
KEY_EXPRESSION_MISSING_EXPRESSION = The identification variable must be provided for an ABS expression.
251
KEY_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the ABS expression.
252
KEY_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the ABS expression.
253
254
// LengthExpression - Grammar
255
LENGTH_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
256
LENGTH_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a LENGTH expression.
257
LENGTH_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the LENGTH expression.
258
LENGTH_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the LENGTH expression.
259
// LikeExpression - Semantic
260
LENGTH_EXPRESSION_WRONG_TYPE = The encapsulated expression is not of string type.
261
262
// LikeExpression - Grammar
263
LIKE_EXPRESSION_INVALID_ESCAPE_CHARACTER = {0} is not a valid escape character.
264
LIKE_EXPRESSION_MISSING_ESCAPE_CHARACTER = The escape character is missing from the LIKE expression.
265
LIKE_EXPRESSION_MISSING_PATTERN_VALUE = The pattern value is missing from the LIKE expression.
266
LIKE_EXPRESSION_MISSING_STRING_EXPRESSION = The string expression is missing from the LIKE expression.
267
268
// LocateExpression - Grammar
269
LOCATE_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
270
LOCATE_EXPRESSION_INVALID_SECOND_EXPRESSION = The second argument is not a valid expression.
271
LOCATE_EXPRESSION_INVALID_THIRD_EXPRESSION = The third argument is not a valid expression.
272
LOCATE_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the LOCATE expression.
273
LOCATE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the LOCATE expression.
274
LOCATE_EXPRESSION_MISSING_FIRST_COMMA = The first comma is missing from the LOCATE expression.
275
LOCATE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the LOCATE expression.
276
LOCATE_EXPRESSION_MISSING_SECOND_COMMA = The second comma is missing from the LOCATE expression.
277
LOCATE_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the LOCATE expression.
278
LOCATE_EXPRESSION_MISSING_THIRD_EXPRESSION = The third argument is missing from the LOCATE expression.
279
// LocateExpression - Semantic
280
LOCATE_EXPRESSION_FIRST_EXPRESSION_WRONG_TYPE = The first expression is not of string type.
281
LOCATE_EXPRESSION_SECOND_EXPRESSION_WRONG_TYPE = The second expression is not of string type.
282
LOCATE_EXPRESSION_THIRD_EXPRESSION_WRONG_TYPE = The third encapsulated expression is not of numeric type.
283
284
// LogicalExpression - Grammar
285
LOGICAL_EXPRESSION_INVALID_LEFT_EXPRESSION = The left expression is missing from the logical expression.
286
LOGICAL_EXPRESSION_INVALID_RIGHT_EXPRESSION = The right expression is missing from the logical expression.
287
LOGICAL_EXPRESSION_MISSING_LEFT_EXPRESSION = The left expression is not a valid expression.
288
LOGICAL_EXPRESSION_MISSING_RIGHT_EXPRESSION = The right expression is not a valid expression.
289
290
// LowerExpression - Grammar
291
LOWER_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
292
LOWER_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a LOWER expression.
293
LOWER_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the LOWER expression.
294
LOWER_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the LOWER expression.
295
// UpperExpression - Semantic
296
LOWER_EXPRESSION_WRONG_TYPE = The expression is not a String.
297
298
// MaxFunction - Grammar
299
MAX_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
300
MAX_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a MAX expression.
301
MAX_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the MAX expression.
302
MAX_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the MAX expression.
303
304
// MinFunction - Grammar
305
MIN_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
306
MIN_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a MIN expression.
307
MIN_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the MIN expression.
308
MIN_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the MIN expression.
309
310
// ModExpression - Grammar
311
MOD_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
312
MOD_EXPRESSION_INVALID_SECOND_PARENTHESIS = The second argument is not a valid expression.
313
MOD_EXPRESSION_MISSING_COMMA = The comma is missing from the MOD expression.
314
MOD_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the MOD expression.
315
MOD_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the MOD expression.
316
MOD_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the MOD expression.
317
MOD_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the MOD expression.
318
// ModExpression - Semantic
319
MOD_EXPRESSION_FIRST_EXPRESSION_WRONG_TYPE = The first expression is not an Integer.
320
MOD_EXPRESSION_SECOND_EXPRESSION_WRONG_TYPE = The second expression is not an Integer.
321
322
// MultiplicationExpression - Semantic
323
MULTIPLICATION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the multiplication is not a valid arithmetic expression.
324
MULTIPLICATION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the multiplication is not a valid arithmetic expression.
325
326
// NotExpression - Grammar
327
NOT_EXPRESSION_MISSING_EXPRESSION = The expression is missing after the identifier NOT.
328
// NotExpression - Semantic
329
NOT_EXPRESSION_WRONG_TYPE = The expression is not of boolean type.
330
331
// NullComparisonExpression - Grammar
332
NULL_COMPARISON_EXPRESSION_MISSING_EXPRESSION = The expression is missing from the null comparison expression.
333
// NullComparisonExpression - Semantic
334
NULL_COMPARISON_EXPRESSION_INVALID_COLLECTION_EXPRESSION = ''{0}'' cannot be resolved to a collection type.
335
336
// NullIfExpression - Grammar
337
NULL_IF_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
338
NULL_IF_EXPRESSION_INVALID_SECOND_EXPRESSION = The second argument is not a valid expression.
339
NULL_IF_EXPRESSION_MISSING_COMMA = The comma is missing from the NULLIF expression.
340
NULL_IF_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the NULLIF expression.
341
NULL_IF_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the NULLIF expression.
342
NULL_IF_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the NULLIF expression.
343
NULL_IF_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the NULLIF expression.
344
345
// NumericLiteral - Grammar
346
NUMERIC_LITERAL_INVALID = ''{0}'' is not a valid numeric value.
347
348
// ObjectByItem - Grammar
349
ORDER_BY_ITEM_INVALID_PATH = ''{0}'' is not a valid state field path expression.
350
ORDER_BY_ITEM_MISSING_STATE_FIELD_PATH_EXPRESSION = A state field path expression must be specified.
351
352
// ObjectExpression - Grammar
353
OBJECT_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
354
OBJECT_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for an OBJECT expression.
355
OBJECT_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the OBJECT expression.
356
OBJECT_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the OBJECT expression.
357
358
// OrderByClause - Grammar
359
ORDER_BY_CLAUSE_ORDER_BY_ITEM_ENDS_WITH_COMMA = The select expression cannot end with a comma.
360
ORDER_BY_CLAUSE_ORDER_BY_ITEM_IS_MISSING_COMMA = The ORDER BY clause has ''{0}'' and ''{1}'' that are not separated by a comma.
361
ORDER_BY_CLAUSE_ORDER_BY_ITEM_MISSING = The ordering item is missing from the ORDER BY clause.
362
363
// RangeVariableDeclaration - Grammar
364
RANGE_VARIABLE_DECLARATION_MISSING_ABSTRACT_SCHEMA_NAME = An abstract schema name must be specified.
365
RANGE_VARIABLE_DECLARATION_MISSING_IDENTIFICATION_VARIABLE = An identification variable must be provider for a range variable declaration.
366
367
// ResultVariable - Grammar
368
RESULT_VARIABLE_MISSING_SELECT_EXPRESSION = The select item is missing from the result variable declaration.
369
RESULT_VARIABLE_MISSING_RESULT_VARIABLE = The result variable is missing from the select item declaration.
370
371
// SelectStatement - Semantic
372
SELECT_STATEMENT_SELECT_CLAUSE_HAS_NON_AGGREGATE_FUNCTIONS = The select list can only consist of aggregate functions because there is no GROUP BY clause and the HAVING clause is used.
373
374
// SimpleSelectClause - Grammar
375
SIMPLE_SELECT_CLAUSE_NOT_SINGLE_EXPRESSION = Only one expression can be declared in a SELECT clause of a subquery.
376
377
// SizeExpression - Grammar
378
SIZE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
379
SIZE_EXPRESSION_MISSING_EXPRESSION = A collection-valued path expression must be provided for a SIZE expression.
380
SIZE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SIZE expression.
381
SIZE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SIZE expression.
382
383
// SqrtExpression - Grammar
384
SQRT_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
385
SQRT_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a SQRT expression.
386
SQRT_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SQRT expression.
387
SQRT_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SQRT expression.
388
// SqrtExpression - Semantic
389
SQRT_EXPRESSION_WRONG_TYPE = The expression is not a numeric type.
390
391
// StateFieldPathExpression - Semantic
392
STATE_FIELD_PATH_EXPRESSION_ASSOCIATION_FIELD = The association field ''{0}'' cannot be used as a state field path.
393
STATE_FIELD_PATH_EXPRESSION_COLLECTION_TYPE = The state field path ''{0}'' cannot resolve to a collection type.
394
STATE_FIELD_PATH_EXPRESSION_INVALID_ENUM_CONSTANT = ''{0}'' cannot be resolved to an Enum constant.
395
STATE_FIELD_PATH_EXPRESSION_NO_MAPPING = No mapping is associated with the state field path ''{0}''.
396
STATE_FIELD_PATH_EXPRESSION_NOT_RESOLVABLE = The state field path ''{0}'' cannot be resolved to a valid type.
397
398
// SubExpression - Grammar
399
SUB_EXPRESSION_MISSING_EXPRESSION = The encapsulated expression is missing.
400
SUB_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the sub-expression.
401
402
// SubstractionExpression - Semantic
403
SUBSTRACTION_EXPRESSION_LEFT_EXPRESSION_WRONG_TYPE = The left side of the substraction is not a valid arithmetic expression.
404
SUBSTRACTION_EXPRESSION_RIGHT_EXPRESSION_WRONG_TYPE = The right side of the substraction is not a valid arithmetic expression.
405
406
// SubstringExpression - Grammar
407
SUBSTRING_EXPRESSION_INVALID_FIRST_EXPRESSION = The first argument is not a valid expression.
408
SUBSTRING_EXPRESSION_INVALID_SECOND_EXPRESSION = The second argument is not a valid expression.
409
SUBSTRING_EXPRESSION_INVALID_THIRD_EXPRESSION = The third argument is not a valid expression.
410
SUBSTRING_EXPRESSION_MISSING_FIRST_COMMA = The first comma is missing from the SUBSTRING expression.
411
SUBSTRING_EXPRESSION_MISSING_FIRST_EXPRESSION = The first argument is missing from the SUBSTRING expression.
412
SUBSTRING_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SUBSTRING expression.
413
SUBSTRING_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SUBSTRING expression.
414
SUBSTRING_EXPRESSION_MISSING_SECOND_COMMA = The second comma is missing from the SUBSTRING expression.
415
SUBSTRING_EXPRESSION_MISSING_SECOND_EXPRESSION = The second argument is missing from the SUBSTRING expression.
416
SUBSTRING_EXPRESSION_MISSING_THIRD_EXPRESSION = The third argument is missing from the SUBSTRING expression.
417
// SubstringExpression - Semantic
418
SUBSTRING_EXPRESSION_FIRST_EXPRESSION_WRONG_TYPE = The first argument is not a String value.
419
SUBSTRING_EXPRESSION_SECOND_EXPRESSION_WRONG_TYPE = The first argument is not an integer value.
420
SUBSTRING_EXPRESSION_THIRD_EXPRESSION_WRONG_TYPE = The first argument is not an integer value.
421
422
// SumFunction - Grammar
423
SUM_FUNCTION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
424
SUM_FUNCTION_MISSING_EXPRESSION = The encapsulated expression must be provided for a SUM expression.
425
SUM_FUNCTION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the SUM expression.
426
SUM_FUNCTION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the SUM expression.
427
// SumFunction - Semantic
428
SUM_FUNCTION_WRONG_TYPE = The argument must be numeric.
429
430
// TrimExpression - Grammar
431
TRIM_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
432
TRIM_EXPRESSION_INVALID_TRIM_CHARACTER = The trim character should be a single-character string literal or a character-valued input parameter (i.e., char or Character).
433
TRIM_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a TRIM expression.
434
TRIM_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the TRIM expression.
435
TRIM_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the TRIM expression.
436
TRIM_EXPRESSION_NOT_SINGLE_STRING_LITERAL = The trim character should be a single-character string literal.
437
438
// TypeExpression - Grammar
439
TYPE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
440
TYPE_EXPRESSION_MISSING_EXPRESSION = An identification variable or a path expression must be provided for a TYPE expression.
441
TYPE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the TYPE expression.
442
TYPE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the TYPE expression.
443
// TypeExpression - Semantic
444
445
// UpdateClause - Grammar
446
UPDATE_CLAUSE_MISSING_RANGE_VARIABLE_DECLARATION = The range variable declaration is missing from the UPDATE clause.
447
UPDATE_CLAUSE_MISSING_SET = The SET identifier is missing from the UPDATE clause.
448
UPDATE_CLAUSE_MISSING_UPDATE_ITEMS = At least one update item must be specified for an UPDATE clause.
449
UPDATE_CLAUSE_UPDATE_ITEM_ENDS_WITH_COMMA = The update item cannot end with a comma.
450
UPDATE_CLAUSE_UPDATE_ITEM_IS_MISSING_COMMA = The UPDATE clause has ''{0}'' and ''{1}'' that are not separated by a comma.
451
452
// UpdateItem - Grammar
453
UPDATE_ITEM_MISSING_EQUAL_SIGN = The equal sign must be specified.
454
UPDATE_ITEM_MISSING_NEW_VALUE = The new value must be specified.
455
UPDATE_ITEM_MISSING_STATE_FIELD_PATH_EXPRESSION = The state field path expression is missing.
456
// UpdateItem - Semantic
457
UPDATE_ITEM_NOT_ASSIGNABLE = Type mismatch: cannot convert from {0} to {1}.
458
UPDATE_ITEM_NOT_RESOLVABLE = The state field cannot be resolved.
459
460
// UpperExpression - Grammar
461
UPPER_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
462
UPPER_EXPRESSION_MISSING_EXPRESSION = An expression must be provided for a UPPER expression.
463
UPPER_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the UPPER expression.
464
UPPER_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the UPPER expression.
465
// UpperExpression - Semantic
466
UPPER_EXPRESSION_WRONG_TYPE = The expression is not a String.
467
468
// ValueExpression - Grammar
469
VALUE_EXPRESSION_INVALID_EXPRESSION = The encapsulated expression is not a valid expression.
470
VALUE_EXPRESSION_MISSING_EXPRESSION = An identification variable must be provided for a VALUE expression.
471
VALUE_EXPRESSION_MISSING_LEFT_PARENTHESIS = The left parenthesis is missing from the VALUE expression.
472
VALUE_EXPRESSION_MISSING_RIGHT_PARENTHESIS = The right parenthesis is missing from the VALUE expression.
473
474
// WhenClause - Grammar
475
WHEN_CLAUSE_MISSING_THEN_EXPRESSION = A conditional expression must be provider for a WHEN clause.
476
WHEN_CLAUSE_MISSING_THEN_IDENTIFIER = The identifier THEN is missing from the WHEN clause.
477
WHEN_CLAUSE_MISSING_WHEN_EXPRESSION = A WHEN expression must be provided for a WHEN clause.
478
479
// WhereClause - Grammar
480
WHERE_CLAUSE_INVALID_CONDITIONAL_EXPRESSION = The expression is not a valid conditional expression.
481
WHERE_CLAUSE_MISSING_CONDITIONAL_EXPRESSION = The conditional expression is missing from the WHERE clause.
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java (-2 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Oracle. All rights reserved.
2
 * Copyright (c) 2007, 2011 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-18 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
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;
13
import org.eclipse.jdt.core.dom.CompilationUnit;
14
import org.eclipse.jpt.common.core.utility.TextRange;
12
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
15
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
13
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
16
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
14
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
17
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
18
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
15
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
19
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
20
import org.eclipse.persistence.utils.jpa.query.JPQLQueryProblem;
21
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
22
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
16
23
17
/**
24
/**
18
 * Java named query
25
 * Java named query
Lines 24-27 Link Here
24
	public GenericJavaNamedQuery(JavaJpaContextNode parent, NamedQueryAnnotation queryAnnotation) {
31
	public GenericJavaNamedQuery(JavaJpaContextNode parent, NamedQueryAnnotation queryAnnotation) {
25
		super(parent, queryAnnotation);
32
		super(parent, queryAnnotation);
26
	}
33
	}
27
}
34
35
36
	// ********** validation **********
37
38
	/**
39
	 * {@inheritDoc}
40
	 */
41
	@Override
42
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
43
		super.validate(messages, reporter, astRoot);
44
45
		JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper(this);
46
		String parsedQuery = helper.getJPQLExpression().toParsedText();
47
		String jpqlQuery = getQuery();
48
49
		for (JPQLQueryProblem problem : helper.validate()) {
50
			TextRange textRange = this.getQueryAnnotation().getQueryTextRange(astRoot);
51
			IMessage message = helper.buildProblem(problem, textRange, jpqlQuery, parsedQuery);
52
			messages.add(message);
53
		}
54
	}
55
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaQueryContainer.java (-2 / +5 lines)
Lines 308-317 Link Here
308
	@Override
308
	@Override
309
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
309
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
310
		super.validate(messages, reporter, astRoot);
310
		super.validate(messages, reporter, astRoot);
311
		this.validateQueries(messages, astRoot);
311
		this.validateQueries(messages, reporter, astRoot);
312
	}
312
	}
313
313
314
	protected void validateQueries(List<IMessage> messages, CompilationUnit astRoot) {
314
	protected void validateQueries(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
315
		for (Iterator<JavaQuery> localQueries = this.queries(); localQueries.hasNext(); ) {
315
		for (Iterator<JavaQuery> localQueries = this.queries(); localQueries.hasNext(); ) {
316
			JavaQuery localQuery = localQueries.next();
316
			JavaQuery localQuery = localQueries.next();
317
			String name = localQuery.getName();
317
			String name = localQuery.getName();
Lines 354-359 Link Here
354
						)
354
						)
355
				);
355
				);
356
			}
356
			}
357
			else {
358
				localQuery.validate(messages, reporter, astRoot);
359
			}
357
		}
360
		}
358
	}
361
	}
359
362
(-)src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaNamedQuery2_0.java (-2 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 Oracle. All rights reserved.
2
* Copyright (c) 2009, 2011 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-19 Link Here
9
*******************************************************************************/
9
*******************************************************************************/
10
package org.eclipse.jpt.jpa.core.internal.jpa2.context.java;
10
package org.eclipse.jpt.jpa.core.internal.jpa2.context.java;
11
11
12
import java.util.List;
13
import org.eclipse.jdt.core.dom.CompilationUnit;
14
import org.eclipse.jpt.common.core.utility.TextRange;
12
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
15
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
13
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
16
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
17
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
14
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
18
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
15
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
19
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
16
import org.eclipse.jpt.jpa.core.jpa2.resource.java.NamedQuery2_0Annotation;
20
import org.eclipse.jpt.jpa.core.jpa2.resource.java.NamedQuery2_0Annotation;
21
import org.eclipse.persistence.utils.jpa.query.JPQLQueryProblem;
22
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
23
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
17
24
18
/**
25
/**
19
 * JPA 2.0
26
 * JPA 2.0
Lines 87-90 Link Here
87
		return LockModeType2_0.NONE;
94
		return LockModeType2_0.NONE;
88
	}
95
	}
89
96
90
}
97
98
	// ********** validation **********
99
100
	/**
101
	 * {@inheritDoc}
102
	 */
103
	@Override
104
	public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
105
		super.validate(messages, reporter, astRoot);
106
107
		JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper(this);
108
		String parsedQuery = helper.getJPQLExpression().toParsedText();
109
		String jpqlQuery = getQuery();
110
111
		for (JPQLQueryProblem problem : helper.validate()) {
112
			TextRange textRange = this.getQueryAnnotation().getQueryTextRange(astRoot);
113
			IMessage message = helper.buildProblem(problem, textRange, jpqlQuery, parsedQuery);
114
			messages.add(message);
115
		}
116
	}
117
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaConstructor.java (+102 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jdt.core.dom.IMethodBinding;
17
import org.eclipse.jdt.core.dom.ITypeBinding;
18
import org.eclipse.jdt.core.dom.MethodDeclaration;
19
import org.eclipse.persistence.utils.jpa.query.spi.IConstructor;
20
import org.eclipse.persistence.utils.jpa.query.spi.IType;
21
import org.eclipse.persistence.utils.jpa.query.spi.ITypeDeclaration;
22
23
/**
24
 * The concrete implementation of {@link IConstructor} that is wrapping the design-time
25
 * representation of a Java constructor.
26
 *
27
 * @version 3.0
28
 * @since 3.0
29
 * @author Pascal Filion
30
 */
31
final class JpaConstructor implements IConstructor {
32
33
	/**
34
	 * The design-time representation of a Java constructor.
35
	 */
36
	private final MethodDeclaration method;
37
38
	/**
39
	 * The cached {@link ITypeDeclaration ITypeDeclarations} representing each of the constructor's
40
	 * parameter types.
41
	 */
42
	private ITypeDeclaration[] typeDeclarations;
43
44
	/**
45
	 * The repository of Java types.
46
	 */
47
	private final JpaTypeRepository typeRepository;
48
49
	/**
50
	 * Creates a new <code>JpaConstructor</code>.
51
	 *
52
	 * @param typeRepository The repository of Java types
53
	 * @param method The design-time representation of a Java constructor
54
	 */
55
	JpaConstructor(JpaTypeRepository typeRepository, MethodDeclaration method) {
56
		super();
57
		this.method         = method;
58
		this.typeRepository = typeRepository;
59
	}
60
61
	private ITypeDeclaration buildTypeDeclaration(ITypeBinding parameterType) {
62
63
		boolean array = parameterType.isArray();
64
		String typeName = array ? parameterType.getComponentType().getBinaryName() : parameterType.getBinaryName();
65
66
		// Retrieve the fully qualified name of the type
67
		ITypeBinding[] typeArguments = parameterType.getTypeArguments();
68
		ITypeDeclaration[] genericTypes = new ITypeDeclaration[typeArguments.length];
69
		int index = 0;
70
71
		for (ITypeBinding typeArgument : typeArguments) {
72
			String genericTypeName = typeArgument.getErasure().getBinaryName();
73
			IType genericType = typeRepository.getType(genericTypeName);
74
			genericTypes[index++] = genericType.getTypeDeclaration();
75
		}
76
77
		return new JpaTypeDeclaration(typeRepository.getType(typeName), genericTypes, array);
78
	}
79
80
	private ITypeDeclaration[] buildTypeDeclarations() {
81
82
		IMethodBinding binding = method.resolveBinding();
83
		ITypeBinding[] parameterTypes = binding.getParameterTypes();
84
		ITypeDeclaration[] declarations = new ITypeDeclaration[parameterTypes.length];
85
86
		for (int index = declarations.length; --index >= 0; ) {
87
			declarations[index] = buildTypeDeclaration(parameterTypes[index]);
88
		}
89
90
		return declarations;
91
	}
92
93
	/**
94
	 * {@inheritDoc}
95
	 */
96
	public ITypeDeclaration[] getParameterTypes() {
97
		if (typeDeclarations == null) {
98
			typeDeclarations = buildTypeDeclarations();
99
		}
100
		return typeDeclarations;
101
	}
102
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaEmbeddable.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.jpa.core.context.Embeddable;
17
import org.eclipse.persistence.utils.jpa.query.spi.IEmbeddable;
18
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeVisitor;
19
20
/**
21
 * The concrete implementation of {@link IEmbeddable} that is wrapping the design-time
22
 * representation of a JPA embeddable.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
final class JpaEmbeddable extends JpaManagedType
29
                          implements IEmbeddable {
30
31
	/**
32
	 * Creates a new <code>JpaEmbeddable</code>.
33
	 *
34
	 * @param provider The provider of JPA managed types
35
	 * @param embeddable The design-time model object wrapped by this class
36
	 */
37
	JpaEmbeddable(JpaManagedTypeProvider provider, Embeddable embeddable) {
38
		super(provider, embeddable);
39
	}
40
41
	/**
42
	 * {@inheritDoc}
43
	 */
44
	public void accept(IManagedTypeVisitor visitor) {
45
		visitor.visit(this);
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	@Override
52
	Embeddable getManagedType() {
53
		return (Embeddable) super.getManagedType();
54
	}
55
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaEntity.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.HashMap;
17
import java.util.ListIterator;
18
import java.util.Map;
19
import org.eclipse.jpt.jpa.core.context.Entity;
20
import org.eclipse.jpt.jpa.core.context.NamedQuery;
21
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
22
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
23
import org.eclipse.persistence.utils.jpa.query.spi.IEntity;
24
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeVisitor;
25
import org.eclipse.persistence.utils.jpa.query.spi.IQuery;
26
27
/**
28
 * The concrete implementation of {@link IEntity} that is wrapping the design-time representation
29
 * of a JPA entity.
30
 *
31
 * @version 3.0
32
 * @since 3.0
33
 * @author Pascal Filion
34
 */
35
final class JpaEntity extends JpaManagedType
36
                      implements IEntity {
37
38
	/**
39
	 * The cached used to quickly retrieve any queries that have been cached.
40
	 */
41
	private Map<String, IQuery> queries;
42
43
	/**
44
	 * Creates a new <code>JpaEntity</code>.
45
	 *
46
	 * @param provider The provider of JPA managed types
47
	 * @param entity The design-time model object wrapped by this class
48
	 */
49
	JpaEntity(JpaManagedTypeProvider provider, Entity entity) {
50
		super(provider, entity);
51
	}
52
53
	/**
54
	 * {@inheritDoc}
55
	 */
56
	public void accept(IManagedTypeVisitor visitor) {
57
		visitor.visit(this);
58
	}
59
60
	private IQuery buildQuery(JpaManagedTypeProvider provider, NamedQuery namedQuery) {
61
		return new JpaQuery(provider, namedQuery);
62
	}
63
64
	/**
65
	 * {@inheritDoc}
66
	 */
67
	@Override
68
	Entity getManagedType() {
69
		return (Entity) super.getManagedType();
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	public IQuery getNamedQuery(String queryName) {
76
		initializeQueries();
77
		return queries.get(queryName);
78
	}
79
80
	private void initializeQueries() {
81
82
		if (queries == null) {
83
			queries = new HashMap<String, IQuery>();
84
			JpaManagedTypeProvider provider = getProvider();
85
86
			for (ListIterator<NamedQuery> iter = namedQueries(); iter.hasNext(); ) {
87
				NamedQuery namedQuery = iter.next();
88
				queries.put(namedQuery.getName(), buildQuery(provider, namedQuery));
89
			}
90
91
			// TODO: Refactor this. ORM doesn't inherit the Java's named queries
92
			if (getManagedType().getPersistentType() instanceof OrmPersistentType) {
93
				OrmPersistentType type = (OrmPersistentType) getManagedType().getPersistentType();
94
				JavaTypeMapping mapping = type.getJavaPersistentType().getMapping();
95
				if (mapping instanceof Entity) {
96
					Entity entity = ((Entity) mapping);
97
					for (ListIterator<NamedQuery> iter = entity.getQueryContainer().namedQueries(); iter.hasNext(); ) {
98
						NamedQuery namedQuery = iter.next();
99
						queries.put(namedQuery.getName(), buildQuery(provider, namedQuery));
100
					}
101
				}
102
			}
103
		}
104
	}
105
106
	private ListIterator<NamedQuery> namedQueries() {
107
		return getManagedType().getQueryContainer().namedQueries();
108
	}
109
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaJpqlQueryHelper.java (+168 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.common.core.internal.utility.SimpleTextRange;
17
import org.eclipse.jpt.common.core.utility.TextRange;
18
import org.eclipse.jpt.jpa.core.context.NamedQuery;
19
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
20
import org.eclipse.persistence.utils.jpa.query.AbstractJPQLQueryHelper;
21
import org.eclipse.persistence.utils.jpa.query.JPQLQueryProblem;
22
import org.eclipse.persistence.utils.jpa.query.parser.ExpressionTools;
23
import org.eclipse.persistence.utils.jpa.query.spi.IQuery;
24
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
25
26
/**
27
 * This helper can perform the following operations over a JPQL query:
28
 * <ul>
29
 * <li>Calculates the result type of a query: {@link #getResultType()};</li>
30
 * <li>Calculates the type of an input parameter: {@link #getParameterType(String)}.</li>
31
 * <li>Calculates the possible choices to complete the query from a given
32
 *     position (used for content assist): {@link #buildContentAssistItems(int)}.</li>
33
 * <li>Validates the query by introspecting its grammar and semantic:
34
 *     <ul>
35
 *     <li>{@link #validate()},</li>
36
 *     <li>{@link #validateGrammar()},</li>
37
 *     <li>{@link #validateSemantic()}.</li>
38
 *     </ul></li>
39
 *
40
 * @version 3.0
41
 * @since 3.0
42
 * @author Pascal Filion
43
 */
44
@SuppressWarnings("nls")
45
public final class JpaJpqlQueryHelper extends AbstractJPQLQueryHelper<NamedQuery> {
46
47
	/**
48
	 * The actual JPQL query, which can differ from the one owned by the model object, which happens
49
	 * when the model is out of sync because it has not been updated yet.
50
	 */
51
	private final String actualQuery;
52
53
	/**
54
	 * The external form of the JPQL query that was already created before this helper, which happens
55
	 * during the execution of the unit-tests.
56
	 */
57
	private IQuery localQuery;
58
59
	/**
60
	 * Creates a new <code>JpaJpqlQueryHelper</code>. This constructor is used only by the unit-tests.
61
	 *
62
	 * @param query The external form that is already wrapping the {@link MWNamedQuery}
63
	 * @exception NullPointerException If the query is <code>null</code>
64
	 */
65
	public JpaJpqlQueryHelper(IQuery query) {
66
		this(((JpaQuery) query).getQuery());
67
		this.localQuery = query;
68
	}
69
70
	/**
71
	 * Creates a new <code>JpaJpqlQueryHelper</code>.
72
	 *
73
	 * @param query The model object where the JPQL query is stored
74
	 * @exception NullPointerException If the given {@link NamedQuery} is <code>null</code>
75
	 */
76
	public JpaJpqlQueryHelper(NamedQuery query) {
77
		this(query, query.getQuery());
78
	}
79
80
	/**
81
	 * Creates a new <code>JpaQueryHelper</code>.
82
	 *
83
	 * @param query The model object where the JPQL query is stored
84
	 * @param actualQuery The actual JPQL query, which can differ from the one owned by the model
85
	 * object, which happens when the model is out of sync because it has not been updated yet
86
	 * @exception NullPointerException If the given {@link NamedQuery} is <code>null</code>
87
	 */
88
	public JpaJpqlQueryHelper(NamedQuery query, String actualQuery) {
89
		super(query);
90
		this.actualQuery = actualQuery;
91
	}
92
93
	/**
94
	 * Creates a new {@link IMessage} for the given {@link JPQLQueryProblem}.
95
	 *
96
	 * @param problem The {@link JPQLQueryProblem problem} that was found in the JPQL query, which is
97
	 * either a grammatical or semantic problem
98
	 * @param textRange The range of the JPQL query in the Java source file
99
	 * @param jpqlQuery The actual JPQL query that was parsed and validated
100
	 * @param parsedJpqlQuery The string representation of the parsed tree representation of the JPQL
101
	 * query, which may differ from the actual JPQL query since it does not keep more than one
102
	 * whitespace
103
	 * @return A new {@link IMessage} that has the required information to display the problem
104
	 * underline and the error message in the Problems view
105
	 */
106
	public IMessage buildProblem(JPQLQueryProblem problem,
107
	                             TextRange textRange,
108
	                             String parsedJpqlQuery,
109
	                             String parsedQuery) {
110
111
		int length = parsedQuery.length();
112
		int startPosition = problem.getStartPosition();
113
		int endPosition = problem.getEndPosition();
114
115
		// If the start and end positions are the same, then expand the text range
116
		if (startPosition == endPosition) {
117
			startPosition = Math.max(startPosition - 2, 0);
118
			endPosition   = Math.min(endPosition + 1, length);
119
		}
120
121
		// Reposition the cursor so it's correctly positioned in the JPQL query, which is the
122
		// since it may contains more than one whitespace for a single whitespace
123
		int newStartPosition = ExpressionTools.repositionCursor(parsedJpqlQuery, parsedQuery, startPosition);
124
125
		if (newStartPosition != startPosition) {
126
			endPosition  += (newStartPosition - startPosition);
127
			startPosition = newStartPosition;
128
		}
129
130
		// Create the text range of the problem
131
		textRange = new SimpleTextRange(
132
			textRange.getOffset() + startPosition + 1,
133
			endPosition - startPosition,
134
			textRange.getLineNumber()
135
		);
136
137
		// Now create the message
138
		IMessage message = DefaultJpaValidationMessages.buildMessage(
139
			IMessage.HIGH_SEVERITY,
140
			problem.getMessageKey(),
141
			problem.getMessageArguments(),
142
			this,
143
			textRange
144
		);
145
		message.setBundleName("jpa_jpql_validation");
146
		return message;
147
	}
148
149
	private JpaManagedTypeProvider buildProvider(NamedQuery query) {
150
		try {
151
			return new JpaPersistenceUnit(query.getJpaProject(), query.getPersistenceUnit());
152
		}
153
		catch (Exception e) {
154
			return new JpaMappingFile(query.getJpaProject(), query.getMappingFileRoot().getParent());
155
		}
156
	}
157
158
	/**
159
	 * {@inheritDoc}
160
	 */
161
	@Override
162
	protected IQuery buildQuery(NamedQuery query) {
163
		if (localQuery == null) {
164
			localQuery = new JpaQuery(buildProvider(query), query, actualQuery);
165
		}
166
		return localQuery;
167
	}
168
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaManagedType.java (+127 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.Map;
19
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
20
import org.eclipse.jpt.jpa.core.context.TypeMapping;
21
import org.eclipse.persistence.utils.jpa.query.spi.IManagedType;
22
import org.eclipse.persistence.utils.jpa.query.spi.IMapping;
23
24
/**
25
 * The abstract definition of {@link IManagedType} defined for wrapping the design-time mapped class
26
 * object.
27
 *
28
 * @version 3.0
29
 * @since 3.0
30
 * @author Pascal Filion
31
 */
32
abstract class JpaManagedType implements IManagedType {
33
34
	/**
35
	 * The design-time model object wrapped by this class.
36
	 */
37
	private final TypeMapping managedType;
38
39
	/**
40
	 * The cached collection of {@link IMapping mappings} that prevent rebuilding them every time one
41
	 * is requested.
42
	 */
43
	private Map<String, IMapping> mappings;
44
45
	/**
46
	 * The provider of JPA managed types.
47
	 */
48
	private final JpaManagedTypeProvider provider;
49
50
	/**
51
	 * The cached wrapper over {@link TODO}.
52
	 */
53
	private JpaType type;
54
55
	/**
56
	 * Creates a new <code>JDeveloperManagedType</code>.
57
	 *
58
	 * @param managedType The provider of JPA managed types
59
	 * @param mappedClass The design-time model object wrapped by this class
60
	 */
61
	JpaManagedType(JpaManagedTypeProvider provider, TypeMapping managedType) {
62
		super();
63
		this.provider    = provider;
64
		this.managedType = managedType;
65
	}
66
67
	private IMapping buildMapping(AttributeMapping mapping) {
68
		return new JpaMapping(this, mapping);
69
	}
70
71
	private Map<String, IMapping> buildMappings() {
72
		Map<String, IMapping> mappings = new HashMap<String, IMapping>();
73
		for (Iterator<AttributeMapping> iter = managedType.allAttributeMappings(); iter.hasNext(); ) {
74
			AttributeMapping mapping = iter.next();
75
			mappings.put(mapping.getName(), buildMapping(mapping));
76
		}
77
		return mappings;
78
	}
79
80
	/**
81
	 * Returns the encapsulated model object.
82
	 *
83
	 * @return The managed type wrapped by this external form
84
	 */
85
	TypeMapping getManagedType() {
86
		return managedType;
87
	}
88
89
	/**
90
	 * {@inheritDoc}
91
	 */
92
	public final IMapping getMappingNamed(String name) {
93
		initializeMappings();
94
		return mappings.get(name);
95
	}
96
97
	/**
98
	 * {@inheritDoc}
99
	 */
100
	public final JpaManagedTypeProvider getProvider() {
101
		return provider;
102
	}
103
104
	/**
105
	 * {@inheritDoc}
106
	 */
107
	public final JpaType getType() {
108
		if (type == null) {
109
			type = provider.getTypeRepository().getType(managedType.getPersistentType().getName());
110
		}
111
		return type;
112
	}
113
114
	private void initializeMappings() {
115
		if (mappings == null) {
116
			mappings = buildMappings();
117
		}
118
	}
119
120
	/**
121
	 * {@inheritDoc}
122
	 */
123
	public final Iterator<IMapping> mappings() {
124
		initializeMappings();
125
		return mappings.values().iterator();
126
	}
127
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaManagedTypeProvider.java (+222 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.Map;
19
import org.eclipse.jpt.jpa.core.JpaFacet;
20
import org.eclipse.jpt.jpa.core.JpaPlatform;
21
import org.eclipse.jpt.jpa.core.JpaProject;
22
import org.eclipse.jpt.jpa.core.context.Embeddable;
23
import org.eclipse.jpt.jpa.core.context.Entity;
24
import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
25
import org.eclipse.jpt.jpa.core.context.PersistentType;
26
import org.eclipse.jpt.jpa.core.context.TypeMapping;
27
import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer;
28
import org.eclipse.persistence.utils.jpa.query.TypeHelper;
29
import org.eclipse.persistence.utils.jpa.query.spi.IJPAVersion;
30
import org.eclipse.persistence.utils.jpa.query.spi.IManagedType;
31
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeProvider;
32
import org.eclipse.persistence.utils.jpa.query.spi.IPlatform;
33
import org.eclipse.persistence.utils.jpa.query.spi.IType;
34
35
/**
36
 * The abstract implementation of {@link IManagedTypeProvider} that is wrapping the design-time
37
 * representation of a provider of managed types.
38
 *
39
 * @version 3.0
40
 * @since 3.0
41
 * @author Pascal Filion
42
 */
43
abstract class JpaManagedTypeProvider implements IManagedTypeProvider {
44
45
	/**
46
	 * The project that gives access to the application's metadata.
47
	 */
48
	private final JpaProject jpaProject;
49
50
	/**
51
	 * The cached {@link IManagedType managed types}.
52
	 */
53
	private Map<String, IManagedType> managedTypes;
54
55
	/**
56
	 * The design-time provider of managed types.
57
	 */
58
	private final PersistentTypeContainer persistentTypeContainer;
59
60
	/**
61
	 * The external form of a type repository.
62
	 */
63
	private JpaTypeRepository typeRepository;
64
65
	/**
66
	 * The version of the Java Persistence this entity for which it was defined.
67
	 */
68
	private IJPAVersion version;
69
70
	/**
71
	 * Creates a new <code>JpaManagedTypeProvider</code>.
72
	 * 
73
	 * @param jpaProject The project that gives access to the application's metadata
74
	 * @param persistentTypeContainer The design-time provider of managed types
75
	 */
76
	JpaManagedTypeProvider(JpaProject jpaProject, PersistentTypeContainer persistentTypeContainer) {
77
78
		super();
79
		this.jpaProject = jpaProject;
80
		this.persistentTypeContainer = persistentTypeContainer;
81
	}
82
83
	private IManagedType buildManagedType(PersistentType persistentType) {
84
85
		TypeMapping mappedClass = persistentType.getMapping();
86
87
		if (mappedClass instanceof Entity) {
88
			return new JpaEntity(this, (Entity) mappedClass);
89
		}
90
91
		if (mappedClass instanceof MappedSuperclass) {
92
			return new JpaMappedSuperclass(this, (MappedSuperclass) mappedClass);
93
		}
94
95
		if (mappedClass instanceof Embeddable) {
96
			return new JpaEmbeddable(this, (Embeddable) mappedClass);
97
		}
98
99
		return new JpaNullManagedType(this, mappedClass);
100
	}
101
102
	private Map<String, IManagedType> buildManagedTypes() {
103
		Map<String, IManagedType> managedTypes = new HashMap<String, IManagedType>();
104
		for (Iterator<? extends PersistentType> iter = persistenceTypes(); iter.hasNext(); ) {
105
			PersistentType persistentType = iter.next();
106
			managedTypes.put(persistentType.getMapping().getName(), buildManagedType(persistentType));
107
		}
108
		return managedTypes;
109
	}
110
111
	private IJPAVersion convert(JpaPlatform.Version version) {
112
113
		String jpaVersion = version.getJpaVersion();
114
115
		if (JpaFacet.VERSION_1_0.getVersionString().equals(jpaVersion)) {
116
			return IJPAVersion.VERSION_1_0;
117
		}
118
119
		return IJPAVersion.VERSION_2_0;
120
	}
121
122
	/**
123
	 * {@inheritDoc}
124
	 */
125
	public Iterator<String> entityNames() {
126
		initializeManagedTypes();
127
		return managedTypes.keySet().iterator();
128
	}
129
130
	/**
131
	 * {@inheritDoc}
132
	 */
133
	public IManagedType getManagedType(IType type) {
134
135
		initializeManagedTypes();
136
137
		for (IManagedType managedType : managedTypes.values()) {
138
			if (managedType.getType() == type) {
139
				return managedType;
140
			}
141
		}
142
143
		return null;
144
	}
145
146
	/**
147
	 * {@inheritDoc}
148
	 */
149
	public IManagedType getManagedType(String abstractSchemaName) {
150
		initializeManagedTypes();
151
		return managedTypes.get(abstractSchemaName);
152
	}
153
154
	/**
155
	 * Returns the container of managed types.
156
	 *
157
	 * @return The container of managed types
158
	 */
159
	PersistentTypeContainer getPersistentTypeContainer() {
160
		return persistentTypeContainer;
161
	}
162
163
	/**
164
	 * {@inheritDoc}
165
	 */
166
	public IPlatform getPlatform() {
167
		return IPlatform.JAVA;
168
		// TODO
169
//		return (jpaProject instanceof EclipseLinkJpaProject) ? IPlatform.ECLIPSE_LINK : IPlatform.JAVA;
170
	}
171
172
	/**
173
	 * Returns the encapsulated {@link PersistentType}, which is the actual object.
174
	 *
175
	 * @return The design-time representation of a managed type provider
176
	 */
177
	PersistentTypeContainer getProvider() {
178
		return persistentTypeContainer;
179
	}
180
181
	/**
182
	 * {@inheritDoc}
183
	 */
184
	public JpaTypeRepository getTypeRepository() {
185
		if (typeRepository == null) {
186
			typeRepository = new JpaTypeRepository(jpaProject.getJavaProject());
187
			TypeHelper.setTypeRepository(typeRepository);
188
		}
189
		return typeRepository;
190
	}
191
192
	/**
193
	 * {@inheritDoc}
194
	 */
195
	public IJPAVersion getVersion() {
196
		if (version == null) {
197
			version = convert(jpaProject.getJpaPlatform().getJpaVersion());
198
		}
199
		return version;
200
	}
201
202
	private void initializeManagedTypes() {
203
		if (managedTypes == null) {
204
			managedTypes = buildManagedTypes();
205
		}
206
	}
207
208
	/**
209
	 * {@inheritDoc}
210
	 */
211
	public Iterator<IManagedType> managedTypes() {
212
		initializeManagedTypes();
213
		return managedTypes.values().iterator();
214
	}
215
216
	/**
217
	 * Retrieves the managed types from the design-time provider.
218
	 *
219
	 * @return The managed types that are defined only in the provider
220
	 */
221
	abstract Iterator<? extends PersistentType> persistenceTypes();
222
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMappedSuperclass.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
17
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeVisitor;
18
import org.eclipse.persistence.utils.jpa.query.spi.IMappedSuperclass;
19
20
/**
21
 * The concrete implementation of {@link IMappedSuperclass} that is wrapping the design-time
22
 * representation of a JPA mapped superclass.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
final class JpaMappedSuperclass extends JpaManagedType
29
                                implements IMappedSuperclass {
30
31
	/**
32
	 * Creates a new <code>JpaMappedSuperclass</code>.
33
	 *
34
	 * @param provider The provider of JPA managed types
35
	 * @param mappedSuperclass The design-time model object wrapped by this class
36
	 */
37
	JpaMappedSuperclass(JpaManagedTypeProvider provider, MappedSuperclass mappedSuperclass) {
38
		super(provider, mappedSuperclass);
39
	}
40
41
	/**
42
	 * {@inheritDoc}
43
	 */
44
	public void accept(IManagedTypeVisitor visitor) {
45
		visitor.visit(this);
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	@Override
52
	MappedSuperclass getManagedType() {
53
		return (MappedSuperclass) super.getManagedType();
54
	}
55
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java (+245 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.annotation.Annotation;
17
import java.util.Iterator;
18
import java.util.List;
19
import org.eclipse.jpt.common.utility.internal.CollectionTools;
20
import org.eclipse.jpt.common.utility.internal.StringTools;
21
import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
22
import org.eclipse.jpt.jpa.core.MappingKeys;
23
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
24
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
25
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
26
import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
27
import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
28
import org.eclipse.persistence.utils.jpa.query.spi.IManagedType;
29
import org.eclipse.persistence.utils.jpa.query.spi.IMapping;
30
import org.eclipse.persistence.utils.jpa.query.spi.IMappingType;
31
import org.eclipse.persistence.utils.jpa.query.spi.IType;
32
import org.eclipse.persistence.utils.jpa.query.spi.ITypeDeclaration;
33
34
/**
35
 * The concrete implementation of {@link IMapping} that is wrapping the design-time representation
36
 * of a mapping.
37
 *
38
 * @version 3.0
39
 * @since 3.0
40
 * @author Pascal Filion
41
 */
42
@SuppressWarnings("nls")
43
final class JpaMapping implements IMapping {
44
45
	/**
46
	 * The design-time {@link AttributeMapping} wrapped by this class.
47
	 */
48
	private final AttributeMapping mapping;
49
50
	/**
51
	 * The type of the actual mapping.
52
	 */
53
	private IMappingType mappingType;
54
55
	/**
56
	 * The parent of this mapping.
57
	 */
58
	private final JpaManagedType parent;
59
60
	/**
61
	 * The type declaration of the property represented by the mapping.
62
	 */
63
	private ITypeDeclaration typeDeclaration;
64
65
	/**
66
	 * Creates a new <code>JpaMapping</code>.
67
	 *
68
	 * @param parent The parent of this mapping
69
	 * @param mapping The design-time {@link AttributeMapping} wrapped by this class
70
	 */
71
	JpaMapping(JpaManagedType parent, AttributeMapping mapping) {
72
		super();
73
		this.parent  = parent;
74
		this.mapping = mapping;
75
	}
76
77
	private Iterator<ITypeDeclaration> buildGenericTypeDeclarations(JavaResourcePersistentAttribute resource) {
78
		return new TransformationIterator<String, ITypeDeclaration>(resource.typeTypeArgumentNames()) {
79
			@Override
80
			protected ITypeDeclaration transform(String next) {
81
				return getTypeRepository().getType(next).getTypeDeclaration();
82
			}
83
		};
84
	}
85
86
	private ITypeDeclaration[] buildGenericTypeDeclarations() {
87
		JavaPersistentAttribute javaPersistentAttribute = mapping.getPersistentAttribute().getJavaPersistentAttribute();
88
		JavaResourcePersistentAttribute resource = javaPersistentAttribute.getResourcePersistentAttribute();
89
		List<ITypeDeclaration> declarations = CollectionTools.list(buildGenericTypeDeclarations(resource));
90
		return declarations.toArray(new ITypeDeclaration[declarations.size()]);
91
	}
92
93
	private ITypeDeclaration buildTypeDeclaration() {
94
		return new JpaTypeDeclaration(
95
			getTypeRepository().getType(mapping.getPersistentAttribute().getTypeName()),
96
			buildGenericTypeDeclarations(),
97
			false /*TODO*/
98
		);
99
	}
100
101
	/**
102
	 * {@inheritDoc}
103
	 */
104
	public IMappingType getMappingType() {
105
		if (mappingType == null) {
106
			mappingType = mappingType();
107
		}
108
		return mappingType;
109
	}
110
111
	/**
112
	 * {@inheritDoc}
113
	 */
114
	public String getName() {
115
		return mapping.getName();
116
	}
117
118
	/**
119
	 * {@inheritDoc}
120
	 */
121
	public IManagedType getParent() {
122
		return parent;
123
	}
124
125
	/**
126
	 * {@inheritDoc}
127
	 */
128
	public IType getType() {
129
		PersistentAttribute property = mapping.getPersistentAttribute();
130
		return getTypeRepository().getType(property.getTypeName());
131
	}
132
133
	/**
134
	 * {@inheritDoc}
135
	 */
136
	public ITypeDeclaration getTypeDeclaration() {
137
		if (typeDeclaration == null) {
138
			typeDeclaration = buildTypeDeclaration();
139
		}
140
		return typeDeclaration;
141
	}
142
143
	private JpaTypeRepository getTypeRepository() {
144
		return parent.getType().getTypeRepository();
145
	}
146
147
	/**
148
	 * {@inheritDoc}
149
	 */
150
	public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
151
		JavaResourcePersistentAttribute attribute = mapping.getPersistentAttribute().getJavaPersistentAttribute().getResourcePersistentAttribute();
152
		return attribute.getAnnotation(annotationType.getName()) != null;
153
	}
154
155
	private IMappingType mappingType() {
156
157
		String type = mapping.getKey();
158
159
		// Basic
160
		if (type == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) {
161
			return IMappingType.BASIC;
162
		}
163
164
		// Embedded
165
		if (type == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) {
166
			return IMappingType.EMBEDDED;
167
		}
168
169
		// Embedded Id
170
		if (type == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) {
171
			return IMappingType.EMBEDDED_ID;
172
		}
173
174
		// Id
175
		if (type == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) {
176
			return IMappingType.ID;
177
		}
178
179
		// M:M
180
		if (type == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) {
181
			return IMappingType.MANY_TO_MANY;
182
		}
183
184
		// 1:M
185
		if (type == MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) {
186
			return IMappingType.ONE_TO_MANY;
187
		}
188
189
		// M:1
190
		if (type == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) {
191
			return IMappingType.MANY_TO_ONE;
192
		}
193
194
		// 1:1
195
		if (type == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) {
196
			return IMappingType.ONE_TO_ONE;
197
		}
198
199
		// Version
200
		if (type == MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) {
201
			return IMappingType.VERSION;
202
		}
203
204
		// Element Collection
205
		if (type == MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY) {
206
			return IMappingType.ELEMENT_COLLECTION;
207
		}
208
209
		// Basic Collection
210
//		if (type == EclipseLinkMappingKeys.BASIC_COLLECTION_ATTRIBUTE_MAPPING_KEY) {
211
//			return IMappingType.BASIC_COLLECTION;
212
//		}
213
//
214
//		// Basic Map
215
//		if (type == EclipseLinkMappingKeys.BASIC_MAP_ATTRIBUTE_MAPPING_KEY) {
216
//			return IMappingType.BASIC_MAP;
217
//		}
218
//
219
//		// Transformation
220
//		if (type == EclipseLinkMappingKeys.TRANSFORMATION_ATTRIBUTE_MAPPING_KEY) {
221
//			return IMappingType.TRANSFORMATION;
222
//		}
223
//
224
//		// Variable 1:1
225
//		if (type == EclipseLinkMappingKeys.VARIABLE_ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) {
226
//			return IMappingType.VARIABLE_ONE_TO_ONE;
227
//		}
228
229
		return IMappingType.TRANSIENT;
230
	}
231
232
	/**
233
	 * {@inheritDoc}
234
	 */
235
	@Override
236
	public String toString() {
237
		StringBuilder sb = new StringBuilder();
238
		StringTools.buildSimpleToStringOn(this, sb);
239
		sb.append("name=");
240
		sb.append(getName());
241
		sb.append(", mappingType=");
242
		sb.append(getMappingType());
243
		return sb.toString();
244
	}
245
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMappingFile.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.Iterator;
17
import org.eclipse.jpt.jpa.core.JpaProject;
18
import org.eclipse.jpt.jpa.core.context.MappingFile;
19
import org.eclipse.jpt.jpa.core.context.PersistentType;
20
21
/**
22
 * The concrete implementation that is wrapping the design-time representation of a mapping file.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
public class JpaMappingFile extends JpaManagedTypeProvider {
29
30
	/**
31
	 * Creates a new <code>JpaMappingFile</code>.
32
	 * 
33
	 * @param jpaProject The project that gives access to the application's metadata
34
	 * @param persistentTypeContainer The design-time provider of managed types
35
	 */
36
	public JpaMappingFile(JpaProject jpaProject, MappingFile persistentTypeContainer) {
37
		super(jpaProject, persistentTypeContainer);
38
	}
39
40
	/**
41
	 * {@inheritDoc}
42
	 */
43
	@Override
44
	protected MappingFile getPersistentTypeContainer() {
45
		return (MappingFile) super.getPersistentTypeContainer();
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	@Override
52
	protected Iterator<? extends PersistentType> persistenceTypes() {
53
		return getPersistentTypeContainer().getPersistentTypes().iterator();
54
	}
55
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaNullManagedType.java (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.Iterator;
17
import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator;
18
import org.eclipse.jpt.jpa.core.context.TypeMapping;
19
import org.eclipse.persistence.utils.jpa.query.spi.IManagedType;
20
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeProvider;
21
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeVisitor;
22
import org.eclipse.persistence.utils.jpa.query.spi.IMapping;
23
import org.eclipse.persistence.utils.jpa.query.spi.IType;
24
25
/**
26
 * The concrete implementation of {@link IManagedType} that is wrapping the design-time
27
 * representation a "null" managed type.
28
 *
29
 * @version 3.0
30
 * @since 3.0
31
 * @author Pascal Filion
32
 */
33
final class JpaNullManagedType implements IManagedType {
34
35
	/**
36
	 * The provider of JPA managed types.
37
	 */
38
	private final JpaManagedTypeProvider provider;
39
40
	/**
41
	 * The design-time model object wrapped by this class.
42
	 */
43
	private final TypeMapping typeMapping;
44
45
	/**
46
	 * Creates a new <code>JpaNullManagedType</code>.
47
	 *
48
	 * @param managedType The provider of JPA managed types
49
	 * @param typeMapping The design-time model object wrapped by this class
50
	 */
51
	JpaNullManagedType(JpaManagedTypeProvider provider, TypeMapping typeMapping) {
52
		super();
53
		this.provider    = provider;
54
		this.typeMapping = typeMapping;
55
	}
56
57
	/**
58
	 * {@inheritDoc}
59
	 */
60
	public void accept(IManagedTypeVisitor visitor) {
61
	}
62
63
	/**
64
	 * {@inheritDoc}
65
	 */
66
	public IMapping getMappingNamed(String name) {
67
		return null;
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public IManagedTypeProvider getProvider() {
74
		return provider;
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public IType getType() {
81
		return provider.getTypeRepository().getType(typeMapping.getPersistentType().getName());
82
	}
83
84
	/**
85
	 * {@inheritDoc}
86
	 */
87
	public Iterator<IMapping> mappings() {
88
		return EmptyIterator.instance();
89
	}
90
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaPersistenceUnit.java (+71 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.Iterator;
17
import org.eclipse.jpt.common.utility.internal.iterators.CompositeIterator;
18
import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
19
import org.eclipse.jpt.jpa.core.JpaProject;
20
import org.eclipse.jpt.jpa.core.context.PersistentType;
21
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
22
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
23
24
/**
25
 * The concrete implementation that is wrapping the design-time representation of a persistence unit.
26
 *
27
 * @version 3.0
28
 * @since 3.0
29
 * @author Pascal Filion
30
 */
31
public final class JpaPersistenceUnit extends JpaManagedTypeProvider {
32
33
	/**
34
	 * Creates a new <code>JpaPersistenceUnit</code>.
35
	 *
36
	 * @param jpaProject The project that gives access to the application's metadata
37
	 * @param persistentUnit The design-time persistence unit
38
	 */
39
	public JpaPersistenceUnit(JpaProject jpaProject, PersistenceUnit persistentUnit) {
40
		super(jpaProject, persistentUnit);
41
	}
42
43
	/**
44
	 * {@inheritDoc}
45
	 */
46
	@Override
47
	PersistenceUnit getPersistentTypeContainer() {
48
		return (PersistenceUnit) super.getPersistentTypeContainer();
49
	}
50
51
	@SuppressWarnings("unchecked")
52
	private Iterator<ClassRef> javaClassRefs() {
53
		return new CompositeIterator<ClassRef>(
54
			getPersistentTypeContainer().specifiedClassRefs(),
55
			getPersistentTypeContainer().impliedClassRefs()
56
		);
57
	}
58
59
	/**
60
	 * {@inheritDoc}
61
	 */
62
	@Override
63
	Iterator<? extends PersistentType> persistenceTypes() {
64
		return new TransformationIterator<ClassRef, PersistentType>(javaClassRefs()) {
65
			@Override
66
			protected PersistentType transform(ClassRef classRef) {
67
				return classRef.getJavaPersistentType();
68
			}
69
		};
70
	}
71
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaQuery.java (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.jpt.common.utility.internal.StringTools;
17
import org.eclipse.jpt.jpa.core.context.NamedQuery;
18
import org.eclipse.persistence.utils.jpa.query.spi.IQuery;
19
20
/**
21
 * The concrete implementation of {@link IQuery} that is wrapping the design-time representation
22
 * of a JPQL query.
23
 *
24
 * @version 3.0
25
 * @since 3.0
26
 * @author Pascal Filion
27
 */
28
@SuppressWarnings("nls")
29
public final class JpaQuery implements IQuery {
30
31
	/**
32
	 * The actual JPQL query, which can differ from the one owned by the model object, which happens
33
	 * when the model is out of sync because it has not been updated yet.
34
	 */
35
	private String actualQuery;
36
37
	/**
38
	 *  The provider of managed types.
39
	 */
40
	private JpaManagedTypeProvider provider;
41
42
	/**
43
	 * The model object holding onto the JPQL query.
44
	 */
45
	private NamedQuery query;
46
47
	/**
48
	 * Creates a new <code>JpaQuery</code>.
49
	 *
50
	 * @param provider The provider of managed types
51
	 * @param query The model object of the JPQL query
52
	 */
53
	public JpaQuery(JpaManagedTypeProvider provider, NamedQuery query) {
54
		this(provider, query, query.getQuery());
55
	}
56
57
	/**
58
	 * Creates a new <code>JpaQuery</code>.
59
	 *
60
	 * @param provider The provider of managed types
61
	 * @param query The model object of the JPQL query
62
	 * @param actualQuery The actual JPQL query, which can differ from the one owned by the model
63
	 * object, which happens when the model is out of sync because it has not been updated yet
64
	 */
65
	JpaQuery(JpaManagedTypeProvider provider, NamedQuery query, String actualQuery) {
66
		super();
67
		initialize(provider, query, actualQuery);
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public String getExpression() {
74
		return actualQuery;
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public JpaManagedTypeProvider getProvider() {
81
		return provider;
82
	}
83
84
	/**
85
	 * Returns the encapsulated {@link NamedQuery}, which is the actual object.
86
	 *
87
	 * @return The design-time representation of a JPQL query
88
	 */
89
	NamedQuery getQuery() {
90
		return query;
91
	}
92
93
	private void initialize(JpaManagedTypeProvider provider, NamedQuery query, String actualQuery) {
94
95
		this.query       = query;
96
		this.provider    = provider;
97
		this.actualQuery = actualQuery;
98
99
		if (this.actualQuery == null) {
100
			this.actualQuery = StringTools.EMPTY_STRING;
101
		}
102
	}
103
104
	/**
105
	 * {@inheritDoc}
106
	 */
107
	@Override
108
	public String toString() {
109
		StringBuilder sb = new StringBuilder();
110
		sb.append(super.toString());
111
		sb.append(", query=");
112
		sb.append(getExpression());
113
		return sb.toString();
114
	}
115
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaType.java (+362 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.lang.annotation.Annotation;
17
import java.util.ArrayList;
18
import java.util.Collection;
19
import java.util.Collections;
20
import java.util.Iterator;
21
import java.util.List;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.jdt.core.IField;
24
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IType;
26
import org.eclipse.jdt.core.ITypeHierarchy;
27
import org.eclipse.jdt.core.dom.AST;
28
import org.eclipse.jdt.core.dom.ASTNode;
29
import org.eclipse.jdt.core.dom.ASTParser;
30
import org.eclipse.jdt.core.dom.ASTVisitor;
31
import org.eclipse.jdt.core.dom.MethodDeclaration;
32
import org.eclipse.jpt.common.utility.internal.StringTools;
33
import org.eclipse.persistence.utils.jpa.query.parser.ExpressionTools;
34
import org.eclipse.persistence.utils.jpa.query.spi.IConstructor;
35
import org.eclipse.persistence.utils.jpa.query.spi.ITypeDeclaration;
36
37
/**
38
 * The concrete implementation of {@link org.eclipse.persistence.jpa.query.spi.IType IType} that is
39
 * wrapping the design-time representation of a Java type.
40
 *
41
 * @version 3.0
42
 * @since 3.0
43
 * @author Pascal Filion
44
 */
45
final class JpaType implements org.eclipse.persistence.utils.jpa.query.spi.IType {
46
47
	/**
48
	 * The cached collection of {@link IConstructor constructors}.
49
	 */
50
	private Collection<IConstructor> constructors;
51
52
	/**
53
	 * The list of names for the {@link Enum}'s constants otherwise an empty array.
54
	 */
55
	private String[] enumConstants;
56
57
	/**
58
	 * The actual Java type.
59
	 */
60
	private Class<?> javaType;
61
62
	/**
63
	 * The design-time representation of a Java type.
64
	 */
65
	private IType type;
66
67
	/**
68
	 * Caches the type hierarchy of the {@link IType} in order to prevent rebuilding it each time.
69
	 */
70
	private ITypeDeclaration typeDeclaration;
71
72
	/**
73
	 * Caches the type hierarchy of the {@link IType} in order to prevent rebuilding it each time
74
	 * {@link #isAssignableTo(org.eclipse.persistence.jpa.query.spi.IType)} is called.
75
	 */
76
	private ITypeHierarchy typeHierarchy;
77
78
	/**
79
	 * The fully qualified name of the Java type.
80
	 */
81
	private final String typeName;
82
83
	/**
84
	 * The external form of a type repository.
85
	 */
86
	private final JpaTypeRepository typeRepository;
87
88
	/**
89
	 * Creates a new <code>JpaType</code>.
90
	 *
91
	 * @param typeRepository The external form of a type repository
92
	 * @param javaType The actual Java type
93
	 */
94
	JpaType(JpaTypeRepository typeRepository, Class<?> javaType) {
95
		this(typeRepository, javaType.getName());
96
		this.javaType = javaType;
97
	}
98
99
	/**
100
	 * Creates a new <code>JpaType</code>.
101
	 *
102
	 * @param typeRepository The external form of a type repository
103
	 * @param type The design-time representation of a Java type
104
	 */
105
	JpaType(JpaTypeRepository typeRepository, IType type) {
106
		this(typeRepository, type.getFullyQualifiedName());
107
		this.type = type;
108
	}
109
110
	/**
111
	 * Creates a new <code>JpaType</code>.
112
	 *
113
	 * @param typeRepository The external form of a type repository
114
	 * @param typeName The fully qualified name of the Java type
115
	 */
116
	JpaType(JpaTypeRepository typeRepository, String typeName) {
117
		super();
118
		this.typeName       = typeName;
119
		this.typeRepository = typeRepository;
120
	}
121
122
	private ASTNode buildASTNode() {
123
		
124
		ASTParser parser = ASTParser.newParser(AST.JLS3);
125
126
		if (type.getElementType() == IJavaElement.CLASS_FILE) {
127
			parser.setSource(type.getClassFile());
128
		}
129
		else {
130
			parser.setSource(type.getTypeRoot());
131
		}
132
133
		parser.setIgnoreMethodBodies(true); // we don't need method bodies
134
		parser.setResolveBindings(true);
135
		parser.setBindingsRecovery(true); // see bugs 196200, 222735
136
137
		return parser.createAST(new NullProgressMonitor());
138
	}
139
140
	private IConstructor buildConstructor(MethodDeclaration method) {
141
		return new JpaConstructor(typeRepository, method);
142
	}
143
144
	private Collection<IConstructor> buildConstructors() {
145
146
		if (type == null) {
147
			return Collections.emptyList();
148
		}
149
150
		final Collection<IConstructor> constructors = new ArrayList<IConstructor>();
151
		ASTNode astNode = buildASTNode();
152
153
		astNode.accept(new ASTVisitor() {
154
			@Override
155
			public boolean visit(MethodDeclaration node) {
156
				if (node.isConstructor()) {
157
					constructors.add(buildConstructor(node));
158
				}
159
				return true;
160
			}
161
		});
162
163
		return constructors;
164
	}
165
166
	private String[] buildEnumConstants() {
167
168
		try {
169
			if ((type != null) && type.isEnum()) {
170
171
				List<String> names = new ArrayList<String>();
172
173
				for (IField field : type.getFields()) {
174
					if (field.isEnumConstant()) {
175
						names.add(field.getElementName());
176
					}
177
				}
178
179
				return names.toArray(new String[names.size()]);
180
			}
181
		}
182
		catch (Exception e) {
183
			// Just ignore and return an empty array
184
		}
185
186
		return ExpressionTools.EMPTY_STRING_ARRAY;
187
	}
188
189
	private ITypeDeclaration buildTypeDeclaration() {
190
		return new JpaTypeDeclaration(this, new ITypeDeclaration[0], false);
191
	}
192
193
	/**
194
	 * {@inheritDoc}
195
	 */
196
	public Iterator<IConstructor> constructors() {
197
		if (constructors == null) {
198
			constructors = buildConstructors();
199
		}
200
		return constructors.iterator();
201
	}
202
203
	/**
204
	 * {@inheritDoc}
205
	 */
206
	@Override
207
	public boolean equals(Object object) {
208
		return (this == object) || equals((org.eclipse.persistence.utils.jpa.query.spi.IType) object);
209
	}
210
211
	/**
212
	 * {@inheritDoc}
213
	 */
214
	public boolean equals(org.eclipse.persistence.utils.jpa.query.spi.IType type) {
215
		return (this == type) || typeName.equals(type.getName());
216
	}
217
218
	/**
219
	 * {@inheritDoc}
220
	 */
221
	public String[] getEnumConstants() {
222
		if (enumConstants == null) {
223
			enumConstants = buildEnumConstants();
224
		}
225
		return enumConstants;
226
	}
227
228
	/**
229
	 * Returns the encapsulated Java {@link Class}, which is the actual type.
230
	 *
231
	 * @return The actual Java type
232
	 */
233
	Class<?> getJavaType() {
234
		return javaType;
235
	}
236
237
	/**
238
	 * {@inheritDoc}
239
	 */
240
	public String getName() {
241
		return typeName;
242
	}
243
244
	/**
245
	 * Returns the encapsulated {@link Type}, which is the actual type.
246
	 *
247
	 * @return The design-time representation of a Java type
248
	 */
249
	IType getType() {
250
		return type;
251
	}
252
253
	/**
254
	 * {@inheritDoc}
255
	 */
256
	public ITypeDeclaration getTypeDeclaration() {
257
		if (typeDeclaration == null) {
258
			typeDeclaration = buildTypeDeclaration();
259
		}
260
		return typeDeclaration;
261
	}
262
263
	/**
264
	 * Returns the repository that gives access to the application's classes.
265
	 *
266
	 * @return The external form of the type repository
267
	 */
268
	JpaTypeRepository getTypeRepository() {
269
		return typeRepository;
270
	}
271
272
	/**
273
	 * {@inheritDoc}
274
	 */
275
	public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
276
277
		if (type != null) {
278
			return type.getAnnotation(annotationType.getName()) != null;
279
		}
280
281
		if (javaType != null) {
282
			return javaType.isAnnotationPresent(annotationType);
283
		}
284
285
		return false;
286
	}
287
288
	/**
289
	 * {@inheritDoc}
290
	 */
291
	@Override
292
	public int hashCode() {
293
		return typeName.hashCode();
294
	}
295
296
	/**
297
	 * {@inheritDoc}
298
	 */
299
	public boolean isAssignableTo(org.eclipse.persistence.utils.jpa.query.spi.IType type) {
300
301
		if (this == type) {
302
			return true;
303
		}
304
305
		JpaType jpaType = (JpaType) type;
306
307
		// Dealing with two IType
308
		if ((this.type != null) && (jpaType.type != null)) {
309
			try {
310
				// TODO: Use ASTTools.typeIsSubTypeOf() instead
311
				if (typeHierarchy == null) {
312
					typeHierarchy = this.type.newTypeHierarchy(new NullProgressMonitor());
313
				}
314
				return typeHierarchy.contains(jpaType.type);
315
			}
316
			catch (Exception e) {
317
				return false;
318
			}
319
		}
320
321
		// Dealing with two Class<?>
322
		if ((javaType != null) && (jpaType.javaType != null)) {
323
			return jpaType.javaType.isAssignableFrom(javaType);
324
		}
325
326
		// Anything else is always false
327
		return false;
328
	}
329
330
	/**
331
	 * {@inheritDoc}
332
	 */
333
	public boolean isEnum() {
334
335
		if (javaType != null) {
336
			return javaType.isEnum();
337
		}
338
339
		try {
340
			return (type != null) ? type.isEnum() : false;
341
		}
342
		catch (Exception e) {
343
			// Simply ignore and return no
344
			return false;
345
		}
346
	}
347
348
	/**
349
	 * {@inheritDoc}
350
	 */
351
	public boolean isResolvable() {
352
		return (type != null) || (javaType != null);
353
	}
354
355
	/**
356
	 * {@inheritDoc}
357
	 */
358
	@Override
359
	public String toString() {
360
		return StringTools.buildToStringFor(this, typeName);
361
	}
362
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaTypeDeclaration.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import org.eclipse.persistence.utils.jpa.query.spi.IType;
17
import org.eclipse.persistence.utils.jpa.query.spi.ITypeDeclaration;
18
19
/**
20
 * The concrete implementation of {@link ITypeDeclaration} that is wrapping the design-time
21
 * representation of the declaration description of a type.
22
 *
23
 * @version 3.0
24
 * @since 3.0
25
 * @author Pascal Filion
26
 */
27
final class JpaTypeDeclaration implements ITypeDeclaration {
28
29
	/**
30
	 * Determines whether this type represents an array or not.
31
	 */
32
	private boolean array;
33
34
	/**
35
	 * The generics of the given type or an empty list if the type is not parameterized.
36
	 */
37
	private final ITypeDeclaration[] genericTypes;
38
39
	/**
40
	 * The external form of the Java type.
41
	 */
42
	private final IType type;
43
44
	/**
45
	 * Creates a new <code>JpaTypeDeclaration</code>.
46
	 *
47
	 * @param type The external form of the Java type
48
	 * @param genericTypes The generics of the given type or an empty list if the type is not
49
	 * parameterized
50
	 * @param array Determines whether this type represents an array or not
51
	 */
52
	JpaTypeDeclaration(IType type, ITypeDeclaration[] genericTypes, boolean array) {
53
		super();
54
		this.type         = type;
55
		this.genericTypes = genericTypes;
56
		this.array        = array;
57
	}
58
59
	/**
60
	 * {@inheritDoc}
61
	 */
62
	public int getDimensionality() {
63
		return array ? 1 : 0; // TODO
64
	}
65
66
	/**
67
	 * {@inheritDoc}
68
	 */
69
	public IType getType() {
70
		return type;
71
	}
72
73
	/**
74
	 * {@inheritDoc}
75
	 */
76
	public ITypeDeclaration[] getTypeParameters() {
77
		return genericTypes;
78
	}
79
80
	/**
81
	 * {@inheritDoc}
82
	 */
83
	public boolean isArray() {
84
		return array;
85
	}
86
87
	/**
88
	 * {@inheritDoc}
89
	 */
90
	@Override
91
	public String toString() {
92
		return type.getName();
93
	}
94
}
(-)src/org/eclipse/jpt/jpa/core/internal/jpql/JpaTypeRepository.java (+274 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.core.internal.jpql;
15
16
import java.util.HashMap;
17
import java.util.Map;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.persistence.utils.jpa.query.spi.IType;
23
import org.eclipse.persistence.utils.jpa.query.spi.ITypeRepository;
24
25
/**
26
 * The concrete implementation of {@link ITypeRepository} that is wrapping the design-time
27
 * representation of a type repository.
28
 *
29
 * @version 3.0
30
 * @since 3.0
31
 * @author Pascal Filion
32
 */
33
@SuppressWarnings("nls")
34
final class JpaTypeRepository implements ITypeRepository {
35
36
	/**
37
	 * The Java project that gives access the design-time objects representing the Java types.
38
	 */
39
	private final IJavaProject javaProject;
40
41
	/**
42
	 * Keeps a map of the primitives for fast access.
43
	 */
44
	private Map<String, Class<?>> primitives;
45
46
	/**
47
	 * The types that have been cached for faster access.
48
	 */
49
	private final Map<String, JpaType> types;
50
51
	/**
52
	 * Creates a new <code>JpaTypeRepository</code>.
53
	 *
54
	 * @param javaProject The Java project that gives access the design-time objects representing
55
	 * the Java types
56
	 */
57
	JpaTypeRepository(IJavaProject javaProject) {
58
		super();
59
		this.javaProject = javaProject;
60
		this.types       = new HashMap<String, JpaType>();
61
	}
62
63
	private Map<String, Class<?>> buildPrimitives() {
64
		Map<String, Class<?>> primitives = new HashMap<String, Class<?>>();
65
		primitives.put(Byte     .TYPE.getName(), Byte     .TYPE);
66
		primitives.put(Short    .TYPE.getName(), Short    .TYPE);
67
		primitives.put(Character.TYPE.getName(), Character.TYPE);
68
		primitives.put(Integer  .TYPE.getName(), Integer  .TYPE);
69
		primitives.put(Long     .TYPE.getName(), Long     .TYPE);
70
		primitives.put(Float    .TYPE.getName(), Float    .TYPE);
71
		primitives.put(Double   .TYPE.getName(), Double   .TYPE);
72
		primitives.put(Boolean  .TYPE.getName(), Boolean  .TYPE);
73
		return primitives;
74
	}
75
76
	private JpaType buildType(Class<?> javaType) {
77
		JpaType jpaType = new JpaType(this, javaType);
78
		types.put(jpaType.getName(), jpaType);
79
		return jpaType;
80
	}
81
82
	private JpaType buildType(org.eclipse.jdt.core.IType type) {
83
		JpaType jpaType = new JpaType(this, type);
84
		types.put(jpaType.getName(), jpaType);
85
		return jpaType;
86
	}
87
88
	private JpaType buildType(String typeName) {
89
		return new JpaType(this, typeName);
90
	}
91
92
	private Class<?> findPrimitive(String typeName) {
93
		if (primitives == null) {
94
			primitives = buildPrimitives();
95
		}
96
		return primitives.get(typeName);
97
	}
98
99
	/**
100
	 * Retrieves the design-time Java type for the given type name, which has to be the fully
101
	 * qualified type name.
102
	 *
103
	 * @param typeName The fully qualified type name
104
	 * @return The design-time Java type if it could be retrieved; <code>null</code> otherwise
105
	 */
106
	private org.eclipse.jdt.core.IType findType(String typeName) {
107
		try {
108
			return javaProject.findType(typeName);
109
		}
110
		catch (JavaModelException e) {
111
			return null;
112
		}
113
	}
114
115
	/**
116
	 * {@inheritDoc}
117
	 */
118
	public JpaType getEnumType(String enumTypeName) {
119
120
		// Get the position of the last dot so we can remove the constant
121
		int lastDotIndex = enumTypeName.lastIndexOf(".");
122
123
		if (lastDotIndex == -1) {
124
			return null;
125
		}
126
127
		// Retrieve the fully qualified enum type name
128
		String typeName = enumTypeName.substring(0, lastDotIndex);
129
130
		// Attempt to load the enum type
131
		JpaType type = getType(typeName);
132
		return type.isEnum() ? type: null;
133
	}
134
135
	/**
136
	 * Returns
137
	 *
138
	 * @return
139
	 */
140
	IJavaProject getJavaProject() {
141
		return javaProject;
142
	}
143
144
	/**
145
	 * {@inheritDoc}
146
	 */
147
	public JpaType getType(Class<?> javaClass) {
148
		return getType(javaClass.getName());
149
	}
150
151
	/**
152
	 * Retrieves the {@link org.eclipse.jdt.core.IType IType} for the given {@link IResource}.
153
	 *
154
	 * @param resource The workspace location of the {@link org.eclipse.jdt.core.IType IType} to
155
	 * retrieve
156
	 * @return The design-time representation of a Java type
157
	 */
158
	org.eclipse.jdt.core.IType getType(IResource resource) {
159
		try {
160
			return (org.eclipse.jdt.core.IType) javaProject.findElement((IPath) resource);
161
		}
162
		catch (Exception e) {
163
			return null;
164
		}
165
	}
166
167
	/**
168
	 * Retrieves the {@link org.eclipse.jdt.core.IType IType} for the given {@link IResource}.
169
	 *
170
	 * @param resource The workspace location of the {@link org.eclipse.jdt.core.IType IType} to
171
	 * retrieve
172
	 * @return The design-time representation of a Java type
173
	 */
174
	IType getType(org.eclipse.jdt.core.IType type) {
175
		try {
176
			IType jpaType = types.get(type.getFullyQualifiedName());
177
			if (jpaType == null) {
178
				jpaType = buildType(type);
179
			}
180
			return jpaType;
181
		}
182
		catch (Exception e) {
183
			return null;
184
		}
185
	}
186
187
	/**
188
	 * {@inheritDoc}
189
	 */
190
	public JpaType getType(String typeName) {
191
		if (typeName.charAt(0) == '[') {
192
			return loadArrayType(typeName);
193
		}
194
		return loadTypeImp(typeName);
195
	}
196
197
	private JpaType loadArrayType(String typeName) {
198
199
		JpaType type = types.get(typeName);
200
201
		if (type == null) {
202
			try {
203
				// Try to see if the type is a JDK class, otherwise, just use the type name
204
				// since IType doesn't support array types
205
				type = buildType(Class.forName(typeName));
206
			}
207
			catch (Exception e) {
208
				type = buildType(typeName);
209
			}
210
211
			types.put(typeName, type);
212
		}
213
214
		return type;
215
	}
216
217
	private JpaType loadInnerType(String typeName) {
218
219
		int index = typeName.lastIndexOf(".");
220
221
		if (index == -1) {
222
			return null;
223
		}
224
225
		StringBuilder sb = new StringBuilder();
226
		sb.append(typeName.substring(0, index));
227
		sb.append("$");
228
		sb.append(typeName.substring(index + 1, typeName.length()));
229
		typeName = sb.toString();
230
231
		JpaType type = types.get(typeName);
232
233
		if (type == null) {
234
			type = loadTypeImp(typeName);
235
		}
236
237
		return type;
238
	}
239
240
	private JpaType loadTypeImp(String typeName) {
241
242
		JpaType type = types.get(typeName);
243
244
		// The type was already cached, simply return it
245
		if (type != null) {
246
			return type;
247
		}
248
249
		// First check for primitive, they don't have a corresponding IType
250
		Class<?> primitive = findPrimitive(typeName);
251
252
		if (primitive != null) {
253
			return buildType(primitive);
254
		}
255
256
		// Attempt to load the Java type
257
		org.eclipse.jdt.core.IType iType = findType(typeName);
258
259
		// A Java type exists, return it
260
		if (iType != null) {
261
			return buildType(iType);
262
		}
263
264
		// Now try with a possible inner enum type
265
		type = loadInnerType(typeName);
266
267
		// No Java type exists, create a "null" IType
268
		if (type == null) {
269
			type = buildType(typeName);
270
		}
271
272
		return type;
273
	}
274
}
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 32-37 Link Here
32
 org.eclipse.jst.common.project.facet.ui;bundle-version="[1.3.100,2.0.0)",
32
 org.eclipse.jst.common.project.facet.ui;bundle-version="[1.3.100,2.0.0)",
33
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
33
 org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)",
34
 org.eclipse.jst.j2ee.ui;bundle-version="[1.1.200,2.0.0)",
34
 org.eclipse.jst.j2ee.ui;bundle-version="[1.1.200,2.0.0)",
35
 org.eclipse.persistence.utils.jpa.query;bundle-version="1.0.0",
35
 org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
36
 org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
36
 org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
37
 org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
37
 org.eclipse.ui.navigator;bundle-version="[3.3.100,4.0.0)",
38
 org.eclipse.ui.navigator;bundle-version="[3.3.100,4.0.0)",
Lines 64-69 Link Here
64
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.connection;x-internal:=true,
65
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.connection;x-internal:=true,
65
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.options;x-internal:=true,
66
 org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.options;x-internal:=true,
66
 org.eclipse.jpt.jpa.ui.internal.jpa2.platform.generic;x-internal:=true,
67
 org.eclipse.jpt.jpa.ui.internal.jpa2.platform.generic;x-internal:=true,
68
 org.eclipse.jpt.jpa.ui.internal.jpql;x-internal:=true,
67
 org.eclipse.jpt.jpa.ui.internal.listeners;x-internal:=true,
69
 org.eclipse.jpt.jpa.ui.internal.listeners;x-internal:=true,
68
 org.eclipse.jpt.jpa.ui.internal.menus;x-internal:=true,
70
 org.eclipse.jpt.jpa.ui.internal.menus;x-internal:=true,
69
 org.eclipse.jpt.jpa.ui.internal.navigator;x-internal:=true,
71
 org.eclipse.jpt.jpa.ui.internal.navigator;x-internal:=true,
(-)src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlQueryCompletionProposalComputer.java (+605 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation
12
 *
13
 ******************************************************************************/
14
package org.eclipse.jpt.jpa.ui.internal.jpql;
15
16
import java.util.ArrayList;
17
import java.util.Collections;
18
import java.util.Iterator;
19
import java.util.List;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.jdt.core.CompletionContext;
25
import org.eclipse.jdt.core.ICompilationUnit;
26
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.core.JavaModelException;
28
import org.eclipse.jdt.core.dom.CompilationUnit;
29
import org.eclipse.jdt.ui.PreferenceConstants;
30
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
31
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
32
import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
33
import org.eclipse.jface.resource.ImageDescriptor;
34
import org.eclipse.jface.resource.ImageRegistry;
35
import org.eclipse.jface.text.contentassist.CompletionProposal;
36
import org.eclipse.jface.text.contentassist.ICompletionProposal;
37
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
38
import org.eclipse.jpt.common.core.utility.TextRange;
39
import org.eclipse.jpt.jpa.core.JpaFile;
40
import org.eclipse.jpt.jpa.core.JpaStructureNode;
41
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
42
import org.eclipse.jpt.jpa.core.context.NamedQuery;
43
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
44
import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
45
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
46
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
47
import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper;
48
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
49
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
50
import org.eclipse.persistence.utils.jpa.query.ContentAssistItems;
51
import org.eclipse.persistence.utils.jpa.query.parser.Expression;
52
import org.eclipse.persistence.utils.jpa.query.parser.IdentifierRole;
53
import org.eclipse.persistence.utils.jpa.query.parser.JPQLExpression;
54
import org.eclipse.persistence.utils.jpa.query.parser.WordParser;
55
import org.eclipse.persistence.utils.jpa.query.spi.IEmbeddable;
56
import org.eclipse.persistence.utils.jpa.query.spi.IEntity;
57
import org.eclipse.persistence.utils.jpa.query.spi.IManagedType;
58
import org.eclipse.persistence.utils.jpa.query.spi.IManagedTypeVisitor;
59
import org.eclipse.persistence.utils.jpa.query.spi.IMappedSuperclass;
60
import org.eclipse.swt.graphics.Image;
61
import org.eclipse.swt.widgets.Display;
62
63
/**
64
 * This computer adds content completion to a JPQL query defined in a {@link javax.persistence.NamedQuery
65
 * &#64;NamedQuery}.
66
 *
67
 * TODO: Add style to the display string by implementing ICompletionProposalExtension6.
68
 *       StyledString.QUALIFIER_STYLER
69
 *
70
 * @version 3.0
71
 * @since 3.0
72
 * @author Pascal Filion
73
 */
74
@SuppressWarnings("nls")
75
public final class JpaJpqlQueryCompletionProposalComputer implements IJavaCompletionProposalComputer {
76
77
	/**
78
	 * Flag used to determine if the word following the cursor should be overwritten or not.
79
	 */
80
	private boolean completionOverwrite;
81
82
	/**
83
	 * The provider of content assist items based on the position of the cursor within the JPQL query.
84
	 */
85
	private ContentAssistItems contentAssistItems;
86
87
	/**
88
	 * The local registry containing the images used to display the possible choices. The registry is
89
	 * disposed when the session ended.
90
	 */
91
	private ImageRegistry imageRegistry;
92
93
	/**
94
	 * This helper is responsible to retrieve the possible choices to complete or to add more
95
	 * information to a JPQL based on the position of the cursor.
96
	 */
97
	private JpaJpqlQueryHelper queryHelper;
98
99
	/**
100
	 * Creates a new <code>JpaQueryCompletionProposalComputer</code>.
101
	 */
102
	public JpaJpqlQueryCompletionProposalComputer() {
103
		super();
104
	}
105
106
	private Image abstractSchemaNameImage(String abstractSchemaName) {
107
		IManagedType managedType = queryHelper.getQuery().getProvider().getManagedType(abstractSchemaName);
108
		ManagedTypeVisitor visitor = new ManagedTypeVisitor();
109
		managedType.accept(visitor);
110
		return getImage(visitor.imageKey);
111
	}
112
113
	/**
114
	 * Adds {@link ICompletionProposal ICompletionProposals} for the abstract schema names that are
115
	 * possible choices.
116
	 *
117
	 * @param query The current value of the JPQL query
118
	 * @param position The position of the cursor within the JPQL query
119
	 * @param offset The position of the cursor within the document
120
	 * @param proposals The list used to store the new {@link ICompletionProposal ICompletionProposals}
121
	 */
122
	private void addAbstractSchemaNames(String query, int position, int offset, List<ICompletionProposal> proposals) {
123
		for (Iterator<String> iter = contentAssistItems.abstractSchemaNames(); iter.hasNext(); ) {
124
			ICompletionProposal proposal = buildAbstractSchemaNameProposal(query, iter.next(), position, offset);
125
			proposals.add(proposal);
126
		}
127
	}
128
129
	/**
130
	 * Adds {@link ICompletionProposal ICompletionProposals} for the identification variables that
131
	 * are possible choices.
132
	 *
133
	 * @param query The current value of the JPQL query
134
	 * @param position The position of the cursor within the JPQL query
135
	 * @param offset The position of the cursor within the document
136
	 * @param proposals The list used to store the new {@link ICompletionProposal ICompletionProposals}
137
	 */
138
	private void addIdentificationVariables(String query, int position, int offset, List<ICompletionProposal> proposals) {
139
		for (Iterator<String> iter = contentAssistItems.identificationVariables(); iter.hasNext(); ) {
140
			ICompletionProposal proposal = buildIdentificationVariableProposal(query, iter.next(), position, offset);
141
			proposals.add(proposal);
142
		}
143
	}
144
145
	/**
146
	 * Adds {@link ICompletionProposal ICompletionProposals} for the JPQL identifiers that are
147
	 * possible choices.
148
	 *
149
	 * @param query The current value of the JPQL query
150
	 * @param position The position of the cursor within the JPQL query
151
	 * @param offset The position of the cursor within the document
152
	 * @param proposals The list used to store the new {@link ICompletionProposal ICompletionProposals}
153
	 */
154
	private void addIdentifiers(String query, int position, int offset, List<ICompletionProposal> proposals) {
155
		for (Iterator<String> iter = contentAssistItems.identifiers(); iter.hasNext(); ) {
156
			ICompletionProposal proposal = buildIdentifierProposal(query, iter.next(), position, offset);
157
			proposals.add(proposal);
158
		}
159
	}
160
161
	/**
162
	 * Adds {@link ICompletionProposal ICompletionProposals} for the state fields and association
163
	 * fields that are possible choices.
164
	 *
165
	 * @param query The current value of the JPQL query
166
	 * @param position The position of the cursor within the JPQL query
167
	 * @param offset The position of the cursor within the document
168
	 * @param proposals The list used to store the new {@link ICompletionProposal ICompletionProposals}
169
	 */
170
	private void addProperties(String query, int position, int offset, List<ICompletionProposal> proposals) {
171
		for (Iterator<String> iter = contentAssistItems.properties(); iter.hasNext(); ) {
172
			ICompletionProposal proposal = buildPropertyProposal(query, iter.next(), position, offset);
173
			proposals.add(proposal);
174
		}
175
	}
176
177
	private ICompletionProposal buildAbstractSchemaNameProposal(String query,
178
	                                                            String choice,
179
	                                                            int position,
180
	                                                            int offset) {
181
		return buildProposal(
182
			query,
183
			choice,
184
			choice,
185
			abstractSchemaNameImage(choice),
186
			position,
187
			offset
188
		);
189
	}
190
191
	private String buildIdentificationVariableDisplayString(String identificationVariable) {
192
193
		String schemaName = contentAssistItems.getAbstractSchemaName(identificationVariable);
194
195
		if (schemaName != null) {
196
			identificationVariable += " : " + schemaName;
197
		}
198
199
		return identificationVariable;
200
	}
201
202
	private ICompletionProposal buildIdentificationVariableProposal(String query, String choice, int position, int offset) {
203
		return buildProposal(
204
			query,
205
			choice,
206
			buildIdentificationVariableDisplayString(choice),
207
			getImage("full/obj16/jpql.variable"), // TODO
208
			position,
209
			offset
210
		);
211
	}
212
213
	private ICompletionProposal buildIdentifierProposal(String query,
214
	                                                    String choice,
215
	                                                    int position,
216
	                                                    int offset) {
217
218
		IdentifierRole role = JPQLExpression.identifierRole(choice);
219
		boolean realFunction = (role == IdentifierRole.FUNCTION) && isRealFunction(choice);
220
		int cursorOffset = 0;
221
222
		// For JPQL function, we add () to the display string, example: AVG()
223
		// But for TRUE, FALSE, etc, we don't add ()
224
		if (realFunction) {
225
			choice += "()";
226
			cursorOffset--;
227
		}
228
229
		return buildProposal(
230
			query,
231
			choice,
232
			choice,
233
			identifierImage(role, realFunction),
234
			position,
235
			offset,
236
			cursorOffset
237
		);
238
	}
239
240
	private ICompletionProposal buildPropertyProposal(String query, String choice, int position, int offset) {
241
		return buildProposal(query, choice, choice, mappingImage(choice), position, offset);
242
	}
243
244
	private ICompletionProposal buildProposal(String query,
245
	                                          String choice,
246
	                                          String displayString,
247
	                                          Image image,
248
	                                          int position,
249
	                                          int offset) {
250
251
		StringBuilder newQuery = new StringBuilder(query);
252
		newQuery.insert(position, choice);
253
254
		return buildProposal(
255
			query,
256
			choice,
257
			displayString,
258
			image,
259
			position,
260
			offset,
261
			0
262
		);
263
	}
264
265
	/**
266
	 * TODO: Possibly remove the behavior used to manipulate the new query and move it to new
267
	 * subclasses of ICompletionProposal that would take care of it. A ICompletionProposal per
268
	 * proposal type.
269
	 */
270
	private ICompletionProposal buildProposal(String query,
271
	                                          String choice,
272
	                                          String displayString,
273
	                                          Image image,
274
	                                          int position,
275
	                                          int offset,
276
	                                          int cursorOffset) {
277
278
		StringBuilder newQuery = new StringBuilder(query);
279
280
		// First remove from the choice the partial word, which is the non-whitespace or delimiter
281
		// characters before the cursor so when adding the choice, we don't add duplicate characters.
282
		// Example: Emp|, we don't want to add EmpEmployee but Employee, so we remove Emp from the choice
283
		WordParser wordParser = new WordParser(query);
284
		wordParser.setPosition(position);
285
		String partialWord = wordParser.partialWord(position);
286
287
		if (partialWord.length() > 0) {
288
			// Don't remove path expression that is before the last dot, for example:
289
			// e.z| or e.zipcode.|, we don't want to remove e. and e.zipcode respectively
290
			int index = query.lastIndexOf('.', position);
291
			if (index == -1) {
292
				index = partialWord.length();
293
				choice = choice.substring(index);
294
			}
295
			else if (position - partialWord.length() < index) {
296
				index = position - index - 1;
297
				choice = choice.substring(index);
298
			}
299
		}
300
301
		// Now check if we should remove the rest of the word at the cursor position
302
		// before adding the choice
303
		if (completionOverwrite) {
304
			String potentialWord = wordParser.potentialWord();
305
			newQuery.delete(position, position + potentialWord.length());
306
		}
307
308
		// Create what could be the new query if the choice was added
309
		newQuery.insert(position, choice);
310
311
		return new CompletionProposal(
312
			newQuery.toString(),
313
			offset + 1,
314
			query.length(),
315
			position + choice.length() + cursorOffset,
316
			image,
317
			displayString,
318
			null,
319
			null
320
		);
321
	}
322
323
	private List<ICompletionProposal> buildProposals(NamedQuery namedQuery,
324
	                                                 String actualQuery,
325
	                                                 int tokenStart,
326
	                                                 int position,
327
	                                                 CompletionContext completionContext) {
328
329
		completionOverwrite = isCompletionOverwrite(namedQuery.getJpaProject().getJavaProject());
330
		List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
331
332
		queryHelper = new JpaJpqlQueryHelper(namedQuery, actualQuery);
333
		contentAssistItems = queryHelper.buildContentAssistItems(position);
334
335
		addAbstractSchemaNames    (actualQuery, position, tokenStart, proposals);
336
		addIdentificationVariables(actualQuery, position, tokenStart, proposals);
337
		addIdentifiers            (actualQuery, position, tokenStart, proposals);
338
		addProperties             (actualQuery, position, tokenStart, proposals);
339
340
		return proposals;
341
	}
342
343
	private void checkCanceled(IProgressMonitor monitor) throws InterruptedException {
344
		if (monitor.isCanceled()) {
345
			throw new InterruptedException();
346
		}
347
	}
348
349
	/**
350
	 * {@inheritDoc}
351
	 */
352
	@SuppressWarnings("rawtypes")
353
	public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
354
355
		if (context instanceof JavaContentAssistInvocationContext) {
356
			monitor.beginTask(null, 100);
357
			try {
358
				return computeCompletionProposals((JavaContentAssistInvocationContext) context, monitor);
359
			}
360
			catch (Exception e) {
361
				Status status = new Status(IStatus.ERROR, JptJpaCorePlugin.PLUGIN_ID, "Can't retrieve JPQL proposals due to an internal error.", e);
362
				JptJpaCorePlugin.log(status);
363
			}
364
			finally {
365
				monitor.done();
366
			}
367
		}
368
369
		return Collections.emptyList();
370
	}
371
372
	private List<ICompletionProposal> computeCompletionProposals(JavaContentAssistInvocationContext context,
373
	                                                             IProgressMonitor monitor) throws Exception {
374
375
		ICompilationUnit compilationUnit = context.getCompilationUnit();
376
		if (compilationUnit == null) return Collections.emptyList();
377
378
		IFile file = getCorrespondingResource(compilationUnit);
379
		if (file == null) return Collections.emptyList();
380
381
		JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
382
		if (jpaFile == null) return Collections.emptyList();
383
384
		monitor.worked(80);
385
		checkCanceled(monitor);
386
387
		Iterator<JpaStructureNode> rootStructureNodes = jpaFile.rootStructureNodes();
388
		if (!rootStructureNodes.hasNext()) return Collections.emptyList();
389
390
		CompletionContext completionContext = context.getCoreContext();
391
392
		// The token "start" is the offset of the token's first character
393
		int tokenStart = completionContext.getTokenStart();
394
395
		// Not sure why this happens - see bug 242286
396
		if (tokenStart == -1) {
397
			return Collections.emptyList();
398
		}
399
400
		CompilationUnit astRoot = ASTTools.buildASTRoot(compilationUnit);
401
402
		for (Iterator<JpaStructureNode> iter = rootStructureNodes; iter.hasNext(); ) {
403
			// First find the Named Query node
404
			JavaNamedQuery namedQuery = findNamedQuery(iter.next(), astRoot, tokenStart);
405
406
			if (namedQuery != null) {
407
				// Make sure the position within the query (inside the double quotes)
408
				TextRange textRange = namedQuery.getQueryAnnotation().getQueryTextRange(astRoot);
409
				int position = completionContext.getOffset() - textRange.getOffset() - 1;
410
411
				if (position >= 0) {
412
					// Retrieve the actual value of the element "query" since the content assist can be
413
					// invoked before the model received the new content
414
					int tokenEnd = completionContext.getTokenEnd();
415
					String actualQuery = context.getDocument().get(tokenStart + 1, tokenEnd - tokenStart - 1);
416
417
					// Now create the proposals
418
					return buildProposals(namedQuery, actualQuery, tokenStart, position, completionContext);
419
				}
420
			}
421
		}
422
423
		return Collections.emptyList();
424
	}
425
426
	/**
427
	 * {@inheritDoc}
428
	 */
429
	@SuppressWarnings("rawtypes")
430
	public List computeContextInformation(ContentAssistInvocationContext context,
431
	                                      IProgressMonitor monitor) {
432
433
		return Collections.emptyList();
434
	}
435
436
	private JavaNamedQuery findNamedQuery(JpaStructureNode structureNode,
437
	                                      CompilationUnit astRoot,
438
	                                      int tokenStart) {
439
440
		if (structureNode instanceof JavaPersistentType) {
441
			JavaPersistentType persistentType = (JavaPersistentType) structureNode;
442
			JavaTypeMapping typeMapping = persistentType.getMapping();
443
444
			if (typeMapping instanceof JavaEntity) {
445
				JavaEntity entity = (JavaEntity) typeMapping;
446
447
				for (Iterator<JavaNamedQuery> queries = entity.getQueryContainer().namedQueries(); queries.hasNext(); ) {
448
					JavaNamedQuery namedQuery = queries.next();
449
					TextRange textRange = namedQuery.getQueryAnnotation().getQueryTextRange(astRoot);
450
451
					if (textRange.includes(tokenStart)) {
452
						return namedQuery;
453
					}
454
				}
455
			}
456
		}
457
458
		return null;
459
	}
460
461
	private IFile getCorrespondingResource(ICompilationUnit compilationUnit) {
462
		try {
463
			return (IFile) compilationUnit.getCorrespondingResource();
464
		}
465
		catch (JavaModelException ex) {
466
			JptJpaCorePlugin.log(ex);
467
			return null;
468
		}
469
	}
470
471
	/**
472
	 * {@inheritDoc}
473
	 */
474
	public String getErrorMessage() {
475
		return null;
476
	}
477
478
	private Image getImage(String key) {
479
		ImageRegistry imageRegistry = getImageRegistry();
480
		Image image = imageRegistry.get(key);
481
		if (image == null) {
482
			imageRegistry.put(key, getImageDescriptor(key));
483
			image = imageRegistry.get(key);
484
		}
485
		return image;
486
	}
487
488
	/**
489
	 * Returns an image descriptor for the specified <code>.gif<code> file in the icons folder.
490
	 */
491
	private ImageDescriptor getImageDescriptor(String key) {
492
		return JptJpaUiPlugin.getImageDescriptor(key);
493
	}
494
495
	private ImageRegistry getImageRegistry() {
496
		if (imageRegistry == null) {
497
			imageRegistry = new ImageRegistry(Display.getCurrent());
498
		}
499
		return imageRegistry;
500
	}
501
502
	@SuppressWarnings("fallthrough")
503
	private Image identifierImage(IdentifierRole role, boolean realFunction) {
504
505
		if (role != null) {
506
			switch (role) {
507
				case FUNCTION: {
508
					if (realFunction) {
509
						// TODO
510
						return getImage("full/obj16/jpql.function");
511
					}
512
				}
513
				default: {
514
					// TODO
515
					return getImage("full/obj16/jpql.identifier");
516
				}
517
			}
518
		}
519
520
		return null;
521
	}
522
523
	private boolean isCompletionOverwrite(IJavaProject javaProject) {
524
		String value = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, javaProject);
525
		return !Boolean.valueOf(value);
526
	}
527
528
	private boolean isRealFunction(String identifier) {
529
		return identifier != Expression.TRUE         &&
530
		       identifier != Expression.FALSE        &&
531
		       identifier != Expression.NULL         &&
532
		       identifier != Expression.CURRENT_DATE &&
533
		       identifier != Expression.CURRENT_TIME &&
534
		       identifier != Expression.CURRENT_TIMESTAMP;
535
	}
536
537
	private Image mappingImage(String propertyName) {
538
		switch (contentAssistItems.getMappingType(propertyName)) {
539
			case BASIC:               return getImage(JptUiIcons.BASIC);
540
			case BASIC_COLLECTION:    return getImage(JptUiIcons.ELEMENT_COLLECTION);
541
			case BASIC_MAP:           return getImage(JptUiIcons.ELEMENT_COLLECTION);
542
			case ELEMENT_COLLECTION:  return getImage(JptUiIcons.ELEMENT_COLLECTION);
543
			case EMBEDDED:            return getImage(JptUiIcons.EMBEDDED);
544
			case EMBEDDED_ID:         return getImage(JptUiIcons.EMBEDDED_ID);
545
			case ID:                  return getImage(JptUiIcons.ID);
546
			case MANY_TO_MANY:        return getImage(JptUiIcons.MANY_TO_MANY);
547
			case MANY_TO_ONE:         return getImage(JptUiIcons.MANY_TO_ONE);
548
			case ONE_TO_MANY:         return getImage(JptUiIcons.ONE_TO_MANY);
549
			case ONE_TO_ONE:          return getImage(JptUiIcons.ONE_TO_ONE);
550
			case TRANSFORMATION:      return getImage(JptUiIcons.TRANSIENT);  // TODO
551
			case VARIABLE_ONE_TO_ONE: return getImage(JptUiIcons.ONE_TO_ONE); // TODO
552
			case VERSION:             return getImage(JptUiIcons.VERSION);
553
			default:                  return getImage(JptUiIcons.TRANSIENT);
554
		}
555
	}
556
557
	/**
558
	 * {@inheritDoc}
559
	 */
560
	public void sessionEnded() {
561
562
		queryHelper = null;
563
		contentAssistItems = null;
564
565
		if (imageRegistry != null) {
566
			imageRegistry.dispose();
567
		}
568
	}
569
570
	/**
571
	 * {@inheritDoc}
572
	 */
573
	public void sessionStarted() {
574
		// Nothing to do
575
	}
576
577
	private class ManagedTypeVisitor implements IManagedTypeVisitor {
578
579
		/**
580
		 * The key used to retrieve the image representing the managed type.
581
		 */
582
		String imageKey;
583
584
		/**
585
		 * {@inheritDoc}
586
		 */
587
		public void visit(IEmbeddable embeddable) {
588
			imageKey = JptUiIcons.EMBEDDABLE;
589
		}
590
591
		/**
592
		 * {@inheritDoc}
593
		 */
594
		public void visit(IEntity entity) {
595
			imageKey = JptUiIcons.ENTITY;
596
		}
597
598
		/**
599
		 * {@inheritDoc}
600
		 */
601
		public void visit(IMappedSuperclass mappedSuperclass) {
602
			imageKey = JptUiIcons.MAPPED_SUPERCLASS;
603
		}
604
	}
605
}

Return to bug 337930