Closing QueryExecution in some code. Adding EditN3GeneratorTest.
This commit is contained in:
parent
646d3ed00c
commit
2751ba798b
7 changed files with 126 additions and 37 deletions
|
@ -18,6 +18,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
@ -130,38 +131,49 @@ public class OntologyController extends VitroHttpServlet{
|
|||
ontModel =(OntModel)session.getAttribute("jenaOntModel");
|
||||
if( ontModel == null)
|
||||
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||
|
||||
|
||||
boolean found = false;
|
||||
Model newModel = ModelFactory.createDefaultModel();
|
||||
ontModel.enterCriticalSection(Lock.READ);
|
||||
OntResource ontResource = ontModel.getOntResource(url);
|
||||
if(ontResource == null)
|
||||
ontResource = ontModel.getOntResource(url + "/");
|
||||
Model newModel = ModelFactory.createDefaultModel();
|
||||
if(ontResource != null){
|
||||
Resource resource = (Resource)ontResource;
|
||||
try{
|
||||
String queryString = "Describe <" + resource.getURI() + ">";
|
||||
newModel = QueryExecutionFactory.create(QueryFactory.create(queryString), ontModel).execDescribe();
|
||||
}
|
||||
finally{
|
||||
ontModel.leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
else{
|
||||
ontModel.leaveCriticalSection();
|
||||
doNotFound(vreq,res);
|
||||
return;
|
||||
}
|
||||
try{
|
||||
OntResource ontResource = ontModel.getOntResource(url);
|
||||
if(ontResource == null)
|
||||
ontResource = ontModel.getOntResource(url + "/");
|
||||
if(ontResource != null){
|
||||
found = true;
|
||||
Resource resource = (Resource)ontResource;
|
||||
QueryExecution qexec = null;
|
||||
try{
|
||||
String queryString = "Describe <" + resource.getURI() + ">";
|
||||
qexec = QueryExecutionFactory.create(QueryFactory.create(queryString), ontModel);
|
||||
newModel = qexec.execDescribe();
|
||||
} finally{
|
||||
qexec.close();
|
||||
}
|
||||
} else {
|
||||
found = false;
|
||||
}
|
||||
}finally{
|
||||
ontModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
if( ! found ){
|
||||
//respond to HTTP outside of critical section
|
||||
doNotFound(req,res);
|
||||
return;
|
||||
} else {
|
||||
res.setContentType(rdfFormat.getMediaType());
|
||||
String format = "";
|
||||
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format = "RDF/XML";
|
||||
else if( N3_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format = "N3";
|
||||
else if ( TTL_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format ="TTL";
|
||||
|
||||
res.setContentType(rdfFormat.getMediaType());
|
||||
String format = "";
|
||||
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format = "RDF/XML";
|
||||
else if( N3_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format = "N3";
|
||||
else if ( TTL_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format ="TTL";
|
||||
|
||||
newModel.write( res.getOutputStream(), format );
|
||||
newModel.write( res.getOutputStream(), format );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static Pattern URI_PATTERN = Pattern.compile("^/ontology/([^/]*)/([^/]*)$");
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.hp.hpl.jena.ontology.OntModel;
|
|||
import com.hp.hpl.jena.ontology.OntProperty;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
|
@ -217,9 +218,11 @@ public class RefactorOperationController extends BaseEditController {
|
|||
queryStr += " union { GRAPH ?graph { ?subj ?prop <" + oldURIStr + ">}}}";
|
||||
Dataset dataset = request.getDataset();
|
||||
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
QueryExecution qexec = null;
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
ResultSet resultSet = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset).execSelect();
|
||||
qexec = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset);
|
||||
ResultSet resultSet = qexec.execSelect();
|
||||
|
||||
while (resultSet.hasNext()) {
|
||||
QuerySolution qs = resultSet.next();
|
||||
|
@ -245,6 +248,7 @@ public class RefactorOperationController extends BaseEditController {
|
|||
renameResourceInModel(model, userURI, oldURIStr, newURIStr, doNotify);
|
||||
}
|
||||
} finally {
|
||||
if(qexec != null) qexec.close();
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
}
|
||||
|
||||
|
|
|
@ -68,9 +68,12 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
|
|||
DatasetWrapper w = dwf.getDatasetWrapper();
|
||||
Dataset dataset = w.getDataset();
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
QueryExecution qexec = null;
|
||||
try {
|
||||
results = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct();
|
||||
qexec = QueryExecutionFactory.create(QueryFactory.create(query), dataset);
|
||||
results = qexec.execConstruct();
|
||||
} finally {
|
||||
if(qexec!=null) qexec.close();
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
w.close();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import com.clarkparsia.pellet.sparqldl.engine.QueryExec;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
|
@ -509,12 +510,15 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
DatasetWrapper w = getDatasetWrapper();
|
||||
Dataset dataset = w.getDataset();
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
try{
|
||||
_hasThumb = QueryExecutionFactory.create(QueryFactory.create(ask), dataset).execAsk();
|
||||
QueryExecution qexec = null;
|
||||
try{
|
||||
qexec = QueryExecutionFactory.create(QueryFactory.create(ask), dataset);
|
||||
_hasThumb = qexec.execAsk();
|
||||
}catch(Exception ex){
|
||||
_hasThumb = false;
|
||||
log.error(ex,ex);
|
||||
}finally{
|
||||
if(qexec!=null) qexec.close();
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
w.close();
|
||||
}
|
||||
|
@ -670,11 +674,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
DatasetWrapper w = getDatasetWrapper();
|
||||
Dataset dataset = w.getDataset();
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
QueryExecution qexec = null;
|
||||
try {
|
||||
String valuesOfProperty =
|
||||
"CONSTRUCT{ <" + this.individualURI + "> <" + propertyURI + "> ?object }" +
|
||||
"WHERE{ <" + this.individualURI + "> <" + propertyURI + "> ?object } \n";
|
||||
tempModel = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execConstruct();
|
||||
qexec = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset);
|
||||
tempModel = qexec.execConstruct();
|
||||
ontModel.add(tempModel.listStatements());
|
||||
Resource ontRes = ontModel.getResource(this.individualURI);
|
||||
StmtIterator sit = ontRes.listProperties(ontRes.getModel().getProperty(propertyURI));
|
||||
|
@ -698,6 +704,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
if(qexec!=null) qexec.close();
|
||||
tempModel.close();
|
||||
ontModel.close();
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
|
|
|
@ -40,6 +40,15 @@ public class EditN3Generator {
|
|||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the method to use to substitute in URIs into variables of target N3 strings.
|
||||
* This takes into account multiple values that would be returned from a select list.
|
||||
* subInUris should no longer be used.
|
||||
*/
|
||||
public static List<String> subInMultiUris(Map<String,List<String>> varsToVals, List<String> n3targets){
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> subInUris(Map<String,String> varsToVals, List<String> targets){
|
||||
if( varsToVals == null || varsToVals.isEmpty() ) return targets;
|
||||
ArrayList<String> outv = new ArrayList<String>();
|
||||
|
@ -80,6 +89,15 @@ public class EditN3Generator {
|
|||
return outv;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the method to use to substitute in Literals into variables of target N3 strings.
|
||||
* This takes into account multiple values that would be returned from a select list.
|
||||
* subInUris should no longer be used.
|
||||
*/
|
||||
public static List<String> subInMultiLiterals(Map<String,List<String>> varsToVals, List<String> n3targets){
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> subInLiterals(Map<String, Literal> varsToVals, List<String> targets){
|
||||
if( varsToVals == null || varsToVals.isEmpty()) return targets;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
|
@ -37,11 +38,14 @@ public class IndividualProhibitedFromSearchImpl implements IndividualProhibitedF
|
|||
return true;
|
||||
|
||||
boolean prohibited = false;
|
||||
QueryExecution qexec = null;
|
||||
try {
|
||||
fullModel.getLock().enterCriticalSection(Lock.READ);
|
||||
Query query = makeAskQueryForUri( uri );
|
||||
prohibited = QueryExecutionFactory.create( query, fullModel).execAsk();
|
||||
qexec = QueryExecutionFactory.create( query, fullModel);
|
||||
prohibited = qexec.execAsk();
|
||||
} finally {
|
||||
if( qexec != null ) qexec.close();
|
||||
fullModel.getLock().leaveCriticalSection();
|
||||
}
|
||||
if( prohibited )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue