Skip to content

Package: JenaDriver

JenaDriver

nameinstructionbranchcomplexitylinemethod
JenaDriver(OntologyStorageProperties, Map)
M: 4 C: 48
92%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 11
100%
M: 0 C: 1
100%
acquireConnection()
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
buildConnectorFactory(Map)
M: 12 C: 38
76%
M: 1 C: 4
80%
M: 1 C: 3
75%
M: 1 C: 7
88%
M: 0 C: 1
100%
close()
M: 0 C: 25
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
connectionClosed(JenaConnection)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
ensureOpen()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
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%
lambda$new$0(Map, ConfigurationParameter)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$new$1(Map, ConfigurationParameter)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reloadStorage()
M: 6 C: 7
54%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 4
67%
M: 0 C: 1
100%
setDataset(Dataset)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 25
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) 2020 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.ontodriver.jena;
16:
17: import cz.cvut.kbss.ontodriver.Closeable;
18: import cz.cvut.kbss.ontodriver.OntologyStorageProperties;
19: import cz.cvut.kbss.ontodriver.config.ConfigurationParameter;
20: import cz.cvut.kbss.ontodriver.config.DriverConfigParam;
21: import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
22: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
23: import cz.cvut.kbss.ontodriver.jena.config.Constants;
24: import cz.cvut.kbss.ontodriver.jena.config.JenaConfigParam;
25: import cz.cvut.kbss.ontodriver.jena.config.JenaOntoDriverProperties;
26: import cz.cvut.kbss.ontodriver.jena.connector.*;
27: import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
28: import cz.cvut.kbss.ontodriver.jena.util.ConnectionListener;
29: import org.apache.jena.query.Dataset;
30:
31: import java.util.*;
32:
33: class JenaDriver implements Closeable, ConnectionListener {
34:
35: private static final List<ConfigurationParameter> CONFIGS = Arrays
36: .asList(DriverConfigParam.AUTO_COMMIT, DriverConfigParam.REASONER_FACTORY_CLASS,
37: JenaConfigParam.ISOLATION_STRATEGY, JenaConfigParam.STORAGE_TYPE,
38: JenaConfigParam.TREAT_DEFAULT_GRAPH_AS_UNION);
39:
40: private volatile boolean open;
41:
42: private final DriverConfiguration configuration;
43: private final ConnectorFactory connectorFactory;
44:
45: private final Set<JenaConnection> openConnections;
46:
47: private boolean autoCommit;
48:
49: JenaDriver(OntologyStorageProperties storageProperties, Map<String, String> properties) {
50:• assert properties != null;
51: this.configuration = new DriverConfiguration(storageProperties);
52: CONFIGS.stream().filter(c -> properties.containsKey(c.toString()))
53: .forEach(c -> configuration.setProperty(c, properties.get(c.toString())));
54: this.connectorFactory = buildConnectorFactory(properties);
55: this.openConnections = Collections.synchronizedSet(new HashSet<>());
56: this.autoCommit =
57:• configuration.isSet(DriverConfigParam.AUTO_COMMIT) ? configuration.is(DriverConfigParam.AUTO_COMMIT) :
58: Constants.DEFAULT_AUTO_COMMIT;
59: this.open = true;
60: }
61:
62: private ConnectorFactory buildConnectorFactory(Map<String, String> properties) {
63: final String isolationStrategy = configuration
64: .getProperty(JenaConfigParam.ISOLATION_STRATEGY, Constants.DEFAULT_ISOLATION_STRATEGY);
65:• if (configuration.isSet(DriverConfigParam.REASONER_FACTORY_CLASS)) {
66: // Once reasoner factory is set, this takes precedence, because only this factory is able to provide
67: // proper reasoning support
68: return new InferenceConnectorFactory(configuration, properties);
69: }
70:• switch (isolationStrategy) {
71: case JenaOntoDriverProperties.READ_COMMITTED:
72: return new ReadCommittedConnectorFactory(configuration);
73: case JenaOntoDriverProperties.SNAPSHOT:
74: return new SnapshotConnectorFactory(configuration);
75: default:
76: throw new IllegalArgumentException("Unsupported transaction isolation strategy " + isolationStrategy);
77: }
78: }
79:
80: JenaConnection acquireConnection() {
81: ensureOpen();
82: final StorageConnector connector = connectorFactory.createConnector();
83: final JenaAdapter adapter = new JenaAdapter(connector, connectorFactory.createInferredConnector(connector));
84: final JenaConnection connection = new JenaConnection(adapter);
85: connection.registerListener(this);
86: connection.setAutoCommit(autoCommit);
87: openConnections.add(connection);
88: return connection;
89: }
90:
91: private void ensureOpen() {
92:• if (!open) {
93: throw new IllegalStateException("Driver is closed.");
94: }
95: }
96:
97: @Override
98: public void connectionClosed(JenaConnection connection) {
99: openConnections.remove(connection);
100: }
101:
102: synchronized void reloadStorage() throws JenaDriverException {
103: ensureOpen();
104: try {
105: connectorFactory.reloadStorage();
106: } catch (IllegalStateException e) {
107: throw new JenaDriverException(e);
108: }
109: }
110:
111: synchronized void setDataset(Dataset dataset) throws JenaDriverException {
112: ensureOpen();
113: try {
114: connectorFactory.setDataset(dataset);
115: } catch (IllegalArgumentException | IllegalStateException e) {
116: throw new JenaDriverException(e);
117: }
118: }
119:
120: @Override
121: public synchronized void close() throws OntoDriverException {
122:• if (!open) {
123: return;
124: }
125:• for (JenaConnection connection : openConnections) {
126: connection.close();
127: }
128: connectorFactory.close();
129: this.open = false;
130: }
131:
132: @Override
133: public boolean isOpen() {
134: return open;
135: }
136: }