j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 367 forks source link

Loader implementations for ORMLite #5

Closed Egorand closed 2 years ago

Egorand commented 11 years ago

I usually use Loaders when populating lists with data, so I've made a couple of Loader implementations for executing queries. There are more ways to query the database in ORMLite, so I'm planning to add more implementations, or maybe find a more generic way to cover all use-cases.

Please let me know if there's anything I can add like unit tests or additional documentation. Thank you.

RomanMinenok commented 11 years ago

As Android developer I can say that it would be really nice to add Loader pattern support to ORMLite.

Egorand commented 11 years ago

Why there's been no feedback on this pull request yet?

j256 commented 11 years ago

Sorry for not responding sooner. The problem with this is that it requires a higher version of Android, correct. But the worse case is a compilation error if you try to use these classes on a lower version of Android, right?

kpgalligan commented 11 years ago

It would require the support v4 package to compile, and presumably would only throw a ClassNotFoundException if an app attempted to use them without the support jar.

We've been doing something similar in our apps, although nothing quite open-sourceable, although its always been on the todo list. It would be great to have easy access to loaders and ORMLite. Will take a look at this when I get a chance as well.

-Kevin

On Thu, Oct 24, 2013 at 10:39 AM, Gray notifications@github.com wrote:

Sorry for not responding sooner. The problem with this is that it requires a higher version of Android, correct. But the worse case is a compilation error if you try to use these classes on a lower version of Android, right?

— Reply to this email directly or view it on GitHubhttps://github.com/j256/ormlite-android/pull/5#issuecomment-26997776 .

Egorand commented 11 years ago

Thanks for replying. Yes, it uses the support version of Loaders, so it requires the support-v4 library. However, the dependency to support-v4 is marked as optional, so there's no need to use it if you're not planning to use the Loaders.

ddfire commented 11 years ago

Hi guys What is a loader? Can you point me a link whit some ifo? Thanks!!! El 24/10/2013 11:49, "kpgalligan" notifications@github.com escribió:

It would require the support v4 package to compile, and presumably would only throw a ClassNotFoundException if an app attempted to use them without the support jar.

We've been doing something similar in our apps, although nothing quite open-sourceable, although its always been on the todo list. It would be great to have easy access to loaders and ORMLite. Will take a look at this when I get a chance as well.

-Kevin

On Thu, Oct 24, 2013 at 10:39 AM, Gray notifications@github.com wrote:

Sorry for not responding sooner. The problem with this is that it requires a higher version of Android, correct. But the worse case is a compilation error if you try to use these classes on a lower version of Android, right?

— Reply to this email directly or view it on GitHub< https://github.com/j256/ormlite-android/pull/5#issuecomment-26997776> .

— Reply to this email directly or view it on GitHubhttps://github.com/j256/ormlite-android/pull/5#issuecomment-26998702 .

kpgalligan commented 11 years ago

Loaders load and monitor data for changes, and live a bit outside of the fragment/activity lifecycle. They're generally preferred to AsyncTask for similar methods of loading data.

http://developer.android.com/guide/components/loaders.html

The general design is for use with ContentProvider, but I'm personally not a fan on ContentProvider, so we use AsyncTaskLoader.

This implementation should be extended somewhat to provider for a way of listening to updates, and I would also say a way to use a cursor rather than load all data at once. Have seen some implementations like this before.

On Sat, Oct 26, 2013 at 9:21 PM, ddfire notifications@github.com wrote:

Hi guys What is a loader? Can you point me a link whit some ifo? Thanks!!!

ddfire commented 11 years ago

Thanks

j256 commented 10 years ago

Ok. I've just checked this code into android trunk. Sorry for the delay. Thanks much EgorAnd!! I could not just merge in the pull request for some reason so I just copied the classes in. I've got a couple XXX comments in there in places to mark outstanding questions. I've also tweaked formatting, used protected fields, etc.. Comments, welcome.

j256 commented 10 years ago

Hey, can someone write a little HelloAndroid like program using Loaders so I can check it in as an example and play with it?

j256 commented 10 years ago

Here's the check-in: https://github.com/j256/ormlite-android/commit/78b2b50ac100bf223fb637551f34572b78817734

Egorand commented 10 years ago

Thank you for taking a look at it, really glad I could contribute. I'm sure I have a sample app using the OrmLiteLoader somewhere, I can add it when I have some spare time. BTW, what will be the right place to put it?

bgorkowy commented 10 years ago

Could you guys provide an example app to use this?

And if I try to use this, will it be an improvement over loading data with standard RuntimeExceptionDao? I mean, standard DAO queries on main thread? I am looking for a way to get my results asynchronously, that's why I'm here. But only if this will improve my performance.

Also, will classes written by Egorand work with RuntimeExceptionDao? And it does't yet provide a functionality of auto-updating data in adapters?

emmby commented 10 years ago

Here's a different loader and adapter implementation that supports notifications and includes a sample application: https://github.com/j256/ormlite-android/pull/8

kpgalligan commented 10 years ago

That's been on our verbal todo list for a while, but never seem to find the time ;)

Will take a look if I can figure out how to check out a pull request properly.

On Sat, Apr 5, 2014 at 1:45 AM, Mike Burton notifications@github.comwrote:

Here's a different loader and adapter implementation that supports notifications and includes a sample application: #8https://github.com/j256/ormlite-android/pull/8

Reply to this email directly or view it on GitHubhttps://github.com/j256/ormlite-android/pull/5#issuecomment-39629780 .

pelotasplus commented 10 years ago

@emmby 's implementation works like a charm. using it with my app. right now three different data models and thus three loaders. more to come. so far so good. thanks mate!

emmby commented 10 years ago

glad to hear it!

j256 commented 10 years ago

I've decided to use Emmby's loading implementation @Egorand. Thanks for your work however. Have you had a chance to review it? Any comments?

Egorand commented 10 years ago

Unfortunately haven't had a chance to take a look, but would love to when I have time. Thanks @emmby !

jeffreydelooff commented 10 years ago

This is good news everyone! I have been waiting for a long time to be able to use ORMLite in conjuction with CursorLoaders. When could we expect this to be released?

atali commented 10 years ago

Hello guys , when this feature will be available ?

hdmchl commented 10 years ago

FYI I just came across this implementation of a CursorLoader / ListLoader: https://github.com/campnic/ormlite-android-extras - it's quite similar to what I've put together in my latest app.

atali commented 10 years ago

@hadimichael thanks I will check this implementation :-)

@j256 Do you need some help to test the implementation ? I will be glad to help you !

gbero commented 9 years ago

Hello guys, any update on this ?

evgenybozhko2 commented 8 years ago

@Egorand I tried your loader implementation, it's very slow. Can you show me best practice of using this loader to really fast and much good result than call from UI thread ?