use of java.lang.reflect.Parameter 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 java.lang.reflect.Parameter 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());
}
};
}
use of java.lang.reflect.Parameter in project commons by terran4j.
the class DsqlRepositoryProxy method getContext.
private Map<String, Object> getContext(Method method, Object[] args) throws BusinessException {
Map<String, Object> context = new HashMap<>();
// 没有参数的情况。
Parameter[] params = method.getParameters();
if (params == null || params.length == 0) {
return context;
}
// 只有一个参数,并且没有 @Param 注解时,用 query 作默认的 key.
if (params.length == 1 && params[0].getAnnotation(Param.class) == null) {
if (args[0] != null) {
context.put("args", args[0]);
}
}
for (int i = 0; i < params.length; i++) {
Parameter param = params[i];
String key = param.getName();
Param paramAnnotation = param.getAnnotation(Param.class);
if (paramAnnotation != null) {
key = paramAnnotation.value();
}
Object value = args[i];
if (value != null) {
context.put(key, value);
}
}
return context;
}
use of java.lang.reflect.Parameter in project OA4MP by ncsa.
the class RequestFactory method convertObjectsToParameters.
public Parameter[] convertObjectsToParameters(Object[] objArray) {
Parameter[] paramArray = new Parameter[objArray.length];
int i = 0;
for (Object obj : objArray) {
try {
Constructor<Parameter> cons = Parameter.class.getConstructor(obj.getClass());
paramArray[i++] = cons.newInstance(obj);
} catch (Exception e) {
throw new IllegalArgumentException("This method can't handle objects of type: " + obj.getClass(), e);
}
}
return paramArray;
}
use of java.lang.reflect.Parameter in project tutorials by eugenp.
the class SpringExtension method resolveParameter.
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
Parameter parameter = parameterContext.getParameter();
Class<?> testClass = extensionContext.getTestClass().get();
ApplicationContext applicationContext = getApplicationContext(extensionContext);
return ParameterAutowireUtils.resolveDependency(parameter, testClass, applicationContext);
}
Aggregations