Class RepositoryComposition
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, Johannes Englmeier
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classValue object representing an ordered list offragments. -
Method Summary
Modifier and TypeMethodDescriptionappend(RepositoryComposition.RepositoryFragments fragments) Create a newRepositoryCompositionretaining current configuration and appendRepositoryComposition.RepositoryFragmentsto the new composition.append(RepositoryFragment<?> fragment) Create a newRepositoryCompositionretaining current configuration and appendRepositoryFragmentto the new composition.static RepositoryCompositionempty()Create an emptyRepositoryComposition.boolean@Nullable RepositoryFragment<?> findFragment(Method method) Find theRepositoryFragmentfor the givenMethodinvoked on the composite interface.findMethod(Method method) Find the implementation method for the givenMethodinvoked on the composite interface.static RepositoryCompositionfromMetadata(RepositoryMetadata metadata) Create anRepositoryCompositionusing the providedRepositoryMetadatato setmethod lookupsdepending on the repository type (reactive/imperative).BiFunction<Method, Object[], Object[]> inthashCode()@Nullable ObjectInvoke a method on the repository by routing the invocation to the appropriateRepositoryFragment.booleanisEmpty()Return true if thisRepositoryCompositioncontains nofragments.static RepositoryCompositionCreate aRepositoryCompositionfor just a singleimplementationwithMethodLookups#direct()method lookup.static RepositoryCompositionof(List<RepositoryFragment<?>> fragments) static RepositoryCompositionof(RepositoryComposition.RepositoryFragments fragments) Create aRepositoryCompositionfromRepositoryComposition.RepositoryFragmentsandRepositoryMetadatawithMethodLookups#direct()method lookup.static RepositoryCompositionof(RepositoryFragment<?>... fragments) voidValidates that allfragmentshave an implementation.withArgumentConverter(BiFunction<Method, Object[], Object[]> argumentConverter) Create a newRepositoryCompositionretaining current configuration and setargumentConverter.withMetadata(RepositoryMetadata metadata) Create a newRepositoryCompositionretaining current configuration and setmetadata.withMethodLookup(MethodLookup methodLookup) Create a newRepositoryCompositionretaining current configuration and setmethodLookup.
-
Method Details
-
empty
Create an emptyRepositoryComposition.- Returns:
- an empty
RepositoryComposition.
-
fromMetadata
Create anRepositoryCompositionusing the providedRepositoryMetadatato setmethod lookupsdepending on the repository type (reactive/imperative).- Returns:
- an empty
RepositoryComposition. - Since:
- 2.4
-
just
Create aRepositoryCompositionfor just a singleimplementationwithMethodLookups#direct()method lookup.- Parameters:
implementation- must not be null.- Returns:
- the
RepositoryCompositionfor a singleimplementation.
-
of
- Parameters:
fragments- must not be null.- Returns:
- the
RepositoryCompositionfromfragments.
-
of
- Parameters:
fragments- must not be null.- Returns:
- the
RepositoryCompositionfromfragments.
-
of
Create aRepositoryCompositionfromRepositoryComposition.RepositoryFragmentsandRepositoryMetadatawithMethodLookups#direct()method lookup.- Parameters:
fragments- must not be null.- Returns:
- the
RepositoryCompositionfromfragments.
-
append
@Contract("_ -> new") @CheckReturnValue public RepositoryComposition append(RepositoryFragment<?> fragment) Create a newRepositoryCompositionretaining current configuration and appendRepositoryFragmentto the new composition. The resulting composition contains the appendedRepositoryFragmentas last element.- Parameters:
fragment- must not be null.- Returns:
- the new
RepositoryComposition.
-
append
@Contract("_ -> new") @CheckReturnValue public RepositoryComposition append(RepositoryComposition.RepositoryFragments fragments) Create a newRepositoryCompositionretaining current configuration and appendRepositoryComposition.RepositoryFragmentsto the new composition. The resulting composition contains the appendedRepositoryComposition.RepositoryFragmentsas last element.- Parameters:
fragments- must not be null.- Returns:
- the new
RepositoryComposition.
-
withArgumentConverter
@Contract("_ -> new") @CheckReturnValue public RepositoryComposition withArgumentConverter(BiFunction<Method, Object[], Object[]> argumentConverter) Create a newRepositoryCompositionretaining current configuration and setargumentConverter.- Parameters:
argumentConverter- must not be null.- Returns:
- the new
RepositoryComposition.
-
withMethodLookup
@Contract("_ -> new") @CheckReturnValue public RepositoryComposition withMethodLookup(MethodLookup methodLookup) Create a newRepositoryCompositionretaining current configuration and setmethodLookup.- Parameters:
methodLookup- must not be null.- Returns:
- the new
RepositoryComposition.
-
withMetadata
@Contract("_ -> new") @CheckReturnValue public RepositoryComposition withMetadata(RepositoryMetadata metadata) Create a newRepositoryCompositionretaining current configuration and setmetadata.- Parameters:
metadata- must not be null.- Returns:
- new instance of
RepositoryComposition. - Since:
- 2.4
-
isEmpty
public boolean isEmpty()Return true if thisRepositoryCompositioncontains nofragments.- Returns:
- true if this
RepositoryCompositioncontains nofragments.
-
invoke
-
findFragment
Find theRepositoryFragmentfor the givenMethodinvoked on the composite interface.- Parameters:
method- must not be null.- Returns:
- the fragment implementing that method or null if not found.
-
findMethod
-
validateImplementation
public void validateImplementation()Validates that allfragmentshave an implementation. -
getFragments
-
getMethodLookup
-
equals
-
hashCode
-
getArgumentConverter
-