Giter Club home page Giter Club logo

Comments (12)

j256 avatar j256 commented on July 17, 2024

So it is static or something? Is there no way to detect the application is starting and specifically clear it or re-create it?

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

You're thinking about a workaround in my application code, right ?

My point of view is that the use case I describe is really simple : one activity which uses one loader. That's it. This use case should work with OrmLite loaders because it is the simpliest use case we can imagine for loaders use !
Android Loaders are designed to load data regardless of activities life cycle, partly to not reload data at each configuration change. When OrmLite Loaders depend on activities life cycle because of the database connection management, they don't comply with android loaders "contract".

So I think the best solution is to find a correction in the OrmLite library code itself. As I said before, the solution may be to make the OrmLite loaders retain the database connection. What do you think of this ?

from ormlite-android.

j256 avatar j256 commented on July 17, 2024

I don't think you should retain the database connection. I don't think that's proper. Can you find some Android docs which say otherwise?

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

When I say "retain the database connection", I mean "call OpenHelperManager.getHelper and OpenHelperManager.releaseHelper".
The Android docs http://developer.android.com/guide/components/loaders.html and http://developer.android.com/reference/android/content/Loader.html don't mention anything about database because Loaders mecanism abstracts the data source.
What other than mine solution would you propose to solve the database connection issue ?

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

@j256 Do you agree that OrmLite must be compliante with the use case I described ?

from ormlite-android.

j256 avatar j256 commented on July 17, 2024

I think your application must be compliant. I'm not sure I agree that it's ORMLite responsibility to protect against it. This is the first time that I've heard of this problem. Feel free to take a poll on the android mailing list however.

from ormlite-android.

kpgalligan avatar kpgalligan commented on July 17, 2024

To be 100% clear on this. You can, and should, keep your db connection open. I wrote the original version of the base activities that open/close the db connection, and have since done a lot of research and testing on this. You should keep a singleton pointing at a single open helper instance.

See: http://stackoverflow.com/a/3689883
And: http://touchlabblog.tumblr.com/post/24474750219/single-sqlite-connection
And (more formally): http://stackoverflow.com/a/12715032

You are correct. I imagine if your db is closed on rotate, your loader is going to freak out if its holding onto Dao. If you're going to change things, though, you'll need to change ALL of your base classes. The key to good DB health is one OpenHelper instance.

I just realized how old this bug was, but its probably good reading if somebody else is having the issue.

This also improves my argument to deprecate the helper activities ;)

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

OK, I understand.
The problem here is that the documentation encourage to do what I did, I mean use OrmLiteBase classes to manage access to the database helper whereas it seems that it is not the right way to go.
So I agree, the helper activities may be deprecated and the documentation updated to explain the good way of doing (using a subclass of OrmLiteSqliteOpenHelper as singleton ?).

from ormlite-android.

kpgalligan avatar kpgalligan commented on July 17, 2024

I'm with you. I have another potential solution, but I'm reluctant to put more work into the helper classes. Its sort of complex to explain, unless you have a deep understanding of Android threading. Essentially, queue the closing call in the helper on the main thread, so by the time it gets there, if you did a rotate, the new activity would've incremented the db counter, and it won't close. TBD.

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

It's becoming quite complicated !!
Why not letting OrmLite Loaders be connected to OpenHelperManager like OrmLite Activities are ?
The dao parameter in constructor would be replaced by a class parameter to let them call getDao() on the database helper (obtained thanks to the OpenHelperManager) and manage their own dao instance ?

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

@kpgalligan , what about initializing the singleton in Application.onCreate() ? This would permit to remove the context parameter in the singleton getInstance() function (which is only used for initialization).

from ormlite-android.

VincentJousse avatar VincentJousse commented on July 17, 2024

@kpgalligan , what do you think of my previous proposals ?

from ormlite-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.