Skip to content

Package: MetamodelImpl

MetamodelImpl

nameinstructionbranchcomplexitylinemethod
MetamodelImpl()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
MetamodelImpl(Configuration)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
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: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
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%
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<?>, ManagedType<?>> typeMap;
37: private Map<Class<?>, EntityType<?>> entities;
38: private Set<Class<?>> inferredClasses;
39:
40: private NamedQueryManager namedQueryManager;
41:
42: private final Configuration configuration;
43:
44: private Set<URI> moduleExtractionSignature;
45:
46: protected MetamodelImpl() {
47: // Protected constructor for easier mocking
48: this.configuration = null;
49: }
50:
51: public MetamodelImpl(Configuration configuration) {
52: this.configuration = Objects.requireNonNull(configuration);
53: }
54:
55: /**
56: * Builds the metamodel for entities discovered by the specified entity loader.
57: *
58: * @param entityLoader Loader of entity classes
59: */
60: public void build(EntityLoader entityLoader) {
61: Objects.requireNonNull(entityLoader);
62: LOG.debug("Building metamodel...");
63: checkForWeaver();
64:
65: final Set<Class<?>> discoveredEntities = entityLoader.discoverEntityClasses(configuration);
66:
67: final MetamodelBuilder metamodelBuilder = new MetamodelBuilder();
68: metamodelBuilder.buildMetamodel(discoveredEntities);
69:
70: this.typeMap = metamodelBuilder.getTypeMap();
71: this.entities = metamodelBuilder.getEntities();
72: this.inferredClasses = metamodelBuilder.getInferredClasses();
73: this.namedQueryManager = metamodelBuilder.getNamedQueryManager();
74: }
75:
76: /**
77: * Check the class path for aspectj weaver, which is vital for using lazy loading.
78: */
79: private void checkForWeaver() {
80: try {
81: MetamodelImpl.class.getClassLoader().loadClass(ASPECTJ_CLASS);
82: } catch (ClassNotFoundException e) {
83: LOG.error("AspectJ not found on classpath. Cannot run without AspectJ.");
84: throw new OWLPersistenceException(e);
85: }
86: }
87:
88: @SuppressWarnings("unchecked")
89: @Override
90: public <X> EntityTypeImpl<X> entity(Class<X> cls) {
91:• if (!entities.containsKey(cls)) {
92: throw new IllegalArgumentException(
93: "Class " + cls.getName() + " is not a known entity in this persistence unit.");
94: }
95: return (EntityTypeImpl<X>) typeMap.get(cls);
96: }
97:
98: @Override
99: public <X> EmbeddableType<X> embeddable(Class<X> cls) {
100: throw new IllegalArgumentException("Embeddable entities not supported.");
101: }
102:
103: @Override
104: public Set<EmbeddableType<?>> getEmbeddables() {
105: return Collections.emptySet();
106: }
107:
108: @Override
109: public Set<EntityType<?>> getEntities() {
110: return new HashSet<>(entities.values());
111: }
112:
113: @Override
114: public Set<ManagedType<?>> getManagedTypes() {
115: return new HashSet<>(typeMap.values());
116: }
117:
118: @Override
119: public Set<Class<?>> getInferredClasses() {
120: return Collections.unmodifiableSet(inferredClasses);
121: }
122:
123: public NamedQueryManager getNamedQueryManager() {
124: return namedQueryManager;
125: }
126:
127: @Override
128: public Set<URI> getModuleExtractionExtraSignature() {
129: return Collections.unmodifiableSet(getSignatureInternal());
130: }
131:
132: @Override
133: public void addUriToModuleExtractionSignature(URI uri) {
134:• if (uri == null) {
135: throw new NullPointerException();
136: }
137: synchronized (this) {
138: getSignatureInternal().add(uri);
139: }
140: }
141:
142: private synchronized Set<URI> getSignatureInternal() {
143: // This can be lazily loaded since we don'attributeType know if we'll need it
144:• if (moduleExtractionSignature == null) {
145: final String sig = configuration.get(OntoDriverProperties.MODULE_EXTRACTION_SIGNATURE);
146:• if (sig == null) {
147: this.moduleExtractionSignature = new HashSet<>();
148: } else {
149: final String[] signature = sig.split(OntoDriverProperties.SIGNATURE_DELIMITER);
150: this.moduleExtractionSignature = new HashSet<>(signature.length);
151: try {
152:• for (String uri : signature) {
153: moduleExtractionSignature.add(new URI(uri));
154: }
155: } catch (URISyntaxException e) {
156: throw new OWLPersistenceException("Invalid URI encountered in module extraction signature.", e);
157: }
158: }
159: }
160: return moduleExtractionSignature;
161: }
162: }