Skip to content

Package: TwoStepInstanceLoader

TwoStepInstanceLoader

nameinstructionbranchcomplexitylinemethod
TwoStepInstanceLoader(TwoStepInstanceLoader.TwoStepInstanceLoaderBuilder)
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%
builder()
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%
loadEntity(LoadingParameters)
M: 0 C: 26
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
resolveEntityType(LoadingParameters, IdentifiableEntityType)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

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.oom;
19:
20: import cz.cvut.kbss.jopa.exceptions.StorageAccessException;
21: import cz.cvut.kbss.jopa.model.metamodel.IdentifiableEntityType;
22: import cz.cvut.kbss.jopa.oom.metamodel.PolymorphicEntityTypeResolver;
23: import cz.cvut.kbss.jopa.sessions.util.LoadingParameters;
24: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
25: import cz.cvut.kbss.ontodriver.model.Axiom;
26: import cz.cvut.kbss.ontodriver.model.NamedResource;
27:
28: import java.net.URI;
29: import java.util.Set;
30:
31: class TwoStepInstanceLoader extends EntityInstanceLoader {
32:
33: private TwoStepInstanceLoader(TwoStepInstanceLoaderBuilder builder) {
34: super(builder);
35: }
36:
37: @Override
38: <T> T loadEntity(LoadingParameters<T> loadingParameters) {
39: final IdentifiableEntityType<T> rootEt = metamodel.entity(loadingParameters.getEntityClass());
40: try {
41: final IdentifiableEntityType<? extends T> et = resolveEntityType(loadingParameters, rootEt);
42:• if (et == null) {
43: return null;
44: }
45: return loadInstance(loadingParameters, et);
46: } catch (OntoDriverException e) {
47: throw new StorageAccessException(e);
48: }
49: }
50:
51: private <T> IdentifiableEntityType<? extends T> resolveEntityType(LoadingParameters<T> loadingParameters,
52: IdentifiableEntityType<T> rootEt) throws OntoDriverException {
53: NamedResource individual = NamedResource.create(loadingParameters.getIdentifier());
54: final Set<Axiom<URI>> types = storageConnection.types().getTypes(individual,
55: loadingParameters.getDescriptor().getContexts(), false);
56: return new PolymorphicEntityTypeResolver<>(individual, rootEt, types).determineActualEntityType();
57: }
58:
59: static TwoStepInstanceLoaderBuilder builder() {
60: return new TwoStepInstanceLoaderBuilder();
61: }
62:
63: static class TwoStepInstanceLoaderBuilder extends EntityInstanceLoaderBuilder {
64:
65: @Override
66: EntityInstanceLoader build() {
67: return new TwoStepInstanceLoader(this);
68: }
69: }
70: }