Skip to content

Package: PoolingStorageConnector

PoolingStorageConnector

nameinstructionbranchcomplexitylinemethod
PoolingStorageConnector(Connector)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addStatements(Collection)
M: 4 C: 10
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
begin()
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%
commit()
M: 0 C: 44
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
executeBooleanQuery(String)
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%
executeSelectQuery(String)
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%
executeUpdate(String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
findStatements(Resource, URI, Value, boolean, URI[])
M: 6 C: 27
82%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 6
67%
M: 0 C: 1
100%
getContexts()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getValueFactory()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
removeStatements(Collection)
M: 4 C: 10
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
rollback()
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%
static {...}
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%

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 java.util.Collection;
18: import java.util.List;
19: import java.util.concurrent.locks.Lock;
20: import java.util.concurrent.locks.ReentrantReadWriteLock;
21:
22: import org.openrdf.model.Resource;
23: import org.openrdf.model.Statement;
24: import org.openrdf.model.URI;
25: import org.openrdf.model.Value;
26: import org.openrdf.model.ValueFactory;
27: import org.openrdf.query.TupleQueryResult;
28:
29: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
30:
31: class PoolingStorageConnector extends AbstractConnector {
32:
33: private static final ReentrantReadWriteLock LOCK = new ReentrantReadWriteLock();
34: private static Lock READ = LOCK.readLock();
35: private static Lock WRITE = LOCK.writeLock();
36:
37: private final Connector centralConnector;
38: private LocalModel localModel;
39:
40: public PoolingStorageConnector(Connector centralConnector) {
41: this.centralConnector = centralConnector;
42: this.open = true;
43: }
44:
45: @Override
46: public TupleQueryResult executeSelectQuery(String query) throws SesameDriverException {
47: READ.lock();
48: try {
49: return centralConnector.executeSelectQuery(query);
50: } finally {
51: READ.unlock();
52: }
53: }
54:
55: @Override
56: public boolean executeBooleanQuery(String query) throws SesameDriverException {
57: READ.lock();
58: try {
59: return centralConnector.executeBooleanQuery(query);
60: } finally {
61: READ.unlock();
62: }
63: }
64:
65: @Override
66: public void executeUpdate(String query) throws SesameDriverException {
67: WRITE.lock();
68: try {
69: centralConnector.executeUpdate(query);
70: } finally {
71: WRITE.unlock();
72: }
73: }
74:
75: @Override
76: public List<Resource> getContexts() throws SesameDriverException {
77: READ.lock();
78: try {
79: return centralConnector.getContexts();
80: } finally {
81: READ.unlock();
82: }
83: }
84:
85: @Override
86: public ValueFactory getValueFactory() {
87: // We don't need to lock the central connector, as getting the value
88: // factory does not require communication with the repository
89: return centralConnector.getValueFactory();
90: }
91:
92: @Override
93: public void begin() throws SesameDriverException {
94: super.begin();
95: this.localModel = new LocalModel();
96: }
97:
98: @Override
99: public void commit() throws SesameDriverException {
100: transaction.commit();
101: WRITE.lock();
102: try {
103: centralConnector.begin();
104: centralConnector.removeStatements(localModel.getRemovedStatements());
105: centralConnector.addStatements(localModel.getAddedStatements());
106: centralConnector.commit();
107: transaction.afterCommit();
108: } catch (SesameDriverException e) {
109: transaction.rollback();
110: centralConnector.rollback();
111: transaction.afterRollback();
112: throw e;
113: } finally {
114: WRITE.unlock();
115: this.localModel = null;
116: }
117: }
118:
119: @Override
120: public void rollback() {
121: transaction.rollback();
122: this.localModel = null;
123: transaction.afterRollback();
124: }
125:
126: @Override
127: public void addStatements(Collection<Statement> statements) {
128: verifyTransactionActive();
129:• assert statements != null;
130: localModel.addStatements(statements);
131: }
132:
133: @Override
134: public void removeStatements(Collection<Statement> statements) throws SesameDriverException {
135: verifyTransactionActive();
136:• assert statements != null;
137: localModel.removeStatements(statements);
138: }
139:
140: @Override
141: public Collection<Statement> findStatements(Resource subject, URI property, Value value,
142: boolean includeInferred, URI... contexts) throws SesameDriverException {
143: verifyTransactionActive();
144: READ.lock();
145: try {
146: final Collection<Statement> statements = centralConnector.findStatements(subject,
147: property, value, includeInferred, contexts);
148: localModel.enhanceStatements(statements, subject, property, value, contexts);
149: return statements;
150: } catch (SesameDriverException e) {
151: centralConnector.rollback();
152: throw e;
153: } finally {
154: READ.unlock();
155: }
156: }
157: }