Skip to content

Package: Connection

Connection

Coverage

1: /**
2: * Copyright (C) 2020 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;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor;
18: import cz.cvut.kbss.ontodriver.descriptor.AxiomValueDescriptor;
19: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
20: import cz.cvut.kbss.ontodriver.model.Axiom;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22:
23: import java.net.URI;
24: import java.util.Collection;
25: import java.util.List;
26: import java.util.Set;
27:
28: public interface Connection extends AutoCloseable, Wrapper {
29:
30: /**
31: * Whether this connection is active.
32: *
33: * @return Active status of this connection
34: */
35: boolean isOpen();
36:
37: /**
38: * Commits this connection.
39: * <p>
40: * This effectively makes persistent any changes made since the last commit/rollback or since this connection was
41: * opened.
42: * <p>
43: * If this connection is in auto-commit mode, calling this method has no effect.
44: *
45: * @throws OntoDriverException If an ontology access error occurs
46: * @throws IllegalStateException If called on a closed connection
47: */
48: void commit() throws OntoDriverException;
49:
50: /**
51: * Rolls back any changes made in the current transaction.
52: * <p>
53: * If this connection is in auto-commit mode, calling this method has no effect.
54: *
55: * @throws OntoDriverException If an ontology access error occurs
56: * @throws IllegalStateException If called on a closed connection
57: */
58: void rollback() throws OntoDriverException;
59:
60: /**
61: * Sets this connection's auto-commit mode to the specified state.
62: *
63: * @param autoCommit The new auto-commit state
64: * @throws IllegalStateException If called on a closed connection
65: */
66: void setAutoCommit(boolean autoCommit);
67:
68: /**
69: * Returns this connection's auto-commit mode.
70: *
71: * @return {@code true} if this connection is in auto-commit mode, {@code false} otherwise
72: * @throws IllegalStateException If called on a closed connection
73: */
74: boolean isAutoCommit();
75:
76: /**
77: * Creates a new SPARQL statement.
78: *
79: * @return a {@code Statement} instance
80: * @throws OntoDriverException If an ontology access error occurs
81: * @throws IllegalStateException If called on a closed connection
82: */
83: Statement createStatement() throws OntoDriverException;
84:
85: /**
86: * Creates and returns a new prepared SPARQL statement.
87: *
88: * @param sparql The query to prepare
89: * @return {@code PreparedStatement}
90: * @throws OntoDriverException If an ontology access error occurs
91: * @throws IllegalStateException If called on a closed connection
92: */
93: PreparedStatement prepareStatement(String sparql) throws OntoDriverException;
94:
95: /**
96: * Verifies consistency of ontology context with the specified URI
97: * <p>
98: * Note that {@code null} argument means checking consistency of the whole repository.
99: *
100: * @param context Context identifier, can be {@code null}
101: * @return Consistency status
102: * @throws OntoDriverException If an ontology access error occurs
103: * @throws IllegalStateException If called on a closed connection
104: */
105: boolean isConsistent(URI context) throws OntoDriverException;
106:
107: /**
108: * Gets a set of currently available contexts in the underlying repository.
109: * <p>
110: * Note that the default context is not included in the result.
111: *
112: * @return List of context URIs
113: * @throws OntoDriverException If an ontology access error occurs
114: * @throws IllegalStateException If called on a closed connection
115: */
116: List<URI> getContexts() throws OntoDriverException;
117:
118: /**
119: * Checks whether the storage contains the specified axiom.
120: * <p>
121: * The context optionally specifies context in which to look for the axiom.
122: *
123: * @param axiom The axiom to look for
124: * @param contexts Optional search contexts, an empty set means to look in the default storage context
125: * @return {@code true} if the storage contains matching axiom, {@code false} otherwise
126: * @throws OntoDriverException If an ontology access error occurs
127: * @throws IllegalStateException If called on a closed connection
128: */
129: boolean contains(Axiom<?> axiom, Set<URI> contexts) throws OntoDriverException;
130:
131: /**
132: * Finds axioms with the corresponding subject and properties.
133: *
134: * @param descriptor Loading descriptor specifies subject, properties to load and possible contexts to work with
135: * @return Collection of axioms matching the specified criteria
136: * @throws OntoDriverException If an ontology access error occurs
137: * @throws IllegalStateException If called on a closed connection
138: */
139: Collection<Axiom<?>> find(AxiomDescriptor descriptor) throws OntoDriverException;
140:
141: /**
142: * Persists new individual and its property values specified by the descriptor.
143: *
144: * @param descriptor Descriptor of the persisted values
145: * @throws OntoDriverException If an ontology access error occurs
146: * @throws IllegalStateException If called on a closed connection
147: */
148: void persist(AxiomValueDescriptor descriptor) throws OntoDriverException;
149:
150: /**
151: * Generates a new unique identifier based on the specified type.
152: * <p>
153: * The identifier is required to be unique in the whole repository.
154: *
155: * @param classUri OWL class identifier
156: * @return Unique identifier
157: * @throws OntoDriverException If an ontology access error occurs
158: */
159: URI generateIdentifier(URI classUri) throws OntoDriverException;
160:
161: /**
162: * Persists the values specified by this descriptor, removing existing property values from the ontology.
163: * <p>
164: * This method removes original values of properties specified in the descriptor and persists new values specified
165: * therein.
166: *
167: * @param descriptor Descriptor of the update values
168: * @throws OntoDriverException If an ontology access error occurs
169: * @throws IllegalStateException If called on a closed connection
170: */
171: void update(AxiomValueDescriptor descriptor) throws OntoDriverException;
172:
173: /**
174: * Removes all axioms related to subject specified by the descriptor.
175: * <p>
176: * The descriptor may also specify contexts from which property assertion axioms should be removed.
177: * <p>
178: * Note that this method will cause also removal of axioms in which the {@link NamedResource} specified by the
179: * argument stands as value.
180: *
181: * @param descriptor Descriptor of contexts and the subject of removal
182: * @throws OntoDriverException If an ontology access error occurs
183: * @throws IllegalStateException If called on a closed connection
184: */
185: void remove(AxiomDescriptor descriptor) throws OntoDriverException;
186:
187: /**
188: * Gets ontology lists handler.
189: *
190: * @return Lists handler
191: */
192: Lists lists();
193:
194: /**
195: * Gets types handler.
196: *
197: * @return Types handler
198: */
199: Types types();
200:
201: /**
202: * Gets handler for unmapped properties.
203: *
204: * @return Properties handler
205: */
206: Properties properties();
207: }