谁能告诉我如何使用协议缓冲区在Java中执行批量/多个数据存储区查询。
Python具有批量获取和放置的功能。但是如何用Java?
适用于Java的Cloud Client Library解决了我所有的问题。
Datastore datastore;
DatastoreOptions options = DatastoreOptions.newBuilder().setProjectId("yourprojectID").setCredentials(GoogleCredentials.fromStream( new FileInputStream("localKeyFile.json"))).build();
dataStore = options.getService();
List<Key> queryKeys = new ArrayList<>();
Key key = datastore.newKeyFactory().setKind("SomeKind").newKey(1234L);
queryKeys.add(key);
// Add more keys if you need to the List..then start query!
Iterable<Key> keyIterable = queryKeys;
List<Entity> entities = null;
// Get Results
entities = dataStore.fetch(keyIterable);
请参阅以下指向下载库和文档的链接。
请投票并享受!
http://googlecloudplatform.github.io/google-cloud-java/0.21.1/index.html
和文档-https ://github.com/GoogleCloudPlatform/google-cloud-java
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句