Skip to content

Package: OwlapiDriver

OwlapiDriver

nameinstructionbranchcomplexitylinemethod
OwlapiDriver(OntologyStorageProperties, Map)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
acquireConnection()
M: 4 C: 78
95%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 9
100%
M: 0 C: 1
100%
close()
M: 13 C: 28
68%
M: 3 C: 3
50%
M: 2 C: 2
50%
M: 5 C: 9
64%
M: 0 C: 1
100%
connectionClosed(Connection)
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%
isOpen()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
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) 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.ontodriver.owlapi;
16:
17: import cz.cvut.kbss.ontodriver.Closeable;
18: import cz.cvut.kbss.ontodriver.Connection;
19: import cz.cvut.kbss.ontodriver.OntologyStorageProperties;
20: import cz.cvut.kbss.ontodriver.config.ConfigParam;
21: import cz.cvut.kbss.ontodriver.config.Configuration;
22: import cz.cvut.kbss.ontodriver.config.ConfigurationParameter;
23: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
24: import cz.cvut.kbss.ontodriver.owlapi.config.OwlapiConfigParam;
25: import cz.cvut.kbss.ontodriver.owlapi.connector.ConnectorFactory;
26: import cz.cvut.kbss.ontodriver.owlapi.exception.OwlapiDriverException;
27: import cz.cvut.kbss.ontodriver.owlapi.list.OwlapiLists;
28:
29: import java.util.*;
30:
31: class OwlapiDriver implements Closeable, ConnectionListener {
32:
33: private static final List<ConfigurationParameter> CONFIGS = Arrays
34: .asList(ConfigParam.AUTO_COMMIT, ConfigParam.MODULE_EXTRACTION_SIGNATURE, ConfigParam.ONTOLOGY_LANGUAGE,
35: ConfigParam.REASONER_FACTORY_CLASS,
36: OwlapiConfigParam.IRI_MAPPING_DELIMITER, OwlapiConfigParam.MAPPING_FILE_LOCATION,
37: OwlapiConfigParam.WRITE_ON_COMMIT);
38:
39: private final Configuration configuration;
40: private boolean open = true;
41:
42: private ConnectorFactory connectorFactory;
43: private final Set<OwlapiConnection> openConnections = new HashSet<>();
44:
45: OwlapiDriver(OntologyStorageProperties storageProperties, Map<String, String> properties) {
46: this.configuration = new Configuration(storageProperties);
47: configuration.addConfiguration(properties, CONFIGS);
48: this.connectorFactory = ConnectorFactory.createFactory();
49: }
50:
51: @Override
52: public void close() throws OntoDriverException {
53:• if (!open) {
54: return;
55: }
56:• for (OwlapiConnection c : openConnections) {
57: try {
58: c.removeListener(this);
59: c.close();
60: } catch (Exception e) {
61:• if (e instanceof OntoDriverException) {
62: throw (OntoDriverException) e;
63: } else {
64: throw new OwlapiDriverException(e);
65: }
66: }
67: }
68: connectorFactory.close();
69: this.open = false;
70: }
71:
72: @Override
73: public boolean isOpen() {
74: return open;
75: }
76:
77: Connection acquireConnection() throws OntoDriverException {
78:• assert open;
79: final OwlapiAdapter adapter = new OwlapiAdapter(connectorFactory.getConnector(configuration), configuration);
80: final OwlapiConnection c = new OwlapiConnection(adapter);
81: c.setTypes(new OwlapiTypes(adapter, c::ensureOpen, c::commitIfAuto));
82: c.setProperties(new OwlapiProperties(adapter, c::ensureOpen, c::commitIfAuto));
83: c.setLists(new OwlapiLists(adapter, c::ensureOpen, c::commitIfAuto));
84: openConnections.add(c);
85: c.addListener(this);
86: return c;
87: }
88:
89: @Override
90: public void connectionClosed(Connection connection) {
91: openConnections.remove(connection);
92: }
93: }