-
Notifications
You must be signed in to change notification settings - Fork 685
Introduce ManagedTypes. #2635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Introduce ManagedTypes. #2635
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
745ee88
Prepare issue branch.
christophstrobl a31091d
Introduce ManagedTypes & TypeScanner.
christophstrobl 96f9b22
Rename static factory methods
christophstrobl 8202c2f
Remove TypeScanner and don't register managed types via repository
christophstrobl 352bbd9
remove identifying annotations
christophstrobl be84bca
Reset annotatedTypeScanner
christophstrobl 1d8f117
revert changes and react to review comments
christophstrobl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
src/main/java/org/springframework/data/domain/ManagedTypes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
import org.springframework.data.util.Lazy; | ||
|
||
/** | ||
* Types managed by a Spring Data implementation. Used to predefine a set of know entities that might need processing | ||
* during the Spring container, Spring Data Repository initialization phase. | ||
* | ||
* @author Christoph Strobl | ||
* @author John Blum | ||
* @see java.lang.FunctionalInterface | ||
* @since 3.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface ManagedTypes { | ||
|
||
/** | ||
* Factory method used to construct a new instance of {@link ManagedTypes} containing no {@link Class types}. | ||
* | ||
* @return an empty {@link ManagedTypes} instance. | ||
* @see java.util.Collections#emptySet() | ||
* @see #fromIterable(Iterable) | ||
*/ | ||
static ManagedTypes empty() { | ||
return fromIterable(Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Factory method used to construct {@link ManagedTypes} from the given, required {@link Iterable} of {@link Class | ||
* types}. | ||
* | ||
* @param types {@link Iterable} of {@link Class types} used to initialize the {@link ManagedTypes}; must not be | ||
* {@literal null}. | ||
* @return new instance of {@link ManagedTypes} initialized the given, required {@link Iterable} of {@link Class | ||
* types}. | ||
* @see java.lang.Iterable | ||
* @see #fromStream(Stream) | ||
* @see #fromSupplier(Supplier) | ||
*/ | ||
static ManagedTypes fromIterable(Iterable<? extends Class<?>> types) { | ||
return types::forEach; | ||
} | ||
|
||
/** | ||
* Factory method used to construct {@link ManagedTypes} from the given, required {@link Stream} of {@link Class | ||
* types}. | ||
* | ||
* @param types {@link Stream} of {@link Class types} used to initialize the {@link ManagedTypes}; must not be | ||
* {@literal null}. | ||
* @return new instance of {@link ManagedTypes} initialized the given, required {@link Stream} of {@link Class types}. | ||
* @see java.util.stream.Stream | ||
* @see #fromIterable(Iterable) | ||
* @see #fromSupplier(Supplier) | ||
*/ | ||
static ManagedTypes fromStream(Stream<? extends Class<?>> types) { | ||
return types::forEach; | ||
} | ||
|
||
/** | ||
* Factory method used to construct {@link ManagedTypes} from the given, required {@link Supplier} of an | ||
* {@link Iterable} of {@link Class types}. | ||
* | ||
* @param dataProvider {@link Supplier} of an {@link Iterable} of {@link Class types} used to lazily initialize the | ||
* {@link ManagedTypes}; must not be {@literal null}. | ||
* @return new instance of {@link ManagedTypes} initialized the given, required {@link Supplier} of an | ||
* {@link Iterable} of {@link Class types}. | ||
* @see java.util.function.Supplier | ||
* @see java.lang.Iterable | ||
* @see #fromIterable(Iterable) | ||
* @see #fromStream(Stream) | ||
*/ | ||
static ManagedTypes fromSupplier(Supplier<Iterable<Class<?>>> dataProvider) { | ||
|
||
return new ManagedTypes() { | ||
|
||
final Lazy<Iterable<Class<?>>> lazyProvider = Lazy.of(dataProvider); | ||
|
||
@Override | ||
public void forEach(Consumer<Class<?>> action) { | ||
lazyProvider.get().forEach(action); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Applies the given {@link Consumer action} to each of the {@link Class types} contained in this {@link ManagedTypes} | ||
* instance. | ||
* | ||
* @param action {@link Consumer} defining the action to perform on the {@link Class types} contained in this | ||
* {@link ManagedTypes} instance; must not be {@literal null}. | ||
* @see java.util.function.Consumer | ||
*/ | ||
void forEach(Consumer<Class<?>> action); | ||
|
||
/** | ||
* Returns all the {@link ManagedTypes} in a {@link List}. | ||
* | ||
* @return these {@link ManagedTypes} in a {@link List}; never {@literal null}. | ||
* @see java.util.List | ||
*/ | ||
default List<Class<?>> toList() { | ||
|
||
List<Class<?>> list = new ArrayList<>(100); | ||
forEach(list::add); | ||
return list; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about implementing
Streamable<Class<?>>
here?