[VIVO-1240] Improve start up time with the graph equivalence test
This commit is contained in:
parent
75b8746026
commit
8b088478f0
10 changed files with 110 additions and 11 deletions
|
@ -196,6 +196,17 @@ public interface RDFService {
|
|||
public boolean isEquivalentGraph(String graphURI, InputStream serializedGraph,
|
||||
ModelSerializationFormat serializationFormat) throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* Tests to see whether the supplied serialization is equivalent to the
|
||||
* named graph, as it exists in the store. Equivalence means that if this
|
||||
* serialization were written to the store, the resulting graph would be
|
||||
* isomorphic to the existing named graph.
|
||||
*
|
||||
* @param graphURI - the URI of the graph to test against. May not be null.
|
||||
* @param graph - the contents to be compared with the existing graph. May not be null.
|
||||
*/
|
||||
public boolean isEquivalentGraph(String graphURI, Model graph) throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* Registers a listener to listen to changes in any graph in
|
||||
* the RDF store.
|
||||
|
|
|
@ -431,6 +431,12 @@ public class LanguageFilteringRDFService implements RDFService {
|
|||
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI,
|
||||
Model graph) throws RDFServiceException {
|
||||
return s.isEquivalentGraph(graphURI, graph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(ChangeListener changeListener)
|
||||
throws RDFServiceException {
|
||||
|
|
|
@ -289,6 +289,12 @@ public class SameAsFilteringRDFServiceFactory implements RDFServiceFactory {
|
|||
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI,
|
||||
Model graph) throws RDFServiceException {
|
||||
return s.isEquivalentGraph(graphURI, graph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
s.close();
|
||||
|
|
|
@ -145,6 +145,12 @@ public class RDFServiceFactorySingle implements RDFServiceFactory {
|
|||
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI,
|
||||
Model graph) throws RDFServiceException {
|
||||
return s.isEquivalentGraph(graphURI, graph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(ChangeListener changeListener)
|
||||
throws RDFServiceException {
|
||||
|
|
|
@ -607,6 +607,21 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
|||
return fileModel.isIsomorphicWith(fromTripleStoreModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* The basic version. Parse the model from the file, read the model from the
|
||||
* tripleStore, and ask whether they are isomorphic.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI, Model graph) throws RDFServiceException {
|
||||
// Retrieve the graph to compare
|
||||
Model tripleStoreModel = new RDFServiceDataset(this).getNamedModel(graphURI);
|
||||
|
||||
// Load the entire graph into memory (faster comparison)
|
||||
Model fromTripleStoreModel = ModelFactory.createDefaultModel().add(tripleStoreModel);
|
||||
|
||||
return graph.isIsomorphicWith(fromTripleStoreModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// nothing
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -211,6 +212,24 @@ public class RDFServiceTDB extends RDFServiceJena {
|
|||
serializationFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* TDB has a bug: if given a literal of type xsd:nonNegativeInteger, it
|
||||
* stores a literal of type xsd:integer.
|
||||
*
|
||||
* To determine whether this serialized graph is equivalent to what's in
|
||||
* TDB, we need to do the same.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI,
|
||||
Model graph)
|
||||
throws RDFServiceException {
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
graph.write(buffer, "N-TRIPLE");
|
||||
InputStream inStream = new ByteArrayInputStream(buffer.toByteArray());
|
||||
return isEquivalentGraph(graphURI, inStream, ModelSerializationFormat.NTRIPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all of the references to "nonNegativeInteger" to "integer" in
|
||||
* this serialized graph.
|
||||
|
|
|
@ -111,6 +111,15 @@ public class LoggingRDFService implements RDFService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI,
|
||||
Model graph)
|
||||
throws RDFServiceException {
|
||||
try (RDFServiceLogger l = new RDFServiceLogger(graphURI)) {
|
||||
return innerService.isEquivalentGraph(graphURI, graph);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Untimed methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -929,6 +929,17 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
|
|||
return fileModel.isIsomorphicWith(fromTripleStoreModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* The basic version. Parse the model from the file, read the model from the
|
||||
* tripleStore, and ask whether they are isomorphic.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI, Model graph) throws RDFServiceException {
|
||||
Model tripleStoreModel = new RDFServiceDataset(this).getNamedModel(graphURI);
|
||||
Model fromTripleStoreModel = ModelFactory.createDefaultModel().add(tripleStoreModel);
|
||||
return graph.isIsomorphicWith(fromTripleStoreModel);
|
||||
}
|
||||
|
||||
protected HttpContext getContext(HttpRequestBase request) {
|
||||
UsernamePasswordCredentials credentials = getCredentials();
|
||||
if (credentials != null) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -247,6 +248,24 @@ public class RDFServiceVirtuoso extends RDFServiceSparql {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TDB has a bug: if given a literal of type xsd:nonNegativeInteger, it
|
||||
* stores a literal of type xsd:integer.
|
||||
*
|
||||
* To determine whether this serialized graph is equivalent to what's in
|
||||
* TDB, we need to do the same.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEquivalentGraph(String graphURI,
|
||||
Model graph)
|
||||
throws RDFServiceException {
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
graph.write(buffer, "N-TRIPLE");
|
||||
InputStream inStream = new ByteArrayInputStream(buffer.toByteArray());
|
||||
return isEquivalentGraph(graphURI, inStream, ModelSerializationFormat.NTRIPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all of the references to "nonNegativeInteger" to "integer" in
|
||||
* this serialized graph.
|
||||
|
|
|
@ -214,10 +214,7 @@ public class FileGraphSetup implements ServletContextListener {
|
|||
public boolean updateGraphInDB(RDFService rdfService, Model fileModel, String type, Path path) throws RDFServiceException {
|
||||
String graphURI = pathToURI(path,type);
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
fileModel.write(buffer, "N-TRIPLE");
|
||||
InputStream inStream = new ByteArrayInputStream(buffer.toByteArray());
|
||||
if (rdfService.isEquivalentGraph(graphURI, inStream, ModelSerializationFormat.NTRIPLE)) {
|
||||
if (rdfService.isEquivalentGraph(graphURI, fileModel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue