package org.jdbi.v3.core.argument;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.jdbi.v3.core.config.ConfigRegistry;
import org.jdbi.v3.core.enums.EnumByName;
import org.jdbi.v3.core.internal.JdbiOptionals;
import org.jdbi.v3.core.qualifier.QualifiedType;
import org.jdbi.v3.core.statement.SqlStatement;
@Deprecated
public class BuiltInArgumentFactory implements ArgumentFactory {
public static final ArgumentFactory INSTANCE = new BuiltInArgumentFactory();
private static final List<ArgumentFactory> FACTORIES = Arrays.asList(
new PrimitivesArgumentFactory(),
new BoxedArgumentFactory(),
new EssentialsArgumentFactory(),
new SqlArgumentFactory(),
new InternetArgumentFactory(),
new SqlTimeArgumentFactory(),
new JavaTimeArgumentFactory(),
new LegacyEnumByNameArgumentFactory(),
new OptionalArgumentFactory(),
new UntypedNullArgumentFactory()
);
@Override
public Optional<Argument> build(Type expectedType, Object value, ConfigRegistry config) {
return FACTORIES.stream()
.flatMap(factory -> JdbiOptionals.stream(factory.build(expectedType, value, config)))
.findFirst();
}
private static class LegacyEnumByNameArgumentFactory implements ArgumentFactory {
private final EnumArgumentFactory delegate = new EnumArgumentFactory();
@Override
public Optional<Argument> build(Type expectedType, Object rawValue, ConfigRegistry config) {
return delegate.build(QualifiedType.of(expectedType).with(EnumByName.class), rawValue, config);
}
}
}