Id idAnnotation = field.getAnnotation(Id.class);
GeneratedValue generatedValueAnnotation = field.getAnnotation(GeneratedValue.class);
OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class);
ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class);
JoinColumn joinColumnAnnotation = field.getAnnotation(JoinColumn.class);
Enumerated enumeratedAnnotation = field.getAnnotation(Enumerated.class);
Version versionAnnotation = field.getAnnotation(Version.class);
if (columnAnnotation == null && basicAnnotation == null && idAnnotation == null && oneToOneAnnotation == null
&& manyToOneAnnotation == null && enumeratedAnnotation == null && versionAnnotation == null) {
return null;
}
DatabaseFieldConfig config = new DatabaseFieldConfig();
String fieldName = field.getName();
if (databaseType.isEntityNamesMustBeUpCase()) {
fieldName = fieldName.toUpperCase();
}
config.setFieldName(fieldName);
if (columnAnnotation != null) {
if (stringNotEmpty(columnAnnotation.name())) {
config.setColumnName(columnAnnotation.name());
}
if (stringNotEmpty(columnAnnotation.columnDefinition())) {
config.setColumnDefinition(columnAnnotation.columnDefinition());
}
config.setWidth(columnAnnotation.length());
config.setCanBeNull(columnAnnotation.nullable());
config.setUnique(columnAnnotation.unique());
}
if (basicAnnotation != null) {
config.setCanBeNull(basicAnnotation.optional());
}
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);
}
}
if (oneToOneAnnotation != null || manyToOneAnnotation != null) {
// if we have a collection then make it a foreign collection
if (Collection.class.isAssignableFrom(field.getType())
|| ForeignCollection.class.isAssignableFrom(field.getType())) {
config.setForeignCollection(true);
if (joinColumnAnnotation != null && stringNotEmpty(joinColumnAnnotation.name())) {
config.setForeignCollectionColumnName(joinColumnAnnotation.name());
}
if (manyToOneAnnotation != null) {
FetchType fetchType = manyToOneAnnotation.fetch();
if (fetchType != null && fetchType == FetchType.EAGER) {
config.setForeignCollectionEager(true);
}
}
} else {
// otherwise it is a foreign field
config.setForeign(true);
if (joinColumnAnnotation != null) {
if (stringNotEmpty(joinColumnAnnotation.name())) {
config.setColumnName(joinColumnAnnotation.name());
}
config.setCanBeNull(joinColumnAnnotation.nullable());
config.setUnique(joinColumnAnnotation.unique());
}
}
}
if (enumeratedAnnotation != null) {
EnumType enumType = enumeratedAnnotation.value();
if (enumType != null && enumType == EnumType.STRING) {
config.setDataType(DataType.ENUM_STRING);
} else {
config.setDataType(DataType.ENUM_INTEGER);
}