Skip to content

Package: Rdf4jDriver

Rdf4jDriver

nameinstructionbranchcomplexitylinemethod
Rdf4jDriver(OntologyStorageProperties, Map)
M: 8 C: 42
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 11
100%
M: 0 C: 1
100%
acquireConnection()
M: 4 C: 85
96%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 11
100%
M: 0 C: 1
100%
close()
M: 19 C: 17
47%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 8 C: 5
38%
M: 0 C: 1
100%
connectionClosed(Rdf4jConnection)
M: 1 C: 8
89%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
isOpen()
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%
setRepository(Repository)
M: 4 C: 9
69%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.ontodriver.rdf4j;
14:
15: import cz.cvut.kbss.ontodriver.Closeable;
16: import cz.cvut.kbss.ontodriver.Connection;
17: import cz.cvut.kbss.ontodriver.OntologyStorageProperties;
18: import cz.cvut.kbss.ontodriver.config.ConfigurationParameter;
19: import cz.cvut.kbss.ontodriver.config.DriverConfigParam;
20: import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
21: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
22: import cz.cvut.kbss.ontodriver.rdf4j.config.Rdf4jConfigParam;
23: import cz.cvut.kbss.ontodriver.rdf4j.config.RuntimeConfiguration;
24: import cz.cvut.kbss.ontodriver.rdf4j.connector.ConnectorFactory;
25: import cz.cvut.kbss.ontodriver.rdf4j.connector.init.FactoryOfFactories;
26: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
27: import cz.cvut.kbss.ontodriver.rdf4j.loader.StatementLoaderFactory;
28: import org.eclipse.rdf4j.repository.Repository;
29:
30: import java.util.*;
31:
32: class Rdf4jDriver implements Closeable, ConnectionListener<Rdf4jConnection> {
33:
34: private static final List<ConfigurationParameter> CONFIGS = Arrays
35: .asList(DriverConfigParam.AUTO_COMMIT, Rdf4jConfigParam.USE_INFERENCE,
36: Rdf4jConfigParam.USE_VOLATILE_STORAGE, Rdf4jConfigParam.LOAD_ALL_THRESHOLD,
37: Rdf4jConfigParam.RECONNECT_ATTEMPTS, Rdf4jConfigParam.REPOSITORY_CONFIG,
38: Rdf4jConfigParam.INFERENCE_IN_DEFAULT_CONTEXT);
39:
40: private final DriverConfiguration configuration;
41: private boolean open;
42: private final ConnectorFactory connectorFactory;
43: private final StatementLoaderFactory statementLoaderFactory;
44:
45: private final Set<Rdf4jConnection> openedConnections;
46:
47: Rdf4jDriver(OntologyStorageProperties storageProperties,
48: Map<String, String> properties) throws Rdf4jDriverException {
49:• assert storageProperties != null;
50:• assert properties != null;
51:
52: this.configuration = new DriverConfiguration(storageProperties);
53: configuration.addConfiguration(properties, CONFIGS);
54: this.openedConnections = new HashSet<>();
55: final FactoryOfFactories factory = new FactoryOfFactories(configuration);
56: this.connectorFactory = factory.createConnectorFactory();
57: this.statementLoaderFactory = factory.createStatementLoaderFactory();
58: this.open = true;
59: }
60:
61: @Override
62: public void close() throws OntoDriverException {
63:• if (!open) {
64: return;
65: }
66: try {
67:• for (Rdf4jConnection c : openedConnections) {
68: c.removeListener();
69: c.close();
70: }
71: connectorFactory.close();
72: } catch (OntoDriverException e) {
73: throw e;
74: } catch (Exception e) {
75: throw new Rdf4jDriverException(e);
76: } finally {
77: this.open = false;
78: }
79: }
80:
81: @Override
82: public boolean isOpen() {
83: return open;
84: }
85:
86: Connection acquireConnection() {
87:• assert open;
88: final RuntimeConfiguration config = new RuntimeConfiguration(configuration);
89: config.setStatementLoaderFactory(statementLoaderFactory);
90: final Rdf4jAdapter adapter = new Rdf4jAdapter(connectorFactory.createStorageConnector(), config);
91: final Rdf4jConnection c = new Rdf4jConnection(adapter);
92: c.setLists(new Rdf4jLists(adapter, c::ensureOpen, c::commitIfAuto));
93: c.setTypes(new Rdf4jTypes(adapter, c::ensureOpen, c::commitIfAuto));
94: c.setProperties(new Rdf4jProperties(adapter, c::ensureOpen, c::commitIfAuto));
95: openedConnections.add(c);
96: c.setListener(this);
97: return c;
98: }
99:
100: @Override
101: public void connectionClosed(Rdf4jConnection connection) {
102:• if (connection == null) {
103: return;
104: }
105: openedConnections.remove(connection);
106: }
107:
108: /**
109: * Sets the underlying repository.
110: * <p>
111: * Note that this functionality is supported only for in-memory stores.
112: *
113: * @param repository The new repository
114: */
115: void setRepository(Repository repository) throws Rdf4jDriverException {
116:• assert open;
117: connectorFactory.setRepository(repository);
118: }
119: }