Skip to content

Package: JenaDataSource

JenaDataSource

nameinstructionbranchcomplexitylinemethod
JenaDataSource()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
close()
M: 1 C: 13
93%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 5
83%
M: 0 C: 1
100%
connect()
M: 1 C: 22
96%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 4
100%
M: 0 C: 1
100%
ensureOpen()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getConnection()
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
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%
reload()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setDataset(Dataset)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setProperties(Map)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setStorageProperties(OntologyStorageProperties)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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;
16:
17: import cz.cvut.kbss.ontodriver.Connection;
18: import cz.cvut.kbss.ontodriver.OntologyStorageProperties;
19: import cz.cvut.kbss.ontodriver.ReloadableDataSource;
20: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
21: import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
22: import org.apache.jena.query.Dataset;
23:
24: import java.util.Collections;
25: import java.util.Map;
26: import java.util.Objects;
27:
28: public class JenaDataSource implements ReloadableDataSource {
29:
30: private volatile boolean open = true;
31:
32: private OntologyStorageProperties storageProperties;
33: private Map<String, String> properties;
34:
35: private JenaDriver driver;
36:
37: @Override
38: public synchronized Connection getConnection() {
39: ensureOpen();
40:• if (driver == null) {
41: connect();
42: }
43: return driver.acquireConnection();
44: }
45:
46: private void ensureOpen() {
47:• if (!open) {
48: throw new IllegalStateException("The data source is closed.");
49: }
50: }
51:
52: private void connect() {
53:• if (storageProperties == null) {
54: throw new IllegalStateException("Data source cannot connect without ontology storage properties.");
55: }
56:• this.driver = new JenaDriver(storageProperties, properties != null ? properties : Collections.emptyMap());
57: }
58:
59: @Override
60: public synchronized void setStorageProperties(OntologyStorageProperties storageProperties) {
61: this.storageProperties = Objects.requireNonNull(storageProperties);
62: }
63:
64: @Override
65: public synchronized void setProperties(Map<String, String> properties) {
66: this.properties = Objects.requireNonNull(properties);
67: }
68:
69: @Override
70: public void close() throws OntoDriverException {
71:• if (!open) {
72: return;
73: }
74: try {
75:• if (driver != null) {
76: driver.close();
77: }
78: } finally {
79: this.open = false;
80: }
81: }
82:
83: @Override
84: public boolean isOpen() {
85: return open;
86: }
87:
88: @Override
89: public void reload() throws JenaDriverException {
90: ensureOpen();
91: driver.reloadStorage();
92: }
93:
94: /**
95: * Sets dataset in the underlying storage.
96: * <p>
97: * Not that this operation is supported only for in-memory storage.
98: *
99: * @param dataset Dataset to set
100: * @throws JenaDriverException If setting new dataset fails
101: */
102: public void setDataset(Dataset dataset) throws JenaDriverException {
103: ensureOpen();
104: driver.setDataset(dataset);
105: }
106: }