NIHVIVO-2079 consuming ResultSet iterators before dataset wrappers are closed
This commit is contained in:
parent
0ed2c4ece5
commit
f0b1a73cff
3 changed files with 16 additions and 4 deletions
|
@ -755,7 +755,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
||||||
public List<DataProperty> getDataPropertyList(String subjectUri) {
|
public List<DataProperty> getDataPropertyList(String subjectUri) {
|
||||||
log.debug("Data property query string:\n" + DATA_PROPERTY_QUERY_STRING);
|
log.debug("Data property query string:\n" + DATA_PROPERTY_QUERY_STRING);
|
||||||
log.debug("Data property query:\n" + dataPropertyQuery);
|
log.debug("Data property query:\n" + dataPropertyQuery);
|
||||||
ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
|
Iterator<QuerySolution> results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
|
||||||
List<DataProperty> properties = new ArrayList<DataProperty>();
|
List<DataProperty> properties = new ArrayList<DataProperty>();
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution sol = results.next();
|
QuerySolution sol = results.next();
|
||||||
|
|
|
@ -886,7 +886,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
|
public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
|
||||||
log.debug("Object property query string:\n" + OBJECT_PROPERTY_QUERY_STRING);
|
log.debug("Object property query string:\n" + OBJECT_PROPERTY_QUERY_STRING);
|
||||||
log.debug("Object property query:\n" + objectPropertyQuery);
|
log.debug("Object property query:\n" + objectPropertyQuery);
|
||||||
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
Iterator<QuerySolution> results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
||||||
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution soln = results.next();
|
QuerySolution soln = results.next();
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.hp.hpl.jena.query.Dataset;
|
||||||
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.QueryExecution;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.QuerySolutionMap;
|
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
@ -401,7 +402,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
||||||
return classSet;
|
return classSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ResultSet getPropertyQueryResults(String subjectUri, Query query) {
|
protected Iterator<QuerySolution> getPropertyQueryResults(String subjectUri, Query query) {
|
||||||
log.debug("SPARQL query:\n" + query.toString());
|
log.debug("SPARQL query:\n" + query.toString());
|
||||||
// Bind the subject's uri to the ?subject query term
|
// Bind the subject's uri to the ?subject query term
|
||||||
QuerySolutionMap subjectBinding = new QuerySolutionMap();
|
QuerySolutionMap subjectBinding = new QuerySolutionMap();
|
||||||
|
@ -409,13 +410,24 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
||||||
ResourceFactory.createResource(subjectUri));
|
ResourceFactory.createResource(subjectUri));
|
||||||
|
|
||||||
// Run the SPARQL query to get the properties
|
// Run the SPARQL query to get the properties
|
||||||
|
System.out.println(dwf.getClass().getName());
|
||||||
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);
|
||||||
try {
|
try {
|
||||||
QueryExecution qexec = QueryExecutionFactory.create(
|
QueryExecution qexec = QueryExecutionFactory.create(
|
||||||
query, dataset, subjectBinding);
|
query, dataset, subjectBinding);
|
||||||
return qexec.execSelect();
|
try {
|
||||||
|
ResultSet rs = qexec.execSelect();
|
||||||
|
// consume iterator before wrapper w is closed in finally block
|
||||||
|
List<QuerySolution> results = new ArrayList<QuerySolution>();
|
||||||
|
while (rs.hasNext()) {
|
||||||
|
results.add(rs.next());
|
||||||
|
}
|
||||||
|
return results.iterator();
|
||||||
|
} finally {
|
||||||
|
qexec.close();
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
w.close();
|
w.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue