in wrapper/src/main/java/software/amazon/jdbc/util/PropertyUtils.java [60:124]
public static void setPropertyOnTarget(
final Object target,
final String propName,
final Object propValue,
final List<Method> methods) {
Method writeMethod = null;
String methodName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
for (final Method method : methods) {
if (method.getName().equals(methodName) && method.getParameterTypes().length == 1) {
writeMethod = method;
break;
}
}
if (writeMethod == null) {
methodName = "set" + propName.toUpperCase();
for (final Method method : methods) {
if (method.getName().equals(methodName) && method.getParameterTypes().length == 1) {
writeMethod = method;
break;
}
}
}
if (writeMethod == null) {
LOGGER.finest(
() ->
Messages.get(
"PropertyUtils.setMethodDoesNotExistOnTarget",
new Object[] {propName, target.getClass()}));
return;
}
try {
final Class<?> paramClass = writeMethod.getParameterTypes()[0];
if (paramClass == String.class) {
writeMethod.invoke(target, propValue.toString());
} else if (paramClass == int.class) {
writeMethod.invoke(target, Integer.parseInt(propValue.toString()));
} else if (paramClass == long.class) {
writeMethod.invoke(target, Long.parseLong(propValue.toString()));
} else if (paramClass == boolean.class || paramClass == Boolean.class) {
writeMethod.invoke(target, Boolean.parseBoolean(propValue.toString()));
} else {
writeMethod.invoke(target, propValue);
}
Object cleanPropValue = isSecretProperty(propName) ? "***" : propValue;
LOGGER.finest(() -> String.format("Set property '%s' with value: %s", propName, cleanPropValue));
} catch (final InvocationTargetException ex) {
LOGGER.warning(
() ->
Messages.get(
"PropertyUtils.failedToSetPropertyWithReason",
new Object[] {propName, target.getClass(), ex.getCause().getMessage()}));
throw new RuntimeException(ex.getCause());
} catch (final Exception e) {
LOGGER.warning(
() ->
Messages.get(
"PropertyUtils.failedToSetProperty", new Object[] {propName, target.getClass()}));
throw new RuntimeException(e);
}
}