use of org.jdbi.v3.core.generic.GenericTypes.getErasedType in project jdbi by jdbi.
the class SqlArrayArgumentFactory method build.
@Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> erasedType = GenericTypes.getErasedType(type);
if (!(erasedType.isArray() || Collection.class.isAssignableFrom(erasedType))) {
return Optional.empty();
}
if (value == null) {
return Optional.of(new NullArgument(Types.ARRAY));
}
Function<Type, Optional<SqlArrayType<?>>> lookup = eT -> config.get(SqlArrayTypes.class).findFor(eT);
if (erasedType.isArray()) {
Class<?> elementType = erasedType.getComponentType();
return lookup.apply(elementType).map(arrayType -> new SqlArrayArgument<>(arrayType, value));
}
return GenericTypes.findGenericParameter(type, Collection.class).flatMap(lookup).map(arrayType -> new SqlArrayArgument<>(arrayType, value));
}
use of org.jdbi.v3.core.generic.GenericTypes.getErasedType in project jdbi by jdbi.
the class SqlArrayMapperFactory method build.
@Override
@SuppressWarnings("unchecked")
public Optional<ColumnMapper<?>> build(Type type, ConfigRegistry config) {
final Class<?> erasedType = GenericTypes.getErasedType(type);
if (erasedType.isArray()) {
Class<?> elementType = erasedType.getComponentType();
return elementTypeMapper(elementType, config).map(elementMapper -> new ArrayColumnMapper(elementMapper, elementType));
}
JdbiCollectors collectorRegistry = config.get(JdbiCollectors.class);
return collectorRegistry.findFor(type).flatMap(collector -> collectorRegistry.findElementTypeFor(type).flatMap(elementType -> elementTypeMapper(elementType, config)).map(elementMapper -> new CollectorColumnMapper(elementMapper, collector)));
}
Aggregations