Skip to content

Method: checkForModuleSignatureExtension(Collection, Metamodel)

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.utils;
19:
20: import cz.cvut.kbss.jopa.model.metamodel.Metamodel;
21: import cz.cvut.kbss.jopa.model.metamodel.gen.GeneratedEntityClass;
22: import cz.cvut.kbss.jopa.proxy.reference.GeneratedEntityReferenceProxy;
23:
24: import java.net.URI;
25: import java.util.Collection;
26: import java.util.Objects;
27: import java.util.Set;
28:
29: /**
30: * Metamodel-related utility functions.
31: */
32: public class MetamodelUtils {
33:
34: private MetamodelUtils() {
35: throw new AssertionError();
36: }
37:
38: /**
39: * Checks whether the specified set of types contains any types not contained in the current module extraction
40: * signature and if so, it adds them into the signature.
41: *
42: * @param types The types to check (can be {@code null})
43: * @param metamodel Persistence unit metamodel containing module extraction signature
44: */
45: public static void checkForModuleSignatureExtension(Collection<?> types, Metamodel metamodel) {
46: Objects.requireNonNull(metamodel);
47:• if (types == null || types.isEmpty()) {
48: return;
49: }
50: final Set<URI> signature = metamodel.getModuleExtractionExtraSignature();
51:• for (Object elem : types) {
52: final URI u = EntityPropertiesUtils.getValueAsURI(elem);
53:• if (!signature.contains(u)) {
54: metamodel.addUriToModuleExtractionSignature(u);
55: }
56: }
57: }
58:
59: /**
60: * Gets an entity class corresponding to the specified class.
61: * <p>
62: * This method returns either the provided class or its superclass in case when the provided class is a generated
63: * subclass created by JOPA.
64: *
65: * @param cls Class to process
66: * @param <T> Type
67: * @return Entity class
68: */
69: public static <T> Class<? super T> getEntityClass(Class<T> cls) {
70: return (cls.getAnnotation(GeneratedEntityClass.class) != null || cls.getAnnotation(GeneratedEntityReferenceProxy.class) != null)
71: ? cls.getSuperclass() : cls;
72: }
73: }