[Owlim-discussion] Rollback does not to work using SPARQL Queries?

2012-09-20 Thread navarro
I want to delete and insert triples from a sesame repository using SPARQL
queries, and I want to execute both operations as a single transaction.

1° DELETE
2° INSERT

If an exception is thrown during the transaction, rollback is executed...
but it seems not to work. The problem is that, if an exception is thrown
during the insert query, the rollback is executed, but the previously
deleted triples are not recovered (Why?).

Here you have some code:

I have a class called OwlimConnector which wraps the repository connection
and provides some methods to make SPARQL Queries. In the constructor of
this class I set up the connection and I set the autocommit to false:

RemoteRepositoryManager repos_manager =
RemoteRepositoryManager.getInstance(SERVER_URL, USER, PASSWORD);
repos_manager.initialize();
Repository ssr = repos_manager.getRepository(REPOSITORY);
rconn = ssr.getConnection();
rconn.setAutoCommit(false);

In OwlimConnector there is a method called executeUpdate:

public void executeUpdate(String queryString) throws RepositoryException,
MalformedQueryException, UpdateExecutionException
{
  Update up = rconn.prepareUpdate(QueryLanguage.SPARQL, queryPrefixString
+ queryString);
  up.execute();
}

and these methods among others:

public void commit(){
rconn.commit();
}

public void rollback() {
rconn.rollback();
}

public void close(){
rconn.close();
}

On the other hand, I have a web service updateUserGroup wich uses the
previous OwlimConnector and a data access object called UserGroupDAO:

@PUT
@Consumes(MediaType.APPLICATION_XML)
public Response updateUserGroup(UserGroup ug) {

try {
oc = new OwlimConnector();
} catch (OwlimInstantiationException e) {
return ResponseFactory.getError(e.getErrorMessage());
}

try {
UserGroupDAO ugdao = new UserGroupDAO(oc);
ugdao.delete(ug.getUri());
ugdao.add(ug);
oc.commit();
oc.close();
return ResponseFactory.getOK();
} catch (MandatoryFieldException e) {
oc.rollback();
oc.close();
return ResponseFactory.getError(e.getErrorMessage());
} catch (NotExistingResourceException e) {
oc.rollback();
oc.close();
return ResponseFactory.getError(e.getErrorMessage());
} catch (Exception e) {
oc.rollback();
oc.close();
return ResponseFactory.getError(new
GenericException(e).getErrorMessage());
}

}

1. What ugdao.delete(ug.getUri()) does is to call the OwlimConnector
method executeUpdate:

oc.executeUpdate(DELETE {  + usergroup +  ?p ?v . } WHERE {  +
usergroup +  ?p ?v . });

Here the triples are deleted even though there is no commit!

2. What ugdao.add(ug) does is:

To check that ug.getName() is not null or spaces, otherwise the
MandatoryFieldException is thrown:

if (ug.getName() == null || ug.getName().equals()){
throw new MandatoryFieldException(name);
}

Then, the data is inserted:

oc.executeUpdate(INSERT DATA {  + ug.getUri() +  a scmu:UserGroup ;
scmu:hasName \ + ug.getName() + \ . });

When ug.getName() is null or spaces the MandatoryFieldException exception
is thrown and caught by updateUserGroup. Then the rollback is executed but
the deleted triples are not recovered.

I don´t know why this happens. Any Idea?

Thank you very much in advance



___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion


Re: [Owlim-discussion] Rollback does not to work using SPARQL Queries?

2012-09-20 Thread damyan

Hi Navarro,

you are using RemoteRepository so each update,  is immediately sent to 
the remote repository at up.execute() and there it is autocommited 
immediately .


what you could do is instead of preparing and executing on each 
delete/add operation in your service to start collecting all individual 
updates (into a StringBuilder for instance)
and on oc.commit() to prepare and execute the whole list of updates at 
once. (and just clear the list on rollback, in case an exception is thrown)


Your update request can have multiple 'INSERT DATA' or 'DELETE DATA' 
updates ...


HTH,
Damyan Ognyanov
Ontotext AD



On 9/20/2012 11:52 AM, nava...@dfki.uni-kl.de wrote:

I want to delete and insert triples from a sesame repository using SPARQL
queries, and I want to execute both operations as a single transaction.

1° DELETE
2° INSERT

If an exception is thrown during the transaction, rollback is executed...
but it seems not to work. The problem is that, if an exception is thrown
during the insert query, the rollback is executed, but the previously
deleted triples are not recovered (Why?).

Here you have some code:

I have a class called OwlimConnector which wraps the repository connection
and provides some methods to make SPARQL Queries. In the constructor of
this class I set up the connection and I set the autocommit to false:

RemoteRepositoryManager repos_manager =
RemoteRepositoryManager.getInstance(SERVER_URL, USER, PASSWORD);
repos_manager.initialize();
Repository ssr = repos_manager.getRepository(REPOSITORY);
rconn = ssr.getConnection();
rconn.setAutoCommit(false);

In OwlimConnector there is a method called executeUpdate:

public void executeUpdate(String queryString) throws RepositoryException,
MalformedQueryException, UpdateExecutionException
{
   Update up = rconn.prepareUpdate(QueryLanguage.SPARQL, queryPrefixString
+ queryString);
   up.execute();
}

and these methods among others:

public void commit(){
rconn.commit();
}

public void rollback() {
rconn.rollback();
}

public void close(){
rconn.close();
}

On the other hand, I have a web service updateUserGroup wich uses the
previous OwlimConnector and a data access object called UserGroupDAO:

@PUT
@Consumes(MediaType.APPLICATION_XML)
public Response updateUserGroup(UserGroup ug) {

try {
 oc = new OwlimConnector();
} catch (OwlimInstantiationException e) {
 return ResponseFactory.getError(e.getErrorMessage());
}

try {
 UserGroupDAO ugdao = new UserGroupDAO(oc);
 ugdao.delete(ug.getUri());
 ugdao.add(ug);
 oc.commit();
 oc.close();
 return ResponseFactory.getOK();
} catch (MandatoryFieldException e) {
 oc.rollback();
 oc.close();
 return ResponseFactory.getError(e.getErrorMessage());
} catch (NotExistingResourceException e) {
 oc.rollback();
 oc.close();
 return ResponseFactory.getError(e.getErrorMessage());
} catch (Exception e) {
 oc.rollback();
 oc.close();
 return ResponseFactory.getError(new
GenericException(e).getErrorMessage());
}

}

1. What ugdao.delete(ug.getUri()) does is to call the OwlimConnector
method executeUpdate:

oc.executeUpdate(DELETE {  + usergroup +  ?p ?v . } WHERE {  +
usergroup +  ?p ?v . });

Here the triples are deleted even though there is no commit!

2. What ugdao.add(ug) does is:

To check that ug.getName() is not null or spaces, otherwise the
MandatoryFieldException is thrown:

if (ug.getName() == null || ug.getName().equals()){
throw new MandatoryFieldException(name);
}

Then, the data is inserted:

oc.executeUpdate(INSERT DATA {  + ug.getUri() +  a scmu:UserGroup ;
scmu:hasName \ + ug.getName() + \ . });

When ug.getName() is null or spaces the MandatoryFieldException exception
is thrown and caught by updateUserGroup. Then the rollback is executed but
the deleted triples are not recovered.

I don´t know why this happens. Any Idea?

Thank you very much in advance



___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion



___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion


[Owlim-discussion] resolution flow of queries with subqueries

2012-09-20 Thread Sinan Yurtsever
Hello

 

For optimizing queries I would like to learn more about the resolution
order of such a query:

 

Imagine that I have such a query:

 

SELECT ?s

WHERE{

 

?s exampleURI1 exampleURI2. (tripleA)

 

SELECT ?s WHERE{

?s exampleURI3 exampleURI4.
(tripleB)

}

 

}

 

Here which will be the resolution order:

 

a)  URIs validating both triples are retrieved seperately, then
their intersection will be the final resultSet

b)  URIs validating the tripleA will be retrieved. Apart from these
URIs, ones that validate tripleB will be retrieved. 

c)   URIs validating the tripleB will be retrieved. Apart from these
URIs, ones that validate tripleA will be retrieved.

 

Kind Regards, 

Sinan Yurtsever

 

--
This e-mail and the documents attached are confidential and intended 
solely for the addressee; it may also be privileged. If you receive 
this e-mail in error, please notify the sender immediately and destroy it. 
As its integrity cannot be secured on the Internet, the Atos 
group liability cannot be triggered for the message content. Although 
the sender endeavours to maintain a computer virus-free network, 
the sender does not warrant that this transmission is virus-free and 
will not be liable for any damages resulting from any virus transmitted. 

Este mensaje y los ficheros adjuntos pueden contener informacion confidencial 
destinada solamente a la(s) persona(s) mencionadas anteriormente 
pueden estar protegidos por secreto profesional. 
Si usted recibe este correo electronico por error, gracias por informar 
inmediatamente al remitente y destruir el mensaje. 
Al no estar asegurada la integridad de este mensaje sobre la red, Atos 
no se hace responsable por su contenido. Su contenido no constituye ningun 
compromiso para el grupo Atos, salvo ratificacion escrita por ambas partes. 
Aunque se esfuerza al maximo por mantener su red libre de virus, el emisor 
no puede garantizar nada al respecto y no sera responsable de cualesquiera 
danos que puedan resultar de una transmision de virus. 
--
___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion


Re: [Owlim-discussion] OWLIM SE and SPARQL dataset

2012-09-20 Thread Ruslan Velkov

Hi Ken,

This bug was due to incorrect setting of a flag and was fixed. It may 
also appear in SELECT queries when specifying FROM clauses and 
includeInferred is set to 'false' (additional statements from the 
default graph will appear in the query result). The fix will be 
available in the next release.


Regards,
Ruslan


On 09/11/2012 01:32 PM, Barry Bishop wrote:

Hi Ken,

Thanks for the extra information. The bit I was missing is that the
problem occurs with includeInferred is set to false. I can now replicate
it and seems to be independent of the context index and the rule-set.

To summarise, an ASK query of this form:

ASK
FROM g
WHERE { x y z }

will incorrectly return true when:

a. triple 'x y z' is in the default graph (not another named graph or
'g') and
b. includeInferred is set to false (in sesame workbench or
programmatically or adding FROM http://www.ontotext.com/explicit)

This is indeed a bug and will be investigated. Thanks for reporting it.

I have not found anything wrong with SELECT queries when includeInferred
is set to false.

For the moment, I suggest leaving your includeInferred parameter set to
true.

I hope this helps,
barry

On 11/09/12 11:07, Wenzel, Ken wrote:

Hi Barry,

thank you for testing this.
I use the rule-set  owl-horst-optimized, but I opted to NOT
includeInferred in the Sesame API and the OpenRDF workbench.

Does this mean that basic axiomatic statements (RDFS, OWL) are always
included when using a rule-set, even if includeInferred=false?

Ken


-Original Message-
From: Barry Bishop [mailto:barry.bis...@ontotext.com]
Sent: Tuesday, September 11, 2012 10:56 AM
To: Wenzel, Ken
Cc: owlim-discussion@ontotext.com
Subject: Re: [Owlim-discussion] OWLIM SE and SPARQL dataset

Hi Ken,

I'm not able to reproduce this with OWLIM 5.2. I tried the following:

insert data {
skos:x skos:y skos:z .
graph skos:g { skos:a skos:b skos:c }
}

select ?s ?p ?o from skos:g where { ?s ?p ?o }

= a b c
correct, only triples in 'g' should be used

select ?s ?p ?o where { ?s ?p ?o }

= a b c
= x y z
= lots of axiomatic statements if using any rule-set apart from 'empty'
correct (for owlim, there is no standard for this), the default graph in
the rdf dataset is made up of an RDF merge of all graphs in the database


ask from skos:g { skos:x skos:y skos:z }
= false
correct, the triple x y z is in the default graph, which is not used

ask from skos:g { skos:a skos:b skos:c }
= true
correct, a b c is in graph g


May I ask what kind of inference you are using? Inferred statements go
in to the default graph,  I wonder if these have interfered with your
experiments?

barry

Barry Bishop
OWLIM Product Manager
Ontotext AD
Tel: +43 650 2000 237
email: barry.bis...@ontotext.com
skype: bazbishop
www.ontotext.com

On 10/09/12 15:23, Wenzel, Ken wrote:

Hello,

I encountered a potential bug in OWLIM SE 5.2 (with Sesame 2.6.8 and

context indexes enabled)

when executing a SPARQL query where the dataset is specified with

FROM ... clauses

(or by using the corresponding Sesame API).

Both queries

select ?s ?p ?o from urn:somegraph where { ?s ?p ?o }

and

ask from urn:somegraph { ?s ?p ?o }

retrieve data from urn:somegraph and the default graph.
But, as I understand from urn:somegraph, only data contained
in urn:somegraph should be used to answer the query.

I am not aware of this behaviour in OWLIM Lite.

I would be glad to get some suggestions.


Regards,

Ken
___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion


___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion



___
Owlim-discussion mailing list
Owlim-discussion@ontotext.com
http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion