Skip to content

Method: reloadData()

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