[Mulgara-general] CRUD Operations in Java

Paul Gearon gearon at ieee.org
Fri Jul 17 03:04:13 UTC 2009


On Thu, Jul 16, 2009 at 1:41 PM, Alex Hall<alexhall at revelytix.com> wrote:
> I'll take a stab at this one since I believe Paul is on vacation this
> week...

Yes, I am, but I have my computer with me, so I guess I should look at
my email occasionally.

> 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].

What Alex said.

>> 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>;

That's what he said he wants to do, yes. But if his SPARQL/Update
command is to be believed then the equivalent is:

delete (select $s $p $o
       from <graphXYZ>
       where $s $p 'University of Sinatra' and $s $p $o)
from <graphXYZ>;

This removes all triples that have the same subject/predicate as a
triple which has an object of
'University of Sinatra'. So if the predicate is "hasName" and the
subject has two names, then this would remove both of the triples
declaring names.

> 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?

It depends. If you're running the database inside your application,
then you pretty much have to use the API. If it's a separate process,
then you're free to choose. The TQL endpoint just parses your command
and then uses the Java API internally, so there's no real difference
at the end of the day.

> 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.

I think that HTTP is a far more standard form of IPC, and is easier to
configure if you move the server (ie. you just change the URL of the
endpoint).

>> 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.

Also....

> I forgot to mention...  The REST interface does not support templated
> deletes.  To delete a statement, you must explicitly provide its
> subject, predicate, and object as URI's or literals (no wildcards).  For
> your specific scenario, to delete all statements with a given object,
> you will need to use TQL instead of REST.

Yes, and for good reason. REST means that you are using URIs to refer
to resources. I decided to refer to individual statements as
resources. That may have been a bit "fine-grained" but I thought it
might be useful.  :-)

However, a "template" that refers to a group of statements did not
make any sense to me in terms of identifying a since resource. It did
cross my mind to do this (it'd be very easy), but if I did then I'd be
moving into the realm of RPC via HTTP. This is certainly a valid thing
to do, but not if you're calling your interface "REST".

Update commands do the job just as well, so this was yet another
reason to not violate the RESTfulness of the interface.

Regards,
Paul Gearon



More information about the Mulgara-general mailing list