【发布时间】:2016-03-16 14:33:53
【问题描述】:
所以基本上我想得到一个人所在的商店?这是商店的 Pojo 代码;
@Entity
public class Store{
@Id
Long StoreId;
String Name;
String Address;
@Index List<Key<Person>> Members;
private House() {
}
public Store(Long StoreId ,String Name, String Address) {
StoreId = StoreId;
this.Name = Name;
this.Address = Address;
Members = new ArrayList<Key<Person>>();
}
public Long getId() {
return StoreId;
}
public String getName() {
return Name;
}
public void setName(String name) {
this.Name = name;
}
public String getAddress() {
return Address;
}
public void setAddress(String postcode) {
this.Address = Address;
}
public void AddToStore(Key<Person> person) {
Members.add(person);
}
这是创建商店并添加当前登录用户(Google 登录)的代码
/**
* Inserts a new {@code Store}.
*/
@ApiMethod(
name = "insert",
path = "Store",
httpMethod = ApiMethod.HttpMethod.POST)
public House insert(User user) throws UnauthorizedException {
if (user == null){
throw new UnauthorizedException("You need to authorisation");
}
String tempName = "cottages";
String tempAddress = "Gogoland";
String userId = user.getUserId();
Key<Person> personKey = Key.create(Person.class, userId);
final Key<Store> storeKey = OfyService.factory().allocateId(Store.class);
final Long StoreId = storeKey.getId();
Store h = new Store(StoreId , tempName,tempAddress);
h.AddToStore(personKey);
ofy().save().entity(h).now();
logger.info("Created Store.");
return ofy().load().entity(h).now();
}
所以如您所见,Store 与 person 之间的关系是一对多的。所以我希望能够获取登录用户的当前房屋,然后检索对象中的其他“人”/成员实体。此外,我还希望在与当前用户相同的商店中检索“Person”实体的“孩子”。
此外,如何通过电子邮件邀请其他人加入用户商店?
感谢任何帮助。
【问题讨论】:
-
修改了问题,使其更清晰。非常感谢任何帮助:-)
标签: java android google-app-engine google-cloud-datastore objectify