Search in sources :

Example 1 with OrmLiteHolder

use of org.androidannotations.ormlite.holder.OrmLiteHolder in project androidannotations by androidannotations.

the class OrmLiteDaoHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) {
    OrmLiteHolder ormLiteHolder = holder.getPluginHolder(new OrmLiteHolder(holder));
    AbstractJClass modelClass = getJClass(ormLiteHelper.getEntityType(param).toString());
    AbstractJClass idClass = getJClass(ormLiteHelper.getEntityIdType(param).toString());
    IJExpression modelClassDotClass = modelClass.dotclass();
    AbstractJClass daoClass = getJClass(OrmLiteClasses.DAO).narrow(modelClass, idClass);
    AbstractJClass daoImplClass = codeModelHelper.typeMirrorToJClass(param.asType());
    TypeMirror databaseHelperTypeMirror = annotationHelper.extractAnnotationParameter(element, "helper");
    JFieldVar databaseHelperRef = ormLiteHolder.getDatabaseHelperRef(databaseHelperTypeMirror);
    IJExpression injectExpr = databaseHelperRef.invoke("getDao").arg(modelClassDotClass);
    if (elementExtendsRuntimeExceptionDao(param)) {
        injectExpr = _new(daoImplClass).arg(cast(daoClass, injectExpr));
    }
    JTryBlock tryBlock = targetBlock._try();
    tryBlock.body().add(fieldRef.assign(injectExpr));
    JCatchBlock catchBlock = tryBlock._catch(getClasses().SQL_EXCEPTION);
    JVar exception = catchBlock.param("e");
    String fieldName = param.getSimpleName().toString();
    // 
    catchBlock.body().staticInvoke(getClasses().LOG, // 
    "e").arg(// 
    logTagForClassHolder(holder)).arg(// 
    "Could not create DAO " + fieldName).arg(exception);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) OrmLiteHolder(org.androidannotations.ormlite.holder.OrmLiteHolder) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 IJExpression (com.helger.jcodemodel.IJExpression)1 JCatchBlock (com.helger.jcodemodel.JCatchBlock)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1 JTryBlock (com.helger.jcodemodel.JTryBlock)1 JVar (com.helger.jcodemodel.JVar)1 TypeMirror (javax.lang.model.type.TypeMirror)1 OrmLiteHolder (org.androidannotations.ormlite.holder.OrmLiteHolder)1