DATACMNS-1371 - Improvements to custom implementation scanning.

CustomRepositoryImplementationDetector now works in two differend modes. If initialized with an ImplementationDetectionConfiguration, it will trigger a canonical, cached component scan for implementation types matching the configured name pattern. Individual custom implementation lookups will then select from this initially scanned set of bean definitions to pick the matching implementation class and potentially resolve ambiguities.
This commit is contained in:
Oliver Gierke
2018-08-09 18:00:56 +02:00
parent 3f613ff13f
commit 13b115068d
18 changed files with 746 additions and 363 deletions

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.util;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
@@ -35,9 +37,12 @@ import org.springframework.util.Assert;
* @since 2.0
*/
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode
public class Lazy<T> implements Supplier<T> {
private static final Lazy<?> EMPTY = new Lazy<>(() -> null, null, true);
private final Supplier<? extends T> supplier;
private @Nullable T value = null;
private boolean resolved = false;
@@ -67,6 +72,17 @@ public class Lazy<T> implements Supplier<T> {
return new Lazy<>(() -> value);
}
/**
* Creates a pre-resolved empty {@link Lazy}.
*
* @return
* @since 2.1
*/
@SuppressWarnings("unchecked")
public static <T> Lazy<T> empty() {
return (Lazy<T>) EMPTY;
}
/**
* Returns the value created by the configured {@link Supplier}. Will return the calculated instance for subsequent
* lookups.

View File

@@ -30,9 +30,10 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 2.0
*/
@FunctionalInterface
public interface Streamable<T> extends Iterable<T> {
public interface Streamable<T> extends Iterable<T>, Supplier<Stream<T>> {
/**
* Returns an empty {@link Streamable}.
@@ -130,4 +131,26 @@ public interface Streamable<T> extends Iterable<T> {
default boolean isEmpty() {
return !iterator().hasNext();
}
/**
* Creates a new {@link Streamable} from the current one and the given {@link Stream} concatenated.
*
* @param stream must not be {@literal null}.
* @return
* @since 2.1
*/
default Streamable<T> and(Supplier<? extends Stream<? extends T>> stream) {
Assert.notNull(stream, "Stream must not be null!");
return Streamable.of(() -> Stream.concat(this.stream(), stream.get()));
}
/*
* (non-Javadoc)
* @see java.util.function.Supplier#get()
*/
default Stream<T> get() {
return stream();
}
}