Class Repositories
- java.lang.Object
-
- org.eclipse.rdf4j.repository.util.Repositories
-
public final class Repositories extends Object
Utility for dealing withRepository
andRepositoryConnection
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 aRepositoryConnection
to 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 void
consume(Repository repository, Consumer<RepositoryConnection> processFunction, Consumer<RepositoryException> exceptionHandler)
Opens aRepositoryConnection
to 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 void
consumeNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenConsumer
.static void
consumeNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction, Consumer<RepositoryException> exceptionHandler)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenConsumer
.static void
consumeSilent(Repository repository, Consumer<RepositoryConnection> processFunction)
Opens aRepositoryConnection
to 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 void
consumeSilentNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenConsumer
.static <T> T
get(Repository repository, Function<RepositoryConnection,T> processFunction)
Opens aRepositoryConnection
to 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> T
get(Repository repository, Function<RepositoryConnection,T> processFunction, Consumer<RepositoryException> exceptionHandler)
Opens aRepositoryConnection
to 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> T
getNoTransaction(Repository repository, Function<RepositoryConnection,T> processFunction)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenFunction
.static <T> T
getNoTransaction(Repository repository, Function<RepositoryConnection,T> processFunction, Consumer<RepositoryException> exceptionHandler)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenFunction
.static <T> T
getSilent(Repository repository, Function<RepositoryConnection,T> processFunction)
Opens aRepositoryConnection
to 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> T
getSilentNoTransaction(Repository repository, Function<RepositoryConnection,T> processFunction)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenFunction
.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 givenFunction
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 givenRDFHandler
.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 givenFunction
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 givenRDFHandler
.static Supplier<RepositoryException>
repositoryException(String message)
Creates aSupplier
ofRepositoryException
objects that be passed toOptional.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 givenFunction
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 givenTupleQueryResultHandler
.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 givenFunction
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 givenTupleQueryResultHandler
.
-
-
-
Method Detail
-
consume
public static void consume(Repository repository, Consumer<RepositoryConnection> processFunction) throws RepositoryException, UnknownTransactionStateException
Opens aRepositoryConnection
to 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
- TheRepository
to open a connection to.processFunction
- AConsumer
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 aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenConsumer
.- Parameters:
repository
- TheRepository
to open a connection to.processFunction
- AConsumer
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 aRepositoryConnection
to 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
- TheRepository
to open a connection to.processFunction
- AConsumer
that performs an action on the connection.exceptionHandler
- AConsumer
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 aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenConsumer
.- Parameters:
repository
- TheRepository
to open a connection to.processFunction
- AConsumer
that performs an action on the connection.exceptionHandler
- AConsumer
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 aRepositoryConnection
to 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
- TheRepository
to open a connection to.processFunction
- AConsumer
that performs an action on the connection.
-
consumeSilentNoTransaction
public static void consumeSilentNoTransaction(Repository repository, Consumer<RepositoryConnection> processFunction)
Opens aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenConsumer
.- Parameters:
repository
- TheRepository
to open a connection to.processFunction
- AConsumer
that performs an action on the connection.
-
get
public static <T> T get(Repository repository, Function<RepositoryConnection,T> processFunction) throws RepositoryException, UnknownTransactionStateException
Opens aRepositoryConnection
to 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
- TheRepository
to open a connection to.processFunction
- AFunction
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 aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenFunction
.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.processFunction
- AFunction
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 aRepositoryConnection
to 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
- TheRepository
to open a connection to.processFunction
- AFunction
that performs an action on the connection and returns a result.exceptionHandler
- AConsumer
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 aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenFunction
.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.processFunction
- AFunction
that performs an action on the connection and returns a result.exceptionHandler
- AConsumer
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 aRepositoryConnection
to 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
- TheRepository
to open a connection to.processFunction
- AFunction
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 aRepositoryConnection
to the given Repository without opening a transaction, sends the connection to the givenFunction
.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.processFunction
- AFunction
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 givenFunction
with the result from the function returned by the method.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.query
- The SPARQL Select query to execute.processFunction
- AFunction
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 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, QueryEvaluationException
Performs a SPARQL Select query on the given Repository without opening a transaction and passes the results to the givenFunction
with the result from the function returned by the method.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.query
- The SPARQL Select query to execute.processFunction
- AFunction
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 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
- TheRepository
to open a connection to.query
- The SPARQL Select query to execute.handler
- ATupleQueryResultHandler
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 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
- TheRepository
to open a connection to.query
- The SPARQL Select query to execute.handler
- ATupleQueryResultHandler
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 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, QueryEvaluationException
Performs a SPARQL Construct or Describe query on the given Repository within a transaction and passes the results to the givenFunction
with the result from the function returned by the method.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.query
- The SPARQL Construct or Describe query to execute.processFunction
- AFunction
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 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, QueryEvaluationException
Performs a SPARQL Construct or Describe query on the given Repository without opening a transaction and passes the results to the givenFunction
with the result from the function returned by the method.- Type Parameters:
T
- The type of the return value.- Parameters:
repository
- TheRepository
to open a connection to.query
- The SPARQL Construct or Describe query to execute.processFunction
- AFunction
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 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
- TheRepository
to open a connection to.query
- The SPARQL Construct or Describe query to execute.handler
- AnRDFHandler
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 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
- TheRepository
to open a connection to.query
- The SPARQL Construct or Describe query to execute.handler
- AnRDFHandler
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 malformedQueryEvaluationException
- If there was an error evaluating the query
-
repositoryException
public static Supplier<RepositoryException> repositoryException(String message)
Creates aSupplier
ofRepositoryException
objects that be passed toOptional.orElseThrow(Supplier)
to generate exceptions as necessary.- Parameters:
message
- The message to be used for the exception- Returns:
- A
Supplier
that will createRepositoryException
objects with the given message.
-
-