Skip to content

Commit

Permalink
OnDemandExtensions.createProxy: Replace streams usage with simpler fl…
Browse files Browse the repository at this point in the history
…at code
  • Loading branch information
stevenschlansker committed Jul 14, 2023
1 parent b24028f commit 495e1f5
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;

import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.config.JdbiConfig;
Expand Down Expand Up @@ -73,14 +72,11 @@ private Object createProxy(Jdbi jdbi, Class<?> extensionType, Class<?>... extraT
return jdbi.withExtension(extensionType, extension -> invoke(extension, method, args));
};

Class<?>[] types = Stream.of(
Stream.of(extensionType),
Arrays.stream(extensionType.getInterfaces()),
Arrays.stream(extraTypes))
.flatMap(Function.identity())
.distinct()
.toArray(Class[]::new);
return Proxy.newProxyInstance(extensionType.getClassLoader(), types, handler);
var types = new LinkedHashSet<Class<?>>();
types.add(extensionType);
types.addAll(Arrays.asList(extensionType.getInterfaces()));
types.addAll(Arrays.asList(extraTypes));
return Proxy.newProxyInstance(extensionType.getClassLoader(), types.toArray(new Class<?>[0]), handler);
}

private static Object invoke(Object target, Method method, Object[] args) {
Expand Down

0 comments on commit 495e1f5

Please sign in to comment.