-
Notifications
You must be signed in to change notification settings - Fork 14
/
Storage.java
59 lines (50 loc) · 1.97 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
package cz.cvut.kbss.ontodriver.jena.connector;
import cz.cvut.kbss.ontodriver.config.Configuration;
import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
abstract class Storage {
static final Logger LOG = LoggerFactory.getLogger(Storage.class);
Dataset dataset;
void writeChanges() throws JenaDriverException {
// Do nothing by default
}
abstract void initialize();
Dataset getDataset() {
return dataset;
}
void close() {
dataset.close();
}
/**
* 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(Configuration configuration) {
final String type = configuration.getProperty(JenaConfigParam.STORAGE_TYPE, JenaOntoDriverProperties.IN_MEMORY);
final Storage storage;
switch (type) {
case JenaOntoDriverProperties.IN_MEMORY:
storage = new MemoryStorage();
break;
case JenaOntoDriverProperties.FILE:
storage = new FileStorage(configuration);
break;
case JenaOntoDriverProperties.SDB:
case JenaOntoDriverProperties.TDB:
throw new UnsupportedOperationException("Not implemented yet.");
default:
throw new OntoDriverInitializationException("Unsupported storage type \'" + type + "\'.");
}
storage.initialize();
return storage;
}
}