栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Datastax Java驱动程序中使用异步/批量写入功能

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Datastax Java驱动程序中使用异步/批量写入功能

对于异步,它就像使用

executeAsync
函数一样简单:

...DatastaxConnection.getSession().executeAsync(query);

对于批处理,您需要构建查询(我使用字符串,因为编译器知道如何很好地优化字符串连接):

String cql =  "BEGIN BATCH "       cql += "INSERT INTO test.prepared (id, col_1) VALUES (?,?); ";       cql += "INSERT INTO test.prepared (id, col_1) VALUES (?,?); ";       cql += "APPLY BATCH; "DatastaxConnection.getInstance();PreparedStatement prepStatement = DatastaxConnection.getSession().prepare(cql);prepStatement.setConsistencyLevel(ConsistencyLevel.ONE);// this is where you need to be careful// bind expects a comma separated list of values for all the params (?) above// so for the above batch we need to supply 4 params:          BoundStatement query = prepStatement.bind(userId, "col1_val", userId_2, "col1_val_2");DatastaxConnection.getSession().execute(query);

附带一提,假设您将属性更改为映射列表,其中每个映射表示批处理中的更新/插入,我认为您对语句的绑定可能类似于以下内容:

BoundStatement query = prepStatement.bind(userId,         attributesList.get(0).values().toArray(new Object[attributes.size()]),          userId_2,         attributesList.get(1).values().toArray(new Object[attributes.size()]));


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570426.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号