使用Java协议缓冲区的批量Google数据存储区查询

时间:2015-03-25 09:30:44

标签: java google-app-engine google-cloud-datastore

有人可以告诉我如何使用协议缓冲区在Java中执行批量/多数据存储查询。

Python有批量获取和放置。但是如何在Java中使用?

1 个答案:

答案 0 :(得分:-1)

适用于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