-
Notifications
You must be signed in to change notification settings - Fork 14
/
ManagedType.java
394 lines (355 loc) · 16.1 KB
/
ManagedType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/**
* Copyright (C) 2020 Czech Technical University in Prague
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.cvut.kbss.jopa.model.metamodel;
import cz.cvut.kbss.jopa.NonJPA;
import java.util.Set;
/**
* Instances of the type ManagedType represent entity, mapped superclass, and
* embeddable types.
*
* @param <X> The represented type.
*/
public interface ManagedType<X> extends Type<X> {
/**
* Return the attributes of the managed type.
*
* @return attributes of the managed type
*/
Set<Attribute<? super X, ?>> getAttributes();
/**
* Return the attributes declared by the managed type. Returns empty set if
* the managed type has no declared attributes.
*
* @return declared attributes of the managed type
*/
Set<Attribute<X, ?>> getDeclaredAttributes();
/**
* Return the single-valued attribute of the managed type that corresponds
* to the specified name and Java type.
*
* @param name the name of the represented attribute
* @param type the type of the represented attribute
* @return single-valued attribute with given name and type
* @throws IllegalArgumentException if attribute of the given name and type is not present in the managed type
*/
<Y> SingularAttribute<? super X, Y> getSingularAttribute(String name,
Class<Y> type);
/**
* Return the single-valued attribute declared by the managed type that
* corresponds to the specified name and Java type.
*
* @param name the name of the represented attribute
* @param type the type of the represented attribute
* @return declared single-valued attribute of the given name and type
* @throws IllegalArgumentException if attribute of the given name and type is not declared in the managed type
*/
<Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(String name,
Class<Y> type);
/**
* Return the single-valued attributes of the managed type. Returns empty
* set if the managed type has no single-valued attributes.
*
* @return single-valued attributes
*/
Set<SingularAttribute<? super X, ?>> getSingularAttributes();
/**
* Return the single-valued attributes declared by the managed type. Returns
* empty set if the managed type has no declared single-valued attributes.
*
* @return declared single-valued attributes
*/
Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes();
/**
* Return the Collection-valued attribute of the managed type that
* corresponds to the specified name and Java element type.
*
* @param name the name of the represented attribute
* @param elementType the element type of the represented attribute
* @return CollectionAttribute of the given name and element type
* @throws IllegalArgumentException if attribute of the given name and type is not present in the managed type
*/
<E> CollectionAttribute<? super X, E> getCollection(String name,
Class<E> elementType);
/**
* Return the Collection-valued attribute declared by the managed type that
* corresponds to the specified name and Java element type.
*
* @param name the name of the represented attribute
* @param elementType the element type of the represented attribute
* @return declared CollectionAttribute of the given name and element type
* @throws IllegalArgumentException if attribute of the given name and type is not declared in the managed type
*/
<E> CollectionAttribute<X, E> getDeclaredCollection(String name,
Class<E> elementType);
/**
* Return the Set-valued attribute of the managed type that corresponds to
* the specified name and Java element type.
*
* @param name the name of the represented attribute
* @param elementType the element type of the represented attribute
* @return SetAttribute of the given name and element type
* @throws IllegalArgumentException if attribute of the given name and type is not present in the managed type
**/
<E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType);
/**
* Return the Set-valued attribute declared by the managed type that
* corresponds to the specified name and Java element type.
*
* @param name the name of the represented attribute
* @param elementType the element type of the represented attribute
* @return declared SetAttribute of the given name and element type
* @throws IllegalArgumentException if attribute of the given name and type is not declared in the managed type
*/
<E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType);
/**
* Return the List-valued attribute of the managed type that corresponds to
* the specified name and Java element type.
*
* @param name the name of the represented attribute
* @param elementType the element type of the represented attribute
* @return ListAttribute of the given name and element type
* @throws IllegalArgumentException if attribute of the given name and type is not present in the managed type
*/
<E> ListAttribute<? super X, E> getList(String name, Class<E> elementType);
/**
* Return the List-valued attribute declared by the managed type that
* corresponds to the specified name and Java element type.
*
* @param name the name of the represented attribute
* @param elementType the element type of the represented attribute
* @return declared ListAttribute of the given name and element type
* @throws IllegalArgumentException if attribute of the given name and type is not declared in the managed type
*/
<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
/**
* Return the Map-valued attribute of the managed type that corresponds to
* the specified name and Java key and value types.
*
* @param name the name of the represented attribute
* @param keyType the key type of the represented attribute
* @param valueType the value type of the represented attribute
* @return MapAttribute of the given name and key and value types
* @throws IllegalArgumentException if attribute of the given name and type is not present in the managed type
*/
<K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType,
Class<V> valueType);
/**
* Return the Map-valued attribute declared by the managed type that
* corresponds to the specified name and Java key and value types.
*
* @param name the name of the represented attribute
* @param keyType the key type of the represented attribute
* @param valueType the value type of the represented attribute
* @return declared MapAttribute of the given name and key and value types
* @throws IllegalArgumentException if attribute of the given name and type is not declared in the managed type
*/
<K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType,
Class<V> valueType);
/**
* Return all multi-valued attributes (Collection-, Set-, List-, and
* Map-valued attributes) of the managed type. Returns empty set if the
* managed type has no multi-valued attributes.
*
* @return Collection-, Set-, List-, and Map-valued attributes
*/
Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes();
/**
* Return all multi-valued attributes (Collection-, Set-, List-, and
* Map-valued attributes) declared by the managed type. Returns empty set if
* the managed type has no declared multi-valued attributes.
*
* @return declared Collection-, Set-, List-, and Map-valued
* <p>
* attributes
*/
Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes();
// String-based:
/**
* Return the attribute of the managed type that corresponds to the
* specified name.
*
* @param name the name of the represented attribute
* @return attribute with given name
* @throws IllegalArgumentException if attribute of the given
* <p>
* name is not present in the managed type
*/
Attribute<? super X, ?> getAttribute(String name);
/**
* Return the attribute declared by the managed type that corresponds to the
* specified name.
*
* @param name the name of the represented attribute
* @return attribute with given name
* @throws IllegalArgumentException if attribute of the given
* <p>
* name is not declared in the managed type
*/
Attribute<X, ?> getDeclaredAttribute(String name);
/**
* Return the single-valued attribute of the managed type that corresponds
* to the specified name.
*
* @param name the name of the represented attribute
* @return single-valued attribute with the given name
* @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
SingularAttribute<? super X, ?> getSingularAttribute(String name);
/**
* Return the single-valued attribute declared by the managed type that
* corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared single-valued attribute of the given
* <p>
* name
* @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
SingularAttribute<X, ?> getDeclaredSingularAttribute(String name);
/**
* Return the Collection-valued attribute of the managed type that
* corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return CollectionAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
CollectionAttribute<? super X, ?> getCollection(String name);
/**
* Return the Collection-valued attribute declared by the managed type that
* corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared CollectionAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
CollectionAttribute<X, ?> getDeclaredCollection(String name);
/**
* Return the Set-valued attribute of the managed type that corresponds to
* the specified name.
*
* @param name the name of the represented attribute
* @return SetAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
SetAttribute<? super X, ?> getSet(String name);
/**
* Return the Set-valued attribute declared by the managed type that
* corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared SetAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
SetAttribute<X, ?> getDeclaredSet(String name);
/**
* Return the List-valued attribute of the managed type that corresponds to
* the specified name.
*
* @param name the name of the represented attribute
* @return ListAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
ListAttribute<? super X, ?> getList(String name);
/**
* Return the List-valued attribute declared by the managed type that
* corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared ListAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
ListAttribute<X, ?> getDeclaredList(String name);
/**
* Return the Map-valued attribute of the managed type that corresponds to
* the specified name.
*
* @param name the name of the represented attribute
* @return MapAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not present in the managed type
*/
MapAttribute<? super X, ?, ?> getMap(String name);
/**
* Return the Map-valued attribute declared by the managed type that
* corresponds to the specified name.
*
* @param name the name of the represented attribute
* @return declared MapAttribute of the given name
* @throws IllegalArgumentException if attribute of the given name is not declared in the managed type
*/
MapAttribute<X, ?, ?> getDeclaredMap(String name);
/**
* Return the query based attributes of the managed type.
*
* @return query based attributes of the managed type
*/
Set<QueryAttribute<? super X, ?>> getQueryAttributes();
/**
* Check if a query based attribute of the managed type that corresponds to the
* specified name exists.
*
* @param name the name of the represented attribute
* @return {@code true} if the query attribute exists
*/
boolean hasQueryAttribute(String name);
/**
* Return the query based attribute of the managed type that corresponds to the
* specified name.
*
* @param name the name of the represented attribute
* @return attribute with given name
* @throws IllegalArgumentException if attribute of the given
* <p>
* name is not present in the managed type
*/
QueryAttribute<? super X, ?> getQueryAttribute(String name);
/**
* Returns types attribute specified by this managed type.
*
* @return Types specification attribute, {@code null} if there are no types present in this managed type
*/
@NonJPA
TypesSpecification<? super X, ?> getTypes();
/**
* Returns unmapped properties attribute specified by this managed type.
*
* @return Properties specification attribute, {@code null} if there are no unmapped properties present in this
* managed type
*/
@NonJPA
PropertiesSpecification<? super X, ?, ?, ?> getProperties();
/**
* Gets specification of a field with the specified name.
* <p>
* In contrast to {@link #getAttribute(String)}, calling this method can also return field specification for
* a query based attribute, types or properties field.
*
* @param fieldName Name of the field
* @return Field specification
* @throws IllegalArgumentException If attribute of the given name is not present in the managed type
*/
@NonJPA
FieldSpecification<? super X, ?> getFieldSpecification(String fieldName);
/**
* Gets all field specifications of this entity type.
* <p>
* In contrast to {@link #getAttributes()}, this method returns also specifications of query based attributes, types and properties (if
* present).
*
* @return Field specifications
*/
@NonJPA
Set<FieldSpecification<? super X, ?>> getFieldSpecifications();
}