Reputation: 319
I need to change a fair amount of entities belonging to different entity groups. If I do a non-ancestor query, sorted by key, like:
Query query = new Query( "Kind" )
.setFilter( ... )
.addSort( Entity.KEY_RESERVED_PROPERTY, ASC or DESC );
Will I always have a result ordered by entity-groups? I am planning to iterate through the result until the parent (or grand-parent) key changes, and create a single transaction for all the entities in the same group - to avoid contention.
Will this work as expected? Any other suggestion?
Thank you.
Upvotes: 2
Views: 123
Reputation: 101149
Yes. Sorting by keys orders them by each entity in the ancestor list in order - eg, first by root entities, then by their children, and so forth.
Upvotes: 1
Reputation: 16825
Kindles Queries or Ancestor Queries can only be sorted by KEY.
You are sorting by key and that is ok.
The key is a result of the PARENT+KIND+ID
Each Kind's keys is a part of the KEY. So all your results will be sorted by kind, and then by key.
From GAE KEYS
Every model instance has an identifying key, which includes the instance's entity kind along with a unique identifier. The identifier may be either a key name string, assigned explicitly by the application when the instance is created, or an integer numeric ID, assigned automatically by App Engine when the instance is written (put) to the Datastore.
Upvotes: 0