Skip to content

Added AbstractQuery.getDao()#345

Open
cwlockhart wants to merge 4 commits into
greenrobot:masterfrom
cwlockhart:master
Open

Added AbstractQuery.getDao()#345
cwlockhart wants to merge 4 commits into
greenrobot:masterfrom
cwlockhart:master

Conversation

@cwlockhart

Copy link
Copy Markdown

Used to check if the dao database isn't already closed to validate a saved query object.

Used to check if the dao database isn't already closed to validate a
saved query object.
@greenrobot

Copy link
Copy Markdown
Owner

Sorry, don't want to expose that. One can always store the dao beforehand.

@greenrobot greenrobot closed this Jul 28, 2016
@jeffdgr8

Copy link
Copy Markdown

@greenrobot Can you please explain why exposing the dao property would be a problem? Storing the dao alongside a saved query object, when the query object itself already has a reference to it would be a dirty solution to this problem.

The problem that needs to be solved is being able to find out if a saved query object is referencing a database that has already been closed or not. Before attempting to reuse a saved query, this needs to be checked, as it's possible the database has been closed in our app.

Invalidating all saved query objects upon closing the database is also a complicated solution, as we'd have to be sure to add every saved query reference to the database closing method, and it would be easy to forget when adding them later.

It's much easier to make this check before attempting to reuse a query. Is there some other way you could propose knowing if a query object is still reusable with a currently opened database or if it is referencing a database which is no longer open?

@greenrobot

Copy link
Copy Markdown
Owner

I was almost convinced, but public AbstractDao<T, ?> getDao() is ugly. It is missing the K (key type). How about getAbstractDaoSession ?

@greenrobot greenrobot reopened this Jul 28, 2016
@jeffdgr8

Copy link
Copy Markdown

That should work as well for this need, since ultimately it would be the dao session that would be gotten from the dao to perform this check.

public AbstractDaoSession getSession() {
    return dao.getSession();
}

@cwlockhart

cwlockhart commented Aug 4, 2016

Copy link
Copy Markdown
Author

I've made the requested changes from getDao() to getSession() so the dao is no longer exposed, but we can validate the session before trying to reuse a saved query object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants