On 05/03/12 19:41, Milorad Tosic wrote:
Andy,

You are right, I overlooked the source of the exception as you correctly 
indicated. So, the code now looks like follows. Maybe not the most elegant code 
ever, but it does the work for me.

Great - glad that's sorted.


         String querystr = "DROP ALL";
         try {
             //SPARQL 1.0 QUERY is handled here

SPARQL 1.1

(if you want SPARQL 1.0, add Syntax.syntaxSPARQL_10)

             Query query = QueryFactory.create(querystr);
             if( query.isAskType() ){
                 log.debug("QueryExecution started. ASK");
                executeAskSPARQL(querystr,out,outFormat);
             }else if( query.isConstructType() ){
                 log.debug("QueryExecution started. CONSTRUCT");
                 executeConstructSPARQL(querystr,out,outFormat);
             }else if( query.isDescribeType() ){
                 log.debug("QueryExecution started. DESCRIBE");
                 executeDescribeSPARQL(querystr,out,outFormat);
             }else if( query.isSelectType() ){
                 log.debug("QueryExecution started. SELECT");
                 executeSelectSPARQL(querystr, out, outFormat);
             }else{
                 // UPDATE is handled here
                 log.debug("QueryExecution started. UPDATE");
                 executeUpdateSPARQL(querystr);
             }
         }catch (Exception e){
             // UPDATE is handled here because UPDATE queries throws exception 
when
             // we try to do QueryFactory.create(querystr)
             log.debug("QueryExecution started. UPDATE after exception");
             try{
                 executeUpdateSPARQL(querystr);
             }catch (Exception ex){
                 log.debug("executeSPARQL: something definitelly wrong with the query: 
\n"+querystr+"\n"+e);
             }
         }

Thanks,
Milorad




________________________________
From: Andy Seaborne<[email protected]>
To: [email protected]
Sent: Monday, March 5, 2012 2:47 PM
Subject: Re: DROP query

On 05/03/12 13:07, Milorad Tosic wrote:
I provided a code snippet.

Except it does not do as you describe!

When I run

   Query query = QueryFactory.create("DROP ALL") ;

I get an exception as expected: Jena 2.7.0 and Jena 2.6.5.

Sure, I would provide the example as you suggested but I am not exactly sure 
that I understand what it should look like. Here is my best try:
/**
* This section throws exception
**/


complete =>  code so that I don't have to guess how to complete it.
Every guess is risk the root issue is being overlooked.
"Complete" mean I can cut and paste it into my development environment.

(Also, I'd rather spend my time on the report, not fixing code - the
longer it will take, the longer it has to wait before I can find time to
do it)

minimal =>  no large than necessary to illusrate the point.

String querystr = "DROP ALL";
Query query = QueryFactory.create(querystr);

As above.  I get an exception and it never gets to the next line.

if( query.isSelectType() ){ // evaluated TRUE
           m_triplestore.enterCriticalSection(Lock.READ) ;
           try {
               QueryExecution qexec = QueryExecutionFactory.create(query, 
m_triplestore) ;
               ResultSet results = qexec.execSelect() ;
               print(outFormat, out, results);
               qexec.close();
           } finally {
               m_triplestore.leaveCriticalSection();
           }
}


/**
* This section works fine
**/

String querystr = "DROP ALL";
Query query = QueryFactory.create(querystr);
m_triplestore.enterCriticalSection(Lock.WRITE);
try {
               UpdateRequest updateRequest = UpdateFactory.create(querystr);
               UpdateAction.execute(updateRequest, m_triplestore);
}catch (Exception e){
               log.debug(e);
} finally {
               m_triplestore.commit();
               TDB.sync(m_triplestore);
               m_triplestore.leaveCriticalSection();
    }


So, the problem is that the query "DROP ALL" is evaluated as a SELECT query by 
query.isSelectType() method instead of being evaluated as an update query.

Milorad


ps. We use jena 2.6.4/arq 2.8.7/tdb 0.8.10 and we still didn't hit the limits 
in our development, so far so good (we are limited to Java 5). Migrating to new 
versions of Jena would usually require some efforts investment, so we will 
probably stick with the current version for some time. Does Jena 7 require Java 
6 or not?

Jena 2.70 requires Java 6 - we don't support Java 5 anymore.  Generally,
we aim for two major versions, currently java 6 and 7.  Java 5 is past
it's end-of-life, depending on the system and support you have

     Andy




Reply via email to