Skip to content

Package: ManagedType

ManagedType

Coverage

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