在 ormlite 中获取旧的 Dao 对象

发布于 2024-12-07 20:59:40 字数 969 浏览 0 评论 0原文

我在我的 Android 应用程序中使用 ormlite 作为 sqlite 数据库。这是一个基于登录的应用程序,我在 SD 卡中有数据库。对于用户 abc,要求是当用户使用 xyz 等不同用户登录时,应用程序从服务器对用户进行身份验证,并且服务器替换用户 xyz 的数据库。但是,当我尝试访问登录凭据时,它会提供旧凭据,而数据库则反映新凭据。

我也尝试过:

DaoManager.clearCache();

它不起作用,我也尝试过:

DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
manager.releaseHelper(DatabaseHelperGenerator.getDataBaseHelperInstance())

此后,当我尝试触发此查询时:

Dao<LoginAuthentication, Integer> loginAuthenticationDao = null;
DatabaseHelperGenerator.getDataBaseHelperInstance().
    clearLoginDao(LoginAuthentication.class);
loginAuthenticationDao = DatabaseHelperGenerator.getDataBaseHelperInstance().
    getUserDao(LoginAuthentication.class);
List<LoginAuthentication> loginAuthenticationList =
    loginAuthenticationDao.queryForAll();

它给出 IllegalStateException :数据库未打开

寻求帮助。

I am using ormlite for sqlite database in my android application. It's a login based application and I have database in SD card. For user abc, the requirement is when user login with different user like xyz then application authenticate the user from the server and server replace the db for user xyz. But when I am trying to access the login credentials it is giving the old credentials while the database is reflecting the new credentials.

I also tried:

DaoManager.clearCache();

It is not working also I tried:

DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
manager.releaseHelper(DatabaseHelperGenerator.getDataBaseHelperInstance())

After this when I tried to fire this query:

Dao<LoginAuthentication, Integer> loginAuthenticationDao = null;
DatabaseHelperGenerator.getDataBaseHelperInstance().
    clearLoginDao(LoginAuthentication.class);
loginAuthenticationDao = DatabaseHelperGenerator.getDataBaseHelperInstance().
    getUserDao(LoginAuthentication.class);
List<LoginAuthentication> loginAuthenticationList =
    loginAuthenticationDao.queryForAll();

It is giving IllegalStateException :Database not open

Looking for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的故事 2024-12-14 20:59:40

在我看来,你在这里走错了方向。

我会对您的应用程序进行一些调试或记录一些值以查看问题所在。以下是一些想法:

  • 如果您正在使用对象缓存,您是否尝试过禁用它?您是否尝试通过调用 Dao.clearObjectCache()?同样,只有在您打开缓存后,缓存才会存在。默认情况下它没有打开。
  • 您使用什么代码来保存登录信息?与其他调用有什么不同吗?
  • 如何使用 Dao.queryRaw() 方法在插入后立即转储数据库?
  • 有交易吗?

祝你好运。

Seems to me that you are going in the wrong direction here.

  • You are assuming that the DAO is caching objects for you but unless you have enabled an object cache on a particular DAO then that's not the case.
  • DaoManager.clearCache() doesn't clear object caches but instead clears the cached DAO objects.
  • Once you release the helper, the database connection is closed which is the reason why you are getting the IllegalStateException.

I'd do some debugging of your application or some logging of values to see where the problem lies. Here are some thoughts:

  • If you are using an object cache, have you tried to disable it? Have you tried flushing the object cache by calling Dao.clearObjectCache()? Again, a cache will only exist if you have turned it on. It is not on by default.
  • What code are you using to persist the login information? Anything different than other calls?
  • How about using the Dao.queryRaw() methods to dump the database right after the insert?
  • Any transactions?

Best of luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文