Skip to content

Commit

Permalink
JENA-1188: Enable loading of the whole dataset.
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Jun 8, 2016
1 parent accab21 commit 8e02240
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions jena-sdb/src/main/java/sdb/sdbload.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@

package sdb;


import java.util.Iterator ;
import java.util.List ;

import jena.cmd.ArgDecl;

import jena.cmd.CmdException ;
import org.apache.jena.atlas.lib.Lib ;
import org.apache.jena.atlas.lib.Timer ;
import org.apache.jena.graph.Graph ;
import org.apache.jena.graph.GraphListener ;
import org.apache.jena.graph.Triple ;
import org.apache.jena.query.Dataset ;
import org.apache.jena.rdf.model.Model ;
import org.apache.jena.riot.Lang ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.RDFLanguages ;
import org.apache.jena.sdb.SDB ;
import org.apache.jena.sdb.SDBFactory ;
import org.apache.jena.sdb.store.StoreBaseHSQL ;
import org.apache.jena.util.FileUtils ;

import sdb.cmd.CmdArgsDB ;
import sdb.cmd.ModGraph ;

Expand Down Expand Up @@ -98,33 +100,54 @@ private void loadOne(String filename, boolean replace)
{
Monitor monitor = null ;

Model model = modGraph.getModel(getStore()) ;
Graph graph = model.getGraph() ;

Model model = null ;
Dataset dataset = null ;
Lang lang = RDFLanguages.filenameToLang(filename) ;
if ( lang == null )
throw new CmdException("Data syntax not recognized: "+filename) ;

if ( modGraph.getGraphName() != null )
model = modGraph.getModel(getStore()) ;
else
dataset = SDBFactory.connectDataset(getStore()) ;

// For monitoring only.
Graph monitorGraph = (model==null) ? null : model.getGraph() ;

if ( isVerbose() && replace )
System.out.println("Emptying: "+filename) ;
if (replace)
model.removeAll();
if (replace) {
if ( model != null )
model.removeAll();
else
dataset.asDatasetGraph().clear();
}

if ( isVerbose() || getModTime().timingEnabled() )
System.out.println("Start load: "+filename) ;
if ( getModTime().timingEnabled() )
{
if ( getModTime().timingEnabled() ) {
if ( monitorGraph == null ) {
// This old monitor code only works for graphs.
// See TDB for a better way using org.apache.jena.atlas.lib.ProgressMonitor
throw new CmdException("Timing only implemented for graphs, not whole datasets") ;
}
monitor = new Monitor(getStore().getLoader().getChunkSize(), isVerbose()) ;
graph.getEventManager().register(monitor) ;
monitorGraph.getEventManager().register(monitor) ;
}

// Crude but convenient
if ( filename.indexOf(':') == -1 )
filename = "file:"+filename ;

String lang = FileUtils.guessLang(filename) ;

// Always time, only print if enabled.
getModTime().startTimer() ;

// Load here
model.read(filename, lang) ;
if ( model == null )
RDFDataMgr.read(dataset, filename, lang);
else
RDFDataMgr.read(model, filename, lang);

long timeMilli = getModTime().endTimer() ;

Expand All @@ -135,7 +158,7 @@ private void loadOne(String filename, boolean replace)
if ( getModTime().timingEnabled() && !isQuiet() )
System.out.printf("Loaded in %.3f seconds [%d triples/s]\n",
timeMilli/1000.0, (1000*monitor.addCount/timeMilli)) ;
graph.getEventManager().unregister(monitor) ;
monitorGraph.getEventManager().unregister(monitor) ;
}
}

Expand Down

0 comments on commit 8e02240

Please sign in to comment.