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