Skip to content

Package: Storage

Storage

nameinstructionbranchcomplexitylinemethod
create(DriverConfiguration)
M: 10 C: 42
81%
M: 2 C: 4
67%
M: 2 C: 4
67%
M: 2 C: 6
75%
M: 0 C: 1
100%
reload()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setDataset(Dataset)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
writeChanges()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

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