com.talk2object.plum.repository.meta.EntityMetaBuilder Maven / Gradle / Ivy
package com.talk2object.plum.repository.meta;
public class EntityMetaBuilder {
private static final String DEFAULT_ID_FIELD_NAME = "id";
private Class entityClass;
public EntityMetaBuilder(Class entityClass) {
this.entityClass = entityClass;
}
public Entity build() {
// scan annotations
Entity metaEntity = new Entity(entityClass);
com.talk2object.plum.repository.meta.annotation.Entity annotationEntity = (com.talk2object.plum.repository.meta.annotation.Entity) entityClass
.getAnnotation(com.talk2object.plum.repository.meta.annotation.Entity.class);
String idFieldName = DEFAULT_ID_FIELD_NAME;
if (annotationEntity != null) {
idFieldName = annotationEntity.idFieldName();
}
metaEntity.setIdFieldName(idFieldName);
try {
java.lang.reflect.Field idField = entityClass
.getDeclaredField(idFieldName);
metaEntity.setIdFieldClass(idField.getType());
} catch (Exception e) {
throw new RuntimeException("get field error on class: "
+ entityClass.getCanonicalName(), e);
}
for (java.lang.reflect.Field field : entityClass.getDeclaredFields()) {
com.talk2object.plum.repository.meta.annotation.Field annotationfield = field
.getAnnotation(com.talk2object.plum.repository.meta.annotation.Field.class);
if (annotationfield != null && annotationfield.hidden()) {
continue;
}
String name = null;
Class type = null;
if (annotationfield != null) {
name = annotationfield.name();
type = field.getType();
} else {
name = field.getName();
type = field.getType();
}
Field metaField = new Field(name, type, field);
metaEntity.addField(metaField);
}
return metaEntity;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy