org.openanzo.commands
Interface IPrecondition

All Known Implementing Classes:
Precondition

public interface IPrecondition

To avoid race conditions during a transaction's commital on the Anzo server, the server allows a transaction author to specify zero or more preconditions that must be satisfied (in an atomic fashion) before the actual triple additions and deletions occur. A precondition is defined as a Sparql query and an expected result from said query. A dataset must be defined to which the query is run against.


  Example:
  
  ...
  final INamedGraph graph = datasetService.getRemoteGraph("http://testGraph", true);
 final Statement stmt = Constants.valueFactory.createStatement(Constants.valueFactory.createURI("http://openanzo.org/subject"),Constants.valueFactory.createURI("http://openanzo.org/predicate1"), Constants.valueFactory.createURI("http://openanzo.org/object1"));
 
  Command testCommand{
                public Object execute() {
                        graph.add(stmt);
                        return null;
                }
        };
  IPrecondition precondition = new Precondition();
 Set<URI> defaults = new HashSet<URI>();
 defaults.add(Constants.valueFactory.createURI("http://testGraph"));
 precondition.setQuery("ASK  { <http://testGraph> " + QueryEncoder.encodeForQuery(NamedGraph.revisionProperty)+" "+ QueryEncoder.encodeForQuery(Constants.valueFactory.createTypedLiteral(new Long(5)))+"}");
 precondition.setResult(AskResult.createAskResult(true));
 command.addPrecondition(precondition);
 graph.executeInTransaction(command);
 

Author:
Matthew Roy ( mroy@cambridgesemantics.com )

Method Summary
 java.util.Set<org.openrdf.model.URI> getDefaultGraphUris()
          Get the set of NamedGraph URIs that make up the default graph for the dataset for this precondition.
 java.util.Set<org.openrdf.model.URI> getNamedGraphUris()
          Get the set of NamedGraph URIs that make up the dataset for this precondition.
 java.lang.String getQuery()
          Get the Sparql query string that defines the precondition
 IResult getResult()
          Get the expected result from the sparql query.
 void setDefaultGraphUris(java.util.Set<org.openrdf.model.URI> namedGraphUris)
          Set the set of NamedGraph URIs that make up the default graph for the dataset for this precondition.
 void setNamedGraphUris(java.util.Set<org.openrdf.model.URI> namedGraphUris)
          Set the set of NamedGraph URIs that make up the dataset for this precondition.
 void setQuery(java.lang.String query)
          Set the Sparql query string that defines the precondition.
 void setResult(IResult result)
          Set the expected result from the sparql query.
 

Method Detail

getNamedGraphUris

java.util.Set<org.openrdf.model.URI> getNamedGraphUris()
Get the set of NamedGraph URIs that make up the dataset for this precondition.

Returns:
Set of NamedGraph URIs

setNamedGraphUris

void setNamedGraphUris(java.util.Set<org.openrdf.model.URI> namedGraphUris)
Set the set of NamedGraph URIs that make up the dataset for this precondition.

Parameters:
namedGraphUris - Set of NamedGraph URIs that make up the dataset.

getDefaultGraphUris

java.util.Set<org.openrdf.model.URI> getDefaultGraphUris()
Get the set of NamedGraph URIs that make up the default graph for the dataset for this precondition.

Returns:
Set of NamedGraph URIs

setDefaultGraphUris

void setDefaultGraphUris(java.util.Set<org.openrdf.model.URI> namedGraphUris)
Set the set of NamedGraph URIs that make up the default graph for the dataset for this precondition.

Parameters:
namedGraphUris - Set of NamedGraph URIs that make up the dataset.

getQuery

java.lang.String getQuery()
Get the Sparql query string that defines the precondition

Returns:
Sparql query string

setQuery

void setQuery(java.lang.String query)
Set the Sparql query string that defines the precondition.

Parameters:
query -

getResult

IResult getResult()
Get the expected result from the sparql query.

Returns:
The expected result.

setResult

void setResult(IResult result)
Set the expected result from the sparql query.

Parameters:
result - the expected results from the query


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.