private ColumnMapper<?> columnMapperFor(Type type) { return columnMappers.computeIfAbsent(type, t -> ctx.findColumnMapperFor(t) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for " + t))); } }
@SuppressWarnings("unchecked") @Override public Option<T> map(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException { final ColumnMapper<?> mapper = ctx.findColumnMapperFor(nestedType) .orElseThrow(() -> new NoSuchMapperException("No mapper for type " + nestedType + " nested in Option")); return (Option<T>) Option.of(mapper.map(r, columnNumber, ctx)); }
@SuppressWarnings("unchecked") @Override public Optional<T> map(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException { final ColumnMapper<?> mapper = ctx.findColumnMapperFor( GenericTypes.findGenericParameter(type, Optional.class) .orElseThrow(() -> new NoSuchMapperException("No mapper for raw Optional type"))) .orElseThrow(() -> new NoSuchMapperException("No mapper for type " + type + " nested in Optional")); return (Optional<T>) Optional.ofNullable(mapper.map(r, columnNumber, ctx)); } }
if (member != null) { QualifiedType<?> memberType = member.getQualifiedType(); ColumnMapper<?> columnMapper = ctx.findColumnMapperFor(memberType) .orElseThrow(() -> new NoSuchMapperException("No column mapper for " + memberType));
.with(getQualifiers(field)); @SuppressWarnings("unchecked") ColumnMapper<?> mapper = ctx.findColumnMapperFor(type) .orElse((ColumnMapper) (r, n, c) -> r.getObject(n)); mappers.add(new SingleColumnMapper<>(mapper, index + 1));
final QualifiedType<?> type = QualifiedType.of(parameter.getParameterizedType()) .with(getQualifiers(parameter)); mappers[i] = ctx.findColumnMapperFor(type) .map(mapper -> new SingleColumnMapper<>(mapper, colIndex + 1)) .orElseThrow(() -> new IllegalArgumentException(
.ifPresent(index -> { @SuppressWarnings({ "unchecked", "rawtypes" }) ColumnMapper<?> mapper = ctx.findColumnMapperFor(property.getQualifiedType()) .orElseGet(() -> (ColumnMapper) defaultColumnMapper(property));
@Test public void qualifiedTypeShouldBePersistent() { StatementContext context = StatementContextAccess.createContext(); // it's about the return type being String and not ? @SuppressWarnings("unused") Optional<ColumnMapper<String>> mapper = context.findColumnMapperFor(QualifiedType.of(String.class).with(NVarchar.class)); }
@Test public void testMapperForDelegatesToRegistry() { ColumnMapper<Foo> mapper = new FooMapper(); ConfigRegistry config = new ConfigRegistry(); config.get(ColumnMappers.class).register(mapper); final StatementContext context = StatementContextAccess.createContext(config); assertThat(context.findColumnMapperFor(Foo.class)).contains(mapper); } }
private ColumnMapper<?> columnMapperFor(Type type) { return columnMappers.computeIfAbsent(type, t -> ctx.findColumnMapperFor(t) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for " + t))); } }
@Override public Optional<ColumnMapper<?>> build(Type type, ConfigRegistry config) { if (String.class.equals(type)) { return Optional.empty(); } return Optional.of((rs, i, ctx) -> { // look for specialized json support first, revert to simple String mapping if absent ColumnMapper<String> jsonStringMapper = JdbiOptionals.findFirstPresent( () -> ctx.findColumnMapperFor(QualifiedType.of(String.class).with(Json.class)), () -> ctx.findColumnMapperFor(String.class)) .orElseThrow(() -> new UnableToProduceResultException(JSON_NOT_RETRIEVABLE, ctx)); String json = jsonStringMapper.map(rs, i, ctx); return json == null ? null : ctx.getConfig(JsonConfig.class).getJsonMapper().fromJson(type, json, ctx); }); } }
final ColumnMapper<?> mapper = ctx.findColumnMapperFor(type) .orElse((r, n, c) -> r.getObject(n));
final ColumnMapper<?> mapper = ctx.findColumnMapperFor(type) .orElse((r, n, c) -> r.getObject(n));
final int columnIndex = columnIndexForParameter(columnNames, paramName, columnNameMatchers); mappers[i] = ctx.findColumnMapperFor(type) .orElseThrow(() -> new IllegalArgumentException(String.format( "Could not find column mapper for type '%s' of parameter '%s' for constructor '%s'",