Class RepositoryMethodContextHolder

java.lang.Object
org.springframework.data.repository.core.RepositoryMethodContextHolder

public class RepositoryMethodContextHolder extends Object
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 Details

    • RepositoryMethodContextHolder

      public RepositoryMethodContextHolder()
  • Method Details

    • setContext

      Make the given repository method metadata available via the getContext() method.

      Note that the caller should be careful to keep the old value as appropriate.

      Parameters:
      context - the metadata to expose (or null to reset it)
      Returns:
      the old metadata, which may be null if none was bound
      See Also:
    • getContext

      public static RepositoryMethodContext 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.