/** * Obtain a row mapper for the given type in the given context. * * @param <T> the type of the mapper to find * @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. */ @SuppressWarnings("unchecked") public <T> Optional<RowMapper<T>> findFor(Class<T> type) { RowMapper<T> mapper = (RowMapper<T>) findFor((Type) type).orElse(null); return Optional.ofNullable(mapper); }
/** * 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(GenericType<T> type) { return getConfig(RowMappers.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 row mapper for the given type in the given context. * * @param <T> the type of the mapper to find * @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. */ @SuppressWarnings("unchecked") public <T> Optional<RowMapper<T>> findFor(GenericType<T> type) { RowMapper<T> mapper = (RowMapper<T>) findFor(type.getType()).orElse(null); return Optional.ofNullable(mapper); }
/** * 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); }
private Optional<RowMapper<?>> getRowMapper(Type type, ConfigRegistry config) { return config.get(RowMappers.class).findFor(type); }
/** * 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); }
private static RowMapper<?> getValueMapper(Type valueType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getValueColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(valueType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map value " + valueType)); } else { return config.get(ColumnMappers.class) .findFor(valueType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map value " + valueType + " in column " + column)); } }
private static RowMapper<?> getKeyMapper(Type keyType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getKeyColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(keyType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map key " + keyType)); } else { return config.get(ColumnMappers.class) .findFor(keyType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map key " + keyType + " in column " + column)); } }
@Test public void registerByGenericType() { @SuppressWarnings("unchecked") RowMapper<Iterable<Calendar>> mapper = mock(RowMapper.class); GenericType<Iterable<Calendar>> iterableOfCalendarType = new GenericType<Iterable<Calendar>>() {}; db.registerRowMapper(iterableOfCalendarType, mapper); assertThat(db.getConfig(RowMappers.class).findFor(iterableOfCalendarType)) .contains(mapper); } }
/** * Obtain a row mapper for the given type in the given context. * * @param <T> the type of the mapper to find * @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. */ @SuppressWarnings("unchecked") public <T> Optional<RowMapper<T>> findFor(Class<T> type) { RowMapper<T> mapper = (RowMapper<T>) findFor((Type) type).orElse(null); return Optional.ofNullable(mapper); }
RowMapper<?> rowMapperForType(Type type) { return getConfig(RowMappers.class).findFor(type) .orElseThrow(() -> new UnsupportedOperationException("No mapper registered for " + type)); } }
/** * 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); }
/** * 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 row mapper for the given type in the given context. * * @param <T> the type of the mapper to find * @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. */ @SuppressWarnings("unchecked") public <T> Optional<RowMapper<T>> findFor(GenericType<T> type) { RowMapper<T> mapper = (RowMapper<T>) findFor(type.getType()).orElse(null); return Optional.ofNullable(mapper); }
/** * 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(GenericType<T> type) { return getConfig(RowMappers.class).findFor(type); }
private static RowMapper<?> getKeyMapper(Type keyType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getKeyColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(keyType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map key " + keyType)); } else { return config.get(ColumnMappers.class) .findFor(keyType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map key " + keyType + " in column " + column)); } }
private static RowMapper<?> getValueMapper(Type valueType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getValueColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(valueType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map value " + valueType)); } else { return config.get(ColumnMappers.class) .findFor(valueType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map value " + valueType + " in column " + column)); } }