You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Mark Hissink Muller <XM...@kombit.dk> on 2019/09/19 14:23:14 UTC

How to update a remote repository from a Java client...?

Hi all,

Could someone please point me in the right direction for updating a remote repository...?

Using I am using org.apache.jena:jena-core-3.10.0 and jena-arq:3.10.0 in a custom Java client application.

Querying works as expected, like this:

    String queryUrl = "http://testserver:8080/rdf4j-server/repositories/QUERY_REPO"
    Query query = QueryFactory.create(SPARQL_QUERY) ;
    QueryEngineHTTP qexec = QueryExecutionFactory.createServiceRequest(queryUrl, query);
    ResultSet resultSet = qexec.execSelect();

The resultSet contains the triples, which I can further process. All fine.

However, when I try to update the repository via a similar service call, nothing seems to be happening. Based on the example found here [1], my code looks as follows:

    String postUrl = "http://testserver:8080/rdf4j-server/repositories/POST_REPO"
    UpdateRequest request = UpdateFactory.create();
    request.add("DROP GRAPH <http://myorg.dk/something>")
            .add("CREATE GRAPH http://myorg.dk/something>");
        // .add("LOAD <file:etc/update-data.ttl> INTO <http://example/g2>") ;

    request.setBaseURI(postUrl);

    Dataset dataset = DatasetFactory.create();
    dataset.setDefaultModel(customModel.getModel());

    UpdateAction.execute(request, dataset);

    log.info("This point is reached without a problem.");

When I execute(..), nothing seems to happen, not even dropping of the graph. There are no exceptions thrown and the last log statement is printed, so no runtime exception is thrown either. It seems like there is no remote server call made. Just no activity at all.

Is this not the correct approach...? What am I missing…?

NB: I've commented the update-data.ttl-part, since I would like my locally created customModel to be inserted. Not sure if this is the correct approach for that.

Your feedback is much appreciated. 🙏🏻

Best, Mark


[1] - https://jena.apache.org/documentation/query/update.html


MARK HISSINK MULLER 


[cid:image001.png@01D56F06.88F2FB50]

Halfdansgade 8 / 2300 København S
Tlf. 3334 9400 / www.kombit.dk<http://www.kombit.dk/>


Re: How to update a remote repository from a Java client...?

Posted by Claude Warren <cl...@xenei.com>.
Using the UpdateBuilder and RDFConnection can make this much easier (i.e.
no missing '<' )

On Thu, Sep 19, 2019 at 11:23 PM Andy Seaborne <an...@apache.org> wrote:

>
>
> On 19/09/2019 15:23, Mark Hissink Muller wrote:
> > String postUrl =
> > "http://testserver:8080/rdf4j-server/repositories/POST_REPO"
> >
> >      UpdateRequest request = UpdateFactory.create();
>
> Normally,
>
> UpdateRequest request = UpdateFactory.create(string);
>
> >
> >      request.add("DROP GRAPH <http://myorg.dk/something>")
> >
> >              .add("CREATE GRAPH http://myorg.dk/something>");
>
> There's a syntax error there - missing < in the URI.
>
> >
> >          // .add("LOAD <file:etc/update-data.ttl> INTO
> > <http://example/g2>") ;
> >
> >      request.setBaseURI(postUrl);
> Does not do anything.  Base URIs are the "BASE" feature of parsing.
>
> >
> >      Dataset dataset = DatasetFactory.create();
> >
> >      dataset.setDefaultModel(customModel.getModel());
> >
> >      UpdateAction.execute(request, dataset);
>
> So we have a local Dataset in-memory, something in the default model, no
> named graphs.
>
>
> DROP GRAPH <http://myorg.dk/something>;
>
> That does not do anything because there are no triples in the graph
> named <http://myorg.dk/something>
>
>
> CREATE GRAPH <http://myorg.dk/something>
>
> That does not do anything either. Graphs get created as needed, no need
> to create them in this kind of dataset.
>
> >      log.info("This point is reached without a problem.");
>
> The syntax error would have happened.
>
> And if the code exits, the in memory dataset is lost.
>
> Did you mean to send it to the sever?
>
> UpdateExecutionFactory.createRemote
>
> ------------
>
> There is also RDFConnection which pulls together all SPARQL operations.
>
>      Andy
>


-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: How to update a remote repository from a Java client...?

Posted by Andy Seaborne <an...@apache.org>.

On 19/09/2019 15:23, Mark Hissink Muller wrote:
> String postUrl = 
> "http://testserver:8080/rdf4j-server/repositories/POST_REPO"
> 
>      UpdateRequest request = UpdateFactory.create();

Normally,

UpdateRequest request = UpdateFactory.create(string);

> 
>      request.add("DROP GRAPH <http://myorg.dk/something>")
> 
>              .add("CREATE GRAPH http://myorg.dk/something>");

There's a syntax error there - missing < in the URI.

> 
>          // .add("LOAD <file:etc/update-data.ttl> INTO 
> <http://example/g2>") ;
> 
>      request.setBaseURI(postUrl);
Does not do anything.  Base URIs are the "BASE" feature of parsing.

> 
>      Dataset dataset = DatasetFactory.create();
> 
>      dataset.setDefaultModel(customModel.getModel());
> 
>      UpdateAction.execute(request, dataset);

So we have a local Dataset in-memory, something in the default model, no 
named graphs.


DROP GRAPH <http://myorg.dk/something>;

That does not do anything because there are no triples in the graph 
named <http://myorg.dk/something>


CREATE GRAPH <http://myorg.dk/something>

That does not do anything either. Graphs get created as needed, no need 
to create them in this kind of dataset.

>      log.info("This point is reached without a problem.");

The syntax error would have happened.

And if the code exits, the in memory dataset is lost.

Did you mean to send it to the sever?

UpdateExecutionFactory.createRemote

------------

There is also RDFConnection which pulls together all SPARQL operations.

     Andy