[Mulgara-general] CRUD Operations in Java
Alex Hall
alexhall at revelytix.com
Thu Jul 16 17:41:48 UTC 2009
I'll take a stab at this one since I believe Paul is on vacation this
week...
Chuck Borromeo wrote:
> Hello,
> I have deployed a mulgara 2.1.1
> server and used the WebUI (http://localhost:xxxx/webui/) to load
> some RDF files into a graph and run some SPARQL select statements. I am also
> using some Java code to perform SPARQL queries against the
> endpoint.
>
> I need to perform CRUD operations on
> the mulgara server using Java. These operations
> include:
> - loading RDF
> files
> - deleting
> data
> - drop
> graphs
All of these operations (load, delete, and drop) are supported by the
new REST interface to Mulgara. More information is available on the
wiki at [http://mulgara.org/trac/wiki/RESTInterface].
> The deleting data commands will
> delete a set of triples (instead of single statements). For example, the RDF
> files contain data from individual universities. These RDF files get updated
> periodically. I would like to delete their data before I load the updated
> information. Ideally, I would like to perform a delete command like this:
>
> delete $s $p $o from
> <graphXYZ>
> where $s $p $o from <graphXYZ>
> where $s $p ‘University of Sinatra’
> AND $s $p
> $o;
>
> So basically I want to delete all
> the triples with an object of ‘University of Sinatra’.
Mulgara does not support SPARQL/Update, but TQL does support an
equivalent delete/select operation. The syntax you're looking for is:
delete (select $s $p 'University of Sinatra'
from <graphXYZ>
where $s $p 'University of Sinatra')
from <graphXYZ>;
Note that, unlike SPARQL, TQL allows constant values in the SELECT list.
> What is the best approach to
> accomplish this through Java? Using the mulgara Java API? Open a URL to the
> iTQL endpoint and pass the delete command?
Once you've written your TQL query, you may execute it any way you like
-- parse it in Java and execute it using the Connection API, or send it
to the TQL endpoint. I don't know that there's necessarily an advantage
of doing it one way or the other, though most people seem to lean
towards using the TQL servlet over the Java API.
> The iTQL syntax appears to require a
> subject, predicate, and object for the delete command to work. Are there some
> examples of deleting using iTQL syntax?
See above for an example. More information about TQL, including
examples, is available at [http://mulgara.org/trac/wiki/TQLUserGuide].
> Is there something in 2.1.2 that makes
> this easier?
The only new feature in 2.1.2 related to this is that multiple TQL
commands may now be sent to the TQL servlet, separated by ';'. Multiple
commands will be wrapped in a single transaction and wound back if any
one of them fails.
Regards,
Alex
More information about the Mulgara-general
mailing list