Skip to content

Package: ManagedType

ManagedType

Coverage

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