Skip to content

Package: AbstractIdentifiableType

AbstractIdentifiableType

nameinstructionbranchcomplexitylinemethod
AbstractIdentifiableType(Class)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
addDeclaredAttribute(String, AbstractAttribute)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addDeclaredQueryAttribute(String, AbstractQueryAttribute)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addDirectTypes(TypesSpecification)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addOtherProperties(PropertiesSpecification)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addSubtype(AbstractIdentifiableType)
M: 0 C: 15
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
attributeMissing(String, boolean)
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
checkPluralAttribute(Attribute, String, String, Class, Class, boolean)
M: 0 C: 28
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getAttribute(String)
M: 0 C: 27
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getAttributes()
M: 0 C: 18
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getCollection(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getCollection(String, Class)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeclaredAttribute(String)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getDeclaredAttributes()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredCollection(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredCollection(String, Class)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredList(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredList(String, Class)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredMap(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeclaredMap(String, Class, Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeclaredPluralAttribute(String, String, Class, Class)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getDeclaredPluralAttributes()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getDeclaredSet(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeclaredSet(String, Class)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeclaredSingularAttribute(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredSingularAttribute(String, Class)
M: 6 C: 21
78%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 5
83%
M: 0 C: 1
100%
getDeclaredSingularAttributes()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getDeclaredVersion(Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getFieldSpecification(String)
M: 0 C: 82
100%
M: 1 C: 17
94%
M: 1 C: 9
90%
M: 0 C: 13
100%
M: 0 C: 1
100%
getFieldSpecifications()
M: 0 C: 36
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
getIdentifier()
M: 0 C: 25
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getJavaType()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLifecycleListenerManager()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getList(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getList(String, Class)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMap(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMap(String, Class, Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPluralAttribute(String, String, Class, Class)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getPluralAttributes()
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getProperties()
M: 0 C: 15
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getQueryAttribute(String)
M: 13 C: 14
52%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 3 C: 3
50%
M: 0 C: 1
100%
getQueryAttributes()
M: 0 C: 18
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getSet(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSet(String, Class)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSingularAttribute(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSingularAttribute(String, Class)
M: 10 C: 25
71%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 6
86%
M: 0 C: 1
100%
getSingularAttributes()
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getSubtypes()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSupertype()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getTypes()
M: 0 C: 15
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getVersion(Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hasQueryAttribute(String)
M: 0 C: 20
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
hasSingleIdAttribute()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasSubtypes()
M: 0 C: 7
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasVersionAttribute()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isAbstract()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getDeclaredPluralAttributes$0(AbstractAttribute)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getDeclaredSingularAttributes$1(AbstractAttribute)
M: 1 C: 6
86%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getDeclaredSingularAttributes$2(AbstractAttribute)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
pluralAttNotFound(String, String, Class, boolean)
M: 0 C: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setIdentifier(Identifier)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setLifecycleListenerManager(EntityLifecycleListenerManager)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setSupertype(AbstractIdentifiableType)
M: 4 C: 10
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
singularAttNotFound(String, Class, boolean)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.metamodel;
16:
17: import java.lang.reflect.Modifier;
18: import java.util.*;
19: import java.util.stream.Collectors;
20:
21: public abstract class AbstractIdentifiableType<X> implements IdentifiableType<X> {
22:
23: private final Class<X> javaType;
24:
25: private Identifier<X, ?> identifier;
26:
27: private AbstractIdentifiableType<? super X> supertype;
28:
29: private Set<AbstractIdentifiableType<? extends X>> subtypes;
30:
31: private TypesSpecification<X, ?> directTypes;
32:
33: private PropertiesSpecification<X, ?, ?, ?> properties;
34:
35: private final Map<String, AbstractAttribute<X, ?>> declaredAttributes = new HashMap<>();
36:
37: private final Map<String, AbstractQueryAttribute<X, ?>> declaredQueryAttributes = new HashMap<>();
38:
39: private EntityLifecycleListenerManager lifecycleListenerManager = EntityLifecycleListenerManager.empty();
40:
41: AbstractIdentifiableType(Class<X> javaType) {
42: this.javaType = javaType;
43: }
44:
45: void addDeclaredAttribute(final String name, final AbstractAttribute<X, ?> a) {
46: declaredAttributes.put(name, a);
47: }
48:
49: void addDeclaredQueryAttribute(final String name, final AbstractQueryAttribute<X, ?> a) {
50: declaredQueryAttributes.put(name, a);
51: }
52:
53: void setSupertype(AbstractIdentifiableType<? super X> supertype) {
54:• assert supertype != null;
55: this.supertype = supertype;
56: supertype.addSubtype(this);
57: }
58:
59: private void addSubtype(AbstractIdentifiableType<? extends X> subtype) {
60:• if (subtypes == null) {
61: this.subtypes = new HashSet<>(2);
62: }
63: subtypes.add(subtype);
64: }
65:
66: void addDirectTypes(TypesSpecification<X, ?> a) {
67: this.directTypes = a;
68: }
69:
70: void addOtherProperties(PropertiesSpecification<X, ?, ?, ?> a) {
71: this.properties = a;
72: }
73:
74: public void setIdentifier(final Identifier<X, ?> identifier) {
75: this.identifier = identifier;
76: }
77:
78: @Override
79: public boolean hasSingleIdAttribute() {
80: return true; // We do not support id classes
81: }
82:
83: @Override
84: public <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type) {
85: // TODO
86: throw new UnsupportedOperationException();
87: }
88:
89: @Override
90: public AbstractIdentifiableType<? super X> getSupertype() {
91: return supertype;
92: }
93:
94: /**
95: * Whether this managed type has any managed subtypes (entities or mapped superclasses).
96: *
97: * @return {@code true} when managed subtypes exist, {@code false} otherwise
98: */
99: public boolean hasSubtypes() {
100:• return subtypes != null;
101: }
102:
103: /**
104: * Whether the Java type represented by this type is an abstract class.
105: *
106: * @return {@code true} if the represented Java type is abstract, {@code false} otherwise
107: */
108: public boolean isAbstract() {
109: return Modifier.isAbstract(javaType.getModifiers());
110: }
111:
112: public Set<AbstractIdentifiableType<? extends X>> getSubtypes() {
113:• return subtypes != null ? Collections.unmodifiableSet(subtypes) : Collections.emptySet();
114: }
115:
116: @Override
117: public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
118: // TODO
119: throw new UnsupportedOperationException();
120: }
121:
122: @Override
123: public boolean hasVersionAttribute() {
124: return false;
125: }
126:
127: @Override
128: public Set<Attribute<? super X, ?>> getAttributes() {
129: final Set<Attribute<? super X, ?>> attributes = new HashSet<>(declaredAttributes.values());
130:• if (supertype != null) {
131: attributes.addAll(supertype.getAttributes());
132: }
133: return attributes;
134: }
135:
136: @Override
137: public Set<QueryAttribute<? super X, ?>> getQueryAttributes() {
138: final Set<QueryAttribute<? super X, ?>> queryAttributes = new HashSet<>(declaredQueryAttributes.values());
139:• if (supertype != null) {
140: queryAttributes.addAll(supertype.getQueryAttributes());
141: }
142: return queryAttributes;
143: }
144:
145: @Override
146: public AbstractAttribute<? super X, ?> getAttribute(String name) {
147: Objects.requireNonNull(name);
148:• if (declaredAttributes.containsKey(name)) {
149: return declaredAttributes.get(name);
150: }
151:• if (supertype != null) {
152: return supertype.getAttribute(name);
153: }
154: throw attributeMissing(name, false);
155: }
156:
157: protected IllegalArgumentException attributeMissing(String name, boolean declared) {
158:• return new IllegalArgumentException("Attribute " + name + " is not "+ (declared ? "declared" : "present") +" in type " + this);
159: }
160:
161: @Override
162: public boolean hasQueryAttribute(String name) {
163: Objects.requireNonNull(name);
164:• if (declaredQueryAttributes.containsKey(name)) {
165: return true;
166: }
167:• if (supertype != null) {
168: return supertype.hasQueryAttribute(name);
169: }
170: return false;
171: }
172:
173: @Override
174: public AbstractQueryAttribute<? super X, ?> getQueryAttribute(String name) {
175: Objects.requireNonNull(name);
176:• if (declaredQueryAttributes.containsKey(name)) {
177: return declaredQueryAttributes.get(name);
178: }
179:• if (supertype != null) {
180: return supertype.getQueryAttribute(name);
181: }
182: throw attributeMissing(name, false);
183: }
184:
185: @Override
186: public CollectionAttribute<? super X, ?> getCollection(String name) {
187: return getCollection(name, Object.class);
188: }
189:
190: @Override
191: public <E> CollectionAttribute<? super X, E> getCollection(String name, Class<E> elementType) {
192: return getPluralAttribute("Collection", name, elementType, CollectionAttribute.class);
193: }
194:
195: private <E, R extends PluralAttribute<? super X, ?, E>> R getPluralAttribute(String type, String name,
196: Class<E> elementType,
197: Class<R> attType) {
198: final Attribute<? super X, ?> a = getAttribute(name);
199:
200: checkPluralAttribute(a, type, name, elementType, attType, false);
201: return attType.cast(a);
202: }
203:
204: private <E, R extends PluralAttribute<? super X, ?, E>> void checkPluralAttribute(Attribute<? super X, ?> att,
205: String type, String name,
206: Class<E> elementType,
207: Class<R> attType,
208: boolean declared) {
209:• if (!attType.isAssignableFrom(att.getClass())) {
210: throw pluralAttNotFound(type, name, elementType, declared);
211: }
212:
213: final PluralAttribute<? super X, ?, E> colAtt = (PluralAttribute<? super X, ?, E>) att;
214:• if (!elementType.isAssignableFrom(colAtt.getBindableJavaType())) {
215: throw pluralAttNotFound(type, name, elementType, declared);
216: }
217: }
218:
219: private IllegalArgumentException pluralAttNotFound(String type, String name, Class<?> elementType,
220: boolean declared) {
221:• return new IllegalArgumentException(type + " attribute " + name + " with element type " + elementType +
222: " is not " + (declared ? "declared" : "present") + " in type " + this);
223: }
224:
225: @Override
226: public <E> ListAttribute<? super X, E> getList(String name, Class<E> elementType) {
227: return getPluralAttribute("List", name, elementType, ListAttribute.class);
228: }
229:
230: @Override
231: public ListAttribute<? super X, ?> getList(String name) {
232: return getList(name, Object.class);
233: }
234:
235: @Override
236: public <K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType, Class<V> valueType) {
237: throw new UnsupportedOperationException();
238: }
239:
240: @Override
241: public MapAttribute<? super X, ?, ?> getMap(String name) {
242: return getMap(name, Object.class, Object.class);
243: }
244:
245: @Override
246: public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) {
247: return getPluralAttribute("Set", name, elementType, SetAttribute.class);
248: }
249:
250: @Override
251: public SetAttribute<? super X, ?> getSet(String name) {
252: return getSet(name, Object.class);
253: }
254:
255: @Override
256: public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
257: final Set<PluralAttribute<? super X, ?, ?>> plurals = new HashSet<>(getDeclaredPluralAttributes());
258:• if (supertype != null) {
259: plurals.addAll(supertype.getPluralAttributes());
260: }
261: return plurals;
262: }
263:
264: @Override
265: public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
266: final Set<SingularAttribute<? super X, ?>> singulars = new HashSet<>(getDeclaredSingularAttributes());
267:• if (supertype != null) {
268: singulars.addAll(supertype.getSingularAttributes());
269: }
270: return singulars;
271: }
272:
273: @Override
274: public <Y> SingularAttribute<? super X, Y> getSingularAttribute(String name, Class<Y> type) {
275: final Attribute<? super X, ?> a = getAttribute(name);
276:
277:• if (a.isCollection()) {
278: throw singularAttNotFound(name, type, false);
279: }
280:• assert a instanceof SingularAttribute;
281:• if (!type.isAssignableFrom(a.getJavaType())) {
282: throw singularAttNotFound(name, type, false);
283: }
284:
285: return (SingularAttribute<? super X, Y>) a;
286: }
287:
288: private IllegalArgumentException singularAttNotFound(String name, Class<?> type, boolean declared) {
289:• return new IllegalArgumentException(
290: "Singular attribute " + name + " of type " + type + " is not " + (declared ? "declared" : "present") +
291: " in type " + this);
292: }
293:
294: @Override
295: public SingularAttribute<? super X, ?> getSingularAttribute(String name) {
296: return getSingularAttribute(name, Object.class);
297: }
298:
299: @Override
300: public Set<Attribute<X, ?>> getDeclaredAttributes() {
301: return new HashSet<>(declaredAttributes.values());
302: }
303:
304: @Override
305: public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
306: return declaredAttributes.values().stream().filter(Attribute::isCollection)
307: .map(a -> (PluralAttribute<X, ?, ?>) a).collect(Collectors.toSet());
308: }
309:
310: @Override
311: public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
312:• return declaredAttributes.values().stream().filter(att -> !att.isCollection()).map(
313: a -> (SingularAttribute<X, ?>) a).collect(Collectors.toSet());
314: }
315:
316: @Override
317: public AbstractAttribute<X, ?> getDeclaredAttribute(String name) {
318:• if (declaredAttributes.containsKey(name)) {
319: return declaredAttributes.get(name);
320: }
321: throw attributeMissing(name, true);
322: }
323:
324: @Override
325: public <E> CollectionAttribute<X, E> getDeclaredCollection(String name, Class<E> elementType) {
326: return getDeclaredPluralAttribute("Collection", name, elementType, CollectionAttribute.class);
327: }
328:
329: private <E, R extends PluralAttribute<? super X, ?, E>> R getDeclaredPluralAttribute(String type, String name,
330: Class<E> elementType,
331: Class<R> attType) {
332: final Attribute<? super X, ?> a = getDeclaredAttribute(name);
333:
334: checkPluralAttribute(a, type, name, elementType, attType, true);
335: return attType.cast(a);
336: }
337:
338: @Override
339: public CollectionAttribute<X, ?> getDeclaredCollection(String name) {
340: return getDeclaredCollection(name, Object.class);
341: }
342:
343: @Override
344: public <E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType) {
345: return getDeclaredPluralAttribute("List", name, elementType, ListAttribute.class);
346: }
347:
348: @Override
349: public ListAttribute<X, ?> getDeclaredList(String name) {
350: return getDeclaredList(name, Object.class);
351: }
352:
353: @Override
354: public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
355: throw new UnsupportedOperationException();
356: }
357:
358: @Override
359: public MapAttribute<X, ?, ?> getDeclaredMap(String name) {
360: return getDeclaredMap(name, Object.class, Object.class);
361: }
362:
363: @Override
364: public <E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType) {
365: return getDeclaredPluralAttribute("Set", name, elementType, SetAttribute.class);
366: }
367:
368: @Override
369: public SetAttribute<X, ?> getDeclaredSet(String name) {
370: return getDeclaredSet(name, Object.class);
371: }
372:
373: @Override
374: public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(String name, Class<Y> type) {
375: final Attribute<X, ?> a = getDeclaredAttribute(name);
376:
377:• if (a.isCollection()) {
378: throw singularAttNotFound(name, type, true);
379: }
380:• if (!type.isAssignableFrom(a.getJavaType())) {
381: throw singularAttNotFound(name, type, true);
382: }
383:
384: return (SingularAttribute<X, Y>) a;
385: }
386:
387: @Override
388: public SingularAttribute<X, ?> getDeclaredSingularAttribute(String name) {
389: return getDeclaredSingularAttribute(name, Object.class);
390: }
391:
392: @Override
393: public TypesSpecification<? super X, ?> getTypes() {
394:• if (directTypes != null) {
395: return directTypes;
396: }
397:• return supertype != null ? supertype.getTypes() : null;
398: }
399:
400: @Override
401: public PropertiesSpecification<? super X, ?, ?, ?> getProperties() {
402:• if (properties != null) {
403: return properties;
404: }
405:• return supertype != null ? supertype.getProperties() : null;
406: }
407:
408: @Override
409: public Set<FieldSpecification<? super X, ?>> getFieldSpecifications() {
410: final Set<FieldSpecification<? super X, ?>> specs = new HashSet<>(getAttributes());
411: specs.addAll(getQueryAttributes());
412: final TypesSpecification<? super X, ?> types = getTypes();
413:• if (types != null) {
414: specs.add(types);
415: }
416: final PropertiesSpecification<? super X, ?, ?, ?> props = getProperties();
417:• if (props != null) {
418: specs.add(props);
419: }
420: specs.add(getIdentifier());
421: return specs;
422: }
423:
424: @Override
425: public FieldSpecification<? super X, ?> getFieldSpecification(String fieldName) {
426:• if (declaredAttributes.containsKey(fieldName)) {
427: return declaredAttributes.get(fieldName);
428: }
429:• if (declaredQueryAttributes.containsKey(fieldName)) {
430: return declaredQueryAttributes.get(fieldName);
431: }
432:• if (directTypes != null && directTypes.getName().equals(fieldName)) {
433: return directTypes;
434:• } else if (properties != null && properties.getName().equals(fieldName)) {
435: return properties;
436:• } else if (identifier != null && identifier.getName().equals(fieldName)) {
437: return identifier;
438: }
439:• if (supertype != null) {
440: return supertype.getFieldSpecification(fieldName);
441: }
442: throw new IllegalArgumentException("Field " + fieldName + " is not present in type " + this);
443: }
444:
445: @Override
446: public Identifier<? super X, ?> getIdentifier() {
447:• if (identifier != null) {
448: return identifier;
449: }
450:• if (supertype != null) {
451: return supertype.getIdentifier();
452: }
453: // This shouldn't happen, because every entity has to contain an identifier, otherwise metamodel building fails
454: throw new IllegalArgumentException("Identifier attribute is not present in type " + this);
455: }
456:
457: @Override
458: public Class<X> getJavaType() {
459: return javaType;
460: }
461:
462: public EntityLifecycleListenerManager getLifecycleListenerManager() {
463: return lifecycleListenerManager;
464: }
465:
466: public void setLifecycleListenerManager(EntityLifecycleListenerManager lifecycleListenerManager) {
467: this.lifecycleListenerManager = lifecycleListenerManager;
468: }
469: }