use of com.coredata.annotation.Entity in project CoreData by FangCloud-Android.
the class EntityDetail method getTableName.
/**
* 获取数据库表名
*
* @return
*/
public String getTableName() {
Entity entity = entityElement.getAnnotation(Entity.class);
String tableName = entity.tableName();
if (TextUtils.isEmpty(tableName)) {
tableName = getEntityName();
}
return tableName;
}
use of com.coredata.annotation.Entity in project CoreData by FangCloud-Android.
the class Utils method fillElementsForDbAndReturnPrimaryKey.
public static Element fillElementsForDbAndReturnPrimaryKey(ProcessingEnvironment env, List<Element> elementList, TypeElement element) {
Entity entity = element.getAnnotation(Entity.class);
String primaryKeyStr = null;
if (entity != null) {
primaryKeyStr = entity.primaryKey();
}
return fillElementsForDbAndReturnPrimaryKey(env, elementList, element, primaryKeyStr);
}
use of com.coredata.annotation.Entity in project CoreData by FangCloud-Android.
the class Utils method getProperties.
public static List<Property> getProperties(ProcessingEnvironment env, List<Element> elements, Element primaryKey) {
Elements elementUtils = env.getElementUtils();
Types typeUtils = env.getTypeUtils();
List<Property> propertyList = new ArrayList<>();
for (Element element : elements) {
String columnName = Utils.getColumnName(element);
TypeName dbBaseType;
TypeMirror typeMirror = element.asType();
TypeName typeNameElement = ClassName.get(typeMirror);
if (Utils.isBaseType(typeNameElement)) {
dbBaseType = typeNameElement;
} else {
TypeElement elementFieldType = (TypeElement) typeUtils.asElement(typeMirror);
Relation annotationRelation = element.getAnnotation(Relation.class);
if (annotationRelation != null) {
// 关联数据
Entity relationEntity = elementFieldType.getAnnotation(Entity.class);
if (relationEntity == null) {
throw new IllegalStateException("@Relation 添加的属性必须是 @Entity 的类");
}
EntityDetail relationEntityDetail = EntityDetail.parse(env, elementFieldType);
Element relationEntityPrimaryKey = relationEntityDetail.getPrimaryKey();
if (relationEntityPrimaryKey == null) {
throw new IllegalStateException(relationEntityDetail.getEntityName() + "是关联类型,@Relation 属性必须有主键");
}
dbBaseType = ClassName.get(relationEntityPrimaryKey.asType());
} else {
Embedded embedded = element.getAnnotation(Embedded.class);
if (embedded != null) {
// 内嵌数据, 循环解析内嵌结构的字段
List<Element> embeddedEleList = new ArrayList<>();
fillElementsForDbAndReturnPrimaryKey(env, embeddedEleList, (TypeElement) typeUtils.asElement(typeMirror));
propertyList.addAll(getProperties(env, embeddedEleList, null));
continue;
} else {
Convert convert = element.getAnnotation(Convert.class);
if (convert != null) {
TypeName classConvertDb = Utils.getConvertDbType(convert);
if (Utils.isBaseType(classConvertDb)) {
dbBaseType = classConvertDb;
} else {
throw new IllegalStateException(element.getSimpleName() + "converter dbtype is not a base type");
}
} else {
throw new IllegalStateException(element.getSimpleName() + " is a complex structure field," + "must indicate it as @Relation or @Embedded, " + "or supply a @Convert for it");
}
}
}
}
propertyList.add(new Property(columnName, Utils.getTypeByTypeName(dbBaseType), element == primaryKey));
}
return propertyList;
}
Aggregations