Skip to content

Commit 7215809

Browse files
committed
Keep the close commands previously removed when replacing dataset wrapper with dataset.
The previous code is only closing the connection when the SDB has a connection. This makes no sense for TDB and unless TDB is requiring a functioning SDB then this is a no-op command. This seems wrong. I removed the close entirely in the previous commit based on this observation. However, I suspect that the SDB connection might still be being made even when using TDB. Put the close back. It also makes more sense to me to properly close things.
1 parent a842da8 commit 7215809

File tree

2 files changed

+90
-56
lines changed

2 files changed

+90
-56
lines changed

api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoJena.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ public List<Literal> getDataPropertyValuesForIndividualByProperty(String subject
386386

387387
} finally {
388388
dataset.getLock().leaveCriticalSection();
389+
dataset.close();
389390
if (qexec != null) {
390391
qexec.close();
391392
}
@@ -454,6 +455,7 @@ public List<Literal> getDataPropertyValuesForIndividualByProperty(
454455
return Collections.emptyList();
455456
} finally {
456457
dataset.getLock().leaveCriticalSection();
458+
dataset.close();
457459
if (qexec != null) {
458460
qexec.close();
459461
}
@@ -504,6 +506,7 @@ private Model constructModelForSelectQueries(String subjectUri,
504506
qe.close();
505507
}
506508
dataset.getLock().leaveCriticalSection();
509+
dataset.close();
507510
}
508511
}
509512

api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java

Lines changed: 87 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -397,28 +397,36 @@ private Model parseModel(ModelChange modelChange) {
397397
private InputStream getRDFResultStream(String query, boolean construct,
398398
ModelSerializationFormat resultFormat) throws RDFServiceException {
399399
Dataset d = getDataset();
400-
Query q = createQuery(query);
401-
QueryExecution qe = createQueryExecution(query, q, d);
402-
ByteArrayOutputStream serializedModel = new ByteArrayOutputStream();
403400
try {
404-
// TODO pipe this
405-
Model m = construct ? qe.execConstruct() : qe.execDescribe();
406-
m.write(serializedModel, getSerializationFormatString(resultFormat));
407-
InputStream result = new ByteArrayInputStream(serializedModel.toByteArray());
408-
return result;
401+
Query q = createQuery(query);
402+
QueryExecution qe = createQueryExecution(query, q, d);
403+
ByteArrayOutputStream serializedModel = new ByteArrayOutputStream();
404+
try {
405+
// TODO pipe this
406+
Model m = construct ? qe.execConstruct() : qe.execDescribe();
407+
m.write(serializedModel, getSerializationFormatString(resultFormat));
408+
InputStream result = new ByteArrayInputStream(serializedModel.toByteArray());
409+
return result;
410+
} finally {
411+
qe.close();
412+
}
409413
} finally {
410-
qe.close();
414+
d.close();
411415
}
412416
}
413417

414418
private void getRDFModel(String query, boolean construct, Model model) throws RDFServiceException {
415419
Dataset d = getDataset();
416-
Query q = createQuery(query);
417-
QueryExecution qe = createQueryExecution(query, q, d);
418420
try {
419-
Model m = construct ? qe.execConstruct(model) : qe.execDescribe(model);
421+
Query q = createQuery(query);
422+
QueryExecution qe = createQueryExecution(query, q, d);
423+
try {
424+
Model m = construct ? qe.execConstruct(model) : qe.execDescribe(model);
425+
} finally {
426+
qe.close();
427+
}
420428
} finally {
421-
qe.close();
429+
d.close();
422430
}
423431
}
424432

@@ -449,56 +457,68 @@ public InputStream sparqlDescribeQuery(String query,
449457
public InputStream sparqlSelectQuery(String query, ResultFormat resultFormat)
450458
throws RDFServiceException {
451459
Dataset d = getDataset();
452-
Query q = createQuery(query);
453-
QueryExecution qe = createQueryExecution(query, q, d);
454460
try {
455-
ResultSet resultSet = qe.execSelect();
456-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
457-
switch (resultFormat) {
458-
case CSV:
459-
ResultSetFormatter.outputAsCSV(outputStream,resultSet);
460-
break;
461-
case TEXT:
462-
ResultSetFormatter.out(outputStream,resultSet);
463-
break;
464-
case JSON:
465-
ResultSetFormatter.outputAsJSON(outputStream, resultSet);
466-
break;
467-
case XML:
468-
ResultSetFormatter.outputAsXML(outputStream, resultSet);
469-
break;
470-
default:
471-
throw new RDFServiceException("unrecognized result format");
461+
Query q = createQuery(query);
462+
QueryExecution qe = createQueryExecution(query, q, d);
463+
try {
464+
ResultSet resultSet = qe.execSelect();
465+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
466+
switch (resultFormat) {
467+
case CSV:
468+
ResultSetFormatter.outputAsCSV(outputStream,resultSet);
469+
break;
470+
case TEXT:
471+
ResultSetFormatter.out(outputStream,resultSet);
472+
break;
473+
case JSON:
474+
ResultSetFormatter.outputAsJSON(outputStream, resultSet);
475+
break;
476+
case XML:
477+
ResultSetFormatter.outputAsXML(outputStream, resultSet);
478+
break;
479+
default:
480+
throw new RDFServiceException("unrecognized result format");
481+
}
482+
InputStream result = new ByteArrayInputStream(outputStream.toByteArray());
483+
return result;
484+
} finally {
485+
qe.close();
472486
}
473-
InputStream result = new ByteArrayInputStream(outputStream.toByteArray());
474-
return result;
475487
} finally {
476-
qe.close();
488+
d.close();
477489
}
478490
}
479491

480492
@Override
481493
public void sparqlSelectQuery(String query, ResultSetConsumer consumer)
482494
throws RDFServiceException {
483495
Dataset d = getDataset();
484-
Query q = createQuery(query);
485-
QueryExecution qe = createQueryExecution(query, q, d);
486496
try {
487-
consumer.processResultSet(qe.execSelect());
497+
Query q = createQuery(query);
498+
QueryExecution qe = createQueryExecution(query, q, d);
499+
try {
500+
consumer.processResultSet(qe.execSelect());
501+
} finally {
502+
qe.close();
503+
}
488504
} finally {
489-
qe.close();
505+
d.close();
490506
}
491507
}
492508

493509
@Override
494510
public boolean sparqlAskQuery(String query) throws RDFServiceException {
495511
Dataset d = getDataset();
496-
Query q = createQuery(query);
497-
QueryExecution qe = createQueryExecution(query, q, d);
498512
try {
499-
return qe.execAsk();
513+
Query q = createQuery(query);
514+
QueryExecution qe = createQueryExecution(query, q, d);
515+
try {
516+
return qe.execAsk();
517+
} finally {
518+
qe.close();
519+
}
500520
} finally {
501-
qe.close();
521+
d.close();
502522
}
503523
}
504524

@@ -507,15 +527,16 @@ public List<String> getGraphURIs() throws RDFServiceException {
507527
if (rebuildGraphURICache) {
508528
synchronized (RDFServiceJena.class) {
509529
if (rebuildGraphURICache) {
530+
Dataset d = getDataset();
510531
try {
511-
Dataset d = getDataset();
512532
Iterator<String> nameIt = d.listNames();
513533
graphURIs.clear();
514534
while (nameIt.hasNext()) {
515535
graphURIs.add(nameIt.next());
516536
}
517537
return graphURIs;
518538
} finally {
539+
d.close();
519540
rebuildGraphURICache = false;
520541
}
521542
}
@@ -546,19 +567,23 @@ public void serializeGraph(String graphURI, OutputStream outputStream)
546567

547568
private void serialize(OutputStream outputStream, String query) throws RDFServiceException {
548569
Dataset d = getDataset();
549-
Query q = createQuery(query);
550-
QueryExecution qe = createQueryExecution(query, q, d);
551570
try {
552-
ResultSet resultSet = qe.execSelect();
553-
if (resultSet.getResultVars().contains("g")) {
554-
Iterator<Quad> quads = new ResultSetQuadsIterator(resultSet);
555-
RDFDataMgr.writeQuads(outputStream, quads);
556-
} else {
557-
Iterator<Triple> triples = new ResultSetTriplesIterator(resultSet);
558-
RDFDataMgr.writeTriples(outputStream, triples);
571+
Query q = createQuery(query);
572+
QueryExecution qe = createQueryExecution(query, q, d);
573+
try {
574+
ResultSet resultSet = qe.execSelect();
575+
if (resultSet.getResultVars().contains("g")) {
576+
Iterator<Quad> quads = new ResultSetQuadsIterator(resultSet);
577+
RDFDataMgr.writeQuads(outputStream, quads);
578+
} else {
579+
Iterator<Triple> triples = new ResultSetTriplesIterator(resultSet);
580+
RDFDataMgr.writeTriples(outputStream, triples);
581+
}
582+
} finally {
583+
qe.close();
559584
}
560585
} finally {
561-
qe.close();
586+
d.close();
562587
}
563588
}
564589

@@ -612,6 +637,8 @@ public long countTriples(RDFNode subject, RDFNode predicate, RDFNode object) thr
612637
Literal literal = soln.getLiteral("count");
613638
return literal.getLong();
614639
}
640+
} finally {
641+
d.close();
615642
}
616643

617644
return 0;
@@ -637,8 +664,12 @@ public Model getTriples(RDFNode subject, RDFNode predicate, RDFNode object, long
637664
Model triples = ModelFactory.createDefaultModel();
638665

639666
Dataset d = getDataset();
640-
try (QueryExecution qexec = QueryExecutionFactory.create(query, d, map)) {
641-
qexec.execConstruct(triples);
667+
try {
668+
try (QueryExecution qexec = QueryExecutionFactory.create(query, d, map)) {
669+
qexec.execConstruct(triples);
670+
}
671+
} finally {
672+
d.close();
642673
}
643674

644675
return triples;

0 commit comments

Comments
 (0)