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
Cache types in ConstructorMapper #2650
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,14 +207,14 @@ private Optional<RowMapper<T>> createSpecializedRowMapper(StatementContext ctx, | |
List<String> unmatchedColumns) { | ||
final int count = factory.getParameterCount(); | ||
final Parameter[] parameters = factory.getParameters(); | ||
final Type[] types = factory.getTypes(); | ||
final List<Type> types = factory.getTypes(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to convert to list due to error about exposing an array. Thinking to change the api to store the array internally and change the signature to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds ok |
||
boolean matchedColumns = false; | ||
final List<String> unmatchedParameters = new ArrayList<>(); | ||
final List<ParameterData> paramData = new ArrayList<>(); | ||
|
||
for (int i = 0; i < count; i++) { | ||
final Parameter parameter = parameters[i]; | ||
final Type parameterType = types[i]; | ||
final Type parameterType = types.get(i); | ||
boolean nullable = isNullable(parameter); | ||
Nested nested = parameter.getAnnotation(Nested.class); | ||
if (nested == null) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,14 @@ | |
import java.lang.reflect.Parameter; | ||
import java.lang.reflect.Type; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
import jakarta.annotation.Nullable; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static java.util.stream.Collectors.toUnmodifiableList; | ||
|
||
abstract class InstanceFactory<T> { | ||
private final Executable executable; | ||
|
@@ -44,10 +46,10 @@ Parameter[] getParameters() { | |
return executable.getParameters(); | ||
} | ||
|
||
Type[] getTypes() { | ||
List<Type> getTypes() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here - should it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK by me |
||
return Arrays.stream(getParameters()) | ||
.map(Parameter::getParameterizedType) | ||
.toArray(Type[]::new); | ||
.collect(toUnmodifiableList()); | ||
} | ||
|
||
@Nullable | ||
|
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.
lmk if this shouldn't be cached.
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.
Let me know if you want the weak hashmap added back vs caching in the constructor instance factory (saved the previous version, so I can quickly update).
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.
So I think there is a bit of a misunderstanding here. I didn't mean to cache the lookup factory instance itself, but the
constructorHandle
instance itself.Something like
SynchronizedMap<WeakHashMap<ConstructorHandleAndTypes, MethodHandle>>>
(referring to the key type from the other PR)Sorry I wasn't clear, and sorry for taking so long to respond! Been a busy couple weeks at work.