Package: Storage
Storage
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
create(DriverConfiguration) |
|
|
|
|
|
||||||||||||||||||||
reload() |
|
|
|
|
|
||||||||||||||||||||
setDataset(Dataset) |
|
|
|
|
|
||||||||||||||||||||
writeChanges() |
|
|
|
|
|
Coverage
1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.jena.connector;
19:
20: import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
21: import cz.cvut.kbss.ontodriver.exception.OntoDriverInitializationException;
22: import cz.cvut.kbss.ontodriver.jena.config.JenaConfigParam;
23: import cz.cvut.kbss.ontodriver.jena.config.JenaOntoDriverProperties;
24: import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
25: import org.apache.jena.query.Dataset;
26: import org.apache.jena.query.Query;
27: import org.apache.jena.query.QueryExecution;
28: import org.apache.jena.query.ReadWrite;
29: import org.apache.jena.rdf.model.Model;
30: import org.apache.jena.rdf.model.Statement;
31: import org.apache.jena.rdf.model.StmtIterator;
32: import org.apache.jena.sparql.core.Transactional;
33:
34: import java.util.List;
35:
36: /**
37: * Represents underlying Jena storage.
38: */
39: interface Storage {
40:
41: /**
42: * Synchronize changes with the storage (e.g., disk).
43: * <p>
44: * Does nothing by default.
45: *
46: * @throws JenaDriverException Indicates that changes could not be written out
47: */
48: default void writeChanges() throws JenaDriverException {
49: }
50:
51: /**
52: * Gets a transactional representation of the underlying storage.
53: * <p>
54: * The results can be used by the {@link org.apache.jena.system.Txn} utility class.
55: *
56: * @return Jena {@code Transactional} instance
57: */
58: Transactional getTransactional();
59:
60: /**
61: * Gets the dataset to which this instance is connected.
62: *
63: * @return Jena {@code Dataset}
64: */
65: Dataset getDataset();
66:
67: /**
68: * Gets the default graph from this storage's dataset.
69: *
70: * @return Default graph
71: */
72: Model getDefaultGraph();
73:
74: /**
75: * Gets a named graph with the specified identifier.
76: *
77: * @param ctx Context identifier
78: * @return Named graph
79: */
80: Model getNamedGraph(String ctx);
81:
82: /**
83: * Begins a transaction.
84: *
85: * @param readWrite Transaction read/write mode
86: */
87: void begin(ReadWrite readWrite);
88:
89: /**
90: * Commits the current transaction.
91: */
92: void commit();
93:
94: /**
95: * Rolls back the current transaction.
96: */
97: void rollback();
98:
99: /**
100: * Closes this storage.
101: */
102: void close();
103:
104: /**
105: * Adds the specified statements to the specified context (can be {@code null}).
106: *
107: * @param statements Statements to add
108: * @param context Context identifier, possibly {@code null} indicating default context
109: */
110: void add(List<Statement> statements, String context);
111:
112: /**
113: * Removes the specified statements from the specified context (can be {@code null}).
114: *
115: * @param statements Statements to remove
116: * @param context Context identifier, possibly {@code null} indicating default context
117: */
118: void remove(List<Statement> statements, String context);
119:
120: /**
121: * Removes the specified statements from the specified context (can be {@code null}).
122: *
123: * @param iterator Statement iterator
124: * @param context Context identifier, possibly {@code null} indicating default context
125: */
126: void remove(StmtIterator iterator, String context);
127:
128: /**
129: * Creates a query execution which can be run.
130: *
131: * @param query Query to prepare execution for
132: * @return {@code QueryExecution}
133: */
134: QueryExecution prepareQuery(Query query);
135:
136: /**
137: * Executes the specified SPARQL update.
138: *
139: * @param update SPARQL update to execute
140: */
141: void executeUpdate(String update);
142:
143: /**
144: * Reloads data from the underlying storage (if applicable).
145: * <p>
146: * Default implementation does nothing.
147: */
148: default void reload() {
149: }
150:
151: /**
152: * Sets the dataset on this storage.
153: * <p>
154: * Note that by default this method throws {@link UnsupportedOperationException}, because such an operation is
155: * supported only by the in-memory storage.
156: *
157: * @param dataset The new dataset
158: */
159: default void setDataset(Dataset dataset) {
160: throw new UnsupportedOperationException("Cannot set dataset on storage of type " + getClass().getSimpleName());
161: }
162:
163: /**
164: * Creates a storage accessor according to the specified configuration.
165: *
166: * @param configuration Access configuration
167: * @return Storage accessor instance
168: * @throws OntoDriverInitializationException When storage type is not supported
169: */
170: static Storage create(DriverConfiguration configuration) {
171: final String type = configuration.getProperty(JenaConfigParam.STORAGE_TYPE, JenaOntoDriverProperties.IN_MEMORY);
172:• switch (type) {
173: case JenaOntoDriverProperties.IN_MEMORY:
174: return new MemoryStorage(configuration);
175: case JenaOntoDriverProperties.FILE:
176: return new FileStorage(configuration);
177: case JenaOntoDriverProperties.TDB:
178: return new TDBStorage(configuration);
179: case JenaOntoDriverProperties.FUSEKI:
180: return new FusekiStorage(configuration);
181: default:
182: throw new OntoDriverInitializationException("Unsupported storage type '" + type + "'.");
183: }
184: }
185: }