use of org.jdbi.v3.core.argument.internal.TypedValue in project jdbi by jdbi.
the class ObjectMethodArguments method load.
private static Map<String, Function<Object, TypedValue>> load(ConfigRegistry config, Class<?> type) {
final HashMap<String, Function<Object, TypedValue>> methodMap = new HashMap<>();
if (Modifier.isPublic(type.getModifiers())) {
Arrays.stream(type.getMethods()).filter(m -> m.getParameterCount() == 0).collect(Collectors.toMap(Method::getName, Function.identity(), ObjectMethodArguments::bridgeMethodMerge)).forEach((name, method) -> {
QualifiedType<?> qualifiedType = QualifiedType.of(method.getGenericReturnType()).withAnnotations(config.get(Qualifiers.class).findFor(method));
MethodHandle mh = Unchecked.function(MethodHandles.lookup()::unreflect).apply(method);
methodMap.put(name, Unchecked.function(value -> new TypedValue(qualifiedType, mh.invoke(value))));
});
} else {
Optional.ofNullable(type.getSuperclass()).ifPresent(superclass -> methodMap.putAll(load(config, superclass)));
Arrays.stream(type.getInterfaces()).forEach(interfaceClass -> methodMap.putAll(load(config, interfaceClass)));
}
return methodMap;
}
use of org.jdbi.v3.core.argument.internal.TypedValue in project jdbi by jdbi.
the class ObjectFieldArguments method getValue.
@Override
Optional<TypedValue> getValue(String name, StatementContext ctx) {
Field field = fields.get(name);
if (field == null) {
return Optional.empty();
}
try {
Type type = field.getGenericType();
Object value = field.get(object);
return Optional.of(new TypedValue(type, value));
} catch (IllegalAccessException e) {
throw new UnableToCreateStatementException(String.format("Access exception getting field for " + "bean property [%s] on [%s]", name, object), e, ctx);
}
}
Aggregations