Using Ormlite in Conjunction with Android's Content Provider
Asked Answered
K

3

13

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!

Kliman answered 4/5, 2012 at 18:42 Comment(2)
There's a google mailing list for ORMLite Android users that may be able to help: groups.google.com/forum/?fromgroups#!forum/ormlite-androidDeejay
A library has been pushed to GitHub for that purpose : github.com/jakenjarvis/Android-OrmLiteContentProvider/blob/…Headwaters
M
2

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. :-)

Melodiemelodion answered 4/5, 2012 at 20:42 Comment(5)
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 Cursors 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
A
4

https://github.com/blandware/android-atleap library is an example of using ContentProvider in conjunction with OrmLite

Alveta answered 8/1, 2014 at 16:47 Comment(1)
Andrey, thanks for the info. I will look into this for some good examples.Kliman
M
2

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. :-)

Melodiemelodion answered 4/5, 2012 at 20:42 Comment(5)
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 Cursors 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
M
2

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.

Myriad answered 23/9, 2014 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.