[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,
|
public boolean isEquivalentGraph(String graphURI, InputStream serializedGraph,
|
||||||
ModelSerializationFormat serializationFormat) throws RDFServiceException;
|
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
|
* Registers a listener to listen to changes in any graph in
|
||||||
* the RDF store.
|
* the RDF store.
|
||||||
|
|
|
@ -431,7 +431,13 @@ public class LanguageFilteringRDFService implements RDFService {
|
||||||
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public boolean isEquivalentGraph(String graphURI,
|
||||||
|
Model graph) throws RDFServiceException {
|
||||||
|
return s.isEquivalentGraph(graphURI, graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void registerListener(ChangeListener changeListener)
|
public void registerListener(ChangeListener changeListener)
|
||||||
throws RDFServiceException {
|
throws RDFServiceException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
|
@ -289,6 +289,12 @@ public class SameAsFilteringRDFServiceFactory implements RDFServiceFactory {
|
||||||
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEquivalentGraph(String graphURI,
|
||||||
|
Model graph) throws RDFServiceException {
|
||||||
|
return s.isEquivalentGraph(graphURI, graph);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
s.close();
|
s.close();
|
||||||
|
|
|
@ -145,7 +145,13 @@ public class RDFServiceFactorySingle implements RDFServiceFactory {
|
||||||
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public boolean isEquivalentGraph(String graphURI,
|
||||||
|
Model graph) throws RDFServiceException {
|
||||||
|
return s.isEquivalentGraph(graphURI, graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void registerListener(ChangeListener changeListener)
|
public void registerListener(ChangeListener changeListener)
|
||||||
throws RDFServiceException {
|
throws RDFServiceException {
|
||||||
s.registerListener(changeListener);
|
s.registerListener(changeListener);
|
||||||
|
|
|
@ -607,7 +607,22 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
|
||||||
return fileModel.isIsomorphicWith(fromTripleStoreModel);
|
return fileModel.isIsomorphicWith(fromTripleStoreModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* 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() {
|
public void close() {
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -211,6 +212,24 @@ public class RDFServiceTDB extends RDFServiceJena {
|
||||||
serializationFormat);
|
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
|
* Convert all of the references to "nonNegativeInteger" to "integer" in
|
||||||
* this serialized graph.
|
* 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
|
// Untimed methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -929,6 +929,17 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
|
||||||
return fileModel.isIsomorphicWith(fromTripleStoreModel);
|
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) {
|
protected HttpContext getContext(HttpRequestBase request) {
|
||||||
UsernamePasswordCredentials credentials = getCredentials();
|
UsernamePasswordCredentials credentials = getCredentials();
|
||||||
if (credentials != null) {
|
if (credentials != null) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -247,6 +248,24 @@ public class RDFServiceVirtuoso extends RDFServiceSparql {
|
||||||
return true;
|
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
|
* Convert all of the references to "nonNegativeInteger" to "integer" in
|
||||||
* this serialized graph.
|
* this serialized graph.
|
||||||
|
|
|
@ -214,12 +214,9 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
public boolean updateGraphInDB(RDFService rdfService, Model fileModel, String type, Path path) throws RDFServiceException {
|
public boolean updateGraphInDB(RDFService rdfService, Model fileModel, String type, Path path) throws RDFServiceException {
|
||||||
String graphURI = pathToURI(path,type);
|
String graphURI = pathToURI(path,type);
|
||||||
|
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
if (rdfService.isEquivalentGraph(graphURI, fileModel)) {
|
||||||
fileModel.write(buffer, "N-TRIPLE");
|
return false;
|
||||||
InputStream inStream = new ByteArrayInputStream(buffer.toByteArray());
|
}
|
||||||
if (rdfService.isEquivalentGraph(graphURI, inStream, ModelSerializationFormat.NTRIPLE)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Model dbModel = new RDFServiceDataset(rdfService).getNamedModel(graphURI);
|
Model dbModel = new RDFServiceDataset(rdfService).getNamedModel(graphURI);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue