1

I'm working with the low-level datastore API. I've created an entity like this:

Entity entity = new Entity("Error");
entity.setProperty("description", "foo");

In the datastore viewer, I ses this:

Key        Write Ops   ID/Name    description
----------------------------------------------
ahN0c...   4           259        foo

So the ID/Name field will be generated for me automatically since I'm not supplying anything in the Entity constructor. It generates an "ID" instead of a "Name", which is a number rather than an opaque string (like the "Key" value).

Is there a way to have the datastore generate a random "Name" instead of an "ID" for the Entity's "ID/Name" field?

I ask because if I share this ID with third parties, they could start to figure out roughly how many Error instances I have in my system. I'd rather give them an opaque string for the lookup ID, similar to what's in the auto-generated "Key" field. But I don't see a way to do this.

Thanks

girasquid
  • 15,121
  • 2
  • 48
  • 58
user291701
  • 38,411
  • 72
  • 187
  • 285
  • 1
    Witht he new SDK, and upcoming appengine release the ID numbering is going to be sparse (ie really big numbers in no specific order) so there is no way someone could infer quantity from that. IN the current SDK my id's are like 6042986275001073664, 5241627016305836032 – Tim Hoffman May 01 '13 at 23:22

2 Answers2

2

For a similar task I used UUID to create a random string.

String uuid = UUID.randomUUID().toString();
Devolus
  • 21,661
  • 13
  • 66
  • 113
0

You can use com.google.appengine.api.datastore.KeyFactory, combining the answer from @Devolus, it would look like

final Key key = KeyFactory.createKey("Error", UUID.randomUUID().toString());
final Entity e = new Entity(key);

You could even pass around the String representation of your Entitie's key via KeyFactory.keyToString(key) , may be after an encrypting depending on your security needs.

skywalker
  • 415
  • 3
  • 9