Package: JenaConnection
JenaConnection
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
JenaConnection(JenaAdapter) |
|
|
|
|
|
||||||||||||||||||||
close() |
|
|
|
|
|
||||||||||||||||||||
commit() |
|
|
|
|
|
||||||||||||||||||||
commitIfAuto() |
|
|
|
|
|
||||||||||||||||||||
contains(Axiom, Set) |
|
|
|
|
|
||||||||||||||||||||
createStatement() |
|
|
|
|
|
||||||||||||||||||||
ensureOpen() |
|
|
|
|
|
||||||||||||||||||||
find(AxiomDescriptor) |
|
|
|
|
|
||||||||||||||||||||
generateIdentifier(URI) |
|
|
|
|
|
||||||||||||||||||||
getContexts() |
|
|
|
|
|
||||||||||||||||||||
isAutoCommit() |
|
|
|
|
|
||||||||||||||||||||
isConsistent(URI) |
|
|
|
|
|
||||||||||||||||||||
isInferred(Axiom, Set) |
|
|
|
|
|
||||||||||||||||||||
isOpen() |
|
|
|
|
|
||||||||||||||||||||
lists() |
|
|
|
|
|
||||||||||||||||||||
persist(AxiomValueDescriptor) |
|
|
|
|
|
||||||||||||||||||||
prepareStatement(String) |
|
|
|
|
|
||||||||||||||||||||
properties() |
|
|
|
|
|
||||||||||||||||||||
registerListener(ConnectionListener) |
|
|
|
|
|
||||||||||||||||||||
remove(AxiomDescriptor) |
|
|
|
|
|
||||||||||||||||||||
rollback() |
|
|
|
|
|
||||||||||||||||||||
setAutoCommit(boolean) |
|
|
|
|
|
||||||||||||||||||||
types() |
|
|
|
|
|
||||||||||||||||||||
unwrap(Class) |
|
|
|
|
|
||||||||||||||||||||
update(AxiomValueDescriptor) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2022 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.jena;
16:
17: import cz.cvut.kbss.ontodriver.Connection;
18: import cz.cvut.kbss.ontodriver.PreparedStatement;
19: import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor;
20: import cz.cvut.kbss.ontodriver.descriptor.AxiomValueDescriptor;
21: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
22: import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
23: import cz.cvut.kbss.ontodriver.jena.list.JenaLists;
24: import cz.cvut.kbss.ontodriver.jena.query.JenaStatement;
25: import cz.cvut.kbss.ontodriver.jena.util.ConnectionListener;
26: import cz.cvut.kbss.ontodriver.model.Axiom;
27:
28: import java.net.URI;
29: import java.util.Collection;
30: import java.util.List;
31: import java.util.Objects;
32: import java.util.Set;
33:
34: public class JenaConnection implements Connection {
35:
36: private boolean open;
37: private boolean autoCommit;
38:
39: private ConnectionListener listener;
40:
41: private final JenaAdapter adapter;
42:
43: JenaConnection(JenaAdapter adapter) {
44: this.adapter = adapter;
45: this.open = true;
46: }
47:
48: void registerListener(ConnectionListener listener) {
49: ensureOpen();
50: this.listener = listener;
51: }
52:
53: @Override
54: public boolean isOpen() {
55: return open;
56: }
57:
58: @Override
59: public void commit() throws JenaDriverException {
60: ensureOpen();
61:• if (!autoCommit) {
62: adapter.commit();
63: }
64: }
65:
66: @Override
67: public void rollback() {
68: ensureOpen();
69:• if (!autoCommit) {
70: adapter.rollback();
71: }
72: }
73:
74: @Override
75: public void setAutoCommit(boolean autoCommit) {
76: ensureOpen();
77: this.autoCommit = autoCommit;
78: }
79:
80: @Override
81: public boolean isAutoCommit() {
82: ensureOpen();
83: return autoCommit;
84: }
85:
86: private void commitIfAuto() throws JenaDriverException {
87:• if (autoCommit) {
88: adapter.commit();
89: }
90: }
91:
92: @Override
93: public JenaStatement createStatement() {
94: ensureOpen();
95: return adapter.createStatement();
96: }
97:
98: @Override
99: public PreparedStatement prepareStatement(String sparql) {
100: ensureOpen();
101: return adapter.prepareStatement(Objects.requireNonNull(sparql));
102: }
103:
104: @Override
105: public boolean isConsistent(URI context) {
106: ensureOpen();
107: return adapter.isConsistent(context);
108: }
109:
110: @Override
111: public List<URI> getContexts() {
112: ensureOpen();
113: return adapter.getContext();
114: }
115:
116: @Override
117: public boolean contains(Axiom<?> axiom, Set<URI> contexts) throws JenaDriverException {
118: ensureOpen();
119: Objects.requireNonNull(axiom);
120: Objects.requireNonNull(contexts);
121: try {
122: return adapter.contains(axiom, contexts);
123: } catch (RuntimeException e) {
124: throw new JenaDriverException(e);
125: }
126: }
127:
128: @Override
129: public boolean isInferred(Axiom<?> axiom, Set<URI> contexts) throws JenaDriverException {
130: ensureOpen();
131: Objects.requireNonNull(axiom);
132: Objects.requireNonNull(contexts);
133: try {
134: return adapter.isInferred(axiom, contexts);
135: } catch (RuntimeException e) {
136: throw new JenaDriverException(e);
137: }
138: }
139:
140: @Override
141: public Collection<Axiom<?>> find(AxiomDescriptor descriptor) throws JenaDriverException {
142: ensureOpen();
143: Objects.requireNonNull(descriptor);
144: try {
145: return adapter.find(descriptor);
146: } catch (RuntimeException e) {
147: throw new JenaDriverException(e);
148: }
149: }
150:
151: @Override
152: public void persist(AxiomValueDescriptor descriptor) throws JenaDriverException {
153: ensureOpen();
154: Objects.requireNonNull(descriptor);
155: try {
156: adapter.persist(descriptor);
157: commitIfAuto();
158: } catch (RuntimeException e) {
159: throw new JenaDriverException(e);
160: }
161: }
162:
163: @Override
164: public URI generateIdentifier(URI classUri) {
165: ensureOpen();
166: Objects.requireNonNull(classUri);
167: return adapter.generateIdentifier(classUri);
168: }
169:
170: @Override
171: public void update(AxiomValueDescriptor descriptor) throws OntoDriverException {
172: ensureOpen();
173: Objects.requireNonNull(descriptor);
174: adapter.update(descriptor);
175: commitIfAuto();
176: }
177:
178: @Override
179: public void remove(AxiomDescriptor descriptor) throws OntoDriverException {
180: ensureOpen();
181: Objects.requireNonNull(descriptor);
182: try {
183: adapter.remove(descriptor);
184: commitIfAuto();
185: } catch (RuntimeException e) {
186: throw new JenaDriverException(e);
187: }
188: }
189:
190: @Override
191: public JenaLists lists() {
192: ensureOpen();
193: return new JenaLists(adapter, this::ensureOpen, this::commitIfAuto);
194: }
195:
196: @Override
197: public JenaTypes types() {
198: ensureOpen();
199: return new JenaTypes(adapter, this::ensureOpen, this::commitIfAuto);
200: }
201:
202: @Override
203: public JenaProperties properties() {
204: ensureOpen();
205: return new JenaProperties(adapter, this::ensureOpen, this::commitIfAuto);
206: }
207:
208: @Override
209: public <T> T unwrap(Class<T> cls) throws OntoDriverException {
210: ensureOpen();
211: Objects.requireNonNull(cls);
212:• if (cls.isAssignableFrom(getClass())) {
213: return cls.cast(this);
214: }
215: return adapter.unwrap(cls);
216: }
217:
218: @Override
219: public void close() throws JenaDriverException {
220:• if (!open) {
221: return;
222: }
223: adapter.close();
224:• if (listener != null) {
225: listener.connectionClosed(this);
226: }
227: this.open = false;
228: }
229:
230: private void ensureOpen() {
231:• if (!open) {
232: throw new IllegalStateException("This connection is closed.");
233: }
234: }
235: }