Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public final class CanonicalNameConstants {
public static final String DAO_MANAGER = "com.j256.ormlite.dao.DaoManager";
public static final String CONNECTION_SOURCE = "com.j256.ormlite.support.ConnectionSource";
public static final String OPEN_HELPER_MANAGER = "com.j256.ormlite.android.apptools.OpenHelperManager";
public static final String RUNTIME_EXCEPTION_DAO = "com.j256.ormlite.dao.RuntimeExceptionDao";

/*
* HttpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,19 @@ public void extendsOrmLiteDaoWithValidModelParameter(Element element, IsValid va
TypeMirror modelTypeMirror = annotationHelper.extractAnnotationParameter(element, "model");

TypeElement daoTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.DAO);
TypeElement runtimeExceptionDaoTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.RUNTIME_EXCEPTION_DAO);

if (daoTypeElement != null) {

TypeMirror wildcardType = annotationHelper.getTypeUtils().getWildcardType(null, null);
DeclaredType daoParameterizedType = annotationHelper.getTypeUtils().getDeclaredType(daoTypeElement, modelTypeMirror, wildcardType);
DeclaredType runtimeExceptionDaoParameterizedType = annotationHelper.getTypeUtils().getDeclaredType(runtimeExceptionDaoTypeElement, modelTypeMirror, wildcardType);

// Checks that elementType extends Dao<ModelType, ?>
if (!annotationHelper.isSubtype(elementType, daoParameterizedType)) {
// Checks that elementType extends Dao<ModelType, ?> or RuntimeExceptionDao<ModelType, ?>
if (!annotationHelper.isSubtype(elementType, daoParameterizedType) && !annotationHelper.isSubtype(elementType, runtimeExceptionDaoParameterizedType)) {
valid.invalidate();
annotationHelper.printAnnotationError(element, "%s can only be used on an element that extends " + daoParameterizedType.toString());
annotationHelper.printAnnotationError(element, "%s can only be used on an element that extends " + daoParameterizedType.toString() //
+ " or " + runtimeExceptionDaoParameterizedType.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public class Classes {
*/
public final JClass CONNECTION_SOURCE = refClass(CanonicalNameConstants.CONNECTION_SOURCE);
public final JClass OPEN_HELPER_MANAGER = refClass(CanonicalNameConstants.OPEN_HELPER_MANAGER);
public final JClass RUNTIME_EXCEPTION_DAO = refClass(CanonicalNameConstants.RUNTIME_EXCEPTION_DAO);
public final JClass DAO_MANAGER = refClass(CanonicalNameConstants.DAO_MANAGER);

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;

import org.androidannotations.annotations.OrmLiteDao;
import org.androidannotations.helper.CanonicalNameConstants;
import org.androidannotations.helper.TargetAnnotationHelper;
import org.androidannotations.processing.EBeansHolder.Classes;

Expand Down Expand Up @@ -82,13 +85,27 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
.arg(dbHelperClass));
}


JExpression modelClass = holder.refClass(modelObjectTypeMirror.toString()).dotclass();

JExpression injectExpr;
if (elementExtendsRuntimeExceptionDao(element, modelObjectTypeMirror)) {

injectExpr = classes.RUNTIME_EXCEPTION_DAO//
.staticInvoke("createDao") //
.arg(databaseHelperRef.invoke("getConnectionSource")) //
.arg(modelClass);

} else {

injectExpr = databaseHelperRef.invoke("getDao").arg(modelClass);

}

// create dao from database helper
JTryBlock tryBlock = initBody._try();

JExpression modelClass = holder.refClass(modelObjectTypeMirror.toString()).dotclass();
tryBlock.body().assign(ref(fieldName), //
databaseHelperRef.invoke("getDao"). //
arg(modelClass));
tryBlock.body().assign(ref(fieldName), injectExpr);

JCatchBlock catchBlock = tryBlock._catch(classes.SQL_EXCEPTION);
JVar exception = catchBlock.param("e");
Expand All @@ -99,4 +116,12 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
.arg("Could not create DAO " + fieldName) //
.arg(exception);
}

private boolean elementExtendsRuntimeExceptionDao(Element element, TypeMirror modelObjectTypeMirror) {
TypeMirror elementType = element.asType();
TypeElement runtimeExceptionDaoTypeElement = helper.typeElementFromQualifiedName(CanonicalNameConstants.RUNTIME_EXCEPTION_DAO);
TypeMirror wildcardType = helper.getTypeUtils().getWildcardType(null, null);
DeclaredType runtimeExceptionDaoParameterizedType = helper.getTypeUtils().getDeclaredType(runtimeExceptionDaoTypeElement, modelObjectTypeMirror, wildcardType);
return helper.isSubtype(elementType, runtimeExceptionDaoParameterizedType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OrmLiteDao;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.RuntimeExceptionDao;

@EActivity
public class OrmLiteActivity extends Activity {
Expand All @@ -30,6 +31,9 @@ public class OrmLiteActivity extends Activity {
@OrmLiteDao(helper = DatabaseHelper.class, model = Car.class)
Dao<Car, Long> carDao;

@OrmLiteDao(helper = DatabaseHelper.class, model = Car.class)
RuntimeExceptionDao<Car, Long> runtimeExceptionDao;

@Bean
OrmLiteBean ormLiteBean;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.