-
Notifications
You must be signed in to change notification settings - Fork 14
/
Storage.java
168 lines (148 loc) · 5.06 KB
/
Storage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package cz.cvut.kbss.ontodriver.jena.connector;
import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
import cz.cvut.kbss.ontodriver.exception.OntoDriverInitializationException;
import cz.cvut.kbss.ontodriver.jena.config.JenaConfigParam;
import cz.cvut.kbss.ontodriver.jena.config.JenaOntoDriverProperties;
import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.sparql.core.Transactional;
import java.util.List;
/**
* Represents underlying Jena storage.
*/
interface Storage {
/**
* Synchronize changes with the storage (e.g., disk).
* <p>
* Does nothing by default.
*
* @throws JenaDriverException Indicates that changes could not be written out
*/
default void writeChanges() throws JenaDriverException {
}
/**
* Gets a transactional representation of the underlying storage.
* <p>
* The results can be used by the {@link org.apache.jena.system.Txn} utility class.
*
* @return Jena {@code Transactional} instance
*/
Transactional getTransactional();
/**
* Gets the dataset to which this instance is connected.
*
* @return Jena {@code Dataset}
*/
Dataset getDataset();
/**
* Gets the default graph from this storage's dataset.
*
* @return Default graph
*/
Model getDefaultGraph();
/**
* Gets a named graph with the specified identifier.
*
* @param ctx Context identifier
* @return Named graph
*/
Model getNamedGraph(String ctx);
/**
* Begins a transaction.
*
* @param readWrite Transaction read/write mode
*/
void begin(ReadWrite readWrite);
/**
* Commits the current transaction.
*/
void commit();
/**
* Rolls back the current transaction.
*/
void rollback();
/**
* Closes this storage.
*/
void close();
/**
* Adds the specified statements to the specified context (can be {@code null}).
*
* @param statements Statements to add
* @param context Context identifier, possibly {@code null} indicating default context
*/
void add(List<Statement> statements, String context);
/**
* Removes the specified statements from the specified context (can be {@code null}).
*
* @param statements Statements to remove
* @param context Context identifier, possibly {@code null} indicating default context
*/
void remove(List<Statement> statements, String context);
/**
* Removes the specified statements from the specified context (can be {@code null}).
*
* @param iterator Statement iterator
* @param context Context identifier, possibly {@code null} indicating default context
*/
void remove(StmtIterator iterator, String context);
/**
* Creates a query execution which can be run.
*
* @param query Query to prepare execution for
* @return {@code QueryExecution}
*/
QueryExecution prepareQuery(Query query);
/**
* Executes the specified SPARQL update.
*
* @param update SPARQL update to execute
*/
void executeUpdate(String update);
/**
* Reloads data from the underlying storage (if applicable).
* <p>
* Default implementation does nothing.
*/
default void reload() {
}
/**
* Sets the dataset on this storage.
* <p>
* Note that by default this method throws {@link UnsupportedOperationException}, because such an operation is
* supported only by the in-memory storage.
*
* @param dataset The new dataset
*/
default void setDataset(Dataset dataset) {
throw new UnsupportedOperationException("Cannot set dataset on storage of type " + getClass().getSimpleName());
}
/**
* Creates a storage accessor according to the specified configuration.
*
* @param configuration Access configuration
* @return Storage accessor instance
* @throws OntoDriverInitializationException When storage type is not supported
*/
static Storage create(DriverConfiguration configuration) {
final String type = configuration.getProperty(JenaConfigParam.STORAGE_TYPE, JenaOntoDriverProperties.IN_MEMORY);
switch (type) {
case JenaOntoDriverProperties.IN_MEMORY:
return new MemoryStorage(configuration);
case JenaOntoDriverProperties.FILE:
return new FileStorage(configuration);
case JenaOntoDriverProperties.TDB:
return new TDBStorage(configuration);
case JenaOntoDriverProperties.SDB:
throw new UnsupportedOperationException("Not implemented, yet.");
default:
throw new OntoDriverInitializationException("Unsupported storage type '" + type + "'.");
}
}
}