使用 Spring Data 对 Google Cloud 数据存储条目进行批量部分更新的有效方法
我在Google DataStore中有一种有数以万计的条目。我正在使用弹簧数据连接并在数据存储器上工作。我正在尝试在数据存储上更新一个(数百个)行的一个实体。
我试图使用的方法具有分页率,并更新所需的属性,并使用datastoreRepo.saveall(列表)保存所有条目,然后重复直到可用于查询条件的行。 Something like :
void partialUpdateSomething () {
List<Trains> trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50));
while (!trains.isEmpty()) {
for(Train t:trains) {
train.isRunning(true); // updating isRunning to true
}
repo.saveAll(trains); // saving all the updated train objects
trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50));
}
}
Is there a better way to update just one or more entities ?
I have a kind in google datastore with tens thousands of entries. I am using spring data to connect to and work on the datastore. I am trying to update one entity on a few (hundreds) rows on datastore.
The method I am trying to use does multiple gets with pagination and update the required attribute and saves all entries using dataStoreRepo.saveAll(list) and repeat until there are rows available for the query criteria.
Something like :
void partialUpdateSomething () {
List<Trains> trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50));
while (!trains.isEmpty()) {
for(Train t:trains) {
train.isRunning(true); // updating isRunning to true
}
repo.saveAll(trains); // saving all the updated train objects
trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50));
}
}
Is there a better way to update just one or more entities ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论