Package: AbstractStorageConnector
AbstractStorageConnector
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AbstractStorageConnector() |
|
|
|
|
|
||||||||||||||||||||
AbstractStorageConnector(DriverConfiguration) |
|
|
|
|
|
||||||||||||||||||||
close() |
|
|
|
|
|
||||||||||||||||||||
ensureOpen() |
|
|
|
|
|
||||||||||||||||||||
getStorage() |
|
|
|
|
|
||||||||||||||||||||
initialize() |
|
|
|
|
|
||||||||||||||||||||
isOpen() |
|
|
|
|
|
||||||||||||||||||||
unwrap(Class) |
|
|
|
|
|
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: }