【问题标题】:Bulk Google Datastore Queries using Java Protocol Buffers使用 Java 协议缓冲区批量 Google 数据存储区查询
【发布时间】:2015-03-25 09:30:43
【问题描述】:

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

Python 具有批量获取和放置功能。但是如何在 Java 中实现呢?

【问题讨论】:

  • 它在 java 文档中。放置和获取允许传递单个键或数组。
  • 这真的取决于您用于访问数据存储的框架,您是否打算使用 Objectify(我推荐)、JDO、JPA?
  • 我已经使用 Protocol Buffers 编写了很多代码......因为 Google 在许多示例中都使用了它们。但是在这个库中找不到这样做的方法。重新编写代码是一场噩梦!

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


【解决方案1】:

Java 的云客户端库解决了我所有的问题。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 2010-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多