2015-03-25 65 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