提高ormlite的批处理速度

http://stackoverflow.com/quegoogstions/11761472/ormlites-createorupdate-seems-slow-what-is-normal-speed

This may be the "expected" speed unfortunately. Make sure you are using ORMLite version 4.39 or higher. createOrUpdate(...) was using a more expensive method to test for existing of the object in the database beforehand. But I suspect this is going to be a minimal speed improvement.

If I create 100 new rows then the speed is even slower.

By default Sqlite is in auto-commit mode. One thing to try is to wrap your inserts (or your createOrUpdates) using the the ORMLite Dao.callBatchTasks(...) method.

In by BulkInsertsTest android unit test, the following doInserts(...) method inserts 1000 items. When I just call it:

doInserts(dao);

It takes 7.3 seconds in my emulator. If I call using the callBatchTasks(...) method which wraps a transactions around the call in Android Sqlite:

dao.callBatchTasks(new Callable<Void>() {
public Void call() throws Exception {
doInserts(dao);
return null;
}
});

It takes 1.6 seconds. The same performance can be had by using the dao.setSavePoint(...)method. This starts a transaction but is not as good as the callBachTasks(...) method because you have to make sure you close your own transaction:

DatabaseConnection conn = dao.startThreadConnection();
Savepoint savePoint = null;
try {
savePoint = conn.setSavePoint(null);
doInserts(dao);
} finally {
// commit at the end
conn.commit(savePoint);
dao.endThreadConnection(conn);
}

This also takes ~1.7 seconds.

dao.setsavePoint开始一个事务,但不如callBachTasks(...)方法,因为你必须确保你闭上你自己的事务:

ormlite 批处理操作的更多相关文章

  1. Hbase之使用回调函数进行批处理操作

    import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...

  2. Hbase之进行批处理操作

    import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...

  3. 批处理操作mysql数据库

    批处理操作mysql数据库 1.使用批处理自动登录mysql数据库 @echo offcd C:\program files\mysql\mysql server 5.5\binmysql -u ro ...

  4. 使用JDBC对数据库实现批处理操作

    本篇讲述如何使用JDBC对数据库实现批处理操作.很多时候单条SQL命令不能满足我们的需求,我们需要对数据库一次实现很多操作,需要发送一批SQL命令给数据库执行. 而JDBC也提供了相应的方法给我们实现 ...

  5. ormlite 删除操作

    ormlite删除操作 DeleteBuilder<TransferDetailDtl, Integer> deleteBuilder = mRawDao.deleteBuilder(); ...

  6. cmd命令行和bat批处理操作windows服务(转载)

    一.cmd命令行---进行Windows服务操作 1.安装服务 sc create 服务名 binPath= "C:\Users\Administrator\Desktop\win32srv ...

  7. 通过批处理操作注册表实现winform应用中Webbrowser以指定的IE版本加载网页

    通过批处理操作注册表实现winform应用中Webbrowser以指定的IE版本加载网页 rem 强制WebBrowser控件使用指定IE版本显示应用的网页 IF EXIST %windir%\Sys ...

  8. 四.使用JDBC进行批处理操作

    1 create table testbatch 2 ( 3 id int primary key, 4 name varchar(20) 5 ); 在实际的项目开发中,有时候需要向数据库发送一批SQ ...

  9. Hibernate批处理操作优化 (批量插入、更新与删除)

    问题描述 我开发的网站加了个新功能:需要在线上处理表数据的批量合并和更新,昨天下午发布上线,执行该功能后,服务器的load突然增高,变化曲线异常,SA教育了我一番,让我尽快处理,将CPU负载降低. 工 ...

随机推荐

  1. j2ee网站项目首页如何直接使用action

    之前做过一些网站项目,大多数都是首页就是登录,直接进入首页的不多,也就没有注意到,今天刚好注意到了就来记一下.也算是一个小技巧 <welcome-file>index.jsp</we ...

  2. LeetCode OJ 222. Count Complete Tree Nodes

    Total Accepted: 32628 Total Submissions: 129569 Difficulty: Medium Given a complete binary tree, cou ...

  3. Moss列表查询,删除条目,更新条目。

    基于Query语句的列表查询 function retrieveListItems(itemId) {    var siteUrl=_spPageContextInfo.webServerRelat ...

  4. 【实验室笔记】太阳能板清洁器DEMO

    <太阳能板清洁器DEMO>2015年的毕昇杯比赛作品,用时两天,整体设计思路很简单: [机械结构]: 清洁器主体采用角钢搭建,用钢锯切割好以后,上螺丝,走线用的尼龙扎带捆绑: 清洗滚轮采用 ...

  5. Laravel中使用Redis

    安装PHP PRedis PRedis是laravel访问redis的扩展包,只需要下载原码即可,不需要安装PHP扩展(如php-redis.so).但在这之前需要了解一个composer,因为lar ...

  6. Linux网卡配置与绑定

    一定要在服务管理中关闭NetworkManager服务并禁用自动启动. 第一步:先查看下本机网卡,使用命令到network-scripts 下 [root@root~]# cd /etc/syscon ...

  7. 上海赛趣-top.mainFrame.tabAddHandler方法详解

    top.mainFrame.tabAddHandler("item"+Id,'项目:'+itemname,'<%=basePath%>bizitem/goEditIte ...

  8. echarts学习总结(一):图表溢出窗口,图表数据窗口显示不全

    如上图所示:echarts图形左面的数据没有完全显示 只需在option中定义一下grid,例如:                                                gri ...

  9. 贪心<haonan>

    题意: 有一列数,每次在相邻的两个书里面选择一个大数留下,同时ans+大数.问题是,求ans的最小值. 题解: 如果a[i]>a[i-1],那么ans+=a[i]; 如果a[i]>=a[i ...

  10. Integer比较值的时候小心使用

    package integerdemo; public class IntegerDemo { public static void main(String[] args) { //-128--127 ...