Skip to content

Method: ensureOpen()

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.ontodriver.rdf4j.connector;
14:
15: import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
16: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
17: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
18: import org.eclipse.rdf4j.repository.Repository;
19:
20: public final class ConnectorFactoryImpl implements ConnectorFactory {
21:
22: private boolean open;
23:
24: private StorageConnector centralConnector;
25:
26: public ConnectorFactoryImpl(DriverConfiguration configuration) throws Rdf4jDriverException {
27: this.open = true;
28: initCentralConnector(configuration);
29: }
30:
31: @Override
32: public Connector createStorageConnector() {
33: ensureOpen();
34: return new PoolingStorageConnector(centralConnector);
35: }
36:
37: private void ensureOpen() {
38:• if (!open) {
39: throw new IllegalStateException("The factory is closed!");
40: }
41: }
42:
43: private void initCentralConnector(DriverConfiguration configuration) throws Rdf4jDriverException {
44: this.centralConnector = new StorageConnector(configuration);
45: }
46:
47: @Override
48: public void setRepository(Repository repository) {
49: ensureOpen();
50: centralConnector.setRepository(repository);
51: }
52:
53: @Override
54: public synchronized void close() throws OntoDriverException {
55: if (!open) {
56: return;
57: }
58: if (centralConnector != null) {
59: centralConnector.close();
60: this.centralConnector = null;
61: }
62: this.open = false;
63: }
64:
65: @Override
66: public boolean isOpen() {
67: return open;
68: }
69: }