Comments (12)
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.
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.
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.
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.
@j256 Do you agree that OrmLite must be compliante with the use case I described ?
from ormlite-android.
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.
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.
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.
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.
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.
@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.
@kpgalligan , what do you think of my previous proposals ?
from ormlite-android.
Related Issues (20)
- android ,执行update操作,总是返回0 HOT 4
- ORMLite Android - Prevent Upgrade inside catch HOT 2
- The connection pool for database has been unable to grant a connection in ORMLite 5.1 HOT 5
- Missing or reset data HOT 3
- getReadWriteConnection: SQLiteCantOpenDatabaseException unknown error (Sqlite code 14): Could not open database, (OS error - 13:Permission denied)
- Is there any way we can get a 5.2 release to benefit from a bugfix in core 5.2? HOT 1
- Feature Request: SupportSQLiteOpenHelper HOT 2
- Null variable AndroidLogBackend causes "Could not construct instance of helper class" HOT 2
- UpdateBuilder use Nonparametric statement cause sql injection problem HOT 3
- Exception when create object with string including single quote HOT 2
- log4j HOT 2
- how to join two table? HOT 2
- [Bug] Using Limit and Offset causes SQL exception. HOT 3
- Duplicate classes and files when depending on a project using ormlite-core HOT 6
- Can't use a dependency with ormlite annotations. HOT 3
- Does ormlite support In-Memory database? HOT 1
- R8 minifyEnabled proguard rules
- EXTERNAL DATA IN SQL QUERIES [SAST] [M7] [CWE-89]
- Security vulnerability - SQL injection
- dao.queryForId() returns null even though row exists HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ormlite-android.