Class InterceptingRepositoryConnectionWrapper
java.lang.Object
org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection
org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper
org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper
- All Implemented Interfaces:
AutoCloseable, DelegatingRepositoryConnection, InterceptingRepositoryConnection, RepositoryConnection
public class InterceptingRepositoryConnectionWrapper
extends RepositoryConnectionWrapper
implements InterceptingRepositoryConnection
Wrapper that notifies interceptors of events on RepositoryConnections before they happen. Any interceptor can block
the operation by returning true from the relevant notification method. To do so will also cause the notification
process to stop, i.e. no other interceptors will be notified. The order in which interceptors are notified is
unspecified.
- Author:
- Herko ter Horst
- See Also:
-
Field Summary
Fields inherited from class AbstractRepositoryConnection
logger -
Constructor Summary
ConstructorsConstructorDescriptionInterceptingRepositoryConnectionWrapper(Repository repository, RepositoryConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a RepositoryConnectionInterceptor that will receive notifications of operations that are performed on this connection.voidaddWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) voidbegin()Begins a new transaction, requiringRepositoryConnection.commit()orRepositoryConnection.rollback()to be called to end the transaction.voidRemoves all statements from a specific contexts in the repository.voidRemoves all namespace declarations from the repository.voidclose()Closes the connection, freeing resources.voidcommit()Commits the active transaction.protected booleanIf false then the following add methods will callRepositoryConnectionWrapper.addWithoutCommit(Resource, IRI, Value, Resource[]).protected booleanIf false then the following remove methods will callRepositoryConnectionWrapper.removeWithoutCommit(Resource, IRI, Value, Resource[]).prepareUpdate(QueryLanguage ql, String update, String baseURI) Prepares an Update operation.voidremoveNamespace(String prefix) Removes a namespace declaration by removing the association between a prefix and a namespace name.voidRemoves a registered RepositoryConnectionInterceptor from this connection.voidremoveWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) voidrollback()Rolls back all updates in the active transaction.voidsetAutoCommit(boolean autoCommit) Deprecated.voidsetNamespace(String prefix, String name) Sets the prefix for a namespace.Methods inherited from class RepositoryConnectionWrapper
add, add, add, add, add, add, add, add, begin, begin, exportStatements, exportStatements, getContextIDs, getDelegate, getIsolationLevel, getNamespace, getNamespaces, getStatements, hasStatement, hasStatement, isActive, isAutoCommit, isDelegatingRead, isEmpty, isOpen, prepare, prepareBooleanQuery, prepareGraphQuery, prepareQuery, prepareTupleQuery, remove, remove, remove, remove, setDelegate, setIsolationLevel, setParserConfig, sizeModifier and TypeMethodDescriptionvoidAdds RDF data from the specified file to a specific contexts in the repository.voidadd(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts) Adds RDF data from an InputStream to the repository, optionally to one or more named contexts.voidAdds RDF data from a Reader to the repository, optionally to one or more named contexts.voidAdds the supplied statements to this repository, optionally to one or more named contexts.voidAdds the RDF data that can be found at the specified URL to the repository, optionally to one or more named contexts.voidadd(CloseableIteration<? extends Statement> statementIter, Resource... contexts) Adds the supplied statements to this repository, optionally to one or more named contexts.voidAdds a statement with the specified subject, predicate and object to this repository, optionally to one or more named contexts.voidAdds the supplied statement to this repository, optionally to one or more named contexts.voidbegin(IsolationLevel level) Begins a new transaction with the suppliedIsolationLevel, requiringRepositoryConnection.commit()orRepositoryConnection.rollback()to be called to end the transaction.voidbegin(TransactionSetting... settings) Begins a new transaction with the suppliedTransactionSetting, requiringRepositoryConnection.commit()orRepositoryConnection.rollback()to be called to end the transaction.voidexportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) Exports all statements with a specific subject, predicate and/or object from the repository, optionally from the specified contexts.protected voidexportStatements(RepositoryResult<Statement> stIter, RDFHandler handler) Exports all statements contained in the supplied statement iterator and all relevant namespace information to the supplied RDFHandler.Gets all resources that are used as context identifiers.Retrieves the currenttransaction isolation levelof the connection.getNamespace(String prefix) Gets the namespace that is associated with the specified prefix, if any.Gets all declared namespaces as a RepositoryResult ofNamespaceobjects.getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) Gets all statements with a specific subject, predicate and/or object from the repository.booleanhasStatement(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) Checks whether the repository contains statements with a specific subject, predicate and/or object, optionally in the specified contexts.booleanhasStatement(Statement st, boolean includeInferred, Resource... contexts) Checks whether the repository contains the specified statement, optionally in the specified contexts.booleanisActive()Indicates if a transaction is currently active on the connection.booleanDeprecated.protected booleanIf false then the following has/export/isEmpty methods will callRepositoryConnectionWrapper.getStatements(Resource, IRI, Value, boolean, Resource[]).booleanisEmpty()Returns true if this repository does not contain any (explicit) statements.booleanisOpen()Checks whether this connection is open.voidprepare()Checks for an error state in the active transaction that would force the transaction to be rolled back.prepareBooleanQuery(QueryLanguage ql, String query, String baseURI) Prepares queries that return true or false.prepareGraphQuery(QueryLanguage ql, String query, String baseURI) Prepares queries that produce RDF graphs.prepareQuery(QueryLanguage ql, String query, String baseURI) Prepares a query for evaluation on this repository (optional operation).prepareTupleQuery(QueryLanguage ql, String query, String baseURI) Prepares a query that produces sets of value tuples.voidRemoves the supplied statements from the specified contexts in this repository.voidremove(CloseableIteration<? extends Statement> statementIter, Resource... contexts) Removes the supplied statements from a specific context in this repository, ignoring any context information carried by the statements themselves.voidRemoves the statement(s) with the specified subject, predicate and object from the repository, optionally restricted to the specified contexts.voidRemoves the supplied statement from the specified contexts in the repository.voidsetDelegate(RepositoryConnection delegate) voidsetIsolationLevel(IsolationLevel level) Sets the transaction isolation level for the next transaction(s) on this connection.voidsetParserConfig(ParserConfig parserConfig) Set the parser configuration this connection should use for RDFParser-based operations.longReturns the number of (explicit) statements that are in the specified contexts in this repository.Methods inherited from class AbstractRepositoryConnection
addWithoutCommit, conditionalCommit, conditionalRollback, export, getParserConfig, getRepository, getValueFactory, prepareBooleanQuery, prepareGraphQuery, prepareQuery, prepareTupleQuery, prepareUpdate, removeWithoutCommit, startLocalTransactionModifier and TypeMethodDescriptionprotected voidaddWithoutCommit(Statement st, Resource... contexts) protected final voidconditionalCommit(boolean condition) InvokesRepositoryConnection.commit()if supplied boolean condition istrue.protected final voidconditionalRollback(boolean condition) InvokesRepositoryConnection.rollback()if supplied boolean condition istrue.voidexport(RDFHandler handler, Resource... contexts) Exports all explicit statements in the specified contexts to the supplied RDFHandler.Returns the parser configuration this connection uses for Rio-based operations.Returns the Repository object to which this connection belongs.Gets a ValueFactory for this RepositoryConnection.prepareBooleanQuery(QueryLanguage ql, String query) Prepares queries that return true or false.prepareGraphQuery(QueryLanguage ql, String query) Prepares queries that produce RDF graphs.prepareQuery(QueryLanguage ql, String query) Prepares a query for evaluation on this repository (optional operation).prepareTupleQuery(QueryLanguage ql, String query) Prepares a query that produces sets of value tuples.prepareUpdate(QueryLanguage ql, String update) Prepares an Update operation.protected voidremoveWithoutCommit(Statement st, Resource... contexts) protected final booleanStarts a new transaction if one is not already active.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RepositoryConnection
add, add, add, add, add, add, add, getStatements, prepareBooleanQuery, prepareGraphQuery, prepareQuery, prepareTupleQuery, prepareUpdate, removeModifier and TypeMethodDescriptiondefault voidAdds RDF data from the specified file to a specific contexts in the repository.default voidAdds RDF data from the specified file to a specific contexts in the repository.default voidadd(InputStream in, RDFFormat dataFormat, Resource... contexts) Adds RDF data from an InputStream to the repository, optionally to one or more named contexts.default voidAdds RDF data from a Reader to the repository, optionally to one or more named contexts.default voidAdds the RDF data that can be found at the specified URL to the repository, optionally to one or more named contexts.default voidAdds the RDF data that can be found at the specified URL to the repository, optionally to one or more named contexts.default voidadd(RepositoryResult<Statement> statements, Resource... contexts) Adds the supplied statements to this repository, optionally to one or more named contexts.default RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, Resource... contexts) Gets all statements with a specific subject, predicate and/or object from the repository.default BooleanQueryprepareBooleanQuery(String query) Prepares SPARQL queries that return true or false, that is, SPARQL ASK queries.default GraphQueryprepareGraphQuery(String query) Prepares SPARQL queries that produce RDF graphs, that is, SPARQL CONSTRUCT or DESCRIBE queries.default QueryprepareQuery(String query) Prepares a SPARQL query for evaluation on this repository (optional operation).default TupleQueryprepareTupleQuery(String query) Prepares a SPARQL query that produces sets of value tuples, that is a SPARQL SELECT query.default UpdateprepareUpdate(String update) Prepares a SPARQL Update operation.default voidremove(RepositoryResult<Statement> statements, Resource... contexts) Removes the supplied statements from a specific context in this repository, ignoring any context information carried by the statements themselves.
-
Constructor Details
-
InterceptingRepositoryConnectionWrapper
public InterceptingRepositoryConnectionWrapper(Repository repository, RepositoryConnection connection)
-
-
Method Details
-
addRepositoryConnectionInterceptor
Registers a RepositoryConnectionInterceptor that will receive notifications of operations that are performed on this connection.- Specified by:
addRepositoryConnectionInterceptorin interfaceInterceptingRepositoryConnection
-
removeRepositoryConnectionInterceptor
Removes a registered RepositoryConnectionInterceptor from this connection.- Specified by:
removeRepositoryConnectionInterceptorin interfaceInterceptingRepositoryConnection
-
isDelegatingAdd
protected boolean isDelegatingAdd()Description copied from class:RepositoryConnectionWrapperIf false then the following add methods will callRepositoryConnectionWrapper.addWithoutCommit(Resource, IRI, Value, Resource[]).- Overrides:
isDelegatingAddin classRepositoryConnectionWrapper- Returns:
trueto delegate add methods,falseto callRepositoryConnectionWrapper.addWithoutCommit(Resource, IRI, Value, Resource[])- See Also:
-
isDelegatingRemove
protected boolean isDelegatingRemove()Description copied from class:RepositoryConnectionWrapperIf false then the following remove methods will callRepositoryConnectionWrapper.removeWithoutCommit(Resource, IRI, Value, Resource[]).- Overrides:
isDelegatingRemovein classRepositoryConnectionWrapper- Returns:
trueto delegate remove methods,falseto callRepositoryConnectionWrapper.removeWithoutCommit(Resource, IRI, Value, Resource...)- See Also:
-
addWithoutCommit
public void addWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException - Overrides:
addWithoutCommitin classRepositoryConnectionWrapper- Throws:
RepositoryException
-
clear
Description copied from interface:RepositoryConnectionRemoves all statements from a specific contexts in the repository.- Specified by:
clearin interfaceRepositoryConnection- Overrides:
clearin classRepositoryConnectionWrapper- Parameters:
contexts- The context(s) to remove the data from. Note that this parameter is a vararg and as such is optional. If no contexts are supplied the method operates on the entire repository.- Throws:
RepositoryException- If the statements could not be removed from the repository, for example because the repository is not writable.
-
begin
Description copied from interface:RepositoryConnectionBegins a new transaction, requiringRepositoryConnection.commit()orRepositoryConnection.rollback()to be called to end the transaction. The transaction will use the currently setisolation levelfor this connection.- Specified by:
beginin interfaceRepositoryConnection- Overrides:
beginin classRepositoryConnectionWrapper- Throws:
RepositoryException- If the connection could not start the transaction. One possible reason this may happen is if a transaction is alreadyactiveon the current connection.- See Also:
-
close
Description copied from interface:RepositoryConnectionCloses the connection, freeing resources. If atransactionisactiveon the connection, all non-committed operations will be lost by actively callingRepositoryConnection.rollback()on any active transactions.Implementation note: All implementations must override this method if they have any resources that they need to free.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceRepositoryConnection- Overrides:
closein classRepositoryConnectionWrapper- Throws:
RepositoryException- If the connection could not be closed.
-
commit
Description copied from interface:RepositoryConnectionCommits the active transaction. This operation ends the active transaction.- Specified by:
commitin interfaceRepositoryConnection- Overrides:
commitin classRepositoryConnectionWrapper- Throws:
RepositoryException- If the connection could not be committed, or if the connection does not have an active transaction.- See Also:
-
removeWithoutCommit
public void removeWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException - Overrides:
removeWithoutCommitin classRepositoryConnectionWrapper- Throws:
RepositoryException
-
removeNamespace
Description copied from interface:RepositoryConnectionRemoves a namespace declaration by removing the association between a prefix and a namespace name.- Specified by:
removeNamespacein interfaceRepositoryConnection- Overrides:
removeNamespacein classRepositoryConnectionWrapper- Parameters:
prefix- The namespace prefix, or an empty string in case of the default namespace.- Throws:
RepositoryException- If the namespace prefix could not be removed.
-
clearNamespaces
Description copied from interface:RepositoryConnectionRemoves all namespace declarations from the repository.- Specified by:
clearNamespacesin interfaceRepositoryConnection- Overrides:
clearNamespacesin classRepositoryConnectionWrapper- Throws:
RepositoryException- If the namespace declarations could not be removed.
-
rollback
Description copied from interface:RepositoryConnectionRolls back all updates in the active transaction. This operation ends the active transaction.- Specified by:
rollbackin interfaceRepositoryConnection- Overrides:
rollbackin classRepositoryConnectionWrapper- Throws:
RepositoryException- If the transaction could not be rolled back, or if the connection does not have an active transaction.- See Also:
-
setAutoCommit
Deprecated.Description copied from interface:RepositoryConnectionEnables or disables auto-commit mode for the connection. If a connection is in auto-commit mode, then all updates will be executed and committed as individual transactions. Otherwise, the updates are grouped into transactions that are terminated by a call to eitherRepositoryConnection.commit()orRepositoryConnection.rollback(). By default, new connections are in auto-commit mode.NOTE: If this connection is switched to auto-commit mode during a transaction, the transaction is committed.
- Specified by:
setAutoCommitin interfaceRepositoryConnection- Overrides:
setAutoCommitin classRepositoryConnectionWrapper- Throws:
RepositoryException- In case the mode switch failed, for example because a currently active transaction failed to commit.- See Also:
-
setNamespace
Description copied from interface:RepositoryConnectionSets the prefix for a namespace.- Specified by:
setNamespacein interfaceRepositoryConnection- Overrides:
setNamespacein classRepositoryConnectionWrapper- Parameters:
prefix- The new prefix, or an empty string in case of the default namespace.name- The namespace name that the prefix maps to.- Throws:
RepositoryException- If the namespace could not be set in the repository, for example because the repository is not writable.
-
prepareUpdate
public Update prepareUpdate(QueryLanguage ql, String update, String baseURI) throws MalformedQueryException, RepositoryException Description copied from interface:RepositoryConnectionPrepares an Update operation.- Specified by:
prepareUpdatein interfaceRepositoryConnection- Overrides:
prepareUpdatein classRepositoryConnectionWrapper- Parameters:
ql- Thequery languagein which the update operation is formulated.update- The update operation string.baseURI- The base URI to resolve any relative URIs that are in the update against, can be null if the update does not contain any relative URIs.- Returns:
- a
Updateready to be executed on thisRepositoryConnection. - Throws:
MalformedQueryException- If the supplied update operation string is malformed.RepositoryException
-
RepositoryConnectionWrapper.isActive()instead.