[VIVO-1399] Improve performance of Graph URI lookups

This commit is contained in:
Graham Triggs 2017-10-11 19:37:07 +01:00
parent e729fc9f38
commit 107c2bff03
4 changed files with 29 additions and 13 deletions

View file

@ -61,6 +61,9 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
protected abstract DatasetWrapper getDatasetWrapper();
protected volatile boolean rebuildGraphURICache = true;
private final List<String> graphURIs = new ArrayList<>();
@Override
public abstract boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException;
@ -527,10 +530,15 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
@Override
public List<String> getGraphURIs() throws RDFServiceException {
if (rebuildGraphURICache) {
synchronized (RDFServiceJena.class) {
if (rebuildGraphURICache) {
rebuildGraphURICache = false;
graphURIs.clear();
DatasetWrapper dw = getDatasetWrapper();
try {
Dataset d = dw.getDataset();
List<String> graphURIs = new ArrayList<String>();
Iterator<String> nameIt = d.listNames();
while (nameIt.hasNext()) {
graphURIs.add(nameIt.next());
@ -540,6 +548,11 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
dw.close();
}
}
}
}
return graphURIs;
}
@Override
public void getGraphMetadata() throws RDFServiceException {

View file

@ -110,6 +110,7 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService {
abortTransaction(sdbConn);
throw new RDFServiceException(e);
} finally {
rebuildGraphURICache = true;
close(sdbConn);
}
}

View file

@ -88,6 +88,8 @@ public class RDFServiceTDB extends RDFServiceJena {
} catch (Exception e) {
log.error(e, e);
throw new RDFServiceException(e);
} finally {
rebuildGraphURICache = true;
}
}

View file

@ -514,7 +514,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
}
}
public void addModel(Model model, String graphURI) throws RDFServiceException {
private void addModel(Model model, String graphURI) throws RDFServiceException {
try {
long start = System.currentTimeMillis();
verbModel(model, graphURI, "INSERT");
@ -524,7 +524,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
}
}
public void deleteModel(Model model, String graphURI) throws RDFServiceException {
private void deleteModel(Model model, String graphURI) throws RDFServiceException {
try {
verbModel(model, graphURI, "DELETE");
} finally {