NIHVIVO-3841 some javadoc updates for RDFService

This commit is contained in:
stellamit 2012-06-27 17:32:15 +00:00
parent f997b7073c
commit 2d72b1aa42
11 changed files with 82 additions and 231 deletions

View file

@ -2,15 +2,12 @@
package edu.cornell.mannlib.vitro.webapp.rdfservice;
/*
*
* A listener that filters all its listening down to the single-statement level. Users of
* this class override addedStatement(statement) and removedStatement(statement).
*
/**
* An interface for listening to triples that are added to or removed
* from the triple store, and other miscellaneous events.
*/
public interface ChangeListener {
/**
* Override this to listen to all statements added to the RDF store.
*

View file

@ -5,7 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.rdfservice;
import java.io.InputStream;
import java.util.List;
/*
/**
* Input parameter to changeSetUpdate() method in RDFService.
* Represents a precondition query and an ordered list of model changes.
*/
@ -13,36 +13,26 @@ import java.util.List;
public interface ChangeSet {
/**
* Getter for the precondition query
*
* @return String - a SPARQL query
*/
public String getPreconditionQuery();
/**
* Setter for the precondition query
*
* @param preconditionQuery - a SPARQL query
*/
public void setPreconditionQuery(String preconditionQuery);
/**
* Getter for the precondition query type
*
* @return RDFService.SPARQLQueryType - the precondition query type
*/
public RDFService.SPARQLQueryType getPreconditionQueryType();
/**
* Setter for the precondition query type
*
* @param queryType - the precondition query type
*/
public void setPreconditionQueryType(RDFService.SPARQLQueryType queryType);
/**
* Getter for the list of model changes
*
* @return List<ModelChange> - list of model changes
*/
public List<ModelChange> getModelChanges();
@ -71,6 +61,8 @@ public interface ChangeSet {
/**
* Creates an instance of the ModelChange class
*
* @return ModelChange - an empty instance of the ModelChange class
*/
public ModelChange manufactureModelChange();
@ -81,6 +73,9 @@ public interface ChangeSet {
* @param serializationFormat - format of the serialized RDF model
* @param operation - the type of operation to be performed with the serialized RDF model
* @param graphURI - URI of the graph on which to apply the model change operation
*
* @return ModelChange - a ModelChange instance initialized with the input
* model, model format, operation and graphURI
*/
public ModelChange manufactureModelChange(InputStream serializedModel,
RDFService.ModelSerializationFormat serializationFormat,
@ -88,31 +83,37 @@ public interface ChangeSet {
String graphURI);
/**
* Add an event that will be be passed to any change listeners in advance of
* Adds an event that will be be passed to any change listeners in advance of
* the change set additions and retractions being performed. The event
* will only be fired if the precondition (if any) is met.
* @param event
*
* @param event - event to notify listeners of in advance of making
* changes to the triple store.
*/
public void addPreChangeEvent(Object event);
/**
* Add an event that will be be passed to any change listeners after all of
* Adds an event that will be be passed to any change listeners after all of
* the change set additions and retractions are performed.
* @param event
*
* @param event - the event to notify listeners of after the changes are
* performed.
*/
public void addPostChangeEvent(Object event);
/**
* Return a list of events to pass to any change listeners in
* Returns a list of events to pass to any change listeners in
* advance of the change set additions and retractions being performed.
* @return
*
* @return List<Object>
*/
public List<Object> getPreChangeEvents();
/**
* Return a list of events to pass to any change listeners after
* Returns a list of events to pass to any change listeners after
* the change set additions and retractions are performed.
* @return
*
* @return List<Object>
*/
public List<Object> getPostChangeEvents();

View file

@ -4,7 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.rdfservice;
import java.io.InputStream;
/*
/**
* A ModelChange is one component of a ChangeSet.
* Represents a model (collection of RDF triples), the URI
* of a graph, and an indication of whether to add or
@ -18,58 +18,45 @@ public interface ModelChange {
}
/**
* Getter for the serialized model
*
* @return InputStream - a serialized model (collection of RDF triples) representing a change to make
* @return InputStream - the serialized model (collection of RDF triples) representing a change to make
*/
public InputStream getSerializedModel();
/**
* Setter for the serialized model
*
* @param serializedModel - a serialized model (collection of RDF triples) representing a change to make
* @param serializedModel - the serialized model (collection of RDF triples) representing a change to make
*/
public void setSerializedModel(InputStream serializedModel);
/**
* Getter for the serialization format of the model
*
* @return RDFService.ModelSerializationFormat - the serialization format of the model
*/
public RDFService.ModelSerializationFormat getSerializationFormat();
/**
* Setter for the serialization format of the model
*
* @param serializationFormat - the serialization format of the model
*/
public void setSerializationFormat(RDFService.ModelSerializationFormat serializationFormat);
/**
* Getter for the operation type
*
* @return ModelChange.Operation - the operation to be performed
*/
public ModelChange.Operation getOperation();
/**
* Setter for the operation type
*
* @param operation - the operation to be performed
*/
public void setOperation(ModelChange.Operation operation);
/**
* Getter for the URI of the graph to which to apply the change
*
* @return String - the URI of the graph to which to apply the change
*/
public String getGraphURI();
/**
* Setter for the URI of the graph to which to apply the change
*
* @param graphURI - the URI of the graph to which to apply the change
* If the graphURI is null the change applies to the
* default write graph. If this method is not used to
* set the write graph the default write graph will be used.
*/
public void setGraphURI(String graphURI);
}

View file

@ -5,7 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.rdfservice;
import java.io.InputStream;
import java.util.List;
/*
/**
* Interface for API to write, read, and update Vitro's RDF store, with support
* to allow listening, logging and auditing.
*/
@ -25,11 +25,11 @@ public interface RDFService {
}
/**
* Perform a series of additions to and or removals from specified graphs
* in the RDF store. preConditionSparql will be executed against the
* Performs a series of additions to and or removals from specified graphs
* in the RDF store. preConditionSparql is executed against the
* union of all the graphs in the knowledge base before any updates are made.
* If the precondition query returns a non-empty result, no updates
* will be made.
* are made made.
*
* @param changeSet - a set of changes to be performed on the RDF store.
*
@ -38,8 +38,8 @@ public interface RDFService {
public boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException;
/**
* If the given individual already exists in the default graph, throws an
* RDFServiceException, otherwise adds one type assertion to the default
* If the given individual already exists in the default write graph, throws an
* RDFServiceException, otherwise adds one type assertion to the default write
* graph.
*
* @param individualURI - URI of the individual to be added
@ -60,7 +60,9 @@ public interface RDFService {
/**
* Performs a SPARQL construct query against the knowledge base. The query may have
* an embedded graph identifier.
* an embedded graph identifier. If the query does not contain a graph identifier
* the query is executed against the union of all named and unnamed graphs in the
* store.
*
* @param query - the SPARQL query to be executed against the RDF store
* @param resultFormat - type of serialization for RDF result of the SPARQL query
@ -72,7 +74,9 @@ public interface RDFService {
/**
* Performs a SPARQL describe query against the knowledge base. The query may have
* an embedded graph identifier.
* an embedded graph identifier. If the query does not contain a graph identifier
* the query is executed against the union of all named and unnamed graphs in the
* store.
*
* @param query - the SPARQL query to be executed against the RDF store
* @param resultFormat - type of serialization for RDF result of the SPARQL query
@ -84,7 +88,9 @@ public interface RDFService {
/**
* Performs a SPARQL select query against the knowledge base. The query may have
* an embedded graph identifier.
* an embedded graph identifier. If the query does not contain a graph identifier
* the query is executed against the union of all named and unnamed graphs in the
* store.
*
* @param query - the SPARQL query to be executed against the RDF store
* @param resultFormat - format for the result of the Select query
@ -96,35 +102,41 @@ public interface RDFService {
/**
* Performs a SPARQL ASK query against the knowledge base. The query may have
* an embedded graph identifier.
* an embedded graph identifier. If the query does not contain a graph identifier
* the query is executed against the union of all named and unnamed graphs in the
* store.
*
* @param query - the SPARQL query to be executed against the RDF store
* @param query - the SPARQL ASK query to be executed against the RDF store
*
* @return boolean - the result of the SPARQL query
* @return boolean - the result of the SPARQL ASK query
*/
public boolean sparqlAskQuery(String query) throws RDFServiceException;
/**
* Get a list of all the graph URIs in the RDF store.
* Returns a list of all the graph URIs in the RDF store.
*
* @return List<String> - list of all the graph URIs in the RDF store
* @return List<String> - list of all the named graph URIs in the RDF store.
* Return an empty list of there no named graphs in
* the store.
*/
public List<String> getGraphURIs() throws RDFServiceException;
/**
* TBD - we need to define this method
* To be determined. This is a place holder and is not implemented
* in current implementations.
*/
public void getGraphMetadata() throws RDFServiceException;
/**
* Get the URI of the default write graph
* Returns the URI of the default write graph
*
* @return String URI of default write graph
* @return String URI of default write graph. Returns null if no
* default write graph has been set.
*/
public String getDefaultWriteGraphURI() throws RDFServiceException;
/**
* Register a listener to listen to changes in any graph in
* Registers a listener to listen to changes in any graph in
* the RDF store.
*
* @param changeListener - the change listener
@ -132,23 +144,25 @@ public interface RDFService {
public void registerListener(ChangeListener changeListener) throws RDFServiceException;
/**
* Unregister a listener from listening to changes in
* the RDF store in any graph.
* Unregisters a listener from listening to changes in
* any graph in the RDF store
*
* @param changeListener - the change listener
*/
public void unregisterListener(ChangeListener changeListener) throws RDFServiceException;
/**
* Create a ChangeSet object
* Creates a ChangeSet object
*
* @return ChangeSet an empty ChangeSet object
*/
public ChangeSet manufactureChangeSet();
/**
* Free any resources held by this RDFService object
* Frees any resources held by this RDFService object
*
* The implementation of this method should be idempotent so that
* multiple invocations do not cause an error.
*/
public void close();
}

View file

@ -4,20 +4,23 @@ package edu.cornell.mannlib.vitro.webapp.rdfservice;
public interface RDFServiceFactory {
/**
* @return RDFService - an RDFService instance
*/
public RDFService getRDFService();
/**
* Register a listener to listen to changes in any graph in
* the RDF store. Any RDFService objects returned by this factory should notify
* this listener of changes.
* Registers a listener to listen to changes in any graph in
* the RDF store. Any RDFService objects returned by this factory
* should notify this listener of changes.
*
* @param changeListener - the change listener
*/
public void registerListener(ChangeListener changeListener) throws RDFServiceException;
/**
* Unregister a listener from listening to changes in
* the RDF store. Any RDFService objects returned by this factory should notify
* Unregisters a listener from listening to changes in the RDF store.
* Any RDFService objects returned by this factory should notify
* this listener of changes.
*
* @param changeListener - the change listener

View file

@ -11,10 +11,6 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange.Operation;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
/*
* Input parameter to changeSetUpdate() method in RDFService.
* Represents a precondition query and an ordered list of model changes.
*/
public class ChangeSetImpl implements ChangeSet {
public ChangeSetImpl() {
@ -27,96 +23,46 @@ public class ChangeSetImpl implements ChangeSet {
private ArrayList<Object> preChangeEvents = new ArrayList<Object>();
private ArrayList<Object> postChangeEvents = new ArrayList<Object>();
/**
* Getter for the precondition query
*
* @return String - a SPARQL query
*/
@Override
public String getPreconditionQuery() {
return preconditionQuery;
}
/**
* Setter for the precondition query
*
* @param String - a SPARQL query
*/
@Override
public void setPreconditionQuery(String preconditionQuery) {
this.preconditionQuery = preconditionQuery;
}
/**
* Getter for the precondition query type
*
* @return RDFService.SPARQLQueryType - the precondition query type
*/
@Override
public RDFService.SPARQLQueryType getPreconditionQueryType() {
return queryType;
}
/**
* Setter for the precondition query type
*
* @param RDFService.SPARQLQueryType - the precondition query type
*/
@Override
public void setPreconditionQueryType(RDFService.SPARQLQueryType queryType) {
this.queryType = queryType;
}
/**
* Getter for the list of model changes
*
* @return List<ModelChange> - list of model changes
*/
@Override
public List<ModelChange> getModelChanges() {
return modelChanges;
}
/**
* Adds one model change representing an addition to the list of model changes
*
* @param InputStream - a serialized RDF model (collection of triples)
* @param RDFService.ModelSerializationFormat - format of the serialized RDF model
* @param String - URI of the graph to which the RDF model should be added
*/
@Override
public void addAddition(InputStream model, RDFService.ModelSerializationFormat format, String graphURI) {
modelChanges.add(manufactureModelChange(model,format, ModelChange.Operation.ADD, graphURI));
}
/**
* Adds one model change representing a deletion to the list of model changes
*
* @param InputStream - a serialized RDF model (collection of triples)
* @param RDFService.ModelSerializationFormat - format of the serialized RDF model
* @param String - URI of the graph from which the RDF model should be removed
*/
@Override
public void addRemoval(InputStream model, RDFService.ModelSerializationFormat format, String graphURI) {
modelChanges.add(manufactureModelChange(model, format, ModelChange.Operation.REMOVE, graphURI));
}
/**
* Creates an instance of the ModelChange class
*/
@Override
public ModelChange manufactureModelChange() {
return new ModelChangeImpl();
}
/**
* Creates an instance of the ModelChange class
*
* @param InputStream - a serialized RDF model (collection of triples)
* @param RDFService.ModelSerializationFormat - format of the serialized RDF model
* @param ModelChange.Operation - the type of operation to be performed with the serialized RDF model
* @param String - URI of the graph on which to apply the model change operation
*/
@Override
public ModelChange manufactureModelChange(InputStream serializedModel,
RDFService.ModelSerializationFormat serializationFormat,
@ -144,5 +90,4 @@ public class ChangeSetImpl implements ChangeSet {
public List<Object> getPostChangeEvents() {
return this.postChangeEvents;
}
}

View file

@ -7,12 +7,6 @@ import java.io.InputStream;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
/*
* A ModelChange is one component of a ChangeSet.
* Represents a model (collection of RDF triples), the URI
* of a graph, and an indication of whether to add or
* remove the model from the graph.
*/
public class ModelChangeImpl implements ModelChange {
private InputStream serializedModel;
@ -33,81 +27,41 @@ public class ModelChangeImpl implements ModelChange {
this.graphURI = graphURI;
}
/**
* Getter for the serialized model
*
* @return InputStream - a model (collection of RDF triples), serialized
*/
@Override
public InputStream getSerializedModel() {
return serializedModel;
}
/**
* Setter for the serialized model
*
* @param InputStream - a model (collection of RDF triples), serialized
*/
@Override
public void setSerializedModel(InputStream serializedModel) {
this.serializedModel = serializedModel;
}
/**
* Getter for the serialization format of the model
*
* @return RDFService.ModelSerializationFormat - the serialization format of the model
*/
@Override
public RDFService.ModelSerializationFormat getSerializationFormat() {
return serializationFormat;
}
/**
* Setter for the serialization format of the model
*
* @param RDFService.ModelSerializationFormat - the serialization format of the model
*/
@Override
public void setSerializationFormat(RDFService.ModelSerializationFormat serializationFormat) {
this.serializationFormat = serializationFormat;
}
/**
* Getter for the operation type
*
* @return ModelChange.Operation - the operation type
*/
@Override
public Operation getOperation() {
return operation;
}
/**
* Setter for the operation type
*
* @param ModelChange.Operation - the operation type
*/
@Override
public void setOperation(Operation operation) {
this.operation = operation;
}
/**
* Getter for the URI of the graph to which to apply the change
*
* @return String - the graph URI
*/
@Override
public String getGraphURI() {
return graphURI;
}
/**
* Setter for the URI of the graph to which to apply the change
*
* @param String - the graph URI
*/
@Override
public void setGraphURI(String graphURI) {
this.graphURI = graphURI;

View file

@ -24,25 +24,12 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
/*
* API to write, read, and update Vitro's RDF store, with support
* to allow listening, logging and auditing.
*/
public abstract class RDFServiceImpl implements RDFService {
private static final Log log = LogFactory.getLog(RDFServiceImpl.class);
protected String defaultWriteGraphURI;
protected List<ChangeListener> registeredListeners = new CopyOnWriteArrayList<ChangeListener>();
/**
* If the given individual already exists in the default graph, throws an
* RDFServiceException, otherwise adds one type assertion to the default
* graph.
*
* @param String individualURI - URI of the individual to be added
* @param String individualTypeURI - URI of the type for the individual
*/
@Override
public void newIndividual(String individualURI,
String individualTypeURI) throws RDFServiceException {
@ -50,15 +37,6 @@ public abstract class RDFServiceImpl implements RDFService {
newIndividual(individualURI, individualTypeURI, defaultWriteGraphURI);
}
/**
* If the given individual already exists in the given graph, throws an
* RDFServiceException, otherwise adds one type assertion to the given
* graph.
*
* @param String individualURI - URI of the individual to be added
* @param String individualTypeURI - URI of the type for the individual
* @param String graphURI - URI of the graph to which to add the individual
*/
@Override
public void newIndividual(String individualURI,
String individualTypeURI,
@ -89,21 +67,11 @@ public abstract class RDFServiceImpl implements RDFService {
}
}
/**
* Get the URI of the default write graph
*
* @return String URI of default write graph
*/
@Override
public String getDefaultWriteGraphURI() throws RDFServiceException {
return defaultWriteGraphURI;
}
/**
* Register a listener to listen to changes in any graph in
* the RDF store.
*
*/
@Override
public synchronized void registerListener(ChangeListener changeListener) throws RDFServiceException {
@ -112,21 +80,11 @@ public abstract class RDFServiceImpl implements RDFService {
}
}
/**
* Unregister a listener from listening to changes in any graph
* in the RDF store.
*
*/
@Override
public synchronized void unregisterListener(ChangeListener changeListener) throws RDFServiceException {
registeredListeners.remove(changeListener);
}
/**
* Create a ChangeSet object
*
* @return a ChangeSet object
*/
@Override
public ChangeSet manufactureChangeSet() {
return new ChangeSetImpl();

View file

@ -81,7 +81,7 @@ public class RDFServiceUtils {
case N3:
return "N3";
default:
throw new RuntimeException("unexpected format in getFormatString");
throw new RuntimeException("unexpected format in getSerializationFormatString");
}
}

View file

@ -161,7 +161,6 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
}
private void removeUsingSparqlUpdate(Dataset dataset, Model model, String graphURI) {
StmtIterator stmtIt = model.listStatements();
if (!stmtIt.hasNext()) {
@ -236,13 +235,6 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
return model;
}
@Override
public void newIndividual(String individualURI, String individualTypeURI,
String graphURI) throws RDFServiceException {
// TODO Auto-generated method stub
}
private InputStream getRDFResultStream(String query, boolean construct,
ModelSerializationFormat resultFormat) throws RDFServiceException {
DatasetWrapper dw = getDatasetWrapper();
@ -353,7 +345,6 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
@Override
public void getGraphMetadata() throws RDFServiceException {
// TODO Auto-generated method stub
}
@Override

View file

@ -33,6 +33,7 @@ public class RDFServiceModel extends RDFServiceJena implements RDFService {
this.model = model;
}
@Override
protected DatasetWrapper getDatasetWrapper() {
DatasetWrapper datasetWrapper = new DatasetWrapper(new DatasetImpl(model));
return datasetWrapper;