VIVO-1009 TDB is based on transactions. Handle them correctly.
This commit is contained in:
parent
0a78ab5687
commit
0362770961
1 changed files with 20 additions and 24 deletions
|
@ -16,9 +16,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.shared.JenaException;
|
import com.hp.hpl.jena.query.ReadWrite;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
|
||||||
import com.hp.hpl.jena.tdb.TDB;
|
|
||||||
import com.hp.hpl.jena.tdb.TDBFactory;
|
import com.hp.hpl.jena.tdb.TDBFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||||
|
@ -65,6 +63,7 @@ public class RDFServiceTDB extends RDFServiceJena {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataset.begin(ReadWrite.WRITE);
|
||||||
try {
|
try {
|
||||||
insureThatInputStreamsAreResettable(changeSet);
|
insureThatInputStreamsAreResettable(changeSet);
|
||||||
|
|
||||||
|
@ -75,23 +74,20 @@ public class RDFServiceTDB extends RDFServiceJena {
|
||||||
|
|
||||||
applyChangeSetToModel(changeSet, dataset);
|
applyChangeSetToModel(changeSet, dataset);
|
||||||
|
|
||||||
dataset.getLock().enterCriticalSection(Lock.WRITE);
|
|
||||||
try {
|
|
||||||
TDB.sync(dataset);
|
|
||||||
} finally {
|
|
||||||
dataset.getLock().leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyListenersOfChanges(changeSet);
|
notifyListenersOfChanges(changeSet);
|
||||||
notifyListenersOfPostChangeEvents(changeSet);
|
notifyListenersOfPostChangeEvents(changeSet);
|
||||||
|
|
||||||
|
dataset.commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
throw new RDFServiceException(e);
|
throw new RDFServiceException(e);
|
||||||
|
} finally {
|
||||||
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (this.dataset != null) {
|
if (this.dataset != null) {
|
||||||
|
@ -102,75 +98,75 @@ public class RDFServiceTDB extends RDFServiceJena {
|
||||||
@Override
|
@Override
|
||||||
public InputStream sparqlConstructQuery(String query,
|
public InputStream sparqlConstructQuery(String query,
|
||||||
ModelSerializationFormat resultFormat) throws RDFServiceException {
|
ModelSerializationFormat resultFormat) throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
return super.sparqlConstructQuery(query, resultFormat);
|
return super.sparqlConstructQuery(query, resultFormat);
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream sparqlDescribeQuery(String query,
|
public InputStream sparqlDescribeQuery(String query,
|
||||||
ModelSerializationFormat resultFormat) throws RDFServiceException {
|
ModelSerializationFormat resultFormat) throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
return super.sparqlDescribeQuery(query, resultFormat);
|
return super.sparqlDescribeQuery(query, resultFormat);
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream sparqlSelectQuery(String query, ResultFormat resultFormat)
|
public InputStream sparqlSelectQuery(String query, ResultFormat resultFormat)
|
||||||
throws RDFServiceException {
|
throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
return super.sparqlSelectQuery(query, resultFormat);
|
return super.sparqlSelectQuery(query, resultFormat);
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sparqlAskQuery(String query) throws RDFServiceException {
|
public boolean sparqlAskQuery(String query) throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
return super.sparqlAskQuery(query);
|
return super.sparqlAskQuery(query);
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getGraphURIs() throws RDFServiceException {
|
public List<String> getGraphURIs() throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
return super.getGraphURIs();
|
return super.getGraphURIs();
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeAll(OutputStream outputStream)
|
public void serializeAll(OutputStream outputStream)
|
||||||
throws RDFServiceException {
|
throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
super.serializeAll(outputStream);
|
super.serializeAll(outputStream);
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeGraph(String graphURI, OutputStream outputStream)
|
public void serializeGraph(String graphURI, OutputStream outputStream)
|
||||||
throws RDFServiceException {
|
throws RDFServiceException {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.begin(ReadWrite.READ);
|
||||||
try {
|
try {
|
||||||
super.serializeGraph(graphURI, outputStream);
|
super.serializeGraph(graphURI, outputStream);
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue