为什么在ORMLite中DAO方法如此之慢? [英] Why is the DAO method so slow in ORMLite?

查看:136
本文介绍了为什么在ORMLite中DAO方法如此之慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的方法

I have a method that looks like this

public Dao<ModelStore, Integer> getDaoStore() throws SQLException {
    return BaseDaoImpl.createDao(getConnectionSource(), ModelStore.class);
}

当我调用 getDaoStore 这是一个相当漫长的过程。在我的日志中,我可以看到每次调用GC之后GC都会运行,所以我猜这个调用有很多事情要做。

when i call getDaoStore it is quite a lengthy process. In my log's i can see that the GC runs after every call to this, so I'm guessing there's a lot going on with this call.

有没有办法速度如此之快?

Is there a way to speed this up?

推荐答案

我们不断提高注释速度。另请参阅: ORMLite在Android上表现不佳?

We continue to improve annotation speeds. See also: ORMLite poor performance on Android?

DAO创建是一个相对昂贵的过程。 ORMLite创建类和类中的字段的数据表示,并构建大量其他实用程序类,以帮助实现各种DAO功能。您应该确保每次调用都调用一次 createDao 方法。我认为这是在Android @Pzanno下?

DAO creation is a relatively expensive process. ORMLite creates a data representation of both the class and the fields in the class and builds a number of other utility classes that help with the various DAO functionality. You should make sure that you call the createDao method once per invocation. I assume this is under Android @Pzanno?

在4.16中,我们添加了一个 DaoManager Dao类,这在4.20版本中得到了改进。您应该始终使用它来创建您的Daos。推荐使用下面的代码:

In 4.16 we added a DaoManager whose job it is to cache the Dao classes and this was improved in version 4.20. You should then always use it to create your Daos. Something like the following code is recommended:

private Dao<ModelStore, Integer> modelStoreDao = null;
...

public Dao<ModelStore, Integer> getDaoStore() throws SQLException {
    if (modelStoreDao == null) {
        modelStoreDao = DaoManager.createDao(getConnectionSource(),
            ModelStore.class);
    }
    return modelStoreDao;
}

希望这会有所帮助。 ORMLite的内存审计也可能是有序的。我看了它的消费已经有一段时间了。

Hope this helps. A memory audit of ORMLite is probably also in order. It's been a while since I looked at it's consumption.

这篇关于为什么在ORMLite中DAO方法如此之慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆