in src/main/java/org/opensearch/performanceanalyzer/rca/persistence/SQLitePersistor.java [560:629]
private <T> void createFieldRegistry(Class<T> clz)
throws IllegalStateException, NoSuchMethodException {
fieldGetterSetterPairsMap.putIfAbsent(clz, new HashMap<>());
classFieldNamesToGetterSetterMap.putIfAbsent(clz, new HashMap<>());
Map<java.lang.reflect.Field, GetterSetterPairs> fieldToGetterSetterMap =
fieldGetterSetterPairsMap.get(clz);
Map<String, GetterSetterPairs> fieldNameToGetterSetterMap =
classFieldNamesToGetterSetterMap.get(clz);
for (java.lang.reflect.Field field : clz.getDeclaredFields()) {
if (field.isAnnotationPresent(ValueColumn.class)
|| field.isAnnotationPresent(RefColumn.class)) {
checkValidType(field, clz);
// Now we try to find the corresponding Getter and Setter for this field.
GetterSetterPairs pair = new GetterSetterPairs();
String capitalizedFieldName = capitalize(field.getName());
for (String prefix : GETTER_PREFIXES) {
String key = prefix + capitalizedFieldName;
Method method;
try {
method = clz.getDeclaredMethod(key);
} catch (NoSuchMethodException nom) {
continue;
}
if (method.getReturnType() != field.getType()) {
StringBuilder sb = new StringBuilder("The return type of the getter '");
sb.append(key)
.append("' (")
.append(method.getReturnType())
.append(") and field '")
.append(field.getName())
.append("' (")
.append(field.getType())
.append(") don't match.");
throw new NoSuchMethodException(sb.toString());
}
checkPublic(method);
pair.getter = method;
break;
}
for (String prefix : SETTER_PREFIXES) {
String key = prefix + capitalizedFieldName;
try {
// This line will throw if no method with the name exists or if a method
// with such name exists
// but the method argument types are not the same. Remember, int and Integer
// are not the same
// types.
Method method = clz.getDeclaredMethod(key, field.getType());
checkPublic(method);
pair.setter = method;
break;
} catch (NoSuchMethodException e) {
}
}
if (pair.getter == null) {
throw new NoSuchMethodException(
getNoGetterSetterExist(clz, field, GetterOrSetter.GETTER));
}
if (pair.setter == null) {
throw new NoSuchMethodException(
getNoGetterSetterExist(clz, field, GetterOrSetter.SETTER));
}
fieldToGetterSetterMap.put(field, pair);
fieldNameToGetterSetterMap.put(field.getName(), pair);
}
}
}