bboss持久层在v5.0.3.5中新增简单的高效的db批处理功能,本文介绍使用方法。
首先在项目中导入bboss 持久层包:
maven坐标
<dependency>
<groupId>com.bbossgroups</groupId>
<artifactId>bboss-persistent</artifactId>
<version>5.8.2</version>
</dependency>
gradle坐标
compile 'com.bbossgroups:bboss-persistent:5.8.2'
轻量级批处理方法
直接操作sql语句的组件SQLExecutor
com.frameworkset.common.poolman.SQLExecutor
public static <T> void executeBatch(String sql,List<T> datas,int batchsize, BatchHandler<T> batchHandler) throws SQLException
//指定数据源dbname
public static <T> void executeBatch(String dbname,String sql,List<T> datas,int batchsize, BatchHandler<T> batchHandler) throws SQLException
加载sql配置文件的组件ConfigSQLExecutor
com.frameworkset.common.poolman.ConfigSQLExecutor
public <T> void executeBatch(String sqlname,List<T> datas,int batchsize, BatchHandler<T> batchHandler) throws SQLException
//指定数据源dbname
public <T> void executeBatch(String dbname,String sqlname,List<T> datas,int batchsize, BatchHandler<T> batchHandler) throws SQLException
批处理语句参数设置器:
package com.frameworkset.common.poolman;
/**
* 轻量级jdbc批处理操作记录设置器
*/
import java.sql.PreparedStatement;
import java.sql.SQLException;
public interface BatchHandler<T> {
/**
*
* @param stmt jdbc PreparedStatement parameterIndex the first parameter is 1, the second is 2, ...
* x the parameter value
* @param record 当前操作的变量
* @param i 行索引
* @throws SQLException
*/
public void handler(PreparedStatement stmt,T record,int i) throws SQLException;
}
使用实例
以SQLExecutor组件来做为例子介绍如下:
@Test
public void testBatch() throws SQLException {
List<Map<String,String>> datas = new ArrayList<Map<String,String>>();//构造数据
for(int i = 0; i < 100000; i ++){
Map<String,String> data = new HashMap<String, String>();
if(i % 3 == 0)
data.put("name","jack_"+i);
else if(i % 3 == 1)
data.put("name","brown_"+i);
else if(i % 3 == 2)
data.put("name","john_"+i);
datas.add(data);
}
SQLExecutor.delete("delete from batchtest");//清空表数据
//批处理执行
SQLExecutor.executeBatch("insert into batchtest (name) values(?)", datas, 10,new BatchHandler<Map<String,String>>() {
@Override
public void handler(PreparedStatement stmt, Map<String,String> record, int i) throws SQLException {
stmt.setString(1,record.get("name"));
}
});
}
分享到:
相关推荐
NULL 博文链接:https://yin-bp.iteye.com/blog/1449900
bboss es特点请访问: https://www.oschina.net/p/bboss-elastic
基于java语言比mybatis更实用的orm框架,支持mysql、oracle、postgresql、sqlserver、db2、dm、mongodb
bboss会话共享培训文档,学习bboss不可多得的资料,值得拥有。
Elasticsearch rest client bboss介绍-Elastic2018中国开发者大会演讲稿
NULL 博文链接:https://yin-bp.iteye.com/blog/2325602
NULL 博文链接:https://yin-bp.iteye.com/blog/2174863
bboss+es基本操作示例,elasticsearch,bboss,java使用demo
企业级 J2EE 开源框架:bboss
bboss-datatran 由 bboss 开源的数据采集&流批一体化工具,提供数据采集、数据清洗转换处理和数据入库以及数据指标统计计算流批一体化处理功能。
NULL 博文链接:https://yin-bp.iteye.com/blog/926166
springboot集成ElasticsearchBboss调用Elasticsearch的案例分享
官方版本,亲测可用
资源目录: 项目源码(eshelloword.rar) bboss elasticsearch开发入门教程.wmv 搭建bboss elasticsearch开发环境.wmv 说明.txt
本实例是一个基于bboss es spring boot starter的demo maven工程,可供spring boot项目集成bboss elasticsearch rest client参考 展示了通过spring boot管理单集群功能和管理多集群功能 单集群测试用例:...
NULL 博文链接:https://yin-bp.iteye.com/blog/2177475
浙江移动BBOSS系统快速入门手册V0.1归类.pdf
包含的功能有: http连接池 http服务调用组件-HttpRequestUtil http负载均衡组件-HttpRequestProxy 使用参考文档 负载均衡组件特点: 1.服务负载均衡(目前提供RoundRobin负载算法) 2.服务健康检查 3.服务容灾故障...
NULL 博文链接:https://yin-bp.iteye.com/blog/1131637