1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package org.bgbm.biovel.drf.store;
|
11
|
|
12
|
import java.io.File;
|
13
|
import java.io.FileInputStream;
|
14
|
import java.io.IOException;
|
15
|
import java.io.InputStream;
|
16
|
|
17
|
import org.apache.jena.query.Dataset;
|
18
|
import org.apache.jena.query.ReadWrite;
|
19
|
import org.apache.jena.rdf.model.Model;
|
20
|
import org.apache.jena.tdb.TDBFactory;
|
21
|
import org.apache.jena.tdb.base.file.Location;
|
22
|
|
23
|
/**
|
24
|
* @author a.kohlbecker
|
25
|
* @date Oct 19, 2015
|
26
|
*
|
27
|
*/
|
28
|
public class TDBStore extends Store {
|
29
|
|
30
|
private Dataset dataset = null;
|
31
|
|
32
|
/**
|
33
|
* @throws Exception
|
34
|
*/
|
35
|
public TDBStore() throws Exception {
|
36
|
super();
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* {@inheritDoc}
|
41
|
*/
|
42
|
@Override
|
43
|
protected String storeName() {
|
44
|
return "tdb";
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* {@inheritDoc}
|
49
|
*/
|
50
|
@Override
|
51
|
protected void initStoreEngine() throws Exception {
|
52
|
|
53
|
Location location = Location.create(storeLocation.toString());
|
54
|
Dataset dataset = TDBFactory.createDataset(location);
|
55
|
dataset.begin(ReadWrite.READ) ;
|
56
|
// Get model inside the transaction
|
57
|
Model model = dataset.getDefaultModel() ;
|
58
|
logger.info("Dataset in TDB has " + dataset.asDatasetGraph().size() + " named graphs");
|
59
|
logger.info("Model-size: " + model.size());
|
60
|
dataset.end();
|
61
|
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* WARNING!!! This needs at least 1.5GB of heap space!!!
|
66
|
* set -Xmx1500M
|
67
|
*
|
68
|
* NOTE: The bulkloader is a faster way to load data into an empty dataset than just using the Jena update operations.
|
69
|
* the bulkloader also requires less memory
|
70
|
* It is accessed through the command line utility tdbloader.
|
71
|
*
|
72
|
* rm /tmp/drf_tnb_store/*; bin/tdbloader2 -l /tmp/drf_tnb_store /tmp/species.rdf
|
73
|
* @throws IOException
|
74
|
*/
|
75
|
@Override
|
76
|
protected void load(File rdfFile) throws IOException {
|
77
|
|
78
|
logger.info("Using TDB store at " + storeLocation);
|
79
|
|
80
|
dataset.begin(ReadWrite.WRITE);
|
81
|
Model model = dataset.getDefaultModel();
|
82
|
// parse InputStream as RDF in Turtle format
|
83
|
InputStream fin = new FileInputStream(rdfFile);
|
84
|
logger.info("loading RDF/XML into TDB store");
|
85
|
model.read(fin, null, "RDF/XML");
|
86
|
logger.info("loading RDF/XML done");
|
87
|
logger.info("Dataset in TDB has " + dataset.asDatasetGraph().size() + " named graphs");
|
88
|
logger.info("Model-size: " + model.size());
|
89
|
dataset.commit();
|
90
|
dataset.end();
|
91
|
logger.info("rdf loaded into TDB store at " + storeLocation);
|
92
|
|
93
|
|
94
|
this.setDataset(dataset);
|
95
|
}
|
96
|
|
97
|
|
98
|
/**
|
99
|
* @return the dataset
|
100
|
*/
|
101
|
public Dataset getDataset() {
|
102
|
return dataset;
|
103
|
}
|
104
|
|
105
|
|
106
|
/**
|
107
|
* @param dataset the dataset to set
|
108
|
*/
|
109
|
public void setDataset(Dataset dataset) {
|
110
|
this.dataset = dataset;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* {@inheritDoc}
|
115
|
*/
|
116
|
@Override
|
117
|
protected void stopStoreEngine() throws Exception {
|
118
|
// TODO Auto-generated method stub
|
119
|
|
120
|
}
|
121
|
|
122
|
}
|