2017-12-18 170 views
0

我們使用GoogleInfo表,在該表中,我們存儲了應用程序的範圍。例如「https://www.googleapis.com/auth/drive.appdata,https://www.googleapis.com/auth/drive.file」 ,並且我試圖根據某個關鍵字(例如範圍內的「drive」)獲取結果,並根據該關鍵字獲得結果。以下是我的代碼。請建議。如何使用Google App Engine中的特定關鍵字獲取結果在Java中使用NO-SQL數據存儲區查詢?

String keywords[] = {"admin","drive","gmail","userinfo"}; 

Query query = pm.newQuery("SELECT scopes FROM com.cloudcodes.gcontrol.dataaccesslayer.insights.google.drive.GoogleInfo where :p.contains(scopes)"); 

result = (List) query.execute(Arrays.asList(keywords)); 
List tempResult = new ArrayList(); 
tempResult.addAll(result); 
return tempResult; 

回答

0

似乎你正在使用JDO [1]和PersistanceManager [2]。

就我所見,您嘗試執行的查詢可能是錯誤的。檢查如何使用JDO執行查詢[3]。

您所查詢的是:

String keywords[] = {"admin","drive","gmail","userinfo"}; 
Query query = pm.newQuery("SELECT scopes FROM com.cloudcodes.gcontrol.dataaccesslayer.insights.google.drive.GoogleInfo where :p.contains(scopes)"); 
result = (List) query.execute(Arrays.asList(keywords)); 

看起來你想要做的事,如:

//Query for all persons with lastName equal to Smith or Jones 
Query q = pm.newQuery(Person.class, ":p.contains(lastName)"); 
q.execute(Arrays.asList("Smith", "Jones")); 
Person.class is the kind 
Arrays.asList("Smith", "Jones") 

此參數 「:p.contains(lastName的)」 定義lastName的是我們想要的屬性檢查。 您正在將該類設置爲com.cloudcodes.gcontrol.dataaccesslayer.insights.google.drive.GoogleInfo,我想這是完整的Java名稱包,其中的類習慣是類名,而類名是GoogleInfo。所以你可以嘗試:

Query q = pm.newQuery(GoogleInfo.class, ":p.contains(scopes)"); 
q.execute(Arrays.asList("admin","drive","gmail","userinfo")); 

你想檢索範圍。我假設你想使用REST API。所以在裏面:p.contains(「scopes」)可能會去與您想要檢索的實體中的keyWords相關的另一個屬性,也許是數組屬性?

在這裏,我與大家分享一些可能有用的文檔[4] [5]。

希望這會有所幫助!

[1] https://cloud.google.com/appengine/docs/standard/java/datastore/jdo/overview-dn2

[2] http://massapi.com/method/javax/jdo/PersistenceManager.newQuery-4.html

[3] https://cloud.google.com/appengine/docs/standard/java/datastore/jdo/queries

[4] https://cloud.google.com/datastore/docs/concepts/overview#comparison_with_traditional_databases

[5] https://cloud.google.com/datastore/docs/reference/gql_reference

相關問題