org.eclipse.rdf4j.repository.sparql.federation

## Class RepositoryFederatedService

- java.lang.Object
- - org.eclipse.rdf4j.repository.sparql.federation.RepositoryFederatedService

- All Implemented Interfaces:
    FederatedService
  Direct Known Subclasses:
    RepositoryFederatedService, SPARQLFederatedService

      public class RepositoryFederatedService
      extends Object
      implements FederatedService

  Federated Service wrapping the `Repository` to communicate with a SPARQL endpoint.
  Author:
    Andreas Schwarte

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `boundJoinBlockSize` The number of bindings sent in a single subquery in `evaluate(Service, CloseableIteration, String)` If blockSize is set to 0, the entire input stream is used as block input the block size effectively determines the number of remote requests
    `protected boolean` | `shutDown`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RepositoryFederatedService(Repository repo)`
    `RepositoryFederatedService(Repository repo, boolean shutDown)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `ask(Service service, BindingSet bindings, String baseUri)` Evaluate the provided sparqlQueryString at the initialized `Repository` of this `FederatedService`.
    `CloseableIteration<BindingSet,QueryEvaluationException>` | `evaluate(Service service, CloseableIteration<BindingSet,QueryEvaluationException> bindings, String baseUri)` Evaluate the provided SPARQL query at this federated service, possibilities for vectored evaluation.
    `protected CloseableIteration<BindingSet,QueryEvaluationException>` | `evaluateInternal(Service service, CloseableIteration<BindingSet,QueryEvaluationException> bindings, String baseUri)` Evaluate the SPARQL query that can be constructed from the SERVICE node at the initialized `Repository` of this `FederatedService`.
    `int` | `getBoundJoinBlockSize()`
    `protected RepositoryConnection` | `getConnection()` Retrieve a (re-usable) connection.
    `void` | `initialize()` Method to perform any initializations, invoked after construction.
    `protected String` | `insertValuesClause(String queryString, String valuesClause)` Insert the constructed VALUES clause in the beginning of the WHERE block.
    `boolean` | `isInitialized()` Method to check if `FederatedService.initialize()` had been called.
    `CloseableIteration<BindingSet,QueryEvaluationException>` | `select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri)` Evaluate the provided sparqlQueryString at the initialized `Repository` of this `FederatedService`.
    `void` | `setBoundJoinBlockSize(int boundJoinBlockSize)`
    `void` | `setUseFreshConnection(boolean flag)`
    `void` | `shutdown()` Method to perform any shutDown code, invoked at unregistering.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### boundJoinBlockSize

          protected int boundJoinBlockSize

      The number of bindings sent in a single subquery in `evaluate(Service, CloseableIteration, String)` If blockSize is set to 0, the entire input stream is used as block input the block size effectively determines the number of remote requests

    - #### shutDown

          protected boolean shutDown

  - ### Constructor Detail

    - #### RepositoryFederatedService

          public RepositoryFederatedService(Repository repo)

      Parameters:
        `repo` - the repository to be used

    - #### RepositoryFederatedService

          public RepositoryFederatedService(Repository repo,
                                            boolean shutDown)

      Parameters:
        `repo` - the repository to be used
        `shutDown` - a flag indicating whether the repository shall be closed in `shutdown()`

  - ### Method Detail

    - #### select

          public CloseableIteration<BindingSet,QueryEvaluationException> select(Service service,
                                                                                Set<String> projectionVars,
                                                                                BindingSet bindings,
                                                                                String baseUri)
                                                                         throws QueryEvaluationException

      Evaluate the provided sparqlQueryString at the initialized `Repository` of this `FederatedService`. Insert bindings into SELECT query and evaluate
      Specified by:
        `select` in interface `FederatedService`
      Parameters:
        `service` - the reference to the service node, contains additional meta information (vars, prefixes)
        `projectionVars` - The variables with unknown value that should be projected from this evaluation
        `bindings` - the bindings serving as additional constraints
      Returns:
        an iteration over the results of the query
      Throws:
        `QueryEvaluationException` - If there was an exception generated while evaluating the query.

    - #### ask

          public boolean ask(Service service,
                             BindingSet bindings,
                             String baseUri)
                      throws QueryEvaluationException

      Evaluate the provided sparqlQueryString at the initialized `Repository` of this `FederatedService`. Insert bindings, send ask query and return final result
      Specified by:
        `ask` in interface `FederatedService`
      Parameters:
        `service` - the reference to the service node, contains additional meta information (vars, prefixes)
        `bindings` - the bindings serving as additional constraints
      Returns:
        `true` if at least one result exists
      Throws:
        `QueryEvaluationException` - If there was an exception generated while evaluating the query.

    - #### evaluate

          public CloseableIteration<BindingSet,QueryEvaluationException> evaluate(Service service,
                                                                                  CloseableIteration<BindingSet,QueryEvaluationException> bindings,
                                                                                  String baseUri)
                                                                           throws QueryEvaluationException

      Description copied from interface: `FederatedService`
      Evaluate the provided SPARQL query at this federated service, possibilities for vectored evaluation.

      Contracts:

      - The original bindings need to be inserted into the result
      - SILENT service must be dealt with in the method

      Compare `SPARQLFederatedService` for a reference implementation

      Specified by:
        `evaluate` in interface `FederatedService`
      Parameters:
        `service` - the reference to the service node, contains information to construct the query
        `bindings` - the bindings serving as additional constraints (for vectored evaluation)
        `baseUri` - the baseUri
      Returns:
        the result of evaluating the query using bindings as constraints, the original bindings need to be inserted into the results!
      Throws:
        `QueryEvaluationException` - If there was an exception generated while evaluating the query.

    - #### evaluateInternal

          protected CloseableIteration<BindingSet,QueryEvaluationException> evaluateInternal(Service service,
                                                                                             CloseableIteration<BindingSet,QueryEvaluationException> bindings,
                                                                                             String baseUri)
                                                                                      throws QueryEvaluationException

      Evaluate the SPARQL query that can be constructed from the SERVICE node at the initialized `Repository` of this `FederatedService`. Use specified bindings as constraints to the query. Try to evaluate using VALUES clause, if this yields an exception fall back to the naive implementation. This method deals with SILENT SERVICEs.
      Throws:
        `QueryEvaluationException`

    - #### insertValuesClause

          protected String insertValuesClause(String queryString,
                                              String valuesClause)

      Insert the constructed VALUES clause in the beginning of the WHERE block. Also adds the `ROW_IDX_VAR` projection if it is not already present.
      Parameters:
        `queryString` - the SELECT query string from the SERVICE node
        `valuesClause` - the constructed VALUES clause
      Returns:
        the final String

    - #### initialize

          public void initialize()
                          throws QueryEvaluationException

      Description copied from interface: `FederatedService`
      Method to perform any initializations, invoked after construction.
      Specified by:
        `initialize` in interface `FederatedService`
      Throws:
        `QueryEvaluationException` - If there was an exception generated while initializing the service.

    - #### isInitialized

          public boolean isInitialized()

      Description copied from interface: `FederatedService`
      Method to check if `FederatedService.initialize()` had been called.
      Specified by:
        `isInitialized` in interface `FederatedService`

    - #### getBoundJoinBlockSize

          public int getBoundJoinBlockSize()

    - #### setBoundJoinBlockSize

          public void setBoundJoinBlockSize(int boundJoinBlockSize)

      Parameters:
        `boundJoinBlockSize` - the bound join block size, 0 to evaluate all in a single request

    - #### setUseFreshConnection

          public void setUseFreshConnection(boolean flag)

      Parameters:
        `flag` - whether to use a fresh `RepositoryConnection` for each individual query

    - #### shutdown

          public void shutdown()
                        throws QueryEvaluationException

      Description copied from interface: `FederatedService`
      Method to perform any shutDown code, invoked at unregistering.
      Specified by:
        `shutdown` in interface `FederatedService`
      Throws:
        `QueryEvaluationException` - If there was an exception generated while shutting down the service.

    - #### getConnection

          protected RepositoryConnection getConnection()
                                                throws RepositoryException

      Retrieve a (re-usable) connection. If it is not yet created, open a fresh connection. Note that this connection is closed automatically when shutting this service.
      Returns:
        connection
      Throws:
        `RepositoryException`

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.