費用対効果の高いエンティティ設計のチュートリアルはありますか?
小さなサンプルを作成して、 usersとgroupsを保存したいとします。これらのグループには、ユーザーのリストがあります。ユーザーがこのグループに参加したい場合は、このグループが存在するかどうか、ユーザーがグループに属していないかどうかを確認する必要があります。
私の質問は、これを行う方法ではありません。問題は、優れたエンティティ設計または優れたオブジェクト化の使用です。
これを行う方法を短縮したサンプルコードを次に示します。
ユーザー.java
@Entity
@Cache
@Embed
public class User {
@Id Long id;
@Index String name;
String passwordHash;
}
Group.java
@Entity
@Cache
public class Group {
@Id Long id;
@Index Long groupAdministratorUserId;
@Index String name;
List<User> users = new ArrayList<User>();
@Index Boolean isPublic;
}
使用して
if (!app.authenticate(getRequest(), getResponse()))
{
// Not authenticated
setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
}
else
{
Group newGroup = ofy().load().type(Group.class).id(Long.parseLong(id)).now(); // is it correct that the embedded data is already loaded?
// following check and insert is only for illustration!
newGroup.getUsers().contains(connectedUser);
newGroup.getUsers().add(connectedUser);
ofy().save().entity(newGroup).now();
}
私の「オーバーヘッド」(認証)
public class MyVerifier extends LocalVerifier {
private User fetched;
public User getFetched() {
return fetched;
}
@Override
public char[] getLocalSecret(String identifier) {
// this is behind search... and another list()
// User fetched = ofy().load().type(User.class).filter("name", userName).first().now();
fetched = User.searchByExactName(identifier);
if (fetched != null)
{
return fetched.getPasswordHash().toCharArray();
}
return null;
}
}
PS Google のページを知っています: https://code.google.com/p/objectify-appengine/wiki/BestPractices
しかし、それは私が探しているものではありません