Class ARQFactory


  • public class ARQFactory
    extends Object
    A singleton that can create ARQ SPARQL Queries and QueryExecution objects. SHACL and SPIN API users should use the provided methods here.
    Author:
    Holger Knublauch
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean LOG_QUERIES
      Fine-grained control for development : switch on and off query printing
    • Constructor Summary

      Constructors 
      Constructor Description
      ARQFactory()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void adjustQueryExecution​(org.apache.jena.query.QueryExecution qexec)
      Can be overloaded to install extra things such as Lucene indices to all local QueryExecutions generated by this factory.
      static java.net.http.HttpClient buildHttpClient​(String user, String password)  
      void clearCaches()
      Programmatically resets any cached queries.
      org.apache.jena.query.Query createExpressionQuery​(String expression)  
      String createPrefixDeclarations​(org.apache.jena.rdf.model.Model model)
      Same as createPrefixDeclarations(model, true).
      String createPrefixDeclarations​(org.apache.jena.rdf.model.Model model, boolean includeExtraPrefixes)
      Creates SPARQL prefix declarations for a given Model.
      org.apache.jena.query.Query createQuery​(String queryString)  
      org.apache.jena.query.Query createQuery​(org.apache.jena.rdf.model.Model model, String partialQuery)
      Creates a new Query from a partial query (possibly lacking PREFIX declarations), using the ARQ syntax specified by getSyntax.
      org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query, org.apache.jena.query.Dataset dataset)  
      org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query, org.apache.jena.query.Dataset dataset, org.apache.jena.query.QuerySolution initialBinding)  
      org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query, org.apache.jena.rdf.model.Model model)
      Creates a QueryExecution for a given Query in a given Model, with no initial bindings.
      org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query, org.apache.jena.rdf.model.Model model, org.apache.jena.query.QuerySolution initialBinding)
      Creates a QueryExecution for a given Query in a given Model, with some given initial bindings.
      org.apache.jena.query.Query createQueryWithPrefixMapping​(String partialQuery, org.apache.jena.shared.PrefixMapping prefixMapping)
      Creates a new Query from a partial query (possibly lacking PREFIX declarations), using the ARQ syntax specified by getSyntax.
      org.apache.jena.sparql.exec.http.QueryExecutionHTTP createRemoteQueryExecution​(String service, org.apache.jena.query.Query query, List<String> defaultGraphURIs, List<String> namedGraphURIs, String user, String password)  
      org.apache.jena.sparql.exec.http.QueryExecutionHTTP createRemoteQueryExecution​(org.apache.jena.query.Query query)
      Creates a remote QueryExecution on a given Query.
      org.apache.jena.sparql.exec.http.QueryExecutionHTTP createRemoteQueryExecution​(org.apache.jena.query.Query query, List<String> graphURIs)  
      org.apache.jena.update.UpdateRequest createUpdateRequest​(String parsableString)  
      org.apache.jena.query.Query doCreateQuery​(String queryString)  
      protected org.apache.jena.query.Query doCreateQuery​(String queryString, org.apache.jena.shared.PrefixMapping prefixMapping)
      Creates the "physical" Jena Query instance.
      static ARQFactory get()
      Gets the singleton instance of this class.
      org.apache.jena.query.Dataset getDataset​(org.apache.jena.rdf.model.Model defaultModel)
      Specifies a Dataset that shall be used for query execution.
      static List<String> getNamedGraphURIs​(org.apache.jena.query.Query query)
      Gets a list of named graphs (GRAPH elements) mentioned in a given Query.
      static org.apache.jena.rdf.model.Model getNamedModel​(String graphURI)
      Convenience method to get a named graph from the current ARQFactory's Dataset.
      org.apache.jena.query.Syntax getSyntax()
      The ARQ Syntax used by default: Syntax.syntaxARQ.
      boolean isUsingCaches()  
      static void set​(ARQFactory value)
      Changes the singleton to some subclass.
      void setUseCaches​(boolean value)
      Tells the ARQFactory whether to use caches for the various createXY functions.
    • Field Detail

      • LOG_QUERIES

        public static boolean LOG_QUERIES
        Fine-grained control for development : switch on and off query printing
    • Constructor Detail

      • ARQFactory

        public ARQFactory()
    • Method Detail

      • get

        public static ARQFactory get()
        Gets the singleton instance of this class.
        Returns:
        the singleton
      • getNamedModel

        public static org.apache.jena.rdf.model.Model getNamedModel​(String graphURI)
        Convenience method to get a named graph from the current ARQFactory's Dataset.
        Parameters:
        graphURI - the URI of the graph to get
        Returns:
        the named graph or null
      • set

        public static void set​(ARQFactory value)
        Changes the singleton to some subclass.
        Parameters:
        value - the new ARQFactory (not null)
      • adjustQueryExecution

        protected void adjustQueryExecution​(org.apache.jena.query.QueryExecution qexec)
        Can be overloaded to install extra things such as Lucene indices to all local QueryExecutions generated by this factory. Does nothing by default.
        Parameters:
        qexec - the QueryExecution to modify
      • clearCaches

        public void clearCaches()
        Programmatically resets any cached queries.
      • createExpressionQuery

        public org.apache.jena.query.Query createExpressionQuery​(String expression)
      • createPrefixDeclarations

        public String createPrefixDeclarations​(org.apache.jena.rdf.model.Model model)
        Same as createPrefixDeclarations(model, true).
        Parameters:
        model - the Model to create prefix declarations for
        Returns:
        the prefix declarations
      • createPrefixDeclarations

        public String createPrefixDeclarations​(org.apache.jena.rdf.model.Model model,
                                               boolean includeExtraPrefixes)
        Creates SPARQL prefix declarations for a given Model.
        Parameters:
        model - the Model to get the prefixes from
        includeExtraPrefixes - true to also include implicit prefixes like afn
        Returns:
        the prefix declarations
      • createQuery

        public org.apache.jena.query.Query createQuery​(String queryString)
      • doCreateQuery

        public org.apache.jena.query.Query doCreateQuery​(String queryString)
      • doCreateQuery

        protected org.apache.jena.query.Query doCreateQuery​(String queryString,
                                                            org.apache.jena.shared.PrefixMapping prefixMapping)
        Creates the "physical" Jena Query instance. Can be overloaded to create engine-specific Query objects such as those for AllegroGraph.
        Parameters:
        queryString - the parsable query string
        prefixMapping - an optional PrefixMapping to initialize the Query with (this object may be modified)
        Returns:
        the ARQ Query object
      • createQuery

        public org.apache.jena.query.Query createQuery​(org.apache.jena.rdf.model.Model model,
                                                       String partialQuery)
        Creates a new Query from a partial query (possibly lacking PREFIX declarations), using the ARQ syntax specified by getSyntax. This will also use the ExtraPrefixes, e.g. for function definitions.
        Parameters:
        model - the Model to use the prefixes from
        partialQuery - the (partial) query string
        Returns:
        the Query
      • createQueryWithPrefixMapping

        public org.apache.jena.query.Query createQueryWithPrefixMapping​(String partialQuery,
                                                                        org.apache.jena.shared.PrefixMapping prefixMapping)
        Creates a new Query from a partial query (possibly lacking PREFIX declarations), using the ARQ syntax specified by getSyntax.
        Parameters:
        partialQuery - the (partial) query string
        prefixMapping - the PrefixMapping to use
        Returns:
        the Query
      • createQueryExecution

        public org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query,
                                                                         org.apache.jena.rdf.model.Model model)
        Creates a QueryExecution for a given Query in a given Model, with no initial bindings. The implementation basically uses Jena's QueryExecutionFactory but with the option to use different Dataset as specified by getDataset(model).
        Parameters:
        query - the Query
        model - the Model to query
        Returns:
        a QueryExecution
      • createQueryExecution

        public org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query,
                                                                         org.apache.jena.rdf.model.Model model,
                                                                         org.apache.jena.query.QuerySolution initialBinding)
        Creates a QueryExecution for a given Query in a given Model, with some given initial bindings. The implementation basically uses Jena's QueryExecutionFactory but with the option to use different Dataset as specified by getDataset(model).
        Parameters:
        query - the Query
        model - the Model to query
        initialBinding - the initial variable bindings or null
        Returns:
        a QueryExecution
      • createQueryExecution

        public org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query,
                                                                         org.apache.jena.query.Dataset dataset)
      • createQueryExecution

        public org.apache.jena.query.QueryExecution createQueryExecution​(org.apache.jena.query.Query query,
                                                                         org.apache.jena.query.Dataset dataset,
                                                                         org.apache.jena.query.QuerySolution initialBinding)
      • createRemoteQueryExecution

        public org.apache.jena.sparql.exec.http.QueryExecutionHTTP createRemoteQueryExecution​(org.apache.jena.query.Query query)
        Creates a remote QueryExecution on a given Query.
        Parameters:
        query - the Query to execute
        Returns:
        a remote QueryExecution
      • createRemoteQueryExecution

        public org.apache.jena.sparql.exec.http.QueryExecutionHTTP createRemoteQueryExecution​(org.apache.jena.query.Query query,
                                                                                              List<String> graphURIs)
      • createRemoteQueryExecution

        public org.apache.jena.sparql.exec.http.QueryExecutionHTTP createRemoteQueryExecution​(String service,
                                                                                              org.apache.jena.query.Query query,
                                                                                              List<String> defaultGraphURIs,
                                                                                              List<String> namedGraphURIs,
                                                                                              String user,
                                                                                              String password)
      • buildHttpClient

        public static java.net.http.HttpClient buildHttpClient​(String user,
                                                               String password)
      • createUpdateRequest

        public org.apache.jena.update.UpdateRequest createUpdateRequest​(String parsableString)
      • getDataset

        public org.apache.jena.query.Dataset getDataset​(org.apache.jena.rdf.model.Model defaultModel)
        Specifies a Dataset that shall be used for query execution. Returns a new DatasetImpl by default but may be overloaded in subclasses. For example, TopBraid delegates this to the currently open Graphs.
        Parameters:
        defaultModel - the default Model of the Dataset
        Returns:
        the Dataset
      • getNamedGraphURIs

        public static List<String> getNamedGraphURIs​(org.apache.jena.query.Query query)
        Gets a list of named graphs (GRAPH elements) mentioned in a given Query.
        Parameters:
        query - the Query to traverse
        Returns:
        a List of those GRAPHs
      • getSyntax

        public org.apache.jena.query.Syntax getSyntax()
        The ARQ Syntax used by default: Syntax.syntaxARQ.
        Returns:
        the default syntax
      • isUsingCaches

        public boolean isUsingCaches()
      • setUseCaches

        public void setUseCaches​(boolean value)
        Tells the ARQFactory whether to use caches for the various createXY functions. These are on by default. Warning: there may be memory leaks if the first executed query of its kind keeps a reference to a E_Function which keeps a reference to a Function, and FunctionBase to a FunctionEnv with an active graph.
        Parameters:
        value - false to switch caches off