I'm in the process of developing an Android application and I am conflicted about whether or not I should use Ormlite for updating and retrieving data in conjunction with Android Content Provider. The content provider would be used to primarily notify the app of changes in the data that have occurred in the app on other platforms. Perhaps I am making this more complicated than what it needs to be. Some more experienced opinions would be greatly appreciated!
Using Ormlite in Conjunction with Android's Content Provider
Asked Answered
There's a google mailing list for ORMLite Android users that may be able to help: groups.google.com/forum/?fromgroups#!forum/ormlite-android –
Deejay
A library has been pushed to GitHub for that purpose : github.com/jakenjarvis/Android-OrmLiteContentProvider/blob/… –
Headwaters
Give it a try. Experience gained is usually worth the effort, even if you end up discarding the result. Oh, and let us know how it goes, because I've been curious about OrmLite too. :-)
So far, my experience with Ormlite has been pleasant. There's a bit of a learning curve, and a lack of documentation on the site. But the framework itself I find to be really helpful. –
Kliman
The conflict that I am having at the moment with using the Android content provider is that being that I have already creating my entities and database normalization, I have just come to realize that I will have to change the column names of the primary key columns of each table and entity to _id. This is recommended due to the use of the ListView needing the primary key identified by this specific column name. The other issue I have is that I have created my DAOs based off of Ormlite. However, a Content Provider IS a DAO. –
Kliman
So, without having to do too much re-coding, I will have to keep DAO's that use Ormlite and simply have another layer that is simply the content provider which accesses the DAO. I'm thinking that my content provider will simply work much as a Webservice layer in my application. I'll keep you guys posted on my progress. –
Kliman
@Kliman "However, a Content Provider IS a DAO" - bingo! That's how I look at it too. Note that, even if you use ormlite to perform database access; there are some use cases where you cannot avoid a
ContentProvider
. 2 cases come to mind: 1) You want to expose your data to other apps; 2) You want to use Android's search framework. So even if you use POJOs for your "daily needs", you'll still need to tinker with Cursor
s and ContentProvider
when it comes to these specific requirements. –
Kaspar As a side note. For anyone planning on using ORMLite in conjunction with Android content providers, I highly recommend that the class in which you are opening the database connection is a singleton factory. The reason for this is to prevent a crash due to the UI thread attempting to access a worker/background thread. This is especially the case when updating data in a ListView. –
Kliman
https://github.com/blandware/android-atleap library is an example of using ContentProvider in conjunction with OrmLite
Andrey, thanks for the info. I will look into this for some good examples. –
Kliman
Give it a try. Experience gained is usually worth the effort, even if you end up discarding the result. Oh, and let us know how it goes, because I've been curious about OrmLite too. :-)
So far, my experience with Ormlite has been pleasant. There's a bit of a learning curve, and a lack of documentation on the site. But the framework itself I find to be really helpful. –
Kliman
The conflict that I am having at the moment with using the Android content provider is that being that I have already creating my entities and database normalization, I have just come to realize that I will have to change the column names of the primary key columns of each table and entity to _id. This is recommended due to the use of the ListView needing the primary key identified by this specific column name. The other issue I have is that I have created my DAOs based off of Ormlite. However, a Content Provider IS a DAO. –
Kliman
So, without having to do too much re-coding, I will have to keep DAO's that use Ormlite and simply have another layer that is simply the content provider which accesses the DAO. I'm thinking that my content provider will simply work much as a Webservice layer in my application. I'll keep you guys posted on my progress. –
Kliman
@Kliman "However, a Content Provider IS a DAO" - bingo! That's how I look at it too. Note that, even if you use ormlite to perform database access; there are some use cases where you cannot avoid a
ContentProvider
. 2 cases come to mind: 1) You want to expose your data to other apps; 2) You want to use Android's search framework. So even if you use POJOs for your "daily needs", you'll still need to tinker with Cursor
s and ContentProvider
when it comes to these specific requirements. –
Kaspar As a side note. For anyone planning on using ORMLite in conjunction with Android content providers, I highly recommend that the class in which you are opening the database connection is a singleton factory. The reason for this is to prevent a crash due to the UI thread attempting to access a worker/background thread. This is especially the case when updating data in a ListView. –
Kliman
You can use OrmLiteContentProvider or Android AtLeap accelerator in conjunction with OrmLite. Both libraries allows you to define content provider easily on top of the OrmLite data model.
© 2022 - 2024 — McMap. All rights reserved.