Module spring.data.commons
Class RepositoryMethodContextHolder
java.lang.Object
org.springframework.data.repository.core.RepositoryMethodContextHolder
Associates a given
RepositoryMethodContext with the current execution thread.
This class provides a series of static methods that interact with a thread-local storage of
RepositoryMethodContext. The purpose of the class is to provide a convenient way to be used for an
application.
- Since:
- 3.4
- Author:
- Christoph Strobl, Mark Paluch
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RepositoryMethodContextTry to return the current repository method metadata.static RepositoryMethodContextsetContext(RepositoryMethodContext context) Make the given repository method metadata available via thegetContext()method.
-
Constructor Details
-
RepositoryMethodContextHolder
public RepositoryMethodContextHolder()
-
-
Method Details
-
setContext
@Nullable public static RepositoryMethodContext setContext(@Nullable RepositoryMethodContext context) Make the given repository method metadata available via thegetContext()method.Note that the caller should be careful to keep the old value as appropriate.
- Parameters:
context- the metadata to expose (ornullto reset it)- Returns:
- the old metadata, which may be
nullif none was bound - See Also:
-
getContext
Try to return the current repository method metadata. This method is usable only if the calling method has been invoked via a repository method, and the repository factory has been set to expose metadata. Otherwise, this method will throw an IllegalStateException.- Returns:
- the current repository method metadata (never returns
null) - Throws:
IllegalStateException- if the repository method metadata cannot be found, because the method was invoked outside a repository method invocation context, or because the repository has not been configured to expose its metadata.
-