private UnsupportedOperationException factoryNotFound(QualifiedType<?> qualifiedType, Object value) { Type type = qualifiedType.getType(); if (type instanceof Class<?>) { // not a ParameterizedType final TypeVariable<?>[] params = ((Class<?>) type).getTypeParameters(); if (params.length > 0) { return new UnsupportedOperationException("No type parameters found for erased type '" + type + Arrays.toString(params) + "' with qualifiers '" + qualifiedType.getQualifiers() + "'. To bind a generic type, prefer using bindByType."); } } return new UnsupportedOperationException("No argument factory registered for '" + value + "' of qualified type " + qualifiedType); }
/** * Adapts a {@link ColumnMapperFactory} into a QualifiedColumnMapperFactory. The returned * factory only matches qualified types with zero qualifiers. * * @param factory the factory to adapt */ static QualifiedColumnMapperFactory adapt(ColumnMapperFactory factory) { Set<Annotation> qualifiers = getQualifiers(factory.getClass()); return (type, config) -> type.getQualifiers().equals(qualifiers) ? factory.build(type.getType(), config) : Optional.empty(); }
/** * Adapts an {@link ArgumentFactory} into a QualifiedArgumentFactory. The returned factory only * matches qualified types with zero qualifiers. * * @param factory the factory to adapt */ static QualifiedArgumentFactory adapt(ArgumentFactory factory) { Set<Annotation> qualifiers = getQualifiers(factory.getClass()); return (type, value, config) -> type.getQualifiers().equals(qualifiers) ? factory.build(type.getType(), value, config) : Optional.empty(); } }
/** * Obtain a mapper for the given qualified type. If the type is unqualified, * and a row mapper is registered for the given type, it is returned. If a * column mapper is registered for the given qualified type, it is adapted * into a row mapper, mapping the first column of the result set. If neither * a row or column mapper is registered, empty is returned. * * @param type the target qualified type to map to * @return a mapper for the given type, or empty if no row or column mapper * is registered for the given type. */ @Beta public <T> Optional<RowMapper<T>> findFor(QualifiedType<T> type) { if (type.getQualifiers().isEmpty()) { Optional<RowMapper<T>> result = rowMappers.findFor(type.getType()).map(m -> (RowMapper<T>) m); if (result.isPresent()) { return result; } } return columnMappers.findFor(type).map(SingleColumnMapper::new); }