English subtitles

← Updating Profile Entities - Developing Scalable Apps with Java

Get Embed Code
4 Languages

Showing Revision 5 created 05/24/2016 by Udacity Robot.

  1. When you save an entity with a key, it creates a new
  2. entity in the data store with that key. As you found out
  3. earlier, this creates a key conflict. If an entity with that key
  4. already exists, it is out of luck and it gets chucked out.
  5. It's overwritten in the data store. So if you want to update
  6. an existing entity, first you need to get it out of the
  7. data store, then you make your updates and then you save it
  8. back into the data store again. So back here in the save profile
  9. method of that conference API, whenever we've been saving our
  10. profile the first thing we do is create a new
  11. profile with the user ID. That means that actually every
  12. time you update your profile, you're not really updating it,
  13. you'll create a new profile entity which overrides the existing
  14. profile entity. You can see how that plays out in
  15. the API Explorer. Now that we've implemented get profile, we
  16. can just call get profile to get the existing profile
  17. for the current user. So lets do that. Okay. Lets see, so my display name
  18. is "Chocolate Cake" and my t-shirt size is XL. Now, lets say I want to
  19. change that, I want to change my t-shirt size, so I go to
  20. saveProfile and the only thing I want to do is to change my
  21. t-shirt size from XL to XS, extra small, this time.
  22. Now we'll execute. And what would be really nice,
  23. would be that the only thing that changes it
  24. the t-shirt size. So let's see if it will
  25. happen. But, no, that's not what happens. You see
  26. how the display name gets set back to the
  27. default, which is example and my t-shirt size did
  28. change. What should really happen, the saveProfile method should
  29. get the existing profile and only update the fields that
  30. have changed. So that's going to be your next task.