You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Improve OrmLite support by requiring less information #289
We currently require two attributes on the @OrmLiteDao annotation :
@EActivitypublicclassMyActivityextendsActivity {
// UserDao is a Dao<User, Long>@OrmLiteDao(helper = DatabaseHelper.class, model = User.class)
UserDaouserDao;
@OrmLiteDao(helper = DatabaseHelper.class, model = Car.class)
Dao<Car, Long> carDao;
}
I think we can get rid of the model parameter, and get that information from the first generic parameter of the Dao class.
Regarding the helper parameter, the current implementation is wrong : we specify it at the annotation level, but we only have one connectionSource_ attribute (the helper is used to get the connection source), so only the helper value of the first @OrmLiteDao annotation will be used.
We should look at the code of the com.j256.ormlite.android.apptools.OrmLiteBaseActivity and copy the features.
By reading the code base, here are a few interesting things I noticed :
The helper must extend com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
There can only be one helper instance in the whole application.
A helper instance is retrieved with com.j256.ormlite.android.apptools.OpenHelperManager.getHelper(Context, Class<T>), but there is an instance count occurring, and we should call com.j256.ormlite.android.apptools.OpenHelperManager.releaseHelper() in the onDestroy() method of the application.
So the helper could be defined at the class level, with a dedicated annotation such as @OrmLite(DatabaseHelper.class). We'd call getHelper() in onCreate(), store it as an attribute, and call releaseHelper() in onDestroy().
The main problem I see here is that this can only work for activities (not any @EBean), at least with our current codebase.
Also, there there could be a @OrmLiteSource to inject a ConnectionSource, and a @OrmLiteHelper to inject the database helper.
I like what you are proposing, especially the @OrmLiteHelper.
I think services should also be supported as the Service class has onCreate() and onDestroy() methods
What about having the helper (and the dao) injected in the application object ?
The issue being that the Application has no reliable onTerminate() method...
I'm wondering if @OrmLite(DatabaseHelper.class) should be required.
In most cases, an android project has only one class that inherits from com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.
So in most cases, the database helper class can be retrieved automatically. Only the minority of projects that uses many database helpers would have to specify which to use.
Well, even if there's only one class that inherits from com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper, how do you find such class ? Annotation processing doesn't allow to search for subclasses.
Activity
PerfectCarl commentedon Oct 12, 2012
I like what you are proposing, especially the
@OrmLiteHelper.I think services should also be supported as the
Serviceclass hasonCreate()andonDestroy()methodsWhat about having the helper (and the dao) injected in the
applicationobject ?The issue being that the Application has no reliable
onTerminate()method...PerfectCarl commentedon Oct 14, 2012
I'm wondering if
@OrmLite(DatabaseHelper.class)should be required.In most cases, an android project has only one class that inherits from
com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.So in most cases, the database helper class can be retrieved automatically. Only the minority of projects that uses many database helpers would have to specify which to use.
What do you think ?
pyricau commentedon Oct 18, 2012
Well, even if there's only one class that inherits from
com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper, how do you find such class ? Annotation processing doesn't allow to search for subclasses.PerfectCarl commentedon Oct 18, 2012
I didn't know. Oh well... :)
WonderCsabo commentedon Sep 2, 2014
This is finally implemented.