asolfre / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Request for incremental ids using something like @IdIncremental #177

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm requesting an enhancement, since upgrading to GAE 1.8, @Id returns 
scattered ids that are enormous and not suitable for using on the UI, 
converting to HexaTriDecimal makes the ids slightly shorter, but they are still 
enormous when a client needs to read it out over the phone.

Also see: 
http://stackoverflow.com/questions/19152016/incremental-ids-on-objectify/1915223
8

Original issue reported on code.google.com by Jan.Most...@gmail.com on 3 Oct 2013 at 9:54

GoogleCodeExporter commented 9 years ago
Please change type to enhancement and not defect.

Original comment by Jan.Most...@gmail.com on 3 Oct 2013 at 9:55

GoogleCodeExporter commented 9 years ago
This is the behavior of the low-level API. AFAICT, there's no configuration 
option available to change that. This is really an issue to be filed in GAE's 
issue tracker. If that facility becomes available, we can reopen this issue.

Objectify could manually pick values for you - but then, you could too. In 
fact, that's what I do - I almost always allocate ids in the constructor, which 
is far more useful than relying any any sort of low-level generation scheme. 
The advantage of doing it yourself is that your entities always have ids and 
thus wiring up relationships is easier.

Original comment by lhori...@gmail.com on 3 Oct 2013 at 2:45

GoogleCodeExporter commented 9 years ago
In retrospect, I'll leave this as an enhancement request in the backlog... It's 
a legitimate feature request. Not my favorite though; I generally prefer to 
follow the expected behavior of the low level api.

Original comment by lhori...@gmail.com on 3 Oct 2013 at 3:07

GoogleCodeExporter commented 9 years ago
This might be a stupid question, but how to you get incremental ids to pass to 
the constructor without getting into a situation where two entities are given 
the same id? 
Are you using some sort of singleton / static counter somewhere that increments 
every time you create a new instance of the object?
How do you initialize that counter and is it thread-safe to do it like this?

Original comment by Jan.Most...@gmail.com on 3 Oct 2013 at 3:07

GoogleCodeExporter commented 9 years ago
See ObjectifyFactory.allocateIds(), which just calls through to 
DatastoreService.allocateIds().

That uses the old-style incremental id generation.

Original comment by lhori...@gmail.com on 3 Oct 2013 at 3:11

GoogleCodeExporter commented 9 years ago
Thanks a million!

Original comment by Jan.Most...@gmail.com on 3 Oct 2013 at 3:12

GoogleCodeExporter commented 9 years ago
I just tried DatastoreService.allocateIds() and it did give me incremental 
ID's, but not sequential.  For example, for my first 3 allocations (for a 
single Kind) I got:

32001
42001
42002

I had been hoping to use incremental ID's such that I could use an array 
(rather then a sparsearray) to hold the entities on my client.

Also, note this issue with the allocator:
https://code.google.com/p/googleappengine/issues/detail?id=4919
(I don't believe this was a factor in my testing.)

I find it hard to imagine that ofy could implement their own allocator without 
some associated cost.

Original comment by t...@malcolmson.ca on 1 Nov 2013 at 7:13

GoogleCodeExporter commented 9 years ago
Yep, they're not sequential, but it's better than those massive ids it used to 
generate.

Original comment by Jan.Most...@gmail.com on 1 Nov 2013 at 7:19

GoogleCodeExporter commented 9 years ago
I'm not getting incremental ids using ObjectifyFactory.allocateIds() ..I'm 
getting random ids. Could anyone confirm?

Original comment by michaelt...@gmail.com on 25 Mar 2014 at 11:54