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: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 6
86%
M: 0 C: 1
100%
createStorageConnector(Configuration)
M: 5 C: 25
83%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 7
88%
M: 0 C: 1
100%
initCentralConnector(Configuration)
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: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.Configuration;
18: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
19: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
20:
21: final class ConnectorFactoryImpl implements ConnectorFactory {
22:
23: private boolean open;
24:
25: private volatile StorageConnector centralConnector;
26:
27: ConnectorFactoryImpl() {
28: this.open = true;
29: }
30:
31: public Connector createStorageConnector(Configuration configuration) throws SesameDriverException {
32:• if (!open) {
33: throw new IllegalStateException("The factory is closed!");
34: }
35:• if (centralConnector == null) {
36: synchronized (this) {
37:• if (centralConnector == null) {
38: initCentralConnector(configuration);
39: }
40: }
41: }
42: return new PoolingStorageConnector(centralConnector);
43: }
44:
45: private void initCentralConnector(Configuration configuration) throws SesameDriverException {
46: this.centralConnector = new StorageConnector(configuration);
47: }
48:
49: public synchronized void close() throws OntoDriverException {
50:• if (!open) {
51: return;
52: }
53:• if (centralConnector != null) {
54: centralConnector.close();
55: this.centralConnector = null;
56: }
57: this.open = false;
58: }
59:
60: public boolean isOpen() {
61: return open;
62: }
63: }