Skip to content

Commit

Permalink
Cache MethodInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
radovanradic committed Nov 27, 2024
1 parent df4bd6d commit 3f983a6
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import java.util.Set;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -167,6 +168,7 @@ public final class DefaultJdbcRepositoryOperations extends AbstractSqlRepository
private final ColumnIndexCallableResultReader columnIndexCallableResultReader;
private final Map<Dialect, List<SqlExceptionMapper>> sqlExceptionMappers = new EnumMap<>(Dialect.class);
private final List<ConnectionCustomizer> connectionCustomizers;
private final Map<MethodInvocationContext<?, ?>, MethodInfo> contextMethodInfoMap = new ConcurrentHashMap<>(30);

/**
* Default constructor.
Expand Down Expand Up @@ -436,16 +438,17 @@ private <T, R> List<R> findAll(SqlStoredQuery<T, R> sqlStoredQuery, ResultSet rs

private @Nullable MethodInfo getMethodInfo(SqlPreparedQuery<?, ?> sqlPreparedQuery) {
if (sqlPreparedQuery.getInvocationContext() instanceof MethodInvocationContext<?, ?> methodInvocationContext) {
return new MethodInfo(methodInvocationContext.getTarget().getClass(), methodInvocationContext.getMethodName(),
sqlPreparedQuery.getAnnotationMetadata());
return contextMethodInfoMap.computeIfAbsent(methodInvocationContext, context ->
new MethodInfo(context.getTarget().getClass(), context.getMethodName(), sqlPreparedQuery.getAnnotationMetadata()));
}
return null;
}

private @Nullable MethodInfo getMethodInfo(EntityOperation<?> operation) {
if (operation.getInvocationContext() instanceof MethodInvocationContext<?, ?> methodInvocationContext) {
return new MethodInfo(methodInvocationContext.getTarget().getClass(), methodInvocationContext.getMethodName(),
operation.getAnnotationMetadata());
return contextMethodInfoMap.computeIfAbsent(methodInvocationContext, context ->
new MethodInfo(context.getTarget().getClass(), context.getMethodName(),
operation.getAnnotationMetadata()));
}
return null;
}
Expand Down

0 comments on commit 3f983a6

Please sign in to comment.