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