網頁

2014年1月31日 星期五

GAE Java - DatastoreService Set Parent-Child

Last Update: 2014/02/01 00:01+08
Type:Note

DatastoreService gaeDatastore = DatastoreServiceFactory.getDatastoreService();

Entity user = gaeDatastore.get(KeyFactory.stringToKey("aglzaG9wc21lbnVyEwsSBlNtVXNlchiAgICAgICoCgw"));
Entity userEMail = gaeDatastore.get(KeyFactory.stringToKey("aglzaG9wc21lbnVyGAsSC1NtVXNlckVNYWlsGICAgICAgKgJDA"));

userEMail.setProperty("relUser", user.getKey());
gaeDatastore.put(userEMail);

@SuppressWarnings("unchecked")
Collection emailList = (Collection) user
  .getProperty("relSetUserEMail");
if(emailList == null) emailList = new ArrayList();
emailList.add(userEMail.getKey());
user.setProperty("relSetUserEMail", emailList);
gaeDatastore.put(user);



沒有留言:

張貼留言