From aeff100428e91e91d417b3c3c9da63cd6e5ad819 Mon Sep 17 00:00:00 2001 From: bjl23 Date: Fri, 21 Jan 2011 16:19:54 +0000 Subject: [PATCH] NIHVIVO-1849 added check for empty result set --- .../vitro/webapp/dao/jena/IndividualSDB.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java index 465b13e8f..93422002b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java @@ -939,17 +939,23 @@ public class IndividualSDB extends IndividualImpl implements Individual { propertyURI + "> ?object} \n" + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + "}"; - ResultSet results = QueryExecutionFactory.create( - QueryFactory.create(valueOfProperty), dataset).execSelect(); - QuerySolution result = results.next(); - RDFNode value = result.get("object"); - if (value != null && value.canAs(OntResource.class)) { - return new IndividualSDB( - ((OntResource) value.as(OntResource.class)).getURI(), - dwf, datasetMode, webappDaoFactory); - } else { - return null; - } + QueryExecution qe = QueryExecutionFactory.create( + QueryFactory.create(valueOfProperty), dataset); + try { + ResultSet results = qe.execSelect(); + if (results.hasNext()) { + QuerySolution result = results.next(); + RDFNode value = result.get("object"); + if (value != null && value.canAs(OntResource.class)) { + return new IndividualSDB( + ((OntResource) value.as(OntResource.class)).getURI(), + dwf, datasetMode, webappDaoFactory); + } + } + return null; + } finally { + qe.close(); + } } finally { dataset.getLock().leaveCriticalSection(); w.close();