if (columnAnnotation == null && idAnnotation == null && oneToOneAnnotation == null
&& manyToOneAnnotation == null) {
return null;
}
DatabaseFieldConfig config = new DatabaseFieldConfig();
String fieldName = field.getName();
if (databaseType.isEntityNamesMustBeUpCase()) {
fieldName = fieldName.toUpperCase();
}
config.setFieldName(fieldName);
if (columnAnnotation != null) {
try {
Method method = columnAnnotation.getClass().getMethod("name");
String name = (String) method.invoke(columnAnnotation);
if (name != null && name.length() > 0) {
config.setColumnName(name);
}
method = columnAnnotation.getClass().getMethod("length");
config.setWidth((Integer) method.invoke(columnAnnotation));
method = columnAnnotation.getClass().getMethod("nullable");
config.setCanBeNull((Boolean) method.invoke(columnAnnotation));
method = columnAnnotation.getClass().getMethod("unique");
config.setUnique((Boolean) method.invoke(columnAnnotation));
} catch (Exception e) {
throw SqlExceptionUtil.create("Problem accessing fields from the Column annotation for field " + field,
e);
}
}
if (idAnnotation != null) {
if (generatedValueAnnotation == null) {
config.setId(true);
} else {
// generatedValue only works if it is also an id according to {@link GeneratedValue)
config.setGeneratedId(true);
}
}
// foreign values are always ones we can't map as primitives (or Strings)
config.setForeign(oneToOneAnnotation != null || manyToOneAnnotation != null);
config.setDataPersister(DataPersisterManager.lookupForField(field));
config.setUseGetSet(DatabaseFieldConfig.findGetMethod(field, false) != null
&& DatabaseFieldConfig.findSetMethod(field, false) != null);
return config;
}