Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Implicit and Explicit Keys - Developing Scalable Apps with Java

Get Embed Code
6 Languages

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

  1. Welcome back. I hope that exercise went great.
  2. Now, let's talk about another important Datastore concept,
  3. keys. When you store an entity in the
  4. Datastore, the Datastore will assign a key to
  5. it. This key uniquely identifies the entity and
  6. it's used for many different purposes. They are
  7. two ways a key can be generated. Let's take a look. The first one is when
  8. Datastore automatically generates this key. Let's say we
  9. define the profile kind with these properties. And inserted
  10. it for the first time. In this case, the
  11. Datastore will automatically assign a key value to it.
  12. The other way is that you specify what is called a key name or ID. In this case,
  13. Datastore will use that value to generate the key.
  14. This is a good alternative when you have something
  15. that is unique for each entity. Because it can clearly
  16. take us to our front entity based on this value
  17. so it's easier to find. But observe that statement. The
  18. Keyname/ID must be unique for all entities of that kind. For
  19. our profile kind that is exactly the case because we
  20. have decided to use the user ID to to uniquely
  21. identify each profile identity. The value of having user ID
  22. as the key name is that we can retrieve the profile
  23. entity directly using this value. And remember, since the
  24. user object is the first parameter to cloud endpoints API
  25. methods. It will become a convenient way to get
  26. the profile, but we'll look more into this later. If
  27. you are familiar with relational database modeling, you probably
  28. see that this is very similar to the concept of
  29. a primary key. There, as well as with Datastore,
  30. you have the option of letting the database generate the
  31. primary key or use the value of your choice.
  32. But now, it's for you to do some work