Allow TripleStore to be persistent after reboot

pull/1/head
cominch 13 years ago committed by Michael Peter Christen
parent 5d20cd324a
commit 282c1620d6

@ -0,0 +1,78 @@
// Author: DL
package net.yacy.interaction;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import java.io.*;
import net.yacy.kelondro.logging.Log;
public class TripleStore {
public static Model model = ModelFactory.createDefaultModel();
public static String file;
public static void Load (String filename) {
Model tmp = ModelFactory.createDefaultModel();
Log.logInfo("TRIPLESTORE", "Loading from " + filename);
try {
InputStream in = FileManager.get().open(filename);
// read the RDF/XML file
tmp.read(in, null);
}
finally
{
model = model.union(tmp);
}
}
public static void Add (String rdffile) {
Model tmp = ModelFactory.createDefaultModel();
try {
@SuppressWarnings("deprecation")
InputStream in = new StringBufferInputStream(rdffile);
// read the RDF/XML file
tmp.read(in, null);
}
finally
{
model = model.union(tmp);
}
}
public static void Save (String filename) {
FileOutputStream fout;
try {
fout = new FileOutputStream(filename);
model.write(fout);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.logWarning("TRIPLESTORE", "Saving to " + filename+" failed");
}
}
}

@ -59,6 +59,7 @@ import net.yacy.cora.sorting.OrderedScoreMap;
import net.yacy.cora.sorting.ScoreMap;
import net.yacy.gui.YaCyApp;
import net.yacy.gui.framework.Browser;
import net.yacy.interaction.TripleStore;
import net.yacy.kelondro.blob.MapDataMining;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.Word;
@ -301,6 +302,12 @@ public final class yacy {
// set user-agent
HTTPClient.setDefaultUserAgent(ClientIdentification.getUserAgent());
// initial fill of the triplestore
mkdirIfNeseccary (new File(sb.getConfig("triplestore", new File (dataHome, "DATA/TRIPLESTORE").toString())));
if (sb.getConfigBool("triplestore.persistent", false) == true) {
TripleStore.Load(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf");
}
// start main threads
final String port = sb.getConfig("port", "8090");
@ -420,6 +427,11 @@ public final class yacy {
Log.logSevere("STARTUP", "FATAL ERROR: " + ee.getMessage(),ee);
} finally {
}
if (sb.getConfigBool("triplestore.persistent", false) == true) {
TripleStore.Save(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf");
}
Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)");
Log.shutdown();
shutdownSemaphore.release(1000);

Loading…
Cancel
Save