use of org.jdbi.v3.core.argument.NullArgument in project jdbi by jdbi.
the class SqlArrayArgumentFactory method build.
@Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> erasedType = GenericTypes.getErasedType(type);
if (!(erasedType.isArray() || Collection.class.isAssignableFrom(erasedType))) {
return Optional.empty();
}
if (value == null) {
return Optional.of(new NullArgument(Types.ARRAY));
}
Function<Type, Optional<SqlArrayType<?>>> lookup = eT -> config.get(SqlArrayTypes.class).findFor(eT);
if (erasedType.isArray()) {
Class<?> elementType = erasedType.getComponentType();
return lookup.apply(elementType).map(arrayType -> new SqlArrayArgument<>(arrayType, value));
}
return GenericTypes.findGenericParameter(type, Collection.class).flatMap(lookup).map(arrayType -> new SqlArrayArgument<>(arrayType, value));
}
use of org.jdbi.v3.core.argument.NullArgument in project providence by morimekta.
the class MessageNamedArgumentFinder method find.
@Nonnull
@Override
@SuppressWarnings("unchecked")
public Optional<Argument> find(String name, StatementContext ctx) {
if (!prefix.isEmpty()) {
if (name.startsWith(prefix)) {
name = name.substring(prefix.length());
} else {
return Optional.empty();
}
}
String[] parts = name.split("[.]");
PMessage leaf = message;
PMessageDescriptor leafDescriptor = message.descriptor();
for (int i = 0; i < parts.length - 1; ++i) {
String part = parts[i];
PField field = leafDescriptor.findFieldByName(part);
if (field == null)
return Optional.empty();
if (field.getType() != PType.MESSAGE) {
throw new IllegalArgumentException("");
}
leafDescriptor = (PMessageDescriptor) field.getDescriptor();
if (leaf != null) {
leaf = (PMessage) leaf.get(field.getId());
}
}
String leafName = parts[parts.length - 1];
PField field = leafDescriptor.findFieldByName(leafName);
if (field != null) {
if (leaf != null) {
return Optional.of(new MessageFieldArgument(leaf, field, getColumnType(field)));
}
return Optional.of(new NullArgument(getColumnType(field)));
}
return Optional.empty();
}
Aggregations