开发者

App engine datastore and Java low-level api: fetch multiple entities by its ids

开发者 https://www.devze.com 2022-12-15 11:31 出处:网络
I\'m with app engine and using the java low level api, and I want to retrieve a group of enti开发者_如何学Cties having its ids. What\'s the way to do so? I could fetch one by one but there must be a b

I'm with app engine and using the java low level api, and I want to retrieve a group of enti开发者_如何学Cties having its ids. What's the way to do so? I could fetch one by one but there must be a better way.

Thanks!


I think you're looking for this method, specifically in the following overload:

java.util.Map<Key,Entity> get(java.lang.Iterable<Key> keys)

to which you pass any iterable collection of Keys and get back a map from those keys (more precisely, the subset of those keys that do correspond to entities) onto the corresponding entities. (To make a Key from an id you use a KeyFactory -- various createKey overloads, depending on parent or no parent). Back to get, there's a transactional overload for it too, if you do need to work in a transaction.

0

精彩评论

暂无评论...
验证码 换一张
取 消