English subtitles

← Saving and Viewing Profile - Developing Scalable Apps with Java

Get Embed Code
4 Languages

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

  1. Now it's time for you to add the functionality
  2. to save entities to your app. Let's see how you
  3. can achieve that. Okay. So here I'm looking at the
  4. saveProfile method in the ConferenceAPI class. If you recall, we
  5. already have the code to create a new profile.
  6. We just call new on the profile, and pass in
  7. the arguments that we need. Creating a new profile entity
  8. is as simple as calling new on the profile class.
  9. If we weren't using objectify, the code would be
  10. more complicated. You already have the code to create a
  11. new profile object, but you don't need to make
  12. any changes now that the profile has been identified as
  13. an entity. However, creating an entity doesn't automatically save
  14. it in the data store. You have to explicitly save
  15. it if you want it saved. Okay, I'm going to
  16. go ahead and add the code to save the profile
  17. entity in the data store. You're going to be writing
  18. this code yourself in your own app in just
  19. a minute. Now, I'll run the app again on
  20. local host, and go to the APIs Explorer. So
  21. here I am in the APIs Explorer and I'm
  22. going to go into the Save Profile method again.
  23. And, execute it. And have Lemon Cake as my
  24. display name. Set my TeeShirtSize to M, and execute it.
  25. Oops, I forgot to authorize. Let's try that again because that's not authorized.
  26. Authorize. Now I can execute the function again, I
  27. don't need to enter the values, just press Execute.
  28. And there it goes. It's creating my profile. And
  29. you see here, the request set the display name
  30. to Lemon Cake, T shirt size to medium to
  31. M. Response returned profile with these fields. So the
  32. response shows that the profile was created. But this
  33. time, hopefully it was more than created, it was actually
  34. saved in the data store. And we can use the data store admin to check that. So
  35. now I'm going to go to the admin console on local host. To get to the admin
  36. console, you go to the port where your app is running, which is for me that's
  37. localhost:8080. And then it's
  38. /_ah/admin and this takes us to the Datastore view. The
  39. Datastore admin for local host opens. You can see here
  40. that it doesn't know what my app ID is. Says your
  41. app ID, and that's okay, because local host doesn't care what
  42. the app ID is. Course when I when actually want to
  43. deploy to appspot I will need to provide a real app
  44. ID. The admin console opens by default showing the Datastore Viewer.
  45. But if you're somewhere else and you want to get back
  46. to the Datastore Viewer, or for some reason it doesn't open
  47. there by default, you just click this Datastore Viewer and there you are in the
  48. Datastore Viewer. This entity kind menu shows the
  49. different kinds of entities that are stored in
  50. your Datastore. Right now, the only one
  51. we've got is Profile. You'll click List Entities,
  52. to seal the entities of that kind that
  53. have already been saved. There'll probably be only
  54. one entity now, which is the profile that
  55. we just saved. So the data store viewer shows
  56. you the entities, it shows you the properties. We've
  57. got displayName, mainEmail, teeShirtSize. Okay, so that was just
  58. a quick review of how to save the entity in the data store, and how to go to
  59. the admin console on local host to look at
  60. your entities. You're going to be doing that now.