improved bnode handling in SparqlGraphBulkUpdater

This commit is contained in:
brianjlowe 2012-04-30 20:53:12 +00:00
parent 2621558728
commit 1d151d63d3
2 changed files with 22 additions and 7 deletions

View file

@ -109,6 +109,8 @@ public class SparqlGraph implements GraphWithPerform {
} catch (MalformedQueryException e) { } catch (MalformedQueryException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (UpdateExecutionException e) { } catch (UpdateExecutionException e) {
log.error(e,e);
log.error("Update command: \n" + updateString);
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
conn.close(); conn.close();

View file

@ -6,12 +6,6 @@ import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryLanguage;
import org.openrdf.query.Update;
import org.openrdf.query.UpdateExecutionException;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import com.hp.hpl.jena.graph.Graph; import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphEvents; import com.hp.hpl.jena.graph.GraphEvents;
@ -21,6 +15,7 @@ import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler; import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.sparql.util.graph.GraphFactory; import com.hp.hpl.jena.sparql.util.graph.GraphFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.util.iterator.ExtendedIterator;
@ -71,9 +66,26 @@ public class SparqlGraphBulkUpdater extends SimpleBulkUpdateHandler {
@Override @Override
public void add(Graph g, boolean arg1) { public void add(Graph g, boolean arg1) {
Model gm = ModelFactory.createModelForGraph(g); Model gm = ModelFactory.createModelForGraph(g);
Model blankNodeModel = ModelFactory.createDefaultModel();
Model nonBlankNodeModel = ModelFactory.createDefaultModel();
StmtIterator sit = gm.listStatements();
while (sit.hasNext()) {
Statement stmt = sit.nextStatement();
if (!stmt.getSubject().isAnon() && !stmt.getObject().isAnon()) {
nonBlankNodeModel.add(stmt);
} else {
blankNodeModel.add(stmt);
}
}
addModel(nonBlankNodeModel);
// replace following call with different method
addModel(blankNodeModel);
}
public void addModel(Model model) {
Model m = ModelFactory.createDefaultModel(); Model m = ModelFactory.createDefaultModel();
int testLimit = 1000; int testLimit = 1000;
StmtIterator stmtIt = gm.listStatements(); StmtIterator stmtIt = model.listStatements();
int count = 0; int count = 0;
try { try {
while (stmtIt.hasNext()) { while (stmtIt.hasNext()) {
@ -102,6 +114,7 @@ public class SparqlGraphBulkUpdater extends SimpleBulkUpdateHandler {
} }
} }
@Override @Override
public void removeAll() { public void removeAll() {
removeAll(graph); removeAll(graph);