Skip to content

Method: close()

1: /**
2: * Copyright (C) 2020 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.jena.connector;
16:
17: import cz.cvut.kbss.ontodriver.Closeable;
18: import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
19: import org.apache.jena.query.Dataset;
20:
21: public abstract class ConnectorFactory implements Closeable {
22:
23: private volatile boolean open = true;
24:
25: @Override
26: public synchronized void close() throws JenaDriverException {
27: this.open = false;
28: }
29:
30: @Override
31: public boolean isOpen() {
32: return open;
33: }
34:
35: void ensureOpen() {
36: if (!open) {
37: throw new IllegalStateException("Factory is closed.");
38: }
39: }
40:
41: /**
42: * Creates a storage connector.
43: *
44: * @return storage connector
45: */
46: public abstract StorageConnector createConnector();
47:
48: /**
49: * Creates an inference-supporting storage connector.
50: * <p>
51: * The {@code connector} parameter is required because both connector need to be kept in sync so that non-inferred
52: * data are consistent across both connectors.
53: *
54: * @param connector Existing storage connector
55: * @return New inference-supporting storage connector
56: */
57: public InferredStorageConnector createInferredConnector(StorageConnector connector) {
58: return new DummyInferredStorageConnector(connector);
59: }
60:
61: /**
62: * Reloads data from storage if it is a file-based one.
63: * <p>
64: * Does nothing for other types of storage.
65: */
66: public abstract void reloadStorage();
67:
68: /**
69: * Sets dataset on the underlying connector.
70: * <p>
71: * Not that this operation is supported only for in-memory storage.
72: *
73: * @param dataset Dataset to set
74: */
75: public abstract void setDataset(Dataset dataset);
76: }