Search in sources :

Example 1 with BindDao

use of com.abubusoft.kripton.android.annotation.BindDao in project kripton by xcesco.

the class M2MEntity method extractEntityManagedByDAO.

/**
 * Works with @BindDaoMany2Many and @BindDao to extract entity name.
 *
 * @param item
 * @return
 */
public static M2MEntity extractEntityManagedByDAO(TypeElement daoElement) {
    ClassName entity1 = null;
    ClassName entity2 = null;
    String prefixId = null;
    String tableName = null;
    String entityName = null;
    PackageElement pkg = null;
    String packageName = null;
    boolean needToCreate = true;
    boolean generatedMethods = true;
    if (daoElement.getAnnotation(BindDaoMany2Many.class) != null) {
        entity1 = TypeUtility.className(AnnotationUtility.extractAsClassName(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.ENTITY_1));
        entity2 = TypeUtility.className(AnnotationUtility.extractAsClassName(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.ENTITY_2));
        prefixId = AnnotationUtility.extractAsString(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.ID_NAME);
        tableName = AnnotationUtility.extractAsString(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.TABLE_NAME);
        generatedMethods = AnnotationUtility.extractAsBoolean(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.METHODS);
        entityName = entity1.simpleName() + entity2.simpleName();
        pkg = BaseProcessor.elementUtils.getPackageOf(daoElement);
        packageName = pkg.isUnnamed() ? null : pkg.getQualifiedName().toString();
    }
    if (daoElement.getAnnotation(BindDao.class) != null) {
        // we have @BindDao
        String derived = AnnotationUtility.extractAsClassName(daoElement, BindDao.class, AnnotationAttributeType.VALUE);
        ClassName clazz = TypeUtility.className(derived);
        packageName = clazz.packageName();
        entityName = clazz.simpleName();
        String tableTemp = AnnotationUtility.extractAsClassName(daoElement, BindDao.class, AnnotationAttributeType.TABLE_NAME);
        if (StringUtils.hasText(tableTemp)) {
            tableName = tableTemp;
        }
        needToCreate = false;
    }
    M2MEntity entity = new M2MEntity(daoElement, packageName, entityName, TypeUtility.className(daoElement.asType().toString()), entity1, entity2, prefixId, tableName, needToCreate, generatedMethods);
    return entity;
}
Also used : BindDao(com.abubusoft.kripton.android.annotation.BindDao) BindDaoMany2Many(com.abubusoft.kripton.android.annotation.BindDaoMany2Many) ClassName(com.squareup.javapoet.ClassName) PackageElement(javax.lang.model.element.PackageElement)

Aggregations

BindDao (com.abubusoft.kripton.android.annotation.BindDao)1 BindDaoMany2Many (com.abubusoft.kripton.android.annotation.BindDaoMany2Many)1 ClassName (com.squareup.javapoet.ClassName)1 PackageElement (javax.lang.model.element.PackageElement)1