Skip to content

Java Client API

Andrea Gazzarini edited this page Jul 15, 2015 · 2 revisions

The module solrdf-client contains a Java client that can be used to interact with SolRDF. This has been mainly designed for hiding, as much as possible,

  • the mixing of Jena (client side) and Solr (actually Solrj) code
  • the interaction (including low level communication details) with a running SolRDF

As the client API development is currently in progress, the content of this chapter will be adjusted / corrected / changed according with the latest changes.

Instantiating the remote proxy

The fully name of the proxy is (not surprisingly) org.gazzax.labs.solrdf.client.SolRDF. It can be instantiated (at the moment) in a couple of ways:

final SolRDF solrdf = new SolRDF("http://127.0.0.1:8080/solr/store");

or, in alternative, providing a DatasetAccessor instance, filled with the (pseudo) Graph Protocol Store endpoing URL:

final String url = "http://127.0.0.1:8080/solr/store/rdf-graph-store";
final DatasetAccessor dataset = DatasetAccessorFactory.createHTTP(url);
final SolRDF solrdf = new SolRDF("http://127.0.0.1:8080/solr/store");

Adding data

You can use one of the add(...) methods provided by the SolRDF class:

void add(List<Statement> statements)   
void add(String uri, List<Statement> statements)      

void add(Statement [] statements)    
void add(String uri, Statement [] statements)    
  
void add(Statement statement)   
void add(String uri, Statement statement)   

void add(Resource subject, Property predicate, RDFNode object)     
void add(String uri, Resource subject, Property predicate, RDFNode object)   

void add(String url, String lang)   
void add(String graphUri, String url, String lang)

void add(InputStream stream, String lang)   
void add(String graphUri, InputStream stream, String lang)

void add(Reader charStream, String lang)     
void add(String graphUri, Reader charStream, String lang)   

For example:

final String address = ...
final SolRDF solrdf = new Solrdf(address);

solrdf.add(new FileReader("/usr/local/data/mydata.nt", "N-TRIPLES");

A complete list of all available Add scenarios can be found in the test case org.gazzax.labs.solrdf.client.AddTestCase (under the test folder)