1 5 6 package org.joseki.server.processors; 7 8 import org.apache.commons.logging.*; 9 import org.joseki.server.*; 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.rdf.model.RDFException; 12 13 20 public abstract class QueryProcessorCom implements QueryProcessor 21 { 22 static final Log logger = LogFactory.getLog(QueryProcessorCom.class.getName()) ; 23 24 boolean readOnlyLock = true ; 25 26 public QueryProcessorCom() { } 27 28 30 public void init(Resource processor, Resource implementation) { } 31 32 public int argsNeeded() { return Processor.ARGS_ONE ; } 35 36 39 public Model exec(Request request) throws ExecutionException 40 { 41 ModelSource aModel = request.getModelSource(); 42 boolean needsEndOperation = false ; 43 try 44 { 45 aModel.startOperation(readOnlyLock); 46 needsEndOperation = true ; 47 try 48 { 49 String queryString = request.getParam("query"); 51 if (queryString != null && queryString.equals("")) 53 queryString = null; 54 55 if (queryString != null && request.getDataArgs().size() > 0) 56 throw new ExecutionException( 57 ExecutionError.rcQueryExecutionFailure, 58 "Query has string and model arguments"); 59 60 if (request.getDataArgs().size() > 0) 61 return execQuery(aModel, (Model) request.getDataArgs().get(0), request); 63 64 return execQuery(aModel, queryString, request); 66 67 } 68 catch (RDFException ex) 69 { 70 needsEndOperation = false; 71 aModel.abortOperation(); 72 logger.trace("RDFException: " + ex.getMessage()); 73 throw new ExecutionException(ExecutionError.rcInternalError, null); 74 } 75 catch (ExecutionException exEx) 76 { 77 throw exEx; 78 } 79 catch (Exception ex) 80 { 81 aModel.abortOperation(); 82 logger.trace("Exception : " + ex.getMessage()); 83 throw new ExecutionException(ExecutionError.rcInternalError, null); 84 } 85 } 86 finally 87 { 88 if ( needsEndOperation ) 89 { 90 needsEndOperation = false ; 91 aModel.endOperation(); 92 } 93 } } 95 96 99 100 abstract public Model execQuery(ModelSource target, String queryString, Request request) throws RDFException, QueryExecutionException ; 101 abstract public Model execQuery(ModelSource target, Model queryModel, Request request) throws RDFException, QueryExecutionException ; 102 } 103 104 105 131 | Popular Tags |