Class SPARQLUpdate


  • public class SPARQLUpdate
    extends Object
    Low level support for POSTing SPARQL update requests to a server. Supports logging of the entire request to a file and serialization of models. Typical sequence:
       SPARQLUpdate up = new SPARQLUpdate(server);
       up.open();
       up.sendPrefixes(model);
       up.send(command);
       up.send(model, true);
       up.send(command);
       up.close();
       int status = up.getStatus();
       boolean ok = up.wasSuccessful();
     
    Version:
    $Revision: $
    Author:
    Dave Reynolds
    • Constructor Summary

      Constructors 
      Constructor Description
      SPARQLUpdate​(String server)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Finish the update command, capturing the result status and any return message
      String getResponseBody()
      Get the body of the HTTP response, in the event of an error response the server may return useful human readable information in the body.
      String getResponseMessage()
      Get the message part of the HTTP response, generally not interesting
      int getStatus()
      Get the returned status code from the request
      boolean isStarted()
      Return true if at least one command string has been sent, whether complete or not
      void open()
      Open the POST channel to the server
      void performUpdate​(String preamble, org.apache.jena.rdf.model.Model model, String postamble)
      Convenience packaging of common pattern of use.
      void send​(InputStream in)
      Write a set of formatted SPARQL Update instructions to the stream
      void send​(String command)
      Send a string (hopefully part of a SPARQL update command!) to the server
      void send​(org.apache.jena.rdf.model.Model model)
      Write a model as part of the update request, typically the body of and INSERT DATA {} or DELETE DATA {} request but it is up to the caller to send the surrounding command syntax.
      void send​(org.apache.jena.rdf.model.Model model, boolean turtle)
      Write a model as part of the update request, typically the body of and INSERT DATA {} or DELETE DATA {} request but it is up to the caller to send the surrounding command syntax.
      void sendPrefixes​(org.apache.jena.shared.PrefixMapping pm)
      Write the prefixes from the given model (or other prefix mapping) in SPARQL update syntax.
      void sendUpdate​(String preamble, org.apache.jena.rdf.model.Model model, String postamble)
      Convenience packaging of common pattern of use.
      void setLogFileBase​(String filebase)
      Request that the entire formatted update request be recorded in a timestamped file with the name "-.log".
      boolean wasSuccessful()
      Return true if the update succeeded (response code 2xx or 3xx)
    • Constructor Detail

      • SPARQLUpdate

        public SPARQLUpdate​(String server)
        Constructor. Throws an unchecked exception (EpiException) if the server URL is malformed.
        Parameters:
        server - URL of the of the server which should be send the request
    • Method Detail

      • setLogFileBase

        public void setLogFileBase​(String filebase)
        Request that the entire formatted update request be recorded in a timestamped file with the name "-.log". Throws an unchecked exception (EpiException) if the file can't be created or is not writable
        Parameters:
        file - name of the file to log to
      • open

        public void open()
        Open the POST channel to the server
      • send

        public void send​(String command)
        Send a string (hopefully part of a SPARQL update command!) to the server
      • isStarted

        public boolean isStarted()
        Return true if at least one command string has been sent, whether complete or not
      • sendPrefixes

        public void sendPrefixes​(org.apache.jena.shared.PrefixMapping pm)
        Write the prefixes from the given model (or other prefix mapping) in SPARQL update syntax. This is separated from send(model) because in SPARQL update the prefix block comes before the command.
      • send

        public void send​(org.apache.jena.rdf.model.Model model,
                         boolean turtle)
        Write a model as part of the update request, typically the body of and INSERT DATA {} or DELETE DATA {} request but it is up to the caller to send the surrounding command syntax.
        Parameters:
        model - the model to send
        turtle - if true then the model will be send in compact turtle syntax using any prefixes declared in the model (the caller must have issued sendPrefixes at the start of the update for this to be legal), if false then N-Triple syntax will be used which is more verbose but faster to write and does not require prefixes
      • send

        public void send​(org.apache.jena.rdf.model.Model model)
        Write a model as part of the update request, typically the body of and INSERT DATA {} or DELETE DATA {} request but it is up to the caller to send the surrounding command syntax. Uses N-triple syntax so that the model data is self-contained with no requirement to have declared prefixes.
      • performUpdate

        public void performUpdate​(String preamble,
                                  org.apache.jena.rdf.model.Model model,
                                  String postamble)
        Convenience packaging of common pattern of use. Opens the connection if not already open, sends Model prefixes, then preamble command, then the model (using compact Turtle) then postamble command then closes.
      • sendUpdate

        public void sendUpdate​(String preamble,
                               org.apache.jena.rdf.model.Model model,
                               String postamble)
        Convenience packaging of common pattern of use. Opens the connection if not already open, sends Model prefixes, then preamble command, then the model (using compact Turtle) then postamble command. Leaves udpate open
      • close

        public void close()
        Finish the update command, capturing the result status and any return message
      • getStatus

        public int getStatus()
        Get the returned status code from the request
      • getResponseMessage

        public String getResponseMessage()
        Get the message part of the HTTP response, generally not interesting
      • getResponseBody

        public String getResponseBody()
        Get the body of the HTTP response, in the event of an error response the server may return useful human readable information in the body. May be null if the there was no response body (e.g. 204 return)
      • wasSuccessful

        public boolean wasSuccessful()
        Return true if the update succeeded (response code 2xx or 3xx)
        Returns: