use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class BindBeanListFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
final BindBeanList bindBeanList = (BindBeanList) annotation;
final String name = ParameterUtil.findParameterName(bindBeanList.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @BindBeanList parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> {
if (arg == null) {
throw new IllegalArgumentException("argument is null; null was explicitly forbidden on BindBeanList");
}
stmt.bindBeanList(name, IterableLike.toList(arg), Arrays.asList(bindBeanList.propertyNames()));
};
}
use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class BindMapFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation a, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
BindMap annotation = (BindMap) a;
List<String> keys = Arrays.asList(annotation.keys());
String prefix = annotation.value().isEmpty() ? "" : annotation.value() + ".";
return (stmt, arg) -> {
Map<?, ?> map = (Map<?, ?>) arg;
Map<String, Object> toBind = new HashMap<>();
map.forEach((k, v) -> {
if (annotation.convertKeys() || k instanceof String) {
String key = k.toString();
if (keys.isEmpty() || keys.contains(key)) {
toBind.put(prefix + key, v);
}
} else {
throw new IllegalArgumentException("Key " + k + " (of " + k.getClass() + ") must be a String");
}
});
keys.forEach(key -> toBind.putIfAbsent(prefix + key, null));
stmt.bindMap(toBind);
};
}
use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class DefineFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
Define define = (Define) annotation;
final String name = ParameterUtil.findParameterName(define.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @Define parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> stmt.define(name, arg);
}
use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class DefineListFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
final DefineList d = (DefineList) annotation;
final String name = ParameterUtil.findParameterName(d.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @DefineList parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> {
List<?> argsList;
if (arg instanceof List) {
argsList = (List<?>) arg;
} else if (arg instanceof Object[]) {
argsList = Arrays.asList((Object[]) arg);
} else if (arg == null) {
throw new IllegalArgumentException("A null object was passed as a @DefineList parameter. " + "@DefineList is only supported on List and array arguments");
} else {
throw new IllegalArgumentException("A " + arg.getClass() + " object was passed as a @DefineList " + "parameter. @DefineList is only supported on List and array arguments");
}
if (argsList.isEmpty()) {
throw new IllegalArgumentException("An empty list was passed as a @DefineList parameter. Can't define " + "an empty attribute.");
}
if (argsList.contains(null)) {
throw new IllegalArgumentException("A @DefineList parameter was passed a list with null values in it.");
}
stmt.defineList(name, argsList);
};
}
use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class BindJpaFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
BindJpa bind = (BindJpa) annotation;
final String prefix;
if (bind.value().isEmpty()) {
prefix = "";
} else {
prefix = bind.value() + ".";
}
return (stmt, arg) -> {
JpaClass<?> jpaClass = JpaClass.get(arg.getClass());
for (JpaMember member : jpaClass.members()) {
stmt.bindByType(prefix + member.getColumnName(), readMember(arg, member), member.getType());
}
};
}
Aggregations