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: 25
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

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