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);
}
Aggregations