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: 41
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 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.ontodriver.rdf4j;
19:
20: import cz.cvut.kbss.ontodriver.Closeable;
21: import cz.cvut.kbss.ontodriver.Connection;
22: import cz.cvut.kbss.ontodriver.OntologyStorageProperties;
23: import cz.cvut.kbss.ontodriver.config.ConfigurationParameter;
24: import cz.cvut.kbss.ontodriver.config.DriverConfigParam;
25: import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
26: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
27: import cz.cvut.kbss.ontodriver.rdf4j.config.Rdf4jConfigParam;
28: import cz.cvut.kbss.ontodriver.rdf4j.config.RuntimeConfiguration;
29: import cz.cvut.kbss.ontodriver.rdf4j.connector.ConnectionFactory;
30: import cz.cvut.kbss.ontodriver.rdf4j.connector.init.FactoryOfFactories;
31: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
32: import cz.cvut.kbss.ontodriver.rdf4j.loader.StatementLoaderFactory;
33: import org.eclipse.rdf4j.repository.Repository;
34:
35: import java.util.*;
36:
37: class Rdf4jDriver implements Closeable, ConnectionListener<Rdf4jConnection> {
38:
39: private static final List<ConfigurationParameter> CONFIGS = Arrays
40: .asList(DriverConfigParam.AUTO_COMMIT, Rdf4jConfigParam.USE_INFERENCE,
41: Rdf4jConfigParam.USE_VOLATILE_STORAGE, Rdf4jConfigParam.LOAD_ALL_THRESHOLD,
42: Rdf4jConfigParam.RECONNECT_ATTEMPTS, Rdf4jConfigParam.REPOSITORY_CONFIG,
43: Rdf4jConfigParam.INFERENCE_IN_DEFAULT_CONTEXT,
44: Rdf4jConfigParam.MAX_CONNECTION_POOL_SIZE, Rdf4jConfigParam.CONNECTION_REQUEST_TIMEOUT);
45:
46: private final DriverConfiguration configuration;
47: private boolean open;
48: private final ConnectionFactory connectionFactory;
49: private final StatementLoaderFactory statementLoaderFactory;
50:
51: private final Set<Rdf4jConnection> openedConnections;
52:
53: Rdf4jDriver(OntologyStorageProperties storageProperties,
54: Map<String, String> properties) throws Rdf4jDriverException {
55:• assert storageProperties != null;
56:• assert properties != null;
57:
58: this.configuration = new DriverConfiguration(storageProperties);
59: configuration.addConfiguration(properties, CONFIGS);
60: this.openedConnections = new HashSet<>();
61: final FactoryOfFactories factory = new FactoryOfFactories(configuration);
62: this.connectionFactory = factory.createConnectorFactory();
63: this.statementLoaderFactory = factory.createStatementLoaderFactory();
64: this.open = true;
65: }
66:
67: @Override
68: public void close() throws OntoDriverException {
69:• if (!open) {
70: return;
71: }
72: try {
73:• for (Rdf4jConnection c : openedConnections) {
74: c.removeListener();
75: c.close();
76: }
77: connectionFactory.close();
78: } catch (OntoDriverException e) {
79: throw e;
80: } catch (Exception e) {
81: throw new Rdf4jDriverException(e);
82: } finally {
83: this.open = false;
84: }
85: }
86:
87: @Override
88: public boolean isOpen() {
89: return open;
90: }
91:
92: Connection acquireConnection() {
93:• assert open;
94: final RuntimeConfiguration config = new RuntimeConfiguration(configuration);
95: config.setStatementLoaderFactory(statementLoaderFactory);
96: final Rdf4jAdapter adapter = new Rdf4jAdapter(connectionFactory.createStorageConnection(), config);
97: final Rdf4jConnection c = new Rdf4jConnection(adapter);
98: c.setLists(new Rdf4jLists(adapter, c::ensureOpen, c::commitIfAuto));
99: c.setTypes(new Rdf4jTypes(adapter, c::ensureOpen, c::commitIfAuto));
100: c.setProperties(new Rdf4jProperties(adapter, c::ensureOpen, c::commitIfAuto));
101: openedConnections.add(c);
102: c.setListener(this);
103: return c;
104: }
105:
106: @Override
107: public void connectionClosed(Rdf4jConnection connection) {
108:• if (connection == null) {
109: return;
110: }
111: openedConnections.remove(connection);
112: }
113:
114: /**
115: * Sets the underlying repository.
116: * <p>
117: * Note that this functionality is supported only for in-memory stores.
118: *
119: * @param repository The new repository
120: */
121: void setRepository(Repository repository) throws Rdf4jDriverException {
122:• assert open;
123: connectionFactory.setRepository(repository);
124: }
125: }