use of org.jdbi.v3.core.annotation.Unmappable in project jdbi by jdbi.
the class PojoMapper method specialize0.
private Optional<RowMapper<T>> specialize0(StatementContext ctx, List<String> columnNames, List<ColumnNameMatcher> columnNameMatchers, List<String> unmatchedColumns) {
final List<PropertyData<T>> propList = new ArrayList<>();
for (PojoProperty<T> property : getProperties(ctx.getConfig()).getProperties().values()) {
Nested anno = property.getAnnotation(Nested.class).orElse(null);
if (property.getAnnotation(Unmappable.class).map(Unmappable::value).orElse(false)) {
continue;
}
if (anno == null) {
String paramName = prefix + getName(property);
findColumnIndex(paramName, columnNames, columnNameMatchers, () -> debugName(property)).ifPresent(index -> {
@SuppressWarnings({ "unchecked", "rawtypes" }) ColumnMapper<?> mapper = ctx.findColumnMapperFor(property.getQualifiedType().mapType(GenericTypes::box)).orElseGet(() -> (ColumnMapper) defaultColumnMapper(property));
propList.add(new PropertyData<>(property, new SingleColumnMapper<>(mapper, index + 1)));
unmatchedColumns.remove(columnNames.get(index));
});
} else {
String nestedPrefix = prefix + anno.value();
if (anyColumnsStartWithPrefix(columnNames, nestedPrefix, columnNameMatchers)) {
nestedMappers.computeIfAbsent(property, d -> createNestedMapper(ctx, d, nestedPrefix)).specialize0(ctx, columnNames, columnNameMatchers, unmatchedColumns).ifPresent(nestedMapper -> propList.add(new PropertyData<>(property, nestedMapper)));
}
}
}
if (propList.isEmpty() && !columnNames.isEmpty()) {
return Optional.empty();
}
propList.sort(Comparator.comparing(p -> p.propagateNull ? 1 : 0));
final Optional<String> nullMarkerColumn = Optional.ofNullable(GenericTypes.getErasedType(type).getAnnotation(PropagateNull.class)).map(PropagateNull::value);
return Optional.of((r, c) -> {
if (propagateNull(r, nullMarkerColumn)) {
return null;
}
final PojoBuilder<T> pojo = getProperties(c.getConfig()).create();
for (PropertyData<T> p : propList) {
Object value = p.mapper.map(r, ctx);
if (p.propagateNull && (value == null || (p.isPrimitive && r.wasNull()))) {
return null;
}
if (value != null) {
pojo.set(p.property, value);
}
}
return pojo.build();
});
}
Aggregations