Skip to content

Package: MetamodelImpl

MetamodelImpl

nameinstructionbranchcomplexitylinemethod
MetamodelImpl(Configuration, EntityLoader)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
addUriToModuleExtractionSignature(URI)
M: 4 C: 15
79%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
build(EntityLoader)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
checkForWeaver()
M: 9 C: 7
44%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 3
50%
M: 0 C: 1
100%
embeddable(Class)
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%
entity(Class)
M: 0 C: 26
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getEmbeddables()
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%
getEntities()
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%
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%
getManagedTypes()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getModuleExtractionExtraSignature()
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%
getSignatureInternal()
M: 43 C: 19
31%
M: 3 C: 3
50%
M: 2 C: 2
50%
M: 7 C: 5
42%
M: 0 C: 1
100%
managedType(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%
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;
16:
17: import cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
18: import cz.cvut.kbss.jopa.loaders.EntityLoader;
19: import cz.cvut.kbss.jopa.model.metamodel.*;
20: import cz.cvut.kbss.jopa.query.NamedQueryManager;
21: import cz.cvut.kbss.jopa.utils.Configuration;
22: import cz.cvut.kbss.ontodriver.config.OntoDriverProperties;
23: import org.slf4j.Logger;
24: import org.slf4j.LoggerFactory;
25:
26: import java.net.URI;
27: import java.net.URISyntaxException;
28: import java.util.*;
29:
30: public class MetamodelImpl implements Metamodel {
31:
32: private static final Logger LOG = LoggerFactory.getLogger(Metamodel.class);
33:
34: private static final String ASPECTJ_CLASS = "org.aspectj.weaver.loadtime.Agent";
35:
36: private Map<Class<?>, EntityType<?>> typeMap;
37: private Set<Class<?>> inferredClasses;
38:
39: private NamedQueryManager namedQueryManager;
40:
41: private final Configuration configuration;
42:
43: private Set<URI> moduleExtractionSignature;
44:
45: public MetamodelImpl(Configuration configuration, EntityLoader entityLoader) {
46: this.configuration = Objects.requireNonNull(configuration);
47: Objects.requireNonNull(entityLoader);
48: build(entityLoader);
49: }
50:
51: private void build(EntityLoader entityLoader) {
52: LOG.debug("Building metamodel...");
53: checkForWeaver();
54:
55: final Set<Class<?>> discoveredEntities = entityLoader.discoverEntityClasses(configuration);
56:
57: final MetamodelBuilder metamodelBuilder = new MetamodelBuilder();
58: metamodelBuilder.buildMetamodel(discoveredEntities);
59:
60: this.typeMap = metamodelBuilder.getTypeMap();
61: this.inferredClasses = metamodelBuilder.getInferredClasses();
62: this.namedQueryManager = metamodelBuilder.getNamedQueryManager();
63: }
64:
65: /**
66: * Check the class path for aspectj weaver, which is vital for using lazy loading.
67: */
68: private void checkForWeaver() {
69: try {
70: MetamodelImpl.class.getClassLoader().loadClass(ASPECTJ_CLASS);
71: } catch (ClassNotFoundException e) {
72: LOG.error("AspectJ not found on classpath. Cannot run without AspectJ.");
73: throw new OWLPersistenceException(e);
74: }
75: }
76:
77: @SuppressWarnings("unchecked")
78: @Override
79: public <X> EntityType<X> entity(Class<X> cls) {
80:• if (!typeMap.containsKey(cls)) {
81: throw new IllegalArgumentException(
82: "Class " + cls.getName() + " is not a known entity in this persistence unit.");
83: }
84: return (EntityType<X>) typeMap.get(cls);
85: }
86:
87: @Override
88: public <X> EmbeddableType<X> embeddable(Class<X> cls) {
89: throw new IllegalArgumentException("Embeddable entities not supported.");
90: }
91:
92: @Override
93: public Set<EmbeddableType<?>> getEmbeddables() {
94: return Collections.emptySet();
95: }
96:
97: @Override
98: public Set<EntityType<?>> getEntities() {
99: return new HashSet<>(typeMap.values());
100: }
101:
102: @Override
103: public Set<ManagedType<?>> getManagedTypes() {
104: return new HashSet<>(typeMap.values());
105: }
106:
107: @Override
108: public <X> ManagedType<X> managedType(Class<X> cls) {
109: return entity(cls);
110: }
111:
112: @Override
113: public Set<Class<?>> getInferredClasses() {
114: return Collections.unmodifiableSet(inferredClasses);
115: }
116:
117: public NamedQueryManager getNamedQueryManager() {
118: return namedQueryManager;
119: }
120:
121: @Override
122: public Set<URI> getModuleExtractionExtraSignature() {
123: return Collections.unmodifiableSet(getSignatureInternal());
124: }
125:
126: @Override
127: public void addUriToModuleExtractionSignature(URI uri) {
128:• if (uri == null) {
129: throw new NullPointerException();
130: }
131: synchronized (this) {
132: getSignatureInternal().add(uri);
133: }
134: }
135:
136: private synchronized Set<URI> getSignatureInternal() {
137: // This can be lazily loaded since we don'attributeType know if we'll need it
138:• if (moduleExtractionSignature == null) {
139: final String sig = configuration.get(OntoDriverProperties.MODULE_EXTRACTION_SIGNATURE);
140:• if (sig == null) {
141: this.moduleExtractionSignature = new HashSet<>();
142: } else {
143: final String[] signature = sig.split(OntoDriverProperties.SIGNATURE_DELIMITER);
144: this.moduleExtractionSignature = new HashSet<>(signature.length);
145: try {
146:• for (String uri : signature) {
147: moduleExtractionSignature.add(new URI(uri));
148: }
149: } catch (URISyntaxException e) {
150: throw new OWLPersistenceException("Invalid URI encountered in module extraction signature.", e);
151: }
152: }
153: }
154: return moduleExtractionSignature;
155: }
156: }