Skip to content

Package: SesameDataSource

SesameDataSource

nameinstructionbranchcomplexitylinemethod
SesameDataSource()
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: 0 C: 14
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
ensureConnected()
M: 3 C: 28
90%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 8
89%
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: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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%
setProperties(Map)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setRepository(Repository)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
setStorageProperties(OntologyStorageProperties)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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.sesame;
16:
17: import cz.cvut.kbss.ontodriver.Connection;
18: import cz.cvut.kbss.ontodriver.DataSource;
19: import cz.cvut.kbss.ontodriver.OntologyStorageProperties;
20: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
21: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
22: import org.eclipse.rdf4j.repository.Repository;
23:
24: import java.util.Collections;
25: import java.util.Map;
26: import java.util.Objects;
27:
28: public class SesameDataSource implements DataSource {
29:
30: private SesameDriver driver;
31: private volatile boolean open = true;
32: private boolean connected;
33:
34: private OntologyStorageProperties storageProperties;
35: private Map<String, String> properties;
36:
37: @Override
38: public synchronized void close() throws OntoDriverException {
39:• if (!open) {
40: return;
41: }
42: try {
43:• if (connected) {
44: driver.close();
45: }
46: } finally {
47: this.open = false;
48: }
49: }
50:
51: @Override
52: public boolean isOpen() {
53: return open;
54: }
55:
56: @Override
57: public synchronized Connection getConnection() throws OntoDriverException {
58: ensureOpen();
59: ensureConnected();
60: return driver.acquireConnection();
61: }
62:
63: private void ensureOpen() {
64:• if (!open) {
65: throw new IllegalStateException("The data source is closed.");
66: }
67: }
68:
69: private void ensureConnected() {
70:• if (connected) {
71: return;
72: }
73:• if (storageProperties == null) {
74: throw new IllegalStateException("Cannot initialize OntoDriver without storageProperties configuration.");
75: }
76:• if (properties == null) {
77: this.properties = Collections.emptyMap();
78: }
79: this.driver = new SesameDriver(storageProperties, properties);
80: this.connected = true;
81: }
82:
83: @Override
84: public void setStorageProperties(OntologyStorageProperties storageProperties) {
85: ensureOpen();
86: this.storageProperties = Objects.requireNonNull(storageProperties);
87: }
88:
89: @Override
90: public void setProperties(Map<String, String> properties) {
91: ensureOpen();
92: this.properties = Objects.requireNonNull(properties);
93: }
94:
95: /**
96: * Sets the underlying repository.
97: * <p>
98: * Note that this functionality is supported only for in-memory stores.
99: *
100: * @param repository The new repository
101: * @throws SesameDriverException When setting repository fails
102: */
103: public synchronized void setRepository(Repository repository) throws SesameDriverException {
104: ensureOpen();
105: ensureConnected();
106: try {
107: driver.setRepository(repository);
108: } catch (IllegalArgumentException | IllegalStateException e) {
109: throw new SesameDriverException(e);
110: }
111: }
112: }