[英]GAE Datastore - query filter on nested class
I'm using Java & GAE datastore to store, manage and retrieve some data for my application. 我正在使用Java和GAE数据存储来存储,管理和检索我的应用程序的一些数据。
Basically I have two classes: Customer and Store. 基本上我有两个类:Customer和Store。 The idea is that one customer can have more than one store associated, and many customers can exist.
这个想法是,一个客户可以关联多个商店,并且可以存在许多客户。
The structure of a customer is something like this: 客户的结构是这样的:
<Customer>
<id>id1</id>
<Stores>
<Store>
<storeId>100</storeId>
<city>Venice</city>
</Store>
<Store>
<storeId>200</storeId>
<city>Milan</city>
</Store>
<Store>
<storeId>300</storeId>
<city>Venice</city>
</Store>
</Stores>
</Customer>
As I said before, there can be MANY customers: 正如我之前所说,可能有很多客户:
<Customers>
<Customer>
...
</Customer>
<Customer>
...
</Customer>
</Customers>
I need to build a filter to get only a portion of these customers, passing to a query a "CITY" parameter: For example, if I want to show Customers that has at least one Store located in Venice, I would do something like ( just to give you the idea) 我需要构建一个过滤器来获取这些客户的一部分,将查询传递给“CITY”参数:例如,如果我想要显示至少有一个位于威尼斯的商店的客户,我会做类似的事情(只是为了给你这个想法)
GET Customer WHERE Customer.Store.City = 'Venice'
What I'd like to get is every Customer that has a Store located in a particular city.. but also, the Customer Object needs to have those stores! 我想得到的是每个客户都有一个位于特定城市的商店..而且,客户对象需要拥有这些商店! like this:
像这样:
<Customer>
<id>id1</id>
<Stores>
<Store>
<storeId>100</storeId>
<city>Venice</city>
</Store>
<Store>
<storeId>300</storeId>
<city>Venice</city>
</Store>
</Stores>
</Customer>
<Customer>
<id>id2</id>
<Stores>
<Store>
<storeId>700</storeId>
<city>Venice</city>
</Store>
</Stores>
</Customer>
I can get those stores correctly, but I need to find a way to connect every store to his ancestor customer.. 我可以正确地获得这些商店,但我需要找到一种方法将每家商店连接到他的祖先客户。
String city = 'something';
Query query = mgr.newQuery(Store.class, "city == '"+city+"' ");
List<Store> oggetti = (List<Store>) query.execute();
Any idea on how to do this? 有关如何做到这一点的任何想法?
I hope I was clear enough.. thanks in advance, best regards 我希望我足够清楚......先谢谢,最诚挚的问候
Additional info: 附加信息:
class Customer: 班级客户:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Cacheable("false")
@FetchGroup(name="customerstores", members={@Persistent(name="storeList")})
public class Customer {
@PrimaryKey
@Persistent
private String id= "";
@Persistent
@Unowned
private List<Store> storeList;
//getters and setters here
....
}
Class Store: 类商店:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Cacheable("false")
public class Store {
@PrimaryKey
@Persistent
private String storeUniqueKey = "";
@Persistent
private String city = "";
//getters and setters here
....
}
See if following code could fit your requirement. 看看以下代码是否符合您的要求。
Query query = pm.newQuery(Customer.class);
query.declareVariables("Customer store");
query.setFilter(
"this.stores.contains(store) && store.city == \"SomeCity\"");
Collection result = (Collection)query.execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.