Skip to contentMethod: ensureOpen()
1: /**
2: * Copyright (C) 2023 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.rdf4j.connector;
16:
17: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
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(StorageConnector connector) {
27: this.open = true;
28: this.centralConnector = connector;
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: @Override
44: public void setRepository(Repository repository) {
45: ensureOpen();
46: centralConnector.setRepository(repository);
47: }
48:
49: @Override
50: public synchronized void close() throws OntoDriverException {
51: if (!open) {
52: return;
53: }
54: if (centralConnector != null) {
55: centralConnector.close();
56: this.centralConnector = null;
57: }
58: this.open = false;
59: }
60:
61: @Override
62: public boolean isOpen() {
63: return open;
64: }
65: }