Skip to content

Package: OwlapiDriver

OwlapiDriver

nameinstructionbranchcomplexitylinemethod
OwlapiDriver(OntologyStorageProperties, Map)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
acquireConnection()
M: 4 C: 80
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: * <p>
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: * <p>
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 OntologyStorageProperties storageProperties;
40: private final Configuration configuration = new Configuration();
41: private boolean open = true;
42:
43: private ConnectorFactory connectorFactory;
44: private final Set<OwlapiConnection> openConnections = new HashSet<>();
45:
46: OwlapiDriver(OntologyStorageProperties storageProperties, Map<String, String> properties) {
47: this.storageProperties = storageProperties;
48: configuration.addConfiguration(properties, CONFIGS);
49: this.connectorFactory = ConnectorFactory.createFactory();
50: }
51:
52: @Override
53: public void close() throws OntoDriverException {
54:• if (!open) {
55: return;
56: }
57:• for (OwlapiConnection c : openConnections) {
58: try {
59: c.removeListener(this);
60: c.close();
61: } catch (Exception e) {
62:• if (e instanceof OntoDriverException) {
63: throw (OntoDriverException) e;
64: } else {
65: throw new OwlapiDriverException(e);
66: }
67: }
68: }
69: connectorFactory.close();
70: this.open = false;
71: }
72:
73: @Override
74: public boolean isOpen() {
75: return open;
76: }
77:
78: Connection acquireConnection() throws OntoDriverException {
79:• assert open;
80: final OwlapiAdapter adapter = new OwlapiAdapter(connectorFactory.getConnector(storageProperties, configuration), configuration);
81: final OwlapiConnection c = new OwlapiConnection(adapter);
82: c.setTypes(new OwlapiTypes(adapter, c::ensureOpen, c::commitIfAuto));
83: c.setProperties(new OwlapiProperties(adapter, c::ensureOpen, c::commitIfAuto));
84: c.setLists(new OwlapiLists(adapter, c::ensureOpen, c::commitIfAuto));
85: openConnections.add(c);
86: c.addListener(this);
87: return c;
88: }
89:
90: @Override
91: public void connectionClosed(Connection connection) {
92: openConnections.remove(connection);
93: }
94: }