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.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
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.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
@ -131,27 +132,36 @@ public class OntologyController extends VitroHttpServlet{
|
||||||
if( ontModel == null)
|
if( ontModel == null)
|
||||||
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
Model newModel = ModelFactory.createDefaultModel();
|
||||||
ontModel.enterCriticalSection(Lock.READ);
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
|
try{
|
||||||
OntResource ontResource = ontModel.getOntResource(url);
|
OntResource ontResource = ontModel.getOntResource(url);
|
||||||
if(ontResource == null)
|
if(ontResource == null)
|
||||||
ontResource = ontModel.getOntResource(url + "/");
|
ontResource = ontModel.getOntResource(url + "/");
|
||||||
Model newModel = ModelFactory.createDefaultModel();
|
|
||||||
if(ontResource != null){
|
if(ontResource != null){
|
||||||
|
found = true;
|
||||||
Resource resource = (Resource)ontResource;
|
Resource resource = (Resource)ontResource;
|
||||||
|
QueryExecution qexec = null;
|
||||||
try{
|
try{
|
||||||
String queryString = "Describe <" + resource.getURI() + ">";
|
String queryString = "Describe <" + resource.getURI() + ">";
|
||||||
newModel = QueryExecutionFactory.create(QueryFactory.create(queryString), ontModel).execDescribe();
|
qexec = QueryExecutionFactory.create(QueryFactory.create(queryString), ontModel);
|
||||||
|
newModel = qexec.execDescribe();
|
||||||
|
} finally{
|
||||||
|
qexec.close();
|
||||||
}
|
}
|
||||||
finally{
|
} else {
|
||||||
|
found = false;
|
||||||
|
}
|
||||||
|
}finally{
|
||||||
ontModel.leaveCriticalSection();
|
ontModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else{
|
|
||||||
ontModel.leaveCriticalSection();
|
|
||||||
doNotFound(vreq,res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if( ! found ){
|
||||||
|
//respond to HTTP outside of critical section
|
||||||
|
doNotFound(req,res);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
res.setContentType(rdfFormat.getMediaType());
|
res.setContentType(rdfFormat.getMediaType());
|
||||||
String format = "";
|
String format = "";
|
||||||
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||||
|
@ -162,6 +172,8 @@ public class OntologyController extends VitroHttpServlet{
|
||||||
format ="TTL";
|
format ="TTL";
|
||||||
|
|
||||||
newModel.write( res.getOutputStream(), format );
|
newModel.write( res.getOutputStream(), format );
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Pattern URI_PATTERN = Pattern.compile("^/ontology/([^/]*)/([^/]*)$");
|
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.OntProperty;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
import com.hp.hpl.jena.ontology.OntResource;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
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.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
|
@ -217,9 +218,11 @@ public class RefactorOperationController extends BaseEditController {
|
||||||
queryStr += " union { GRAPH ?graph { ?subj ?prop <" + oldURIStr + ">}}}";
|
queryStr += " union { GRAPH ?graph { ?subj ?prop <" + oldURIStr + ">}}}";
|
||||||
Dataset dataset = request.getDataset();
|
Dataset dataset = request.getDataset();
|
||||||
|
|
||||||
|
QueryExecution qexec = null;
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
ResultSet resultSet = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset).execSelect();
|
qexec = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset);
|
||||||
|
ResultSet resultSet = qexec.execSelect();
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
while (resultSet.hasNext()) {
|
||||||
QuerySolution qs = resultSet.next();
|
QuerySolution qs = resultSet.next();
|
||||||
|
@ -245,6 +248,7 @@ public class RefactorOperationController extends BaseEditController {
|
||||||
renameResourceInModel(model, userURI, oldURIStr, newURIStr, doNotify);
|
renameResourceInModel(model, userURI, oldURIStr, newURIStr, doNotify);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if(qexec != null) qexec.close();
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,12 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
|
||||||
DatasetWrapper w = dwf.getDatasetWrapper();
|
DatasetWrapper w = dwf.getDatasetWrapper();
|
||||||
Dataset dataset = w.getDataset();
|
Dataset dataset = w.getDataset();
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
QueryExecution qexec = null;
|
||||||
try {
|
try {
|
||||||
results = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct();
|
qexec = QueryExecutionFactory.create(QueryFactory.create(query), dataset);
|
||||||
|
results = qexec.execConstruct();
|
||||||
} finally {
|
} finally {
|
||||||
|
if(qexec!=null) qexec.close();
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
w.close();
|
w.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.joda.time.DateTime;
|
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.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
import com.hp.hpl.jena.ontology.OntResource;
|
||||||
|
@ -509,12 +510,15 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
DatasetWrapper w = getDatasetWrapper();
|
DatasetWrapper w = getDatasetWrapper();
|
||||||
Dataset dataset = w.getDataset();
|
Dataset dataset = w.getDataset();
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
QueryExecution qexec = null;
|
||||||
try{
|
try{
|
||||||
_hasThumb = QueryExecutionFactory.create(QueryFactory.create(ask), dataset).execAsk();
|
qexec = QueryExecutionFactory.create(QueryFactory.create(ask), dataset);
|
||||||
|
_hasThumb = qexec.execAsk();
|
||||||
}catch(Exception ex){
|
}catch(Exception ex){
|
||||||
_hasThumb = false;
|
_hasThumb = false;
|
||||||
log.error(ex,ex);
|
log.error(ex,ex);
|
||||||
}finally{
|
}finally{
|
||||||
|
if(qexec!=null) qexec.close();
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
w.close();
|
w.close();
|
||||||
}
|
}
|
||||||
|
@ -670,11 +674,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
DatasetWrapper w = getDatasetWrapper();
|
DatasetWrapper w = getDatasetWrapper();
|
||||||
Dataset dataset = w.getDataset();
|
Dataset dataset = w.getDataset();
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
QueryExecution qexec = null;
|
||||||
try {
|
try {
|
||||||
String valuesOfProperty =
|
String valuesOfProperty =
|
||||||
"CONSTRUCT{ <" + this.individualURI + "> <" + propertyURI + "> ?object }" +
|
"CONSTRUCT{ <" + this.individualURI + "> <" + propertyURI + "> ?object }" +
|
||||||
"WHERE{ <" + this.individualURI + "> <" + propertyURI + "> ?object } \n";
|
"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());
|
ontModel.add(tempModel.listStatements());
|
||||||
Resource ontRes = ontModel.getResource(this.individualURI);
|
Resource ontRes = ontModel.getResource(this.individualURI);
|
||||||
StmtIterator sit = ontRes.listProperties(ontRes.getModel().getProperty(propertyURI));
|
StmtIterator sit = ontRes.listProperties(ontRes.getModel().getProperty(propertyURI));
|
||||||
|
@ -698,6 +704,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if(qexec!=null) qexec.close();
|
||||||
tempModel.close();
|
tempModel.close();
|
||||||
ontModel.close();
|
ontModel.close();
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
|
|
@ -40,6 +40,15 @@ public class EditN3Generator {
|
||||||
return Collections.EMPTY_LIST;
|
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){
|
public static List<String> subInUris(Map<String,String> varsToVals, List<String> targets){
|
||||||
if( varsToVals == null || varsToVals.isEmpty() ) return targets;
|
if( varsToVals == null || varsToVals.isEmpty() ) return targets;
|
||||||
ArrayList<String> outv = new ArrayList<String>();
|
ArrayList<String> outv = new ArrayList<String>();
|
||||||
|
@ -80,6 +89,15 @@ public class EditN3Generator {
|
||||||
return outv;
|
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){
|
public List<String> subInLiterals(Map<String, Literal> varsToVals, List<String> targets){
|
||||||
if( varsToVals == null || varsToVals.isEmpty()) return 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.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.query.Query;
|
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.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
@ -37,11 +38,14 @@ public class IndividualProhibitedFromSearchImpl implements IndividualProhibitedF
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
boolean prohibited = false;
|
boolean prohibited = false;
|
||||||
|
QueryExecution qexec = null;
|
||||||
try {
|
try {
|
||||||
fullModel.getLock().enterCriticalSection(Lock.READ);
|
fullModel.getLock().enterCriticalSection(Lock.READ);
|
||||||
Query query = makeAskQueryForUri( uri );
|
Query query = makeAskQueryForUri( uri );
|
||||||
prohibited = QueryExecutionFactory.create( query, fullModel).execAsk();
|
qexec = QueryExecutionFactory.create( query, fullModel);
|
||||||
|
prohibited = qexec.execAsk();
|
||||||
} finally {
|
} finally {
|
||||||
|
if( qexec != null ) qexec.close();
|
||||||
fullModel.getLock().leaveCriticalSection();
|
fullModel.getLock().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
if( prohibited )
|
if( prohibited )
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class EditN3GeneratorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSubInMultiUris() {
|
||||||
|
// String n3 = "?subject ?predicate ?multivalue." ;
|
||||||
|
// List<String> strs = new ArrayList<String>();
|
||||||
|
// strs.add(n3);
|
||||||
|
//
|
||||||
|
// Map<String,List<String>> keyToValues = new HashMap<String,List<String>>();
|
||||||
|
// List<String> values = new ArrayList<String>();
|
||||||
|
// values.add("http://a.com/2");
|
||||||
|
// values.add("http://b.com/ont#2");
|
||||||
|
// values.add("http://c.com/individual/n23431");
|
||||||
|
// keyToValues.put("multivalue", values);
|
||||||
|
//
|
||||||
|
// List<String> n3results = EditN3Generator.subInMultiLiterals(keyToValues, strs);
|
||||||
|
//
|
||||||
|
// Assert.assertNotNull(n3results);
|
||||||
|
// Assert.assertTrue( n3results.size() == 1 );
|
||||||
|
// String expected ="?subject ?predicate <http://a.com/2>, <http://b.com/ont#2>, <http://c.com/individual/n23431>.";
|
||||||
|
// Assert.assertEquals(expected, n3results);
|
||||||
|
//
|
||||||
|
//make a model,
|
||||||
|
//add statements
|
||||||
|
//prase resultn3
|
||||||
|
//compare
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue