Skip to content

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