venkateshchannal
venkateshchannal

Reputation: 11

Update VOS 6.1.6 using Jena without loading to memory by invoking Sparql endpoint

If I run DELETE/INSERT query from the SPARQL endpoint, the UPDATE operation works. The SPARQL query is

SELECT ALL
INSERT DATA  INTO <PERSONGRAPH>  { personURI rdf:type   foaf:Person }

Is it possible to do the same operation using Java code (either Jena or VirtuosoExecutionFactory), such that the UPDATE operation happens without needing to load the entire graphs into memory? I would like to invoke SPARQL endpoint from code to do the UPDATE operation. Please correct me if the assumption that the entire triples of a graph will be loaded in memory is wrong. The following Jena code works, but it loads the entire model to memory which causes the machine to not work when the triple size grows above 50,000.

SELECT ALL
String queryString1 = " INSERT DATA  { personURI 
                rdf:type   foaf:Person } "; 

UpdateRequest request1 = UpdateFactory.create(queryString1);
         UpdateAction.execute(request1, personModel);

I would like to do the same by invoking sparqlService or using createServiceRequest so that it avoids loading the entire graph into memory similar to the way it works for SPARQL endpoint.

The following code is not updating the Virtuoso store.

  SELECT ALL
    String queryString1 = " INSERT DATA  { personURI 
                    rdf:type  foaf:Person } ";

    com.hp.hpl.jenafix.query.Query query1 = com.hp.hpl.jenafix.query.QueryFactory.create(queryString1);
             com.hp.hpl.jenafix.query.QueryExecution qexec1 = com.hp.hpl.jenafix.query.QueryExecutionFactory.sparqlService("http://IP:8890/sparql", query1);

I have tried using VirtuosoQueryExecutionFactory.sparqlService, QueryExecutionFactory.createServiceRequest and QueryExecutionFactory.sparqlService. These work for SELECT but not for UPDATE. Please let me know how to do update by invoking the SPARQL endpoint from Java code. Any suggestions, tips are much appreciated.

For new StackOverflow users there is a restriction of 2 URLs. Sadly personUri is an URL and can't be mentioned due to restriction. I am mentioning the personUri here for completeness. personUri is http://onmobile.com/umdb/person/juhi_chawla_268e7a02-8737-464f-97f8-172961d3335b

Based on Andy's feedback tried using both suggestions of UpdateExecutionFactory and Http Client.

On trying to use UpdateExecutionFactory and Http Client, got Connection refused problem while performing UPDATE but not on doing SELECT. Proxy Host and port are already set.

Thank you for the comment. The INSERT syntax works for Virtuoso Open Source which is the store that is being used. I have problem using the UpdateExecutionFactory. I tried with the following

String queryString =  "DELETE DATA FROM <PERSONGRAPH> {  <"
                    + personURI
                    + "> rdf:type   foaf:Person } ";
            com.hp.hpl.jena.update.UpdateRequest request = com.hp.hpl.jena.update.UpdateFactory.create(queryString);
            UpdateProcessor proc = UpdateExecutionFactory.createRemote(request, "http://IP:8890/sparql");
proc.execute(); 

and got the following error stacktrace

org.apache.http.conn.HttpHostConnectException: Connection to IP:8890 refused
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at org.openjena.riot.web.HttpOp.execHttpPost(HttpOp.java:208)
    at org.openjena.riot.web.HttpOp.execHttpPost(HttpOp.java:154)
    at org.openjena.riot.web.HttpOp.execHttpPost(HttpOp.java:128)
    at com.hp.hpl.jena.sparql.modify.UpdateProcessRemote.execute(UpdateProcessRemote.java:60)

Could it be possible that Virtuoso has a different URL endpoint for update?

Upvotes: 1

Views: 526

Answers (3)

AndyS
AndyS

Reputation: 16630

An update is not a query in SPARQL.

Use

UpdateExecutionFactory

To stream data to the server, simply open an HTTP POST connection with content type application/sparql-update, and write the update (with large data) into the stream.

BTW:

INSERT DATA  INTO <PERSONGRAPH>

isn't legal SPARQL Update syntax.

Upvotes: 2

Sergey Malinin
Sergey Malinin

Reputation: 166

You could use the following code to update data directly on server side without loading to local client memory.

    public static void main(String[] args) {

            String url;
            if(args.length == 0)
               url = "jdbc:virtuoso://localhost:1111";
            else
               url = args[0];

            VirtGraph set = new VirtGraph (url, "dba", "dba");

            String str = "CLEAR GRAPH <http://test1>";
            VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, set);
            vur.exec();                  

            str = "INSERT INTO GRAPH <http://test1> { <http://aa> <http://bb> 'cc' . <http://aa1> <http://bb> 123 . <http://aa1> <http://bb> 124 . <http://aa1> <http://bb> 125 .  }";
            vur = VirtuosoUpdateFactory.create(str, set);
            vur.exec();

Look at VirtuosoSPARQLExample8.java and VirtuosoSPARQLExample9.java in Virtuoso Jena Provider examples.

Upvotes: 0

TallTed
TallTed

Reputation: 9434

I'm not sure I follow your question. It's not clear what was added after AndyS' response, and what was there to start with. His note about your syntax error is probably worth more study, if you haven't resolved this yet -- and if you have, an update sharing that resolution would be a good idea.

I'd also recommend reviewing the documentation regarding Jena connections to Virtuoso.

Also worth noting -- questions specifically regarding Virtuoso are generally best raised on the public OpenLink Discussion Forums, the Virtuoso Users mailing list, or through a confidential Support Case.

Upvotes: 1

Related Questions