Skip to content

Package: AbstractStorageConnector

AbstractStorageConnector

nameinstructionbranchcomplexitylinemethod
AbstractStorageConnector()
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
AbstractStorageConnector(DriverConfiguration)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
close()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
ensureOpen()
M: 5 C: 4
44%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
getStorage()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
initialize()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isOpen()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
unwrap(Class)
M: 0 C: 33
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

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.config.DriverConfiguration;
18: import cz.cvut.kbss.ontodriver.util.Transaction;
19: import org.apache.jena.query.Dataset;
20:
21: /**
22: * Base implementation of the {@link StorageConnector} interface.
23: */
24: abstract class AbstractStorageConnector implements StorageConnector {
25:
26: final DriverConfiguration configuration;
27:
28: final Transaction transaction = new Transaction();
29:
30: private volatile boolean open;
31:
32: Storage storage;
33:
34: /**
35: * Constructs this connector without using any configuration.
36: */
37: AbstractStorageConnector() {
38: this.configuration = null;
39: initialize();
40: this.open = true;
41: }
42:
43: AbstractStorageConnector(DriverConfiguration configuration) {
44: this.configuration = configuration;
45: initialize();
46: this.open = true;
47: }
48:
49: Storage getStorage() {
50: return storage;
51: }
52:
53: @Override
54: public synchronized void close() {
55: this.open = false;
56: }
57:
58: @Override
59: public boolean isOpen() {
60: return open;
61: }
62:
63: void ensureOpen() {
64:• if (!open) {
65: throw new IllegalStateException("This connector is closed.");
66: }
67: }
68:
69: /**
70: * Initializes this connector.
71: * <p>
72: * Does nothing by default.
73: */
74: void initialize() {
75: // Do nothing
76: }
77:
78: @Override
79: public <T> T unwrap(Class<T> cls) {
80:• if (cls.isAssignableFrom(getClass())) {
81: return cls.cast(this);
82:• } else if (cls.isAssignableFrom(Dataset.class)) {
83: return cls.cast(storage.dataset);
84: }
85: throw new UnsupportedOperationException("Unwrapping type " + cls + "not supported.");
86: }
87: }