org.springframework.data.repository.core.support

## Class RepositoryComposition

- java.lang.Object
- - org.springframework.data.repository.core.support.RepositoryComposition

    public class RepositoryComposition
    extends Object

Composite implementation to back repository method implementations.

A `RepositoryComposition` represents an ordered collection of `fragments`. Each fragment contributes executable method signatures that are used by this composition to route method calls into the according `RepositoryFragment`.

Fragments are allowed to contribute multiple implementations for a single method signature exposed through the repository interface. `MethodLookup` selects the first matching method for invocation. A composition also supports argument conversion between the repository method signature and fragment implementation method through `withArgumentConverter(BiFunction)`. Use argument conversion with a single implementation method that can be exposed accepting convertible types.

Composition objects are immutable and thread-safe.

Since:
  2.0
Author:
  Mark Paluch, Christoph Strobl
See Also:
  `RepositoryFragment`

### Nested Class Summary

Nested Classes
`static class` `RepositoryComposition.RepositoryFragments` Value object representing an ordered list of `fragments`.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`RepositoryComposition` `append(RepositoryComposition.RepositoryFragments fragments)` Create a new `RepositoryComposition` retaining current configuration and append `RepositoryComposition.RepositoryFragments` to the new composition.
`RepositoryComposition` `append(RepositoryFragment<?> fragment)` Create a new `RepositoryComposition` retaining current configuration and append `RepositoryFragment` to the new composition.
`static RepositoryComposition` `empty()` Create an empty `RepositoryComposition`.
`boolean` `equals(Object o)`
`Optional<Method>` `findMethod(Method method)` Find the implementation method for the given `Method` invoked on the composite interface.
`static RepositoryComposition` `fromMetadata(RepositoryMetadata metadata)` Create an `RepositoryComposition` using the provided `RepositoryMetadata` to set `method lookups` depending in the repository type (reactive/imperative).
`BiFunction<Method,Object[],Object[]>` `getArgumentConverter()`
`RepositoryComposition.RepositoryFragments` `getFragments()`
`MethodLookup` `getMethodLookup()`
`int` `hashCode()`
`Object` `invoke(Method method, Object... args)` Invoke a method on the repository by routing the invocation to the appropriate `RepositoryFragment`.
`boolean` `isEmpty()` Return true if this `RepositoryComposition` contains no `fragments`.
`static RepositoryComposition` `just(Object implementation)` Create a `RepositoryComposition` for just a single `implementation` with {@link MethodLookups#direct()) method lookup.
`static RepositoryComposition` `of(List<RepositoryFragment<?>> fragments)` Create a `RepositoryComposition` from `fragments` with {@link MethodLookups#direct()) method lookup.
`static RepositoryComposition` `of(RepositoryComposition.RepositoryFragments fragments)` Create a `RepositoryComposition` from `RepositoryComposition.RepositoryFragments` and `RepositoryMetadata` with {@link MethodLookups#direct()) method lookup.
`static RepositoryComposition` `of(RepositoryFragment<?>... fragments)` Create a `RepositoryComposition` from `fragments` with {@link MethodLookups#direct()) method lookup.
`void` `validateImplementation()` Validates that all `fragments` have an implementation.
`RepositoryComposition` `withArgumentConverter(BiFunction<Method,Object[],Object[]> argumentConverter)` Create a new `RepositoryComposition` retaining current configuration and set `argumentConverter`.
`RepositoryComposition` `withMetadata(RepositoryMetadata metadata)` Create a new `RepositoryComposition` retaining current configuration and set `metadata`.
`RepositoryComposition` `withMethodLookup(MethodLookup methodLookup)` Create a new `RepositoryComposition` retaining current configuration and set `methodLookup`.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### empty

    public static RepositoryComposition empty()

Create an empty `RepositoryComposition`.

Returns:
  an empty `RepositoryComposition`.

#### fromMetadata

    public static RepositoryComposition fromMetadata(RepositoryMetadata metadata)

Create an `RepositoryComposition` using the provided `RepositoryMetadata` to set `method lookups` depending in the repository type (reactive/imperative).

Returns:
  an empty `RepositoryComposition`.
Since:
  2.4

#### just

    public static RepositoryComposition just(Object implementation)

Create a `RepositoryComposition` for just a single `implementation` with {@link MethodLookups#direct()) method lookup.

Parameters:
  `implementation` - must not be null.
Returns:
  the `RepositoryComposition` for a single `implementation`.

#### of

    public static RepositoryComposition of(RepositoryFragment<?>... fragments)

Create a `RepositoryComposition` from `fragments` with {@link MethodLookups#direct()) method lookup.

Parameters:
  `fragments` - must not be null.
Returns:
  the `RepositoryComposition` from `fragments`.

#### of

    public static RepositoryComposition of(List<RepositoryFragment<?>> fragments)

Create a `RepositoryComposition` from `fragments` with {@link MethodLookups#direct()) method lookup.

Parameters:
  `fragments` - must not be null.
Returns:
  the `RepositoryComposition` from `fragments`.

#### of

    public static RepositoryComposition of(RepositoryComposition.RepositoryFragments fragments)

Create a `RepositoryComposition` from `RepositoryComposition.RepositoryFragments` and `RepositoryMetadata` with {@link MethodLookups#direct()) method lookup.

Parameters:
  `fragments` - must not be null.
Returns:
  the `RepositoryComposition` from `fragments`.

#### append

    public RepositoryComposition append(RepositoryFragment<?> fragment)

Create a new `RepositoryComposition` retaining current configuration and append `RepositoryFragment` to the new composition. The resulting composition contains the appended `RepositoryFragment` as last element.

Parameters:
  `fragment` - must not be null.
Returns:
  the new `RepositoryComposition`.

#### append

    public RepositoryComposition append(RepositoryComposition.RepositoryFragments fragments)

Create a new `RepositoryComposition` retaining current configuration and append `RepositoryComposition.RepositoryFragments` to the new composition. The resulting composition contains the appended `RepositoryComposition.RepositoryFragments` as last element.

Parameters:
  `fragments` - must not be null.
Returns:
  the new `RepositoryComposition`.

#### withArgumentConverter

    public RepositoryComposition withArgumentConverter(BiFunction<Method,Object[],Object[]> argumentConverter)

Create a new `RepositoryComposition` retaining current configuration and set `argumentConverter`.

Parameters:
  `argumentConverter` - must not be null.
Returns:
  the new `RepositoryComposition`.

#### withMethodLookup

    public RepositoryComposition withMethodLookup(MethodLookup methodLookup)

Create a new `RepositoryComposition` retaining current configuration and set `methodLookup`.

Parameters:
  `methodLookup` - must not be null.
Returns:
  the new `RepositoryComposition`.

#### withMetadata

    public RepositoryComposition withMetadata(RepositoryMetadata metadata)

Create a new `RepositoryComposition` retaining current configuration and set `metadata`.

Parameters:
  `metadata` - must not be null.
Returns:
  new instance of `RepositoryComposition`.
Since:
  2.4

#### isEmpty

    public boolean isEmpty()

Return true if this `RepositoryComposition` contains no `fragments`.

Returns:
  true if this `RepositoryComposition` contains no `fragments`.

#### invoke

    public Object invoke(Method method,
                         Object... args)
                  throws Throwable

Invoke a method on the repository by routing the invocation to the appropriate `RepositoryFragment`.

Parameters:
  `method` -
  `args` -
Returns:
Throws:
  `Throwable`

#### findMethod

    public Optional<Method> findMethod(Method method)

Find the implementation method for the given `Method` invoked on the composite interface.

Parameters:
  `method` - must not be null.
Returns:

#### validateImplementation

    public void validateImplementation()

Validates that all `fragments` have an implementation.

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### getFragments

    public RepositoryComposition.RepositoryFragments getFragments()

#### getMethodLookup

    public MethodLookup getMethodLookup()

#### getArgumentConverter

    public BiFunction<Method,Object[],Object[]> getArgumentConverter()