public class RepositoryComposition extends Object
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.RepositoryFragment| Modifier and Type | Class and Description |
|---|---|
static class |
RepositoryComposition.RepositoryFragments
Value object representing an ordered list of
fragments. |
| Modifier and Type | Method and Description |
|---|---|
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. |
public static RepositoryComposition empty()
RepositoryComposition.RepositoryComposition.public static RepositoryComposition fromMetadata(RepositoryMetadata metadata)
RepositoryComposition using the provided RepositoryMetadata to set method lookups depending in the repository type (reactive/imperative).RepositoryComposition.public static RepositoryComposition just(Object implementation)
RepositoryComposition for just a single implementation with {@link MethodLookups#direct())
method lookup.implementation - must not be null.RepositoryComposition for a single implementation.public static RepositoryComposition of(RepositoryFragment<?>... fragments)
RepositoryComposition from fragments with
{@link MethodLookups#direct()) method lookup.fragments - must not be null.RepositoryComposition from fragments.public static RepositoryComposition of(List<RepositoryFragment<?>> fragments)
RepositoryComposition from fragments with
{@link MethodLookups#direct()) method lookup.fragments - must not be null.RepositoryComposition from fragments.public static RepositoryComposition of(RepositoryComposition.RepositoryFragments fragments)
RepositoryComposition from RepositoryComposition.RepositoryFragments and RepositoryMetadata with
{@link MethodLookups#direct()) method lookup.fragments - must not be null.RepositoryComposition from fragments.public RepositoryComposition append(RepositoryFragment<?> fragment)
RepositoryComposition retaining current configuration and append RepositoryFragment to
the new composition. The resulting composition contains the appended RepositoryFragment as last element.fragment - must not be null.RepositoryComposition.public RepositoryComposition append(RepositoryComposition.RepositoryFragments fragments)
RepositoryComposition retaining current configuration and append RepositoryComposition.RepositoryFragments
to the new composition. The resulting composition contains the appended RepositoryComposition.RepositoryFragments as last
element.fragments - must not be null.RepositoryComposition.public RepositoryComposition withArgumentConverter(BiFunction<Method,Object[],Object[]> argumentConverter)
RepositoryComposition retaining current configuration and set argumentConverter.argumentConverter - must not be null.RepositoryComposition.public RepositoryComposition withMethodLookup(MethodLookup methodLookup)
RepositoryComposition retaining current configuration and set methodLookup.methodLookup - must not be null.RepositoryComposition.public RepositoryComposition withMetadata(RepositoryMetadata metadata)
RepositoryComposition retaining current configuration and set metadata.metadata - must not be null.RepositoryComposition.public boolean isEmpty()
RepositoryComposition contains no fragments.RepositoryComposition contains no fragments.public Object invoke(Method method, Object... args) throws Throwable
RepositoryFragment.method - args - Throwablepublic Optional<Method> findMethod(Method method)
Method invoked on the composite interface.method - must not be null.public void validateImplementation()
fragments have an implementation.public RepositoryComposition.RepositoryFragments getFragments()
public MethodLookup getMethodLookup()
public BiFunction<Method,Object[],Object[]> getArgumentConverter()
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.