【发布时间】:2010-08-11 18:10:09
【问题描述】:
我有以下数据模型:
class StadiumOccupant {
String stadiumname;
String username;
}
class Friend {
String username;
String friendname;
}
我想找到体育场内所有同时也是我朋友的用户。我可以这样做:
List<String> friendsAtStadium;
String stadiumId = 'xyz';
List<Friend> friends = select from Friend where username = 'me';
for (Friend friend : friends) {
List<StadiumOccupant> friendAtStadium =
select from StadiumOccupant where
stadiumname = stadiumId and
username = friend.friendname;
friendsAtStadium.addAll(friendAtStadium);
}
这适用于非常少量的对象。一旦用户拥有多个朋友,这将不起作用。应用引擎上有解决方案吗?我想不出一个表现好的。
谢谢
--------一些示例数据--------
Friend { john, tim }
Friend { john, mary }
Friend { mary, frank }
StadiumOccupant { abc, tim }
StadiumOccupant { abc, frank }
StadiumOccupant { abc, kim }
所以如果我是用户“john”,我的朋友是:{ tim, mary }。 如果我使用 Stadiumname='abc' 运行体育场查询,我应该返回 { tim }。
【问题讨论】:
-
您可以更改数据建模吗?
-
username = friend.getUsername();username = friend.getFriendName();,因为friend.getUserName()将永远是“我”,因为friend是friends的一个元素,您之前通过过滤选择了它username = "me"? -
@Edward:是的,我可以更改建模,我正在尝试找出是否有任何可能的方法,可以是任何方法。
-
@Andrei:你是对的,修正了那个错字。
-
一个人一次可以在多个体育场内吗? “体育场占用”可能是用户的财产。或者,我猜更准确地说,是人实体的子实体?
标签: java google-app-engine bigtable