Skip to content

Package: ConnectorFactoryImpl

ConnectorFactoryImpl

nameinstructionbranchcomplexitylinemethod
ConnectorFactoryImpl()
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%
close()
M: 1 C: 16
94%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 6
86%
M: 0 C: 1
100%
createStorageConnector(DriverConfiguration)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
ensureConnected(DriverConfiguration)
M: 0 C: 17
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 6
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%
initCentralConnector(DriverConfiguration)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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%
setRepository(Repository, DriverConfiguration)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 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.connector;
16:
17: import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
18: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
19: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
20: import org.eclipse.rdf4j.repository.Repository;
21:
22: final class ConnectorFactoryImpl implements ConnectorFactory {
23:
24: private boolean open;
25:
26: private volatile StorageConnector centralConnector;
27:
28: ConnectorFactoryImpl() {
29: this.open = true;
30: }
31:
32: @Override
33: public Connector createStorageConnector(DriverConfiguration configuration) throws SesameDriverException {
34: ensureOpen();
35: ensureConnected(configuration);
36: return new PoolingStorageConnector(centralConnector);
37: }
38:
39: private void ensureOpen() {
40:• if (!open) {
41: throw new IllegalStateException("The factory is closed!");
42: }
43: }
44:
45: private void ensureConnected(DriverConfiguration configuration) throws SesameDriverException {
46:• if (centralConnector == null) {
47: synchronized (this) {
48:• if (centralConnector == null) {
49: initCentralConnector(configuration);
50: }
51: }
52: }
53: }
54:
55: private void initCentralConnector(DriverConfiguration configuration) throws SesameDriverException {
56: this.centralConnector = new StorageConnector(configuration);
57: }
58:
59: @Override
60: public void setRepository(Repository repository, DriverConfiguration configuration) throws SesameDriverException {
61: ensureOpen();
62: ensureConnected(configuration);
63: centralConnector.setRepository(repository);
64: }
65:
66: @Override
67: public synchronized void close() throws OntoDriverException {
68:• if (!open) {
69: return;
70: }
71:• if (centralConnector != null) {
72: centralConnector.close();
73: this.centralConnector = null;
74: }
75: this.open = false;
76: }
77:
78: @Override
79: public boolean isOpen() {
80: return open;
81: }
82: }