Package org.eclipse.rdf4j.repository.util

## Class Repositories

- java.lang.Object
- - org.eclipse.rdf4j.repository.util.Repositories

-     public final class Repositories
      extends Object

  Utility for dealing with `Repository` and `RepositoryConnection` objects.
  Author:
    Peter Ansell

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `consume​(Repository repository, Consumer<RepositoryConnection> processFunction)` | Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Consumer`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
    `static void` | `consume​(Repository repository, Consumer<RepositoryConnection> processFunction, Consumer<RepositoryException> exceptionHandler)` | Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Consumer`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
    `static void` | `consumeNoTransaction​(Repository repository, Consumer<RepositoryConnection> processFunction)` | Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Consumer`.
    `static void` | `consumeNoTransaction​(Repository repository, Consumer<RepositoryConnection> processFunction, Consumer<RepositoryException> exceptionHandler)` | Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Consumer`.
    `static void` | `consumeSilent​(Repository repository, Consumer<RepositoryConnection> processFunction)` | Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Consumer`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
    `static void` | `consumeSilentNoTransaction​(Repository repository, Consumer<RepositoryConnection> processFunction)` | Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Consumer`.
    `static <T> T` | `get​(Repository repository, Function<RepositoryConnection,​T> processFunction)` | Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Function`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
    `static <T> T` | `get​(Repository repository, Function<RepositoryConnection,​T> processFunction, Consumer<RepositoryException> exceptionHandler)` | Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Function`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
    `static <T> T` | `getNoTransaction​(Repository repository, Function<RepositoryConnection,​T> processFunction)` | Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Function`.
    `static <T> T` | `getNoTransaction​(Repository repository, Function<RepositoryConnection,​T> processFunction, Consumer<RepositoryException> exceptionHandler)` | Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Function`.
    `static <T> T` | `getSilent​(Repository repository, Function<RepositoryConnection,​T> processFunction)` | Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Function`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
    `static <T> T` | `getSilentNoTransaction​(Repository repository, Function<RepositoryConnection,​T> processFunction)` | Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Function`.
    `static <T> T` | `graphQuery​(Repository repository, String query, Function<GraphQueryResult,​T> processFunction)` | Performs a SPARQL Construct or Describe query on the given Repository within a transaction and passes the results to the given `Function` with the result from the function returned by the method.
    `static void` | `graphQuery​(Repository repository, String query, RDFHandler handler)` | Performs a SPARQL Construct or Describe query on the given Repository within a transaction and passes the results to the given `RDFHandler`.
    `static <T> T` | `graphQueryNoTransaction​(Repository repository, String query, Function<GraphQueryResult,​T> processFunction)` | Performs a SPARQL Construct or Describe query on the given Repository without opening a transaction and passes the results to the given `Function` with the result from the function returned by the method.
    `static void` | `graphQueryNoTransaction​(Repository repository, String query, RDFHandler handler)` | Performs a SPARQL Construct or Describe query on the given Repository without opening a transaction and passes the results to the given `RDFHandler`.
    `static Supplier<RepositoryException>` | `repositoryException​(String message)` | Creates a `Supplier` of `RepositoryException` objects that be passed to `Optional.orElseThrow(Supplier)` to generate exceptions as necessary.
    `static <T> T` | `tupleQuery​(Repository repository, String query, Function<TupleQueryResult,​T> processFunction)` | Performs a SPARQL Select query on the given Repository within a transaction and passes the results to the given `Function` with the result from the function returned by the method.
    `static void` | `tupleQuery​(Repository repository, String query, TupleQueryResultHandler handler)` | Performs a SPARQL Select query on the given Repository within a transaction and passes the results to the given `TupleQueryResultHandler`.
    `static <T> T` | `tupleQueryNoTransaction​(Repository repository, String query, Function<TupleQueryResult,​T> processFunction)` | Performs a SPARQL Select query on the given Repository without opening a transaction and passes the results to the given `Function` with the result from the function returned by the method.
    `static void` | `tupleQueryNoTransaction​(Repository repository, String query, TupleQueryResultHandler handler)` | Performs a SPARQL Select query on the given Repository without opening a transaction and passes the results to the given `TupleQueryResultHandler`.

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

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

- - ### Method Detail

    - #### consume

          public static void consume​(Repository repository,
                                     Consumer<RepositoryConnection> processFunction)
                              throws RepositoryException,
                                     UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Consumer`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Consumer` that performs an action on the connection.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### consumeNoTransaction

          public static void consumeNoTransaction​(Repository repository,
                                                  Consumer<RepositoryConnection> processFunction)
                                           throws RepositoryException,
                                                  UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Consumer`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Consumer` that performs an action on the connection.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### consume

          public static void consume​(Repository repository,
                                     Consumer<RepositoryConnection> processFunction,
                                     Consumer<RepositoryException> exceptionHandler)
                              throws RepositoryException,
                                     UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Consumer`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Consumer` that performs an action on the connection.
        `exceptionHandler` - A `Consumer` that handles an exception if one was generated.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### consumeNoTransaction

          public static void consumeNoTransaction​(Repository repository,
                                                  Consumer<RepositoryConnection> processFunction,
                                                  Consumer<RepositoryException> exceptionHandler)
                                           throws RepositoryException,
                                                  UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Consumer`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Consumer` that performs an action on the connection.
        `exceptionHandler` - A `Consumer` that handles an exception if one was generated.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### consumeSilent

          public static void consumeSilent​(Repository repository,
                                           Consumer<RepositoryConnection> processFunction)

      Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Consumer`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Consumer` that performs an action on the connection.

    - #### consumeSilentNoTransaction

          public static void consumeSilentNoTransaction​(Repository repository,
                                                        Consumer<RepositoryConnection> processFunction)

      Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Consumer`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Consumer` that performs an action on the connection.

    - #### get

          public static <T> T get​(Repository repository,
                                  Function<RepositoryConnection,​T> processFunction)
                           throws RepositoryException,
                                  UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Function`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Function` that performs an action on the connection and returns a result.
      Returns:
        The result of applying the function.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### getNoTransaction

          public static <T> T getNoTransaction​(Repository repository,
                                               Function<RepositoryConnection,​T> processFunction)
                                        throws RepositoryException,
                                               UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Function`.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Function` that performs an action on the connection and returns a result.
      Returns:
        The result of applying the function.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### get

          public static <T> T get​(Repository repository,
                                  Function<RepositoryConnection,​T> processFunction,
                                  Consumer<RepositoryException> exceptionHandler)
                           throws RepositoryException,
                                  UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Function`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Function` that performs an action on the connection and returns a result.
        `exceptionHandler` - A `Consumer` that handles an exception if one was generated.
      Returns:
        The result of applying the function, or null if an exception occurs and the exception handler does not rethrow the exception.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### getNoTransaction

          public static <T> T getNoTransaction​(Repository repository,
                                               Function<RepositoryConnection,​T> processFunction,
                                               Consumer<RepositoryException> exceptionHandler)
                                        throws RepositoryException,
                                               UnknownTransactionStateException

      Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Function`.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Function` that performs an action on the connection and returns a result.
        `exceptionHandler` - A `Consumer` that handles an exception if one was generated.
      Returns:
        The result of applying the function, or null if an exception occurs and the exception handler does not rethrow the exception.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)

    - #### getSilent

          public static <T> T getSilent​(Repository repository,
                                        Function<RepositoryConnection,​T> processFunction)

      Opens a `RepositoryConnection` to the given Repository within a transaction, sends the connection to the given `Function`, before either rolling back the transaction if it failed, or committing the transaction if it was successful.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Function` that performs an action on the connection and returns a result.
      Returns:
        The result of applying the function, or null if an exception is thrown.

    - #### getSilentNoTransaction

          public static <T> T getSilentNoTransaction​(Repository repository,
                                                     Function<RepositoryConnection,​T> processFunction)

      Opens a `RepositoryConnection` to the given Repository without opening a transaction, sends the connection to the given `Function`.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `processFunction` - A `Function` that performs an action on the connection and returns a result.
      Returns:
        The result of applying the function, or null if an exception is thrown.

    - #### tupleQuery

          public static <T> T tupleQuery​(Repository repository,
                                         String query,
                                         Function<TupleQueryResult,​T> processFunction)
                                  throws RepositoryException,
                                         UnknownTransactionStateException,
                                         MalformedQueryException,
                                         QueryEvaluationException

      Performs a SPARQL Select query on the given Repository within a transaction and passes the results to the given `Function` with the result from the function returned by the method.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Select query to execute.
        `processFunction` - A `Function` that performs an action on the results of the query and returns a result.
      Returns:
        The result of processing the query results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### tupleQueryNoTransaction

          public static <T> T tupleQueryNoTransaction​(Repository repository,
                                                      String query,
                                                      Function<TupleQueryResult,​T> processFunction)
                                               throws RepositoryException,
                                                      UnknownTransactionStateException,
                                                      MalformedQueryException,
                                                      QueryEvaluationException

      Performs a SPARQL Select query on the given Repository without opening a transaction and passes the results to the given `Function` with the result from the function returned by the method.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Select query to execute.
        `processFunction` - A `Function` that performs an action on the results of the query and returns a result.
      Returns:
        The result of processing the query results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### tupleQuery

          public static void tupleQuery​(Repository repository,
                                        String query,
                                        TupleQueryResultHandler handler)
                                 throws RepositoryException,
                                        UnknownTransactionStateException,
                                        MalformedQueryException,
                                        QueryEvaluationException

      Performs a SPARQL Select query on the given Repository within a transaction and passes the results to the given `TupleQueryResultHandler`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Select query to execute.
        `handler` - A `TupleQueryResultHandler` that consumes the results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### tupleQueryNoTransaction

          public static void tupleQueryNoTransaction​(Repository repository,
                                                     String query,
                                                     TupleQueryResultHandler handler)
                                              throws RepositoryException,
                                                     UnknownTransactionStateException,
                                                     MalformedQueryException,
                                                     QueryEvaluationException

      Performs a SPARQL Select query on the given Repository without opening a transaction and passes the results to the given `TupleQueryResultHandler`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Select query to execute.
        `handler` - A `TupleQueryResultHandler` that consumes the results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### graphQuery

          public static <T> T graphQuery​(Repository repository,
                                         String query,
                                         Function<GraphQueryResult,​T> processFunction)
                                  throws RepositoryException,
                                         UnknownTransactionStateException,
                                         MalformedQueryException,
                                         QueryEvaluationException

      Performs a SPARQL Construct or Describe query on the given Repository within a transaction and passes the results to the given `Function` with the result from the function returned by the method.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Construct or Describe query to execute.
        `processFunction` - A `Function` that performs an action on the results of the query and returns a result.
      Returns:
        The result of processing the query results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### graphQueryNoTransaction

          public static <T> T graphQueryNoTransaction​(Repository repository,
                                                      String query,
                                                      Function<GraphQueryResult,​T> processFunction)
                                               throws RepositoryException,
                                                      UnknownTransactionStateException,
                                                      MalformedQueryException,
                                                      QueryEvaluationException

      Performs a SPARQL Construct or Describe query on the given Repository without opening a transaction and passes the results to the given `Function` with the result from the function returned by the method.
      Type Parameters:
        `T` - The type of the return value.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Construct or Describe query to execute.
        `processFunction` - A `Function` that performs an action on the results of the query and returns a result.
      Returns:
        The result of processing the query results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### graphQuery

          public static void graphQuery​(Repository repository,
                                        String query,
                                        RDFHandler handler)
                                 throws RepositoryException,
                                        UnknownTransactionStateException,
                                        MalformedQueryException,
                                        QueryEvaluationException

      Performs a SPARQL Construct or Describe query on the given Repository within a transaction and passes the results to the given `RDFHandler`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Construct or Describe query to execute.
        `handler` - An `RDFHandler` that consumes the results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### graphQueryNoTransaction

          public static void graphQueryNoTransaction​(Repository repository,
                                                     String query,
                                                     RDFHandler handler)
                                              throws RepositoryException,
                                                     UnknownTransactionStateException,
                                                     MalformedQueryException,
                                                     QueryEvaluationException

      Performs a SPARQL Construct or Describe query on the given Repository without opening a transaction and passes the results to the given `RDFHandler`.
      Parameters:
        `repository` - The `Repository` to open a connection to.
        `query` - The SPARQL Construct or Describe query to execute.
        `handler` - An `RDFHandler` that consumes the results.
      Throws:
        `RepositoryException` - If there was an exception dealing with the Repository.
        `UnknownTransactionStateException` - If the transaction state was not properly recognised. (Optional specific exception)
        `MalformedQueryException` - If the supplied query is malformed
        `QueryEvaluationException` - If there was an error evaluating the query

    - #### repositoryException

          public static Supplier<RepositoryException> repositoryException​(String message)

      Creates a `Supplier` of `RepositoryException` objects that be passed to `Optional.orElseThrow(Supplier)` to generate exceptions as necessary.
      Parameters:
        `message` - The message to be used for the exception
      Returns:
        A `Supplier` that will create `RepositoryException` objects with the given message.