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
Modifier and TypeClassDescriptionstatic class
Value object representing an ordered list offragments
. -
Method Summary
Modifier and TypeMethodDescriptionappend
(RepositoryComposition.RepositoryFragments fragments) Create a newRepositoryComposition
retaining current configuration and appendRepositoryComposition.RepositoryFragments
to the new composition.append
(RepositoryFragment<?> fragment) Create a newRepositoryComposition
retaining current configuration and appendRepositoryFragment
to the new composition.static RepositoryComposition
empty()
Create an emptyRepositoryComposition
.boolean
findMethod
(Method method) Find the implementation method for the givenMethod
invoked on the composite interface.static RepositoryComposition
fromMetadata
(RepositoryMetadata metadata) Create anRepositoryComposition
using the providedRepositoryMetadata
to setmethod lookups
depending in the repository type (reactive/imperative).BiFunction<Method,
Object[], Object[]> int
hashCode()
Invoke a method on the repository by routing the invocation to the appropriateRepositoryFragment
.boolean
isEmpty()
Return true if thisRepositoryComposition
contains nofragments
.static RepositoryComposition
Create aRepositoryComposition
for just a singleimplementation
withMethodLookups#direct()
method lookup.static RepositoryComposition
of
(List<RepositoryFragment<?>> fragments) static RepositoryComposition
of
(RepositoryComposition.RepositoryFragments fragments) Create aRepositoryComposition
fromRepositoryComposition.RepositoryFragments
andRepositoryMetadata
withMethodLookups#direct()
method lookup.static RepositoryComposition
of
(RepositoryFragment<?>... fragments) void
Validates that allfragments
have an implementation.withArgumentConverter
(BiFunction<Method, Object[], Object[]> argumentConverter) Create a newRepositoryComposition
retaining current configuration and setargumentConverter
.withMetadata
(RepositoryMetadata metadata) Create a newRepositoryComposition
retaining current configuration and setmetadata
.withMethodLookup
(MethodLookup methodLookup) Create a newRepositoryComposition
retaining current configuration and setmethodLookup
.
-
Method Details
-
empty
Create an emptyRepositoryComposition
.- Returns:
- an empty
RepositoryComposition
.
-
fromMetadata
Create anRepositoryComposition
using the providedRepositoryMetadata
to setmethod lookups
depending in the repository type (reactive/imperative).- Returns:
- an empty
RepositoryComposition
. - Since:
- 2.4
-
just
Create aRepositoryComposition
for just a singleimplementation
withMethodLookups#direct()
method lookup.- Parameters:
implementation
- must not be null.- Returns:
- the
RepositoryComposition
for a singleimplementation
.
-
of
- Parameters:
fragments
- must not be null.- Returns:
- the
RepositoryComposition
fromfragments
.
-
of
- Parameters:
fragments
- must not be null.- Returns:
- the
RepositoryComposition
fromfragments
.
-
of
Create aRepositoryComposition
fromRepositoryComposition.RepositoryFragments
andRepositoryMetadata
withMethodLookups#direct()
method lookup.- Parameters:
fragments
- must not be null.- Returns:
- the
RepositoryComposition
fromfragments
.
-
append
Create a newRepositoryComposition
retaining current configuration and appendRepositoryFragment
to the new composition. The resulting composition contains the appendedRepositoryFragment
as last element.- Parameters:
fragment
- must not be null.- Returns:
- the new
RepositoryComposition
.
-
append
Create a newRepositoryComposition
retaining current configuration and appendRepositoryComposition.RepositoryFragments
to the new composition. The resulting composition contains the appendedRepositoryComposition.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 newRepositoryComposition
retaining current configuration and setargumentConverter
.- Parameters:
argumentConverter
- must not be null.- Returns:
- the new
RepositoryComposition
.
-
withMethodLookup
Create a newRepositoryComposition
retaining current configuration and setmethodLookup
.- Parameters:
methodLookup
- must not be null.- Returns:
- the new
RepositoryComposition
.
-
withMetadata
Create a newRepositoryComposition
retaining 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 thisRepositoryComposition
contains nofragments
.- Returns:
- true if this
RepositoryComposition
contains nofragments
.
-
invoke
Invoke a method on the repository by routing the invocation to the appropriateRepositoryFragment
.- Parameters:
method
-args
-- Returns:
- Throws:
Throwable
-
findMethod
Find the implementation method for the givenMethod
invoked on the composite interface.- Parameters:
method
- must not be null.- Returns:
-
validateImplementation
public void validateImplementation()Validates that allfragments
have an implementation. -
equals
-
hashCode
public int hashCode() -
getFragments
-
getMethodLookup
-
getArgumentConverter
-