2015-03-25 61 views
-1

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

Python已批量获取和放置。但如何在Java?

+0

它在Java文档。放入并允许传递一个键或一个数组。 – 2015-03-25 14:02:19

+1

它确实取决于您用来访问数据存储的框架,您打算使用Objectify(我推荐),JDO,JPA吗? – jirungaray 2015-03-25 14:29:15

+0

我已经用Protocol Buffers写了很多代码...... bcoz在很多例子中都使用了它们。但是在这个库中找不到这样做的方法。重新编写代码是一场噩梦! – Oru 2015-03-25 15:40:36

回答

-1

Cloud Client Library for 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

而且Docs- https://github.com/GoogleCloudPlatform/google-cloud-java