2
我正在阅读应用程序引擎中的密钥生成文档。我不确定使用简单的字符串键会对真正的键产生什么影响。例如,当我的用户注册,他们必须提供一个唯一的用户名:使用未编码密钥与真实密钥,好处?
class User {
/** Key type = unencoded string. */
@PrimaryKey
private String name;
}
现在如果我理解正确的文档,我还是应该能够生成使用此命名键和实体组,右?:
// Find an instance of this entity:
User user = pm.findObjectById(User.class, "myusername");
// Create a new obj and put it in same entity group:
Key key = new KeyFactory.Builder(
User.class.getSimpleName(), "myusername")
.addChild(Goat.class.getSimpleName(), "baa").getKey();
Goat goat = new Goat();
goat.setKey(key);
pm.makePersistent(goat);
山羊实例现在应该是相同的实体组作为用户,对不对?我的意思是把用户的主键只留作原始字符串没有问题?
尽管使用密钥有没有性能优势?我应该更新:
class User {
/** Key type = unencoded string. */
@PrimaryKey
private Key key;
}
// Generate like:
Key key = KeyFactory.createKey(
User.class.getSimpleName(),
"myusername");
user.setKey(key);
它几乎同样的事情,我仍然只是采用独特的用户名无论如何生成密钥,
感谢
我现在看到了,谢谢。 – user246114 2010-04-29 04:37:26