Interface RepositoryMethodContext


public interface RepositoryMethodContext
Interface containing methods and value objects to obtain information about the current repository method invocation.

The currentMethod() method is usable if the repository factory is configured to expose the current repository method metadata (not the default). It returns the invoked repository method. Target objects or advice can use this to make advised calls.

Spring Data's framework does not expose method metadata by default, as there is a performance cost in doing so.

The functionality in this class might be used by a target object that needed access to resources on the invocation. However, this approach should not be used when there is a reasonable alternative, as it makes application code dependent on usage in particular.

Since:
3.4.0
Author:
Christoph Strobl, Mark Paluch
  • Method Details

    • currentMethod

      static RepositoryMethodContext currentMethod() throws IllegalStateException
      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.
    • setCurrentMetadata

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

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

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

      RepositoryMetadata getRepository()
      Returns the metadata for the repository.
      Returns:
      the repository metadata.
    • getMethod

      Method getMethod()
      Returns the current method that is being invoked.

      The method object represents the method as being invoked on the repository interface. It doesn't match the backing repository implementation in case the method invocation is delegated to an implementation method.

      Returns:
      the current method.