/** * Obtain a mapper for the given type in this context. * * @param <T> the type to map * @param type the target type to map to * @return a mapper for the given type, or empty if no row or column mappers * is registered for the given type. */ public <T> Optional<RowMapper<T>> findMapperFor(GenericType<T> type) { return getConfig(Mappers.class).findFor(type); }
/** * Obtain a mapper for the given type in this context. * * @param type the target type to map to * @return a mapper for the given type, or empty if no row or column mappers * is registered for the given type. */ public Optional<RowMapper<?>> findMapperFor(Type type) { return getConfig(Mappers.class).findFor(type); }
/** * Obtain a column mapper for the given type in this context. * * @param <T> the type to map * @param type the target type to map to * @return a ColumnMapper for the given type, or empty if no column mapper is registered for the given type. */ public <T> Optional<ColumnMapper<T>> findColumnMapperFor(GenericType<T> type) { return getConfig(ColumnMappers.class).findFor(type); }
/** * Obtain a row mapper for the given type in this context. * * @param <T> the type to map * @param type the target type to map to * @return a RowMapper for the given type, or empty if no row mapper is registered for the given type. */ public <T> Optional<RowMapper<T>> findRowMapperFor(Class<T> type) { return getConfig(RowMappers.class).findFor(type); }
/** * Obtain a collector for the given type. * * @param containerType the container type. * @return a Collector for the given container type, or empty null if no collector is registered for the given type. */ public Optional<Collector<?, ?, ?>> findCollectorFor(Type containerType) { return getConfig(JdbiCollectors.class).findFor(containerType); }
/** * Obtain the value of an attribute * * @param key the name of the attribute * @return the value of the attribute */ public Object getAttribute(String key) { return getConfig(SqlStatements.class).getAttribute(key); }
/** * Obtain a row mapper for the given type in this context. * * @param type the target type to map to * @return a RowMapper for the given type, or empty if no row mapper is registered for the given type. */ public Optional<RowMapper<?>> findRowMapperFor(Type type) { return getConfig(RowMappers.class).findFor(type); }
/** * Returns the attributes applied in this context. * * @return the defined attributes. */ public Map<String, Object> getAttributes() { return getConfig(SqlStatements.class).getAttributes(); }
/** * Obtain an {@link SqlArrayType} for the given array element type in this context * * @param elementType the array element type. * @return an {@link SqlArrayType} for the given element type. */ public Optional<SqlArrayType<?>> findSqlArrayTypeFor(Type elementType) { return getConfig(SqlArrayTypes.class).findFor(elementType); }
/** * Obtain a column mapper for the given type in this context. * * @param <T> the type to map * @param type the target type to map to * @return a ColumnMapper for the given type, or empty if no column mapper is registered for the given type. */ public <T> Optional<ColumnMapper<T>> findColumnMapperFor(Class<T> type) { return getConfig(ColumnMappers.class).findFor(type); }
/** * Returns the element type for the given container type. * * @param containerType the container type. * @return the element type for the given container type, if available. */ public Optional<Type> findElementTypeFor(Type containerType) { return getConfig(JdbiCollectors.class).findElementTypeFor(containerType); }
public PojoPropertyArguments(String prefix, Object obj, StatementContext ctx) { this(prefix, obj, ctx.getConfig(PojoTypes.class).findFor(obj.getClass()) .orElseThrow(() -> new UnableToCreateStatementException("Couldn't find pojo type of " + obj.getClass(), ctx)), ctx); }
@Override public RowMapper<Map<String, T>> specialize(ResultSet rs, StatementContext ctx) throws SQLException { List<String> keyNames = getMapKeys(rs.getMetaData(), ctx.getConfig(MapMappers.class).getCaseChange()); return (r, c) -> { Map<String, T> row = new HashMap<>(); for (int i = 0; i < keyNames.size(); i++) { T value = mapper.map(r, i + 1, ctx); row.put(keyNames.get(i), value); } return row; }; }
@Override public void apply(final int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (sqlType == null) { ctx.getConfig(Arguments.class).getUntypedNullArgument().apply(position, statement, ctx); } else { statement.setNull(position, sqlType); } }
/** * Obtain a mapper for the given qualified type in this context. * * @param type the target qualified type to map to * @return a mapper for the given qualified type, or empty if no row or column mappers * is registered for the given type. */ @Beta public <T> Optional<RowMapper<T>> findMapperFor(QualifiedType<T> type) { return getConfig(Mappers.class).findFor(type); }
/** * Obtain a column mapper for the given qualified type in this context. * * @param type the qualified target type to map to * @return a ColumnMapper for the given type, or empty if no column mapper is registered for the given type. */ @Beta public <T> Optional<ColumnMapper<T>> findColumnMapperFor(QualifiedType<T> type) { return getConfig(ColumnMappers.class).findFor(type); }
/** * Obtain an argument for given value in this context * * @param type the type of the argument. * @param value the argument value. * @return an Argument for the given value. */ @Beta public Optional<Argument> findArgumentFor(QualifiedType<?> type, Object value) { return getConfig(Arguments.class).findFor(type, value); }
@Override protected Void mappedResult(ResultIterable<?> iterable, StatementContext ctx) { @SuppressWarnings("unchecked") Consumer<Object> consumer = (Consumer<Object>) ctx.getConfig(SqlObjectStatementConfiguration.class).getArgs()[consumerIndex]; iterable.forEach(consumer); return null; }
@SuppressWarnings({ "rawtypes", "unchecked" }) // Type loses <T> protected PojoMapper<?> createNestedMapper(StatementContext ctx, PojoProperty<T> property, String nestedPrefix) { final Type propertyType = property.getQualifiedType().getType(); return new PojoMapper( GenericTypes.getErasedType(propertyType), ctx.getConfig(PojoTypes.class).findFor(type) .orElseThrow(() -> new UnableToProduceResultException("Couldn't find properties for nested type " + propertyType, ctx)), nestedPrefix); }
@Test public void shouldThrowOnMismatchedColumnsStrictMatch() throws Exception { ctx.getConfig(ReflectionMappers.class).setStrictMatching(true); mockColumns("longField", "misspelledField"); assertThatThrownBy(() -> mapper.map(resultSet, ctx)).isInstanceOf(IllegalArgumentException.class); }