Skip to content

Package: MetamodelBuilder

MetamodelBuilder

nameinstructionbranchcomplexitylinemethod
MetamodelBuilder()
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
addInferredClass(Class)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
buildMetamodel(Set)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getEntityClass(Class)
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getInferredClasses()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getNamedQueryManager()
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%
getTypeMap()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$buildMetamodel$0(Class)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
processOWLClass(Class)
M: 0 C: 54
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
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) 2016 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 cz.cvut.kbss.jopa.exception.MetamodelInitializationException;
18: import cz.cvut.kbss.jopa.model.EntityTypeImpl;
19: import cz.cvut.kbss.jopa.query.NamedQueryManager;
20: import org.slf4j.Logger;
21: import org.slf4j.LoggerFactory;
22:
23: import java.util.*;
24:
25: public class MetamodelBuilder {
26:
27: private static final Logger LOG = LoggerFactory.getLogger(MetamodelBuilder.class);
28:
29: private final NamedNativeQueryProcessor queryProcessor;
30:
31: private final Map<Class<?>, EntityType<?>> typeMap = new HashMap<>();
32: private final Set<Class<?>> inferredClasses = new HashSet<>();
33: private final NamedQueryManager namedQueryManager = new NamedQueryManager();
34:
35: public MetamodelBuilder() {
36: this.queryProcessor = new NamedNativeQueryProcessor(namedQueryManager);
37: }
38:
39: /**
40: * Builds persistence unit metamodel from the specified set of entities.
41: *
42: * @param entities Entities declared for the persistence unit
43: */
44: public void buildMetamodel(Set<Class<?>> entities) {
45: // AJC won't compile a method reference here
46: entities.forEach(cls -> processOWLClass(cls));
47: }
48:
49: private <X> void processOWLClass(final Class<X> cls) {
50:• if (typeMap.containsKey(cls)) {
51: return;
52: }
53:
54: LOG.debug("Processing OWL class: {}", cls);
55:
56: final EntityTypeImpl<X> et = EntityClassProcessor.processEntityType(cls);
57:
58: typeMap.put(cls, et);
59: final EntityFieldMetamodelProcessor<X> fieldProcessor = new EntityFieldMetamodelProcessor<>(cls, et, this);
60:
61: EntityClassProcessor.getEntityFields(cls).forEach(fieldProcessor::processField);
62:
63:• if (et.getIdentifier() == null) {
64: throw new MetamodelInitializationException("Missing identifier field in entity class " + cls);
65: }
66: queryProcessor.processClass(cls);
67: }
68:
69: public Map<Class<?>, EntityType<?>> getTypeMap() {
70: return Collections.unmodifiableMap(typeMap);
71: }
72:
73: public Set<Class<?>> getInferredClasses() {
74: return Collections.unmodifiableSet(inferredClasses);
75: }
76:
77: public NamedQueryManager getNamedQueryManager() {
78: return namedQueryManager;
79: }
80:
81: void addInferredClass(Class<?> cls) {
82: inferredClasses.add(cls);
83: }
84:
85: @SuppressWarnings("unchecked")
86: <X> EntityType<X> getEntityClass(Class<X> cls) {
87:• if (!typeMap.containsKey(cls)) {
88: processOWLClass(cls);
89: }
90: return (EntityType<X>) typeMap.get(cls);
91: }
92: }