Class Repositories
java.lang.Object
org.eclipse.rdf4j.repository.util.Repositories
Utility for dealing with
Repository and RepositoryConnection objects.- Author:
- Peter Ansell
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidconsume(Repository repository, Consumer<RepositoryConnection> processFunction) Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenConsumer, before either rolling back the transaction if it failed, or committing the transaction if it was successful.static voidconsume(Repository repository, Consumer<RepositoryConnection> processFunction, Consumer<RepositoryException> exceptionHandler) Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenConsumer, before either rolling back the transaction if it failed, or committing the transaction if it was successful.static voidconsumeNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenConsumer.static voidconsumeNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction, Consumer<RepositoryException> exceptionHandler) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenConsumer.static voidconsumeSilent(Repository repository, Consumer<RepositoryConnection> processFunction) Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenConsumer, before either rolling back the transaction if it failed, or committing the transaction if it was successful.static voidconsumeSilentNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenConsumer.static <T> Tget(Repository repository, Function<RepositoryConnection, T> processFunction) Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenFunction, before either rolling back the transaction if it failed, or committing the transaction if it was successful.static <T> Tget(Repository repository, Function<RepositoryConnection, T> processFunction, Consumer<RepositoryException> exceptionHandler) Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenFunction, before either rolling back the transaction if it failed, or committing the transaction if it was successful.static <T> TgetNoTransaction(Repository repository, Function<RepositoryConnection, T> processFunction) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenFunction.static <T> TgetNoTransaction(Repository repository, Function<RepositoryConnection, T> processFunction, Consumer<RepositoryException> exceptionHandler) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenFunction.static <T> TgetSilent(Repository repository, Function<RepositoryConnection, T> processFunction) Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenFunction, before either rolling back the transaction if it failed, or committing the transaction if it was successful.static <T> TgetSilentNoTransaction(Repository repository, Function<RepositoryConnection, T> processFunction) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenFunction.static <T> TgraphQuery(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 givenFunctionwith the result from the function returned by the method.static voidgraphQuery(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 givenRDFHandler.static <T> TgraphQueryNoTransaction(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 givenFunctionwith the result from the function returned by the method.static voidgraphQueryNoTransaction(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 givenRDFHandler.static Supplier<RepositoryException>repositoryException(String message) Creates aSupplierofRepositoryExceptionobjects that be passed toOptional.orElseThrow(Supplier)to generate exceptions as necessary.static <T> TtupleQuery(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 givenFunctionwith the result from the function returned by the method.static voidtupleQuery(Repository repository, String query, TupleQueryResultHandler handler) Performs a SPARQL Select query on the given Repository within a transaction and passes the results to the givenTupleQueryResultHandler.static <T> TtupleQueryNoTransaction(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 givenFunctionwith the result from the function returned by the method.static voidtupleQueryNoTransaction(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 givenTupleQueryResultHandler.
-
Method Details
-
consume
public static void consume(Repository repository, Consumer<RepositoryConnection> processFunction) throws RepositoryException, UnknownTransactionStateException Opens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenConsumer, before either rolling back the transaction if it failed, or committing the transaction if it was successful.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AConsumerthat 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 aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenConsumer.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AConsumerthat 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 aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenConsumer, before either rolling back the transaction if it failed, or committing the transaction if it was successful.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AConsumerthat performs an action on the connection.exceptionHandler- AConsumerthat 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 aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenConsumer.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AConsumerthat performs an action on the connection.exceptionHandler- AConsumerthat 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 aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenConsumer, before either rolling back the transaction if it failed, or committing the transaction if it was successful.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AConsumerthat performs an action on the connection.
-
consumeSilentNoTransaction
public static void consumeSilentNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction) Opens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenConsumer.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AConsumerthat performs an action on the connection.
-
get
public static <T> T get(Repository repository, Function<RepositoryConnection, T> processFunction) throws RepositoryException, UnknownTransactionStateExceptionOpens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenFunction, 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- TheRepositoryto open a connection to.processFunction- AFunctionthat 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, UnknownTransactionStateExceptionOpens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenFunction.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AFunctionthat 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, UnknownTransactionStateExceptionOpens aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenFunction, 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- TheRepositoryto open a connection to.processFunction- AFunctionthat performs an action on the connection and returns a result.exceptionHandler- AConsumerthat 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, UnknownTransactionStateExceptionOpens aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenFunction.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AFunctionthat performs an action on the connection and returns a result.exceptionHandler- AConsumerthat 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 aRepositoryConnectionto the given Repository within a transaction, sends the connection to the givenFunction, 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- TheRepositoryto open a connection to.processFunction- AFunctionthat 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 aRepositoryConnectionto the given Repository without opening a transaction, sends the connection to the givenFunction.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.processFunction- AFunctionthat 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, QueryEvaluationExceptionPerforms a SPARQL Select query on the given Repository within a transaction and passes the results to the givenFunctionwith the result from the function returned by the method.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Select query to execute.processFunction- AFunctionthat 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 malformedQueryEvaluationException- 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, QueryEvaluationExceptionPerforms a SPARQL Select query on the given Repository without opening a transaction and passes the results to the givenFunctionwith the result from the function returned by the method.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Select query to execute.processFunction- AFunctionthat 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 malformedQueryEvaluationException- 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 givenTupleQueryResultHandler.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Select query to execute.handler- ATupleQueryResultHandlerthat 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 malformedQueryEvaluationException- 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 givenTupleQueryResultHandler.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Select query to execute.handler- ATupleQueryResultHandlerthat 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 malformedQueryEvaluationException- 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, QueryEvaluationExceptionPerforms a SPARQL Construct or Describe query on the given Repository within a transaction and passes the results to the givenFunctionwith the result from the function returned by the method.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Construct or Describe query to execute.processFunction- AFunctionthat 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 malformedQueryEvaluationException- 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, QueryEvaluationExceptionPerforms a SPARQL Construct or Describe query on the given Repository without opening a transaction and passes the results to the givenFunctionwith the result from the function returned by the method.- Type Parameters:
T- The type of the return value.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Construct or Describe query to execute.processFunction- AFunctionthat 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 malformedQueryEvaluationException- 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 givenRDFHandler.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Construct or Describe query to execute.handler- AnRDFHandlerthat 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 malformedQueryEvaluationException- 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 givenRDFHandler.- Parameters:
repository- TheRepositoryto open a connection to.query- The SPARQL Construct or Describe query to execute.handler- AnRDFHandlerthat 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 malformedQueryEvaluationException- If there was an error evaluating the query
-
repositoryException
Creates aSupplierofRepositoryExceptionobjects that be passed toOptional.orElseThrow(Supplier)to generate exceptions as necessary.- Parameters:
message- The message to be used for the exception- Returns:
- A
Supplierthat will createRepositoryExceptionobjects with the given message.
-