我如何在Google Datastore的单个查询中使用两个.contains。 我的代码:
Query query = pm.newQuery("SELECT DISTINCT actualUserEmail FROM packageName :p.contains(actualUserEmail) && :p.contains(OrgUnitPath)");
result = (List) query.executeWithArray(Arrays.asList(data),Arrays.asList(test));
System.out.println("result ="+result.size());
List tempResult = new ArrayList();
tempResult.addAll(result);
return tempResult;
我只获得第一个包含结果。我如何在单个查询中使用两个包含。
答案 0 :(得分:0)
示例看起来像:
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Filter property1Filter = new FilterPredicate("property1", FilterOperator.EQUAL, value1);
Filter property2Filter =new FilterPredicate("property2", FilterOperator.IN, valueList1);
Filter property3Filter =new FilterPredicate("property3", FilterOperator.IN, valueList2);
Filter compositeFilter= CompositeFilterOperator.and(property1Filter, property2Filter);
compositeFilterExtended=CompositeFilterOperator.and(compositeFilter, property3Filter);
com.google.appengine.api.datastore.Query gaeQuery = new Query("DatastoreKind").setFilter(compositeFilterExtended);
PreparedQuery pq = datastore.prepare(gaeQuery);
List<Entity> entities = pq.asList(FetchOptions.Builder.withDefaults());
return entities;
希望这有帮助。
答案 1 :(得分:0)
我得到了答案我做了一个改变p&amp;查询中的p1工作正常。
Query query = pm.newQuery("SELECT DISTINCT actualUserEmail FROM packageName :p.contains(actualUserEmail) && :p1.contains(OrgUnitPath)");
result = (List) query.executeWithArray(Arrays.asList(data),Arrays.asList(test));
System.out.println("result ="+result.size());
List tempResult = new ArrayList();
tempResult.addAll(result);
return tempResult;