obelloc
obelloc

Reputation: 319

When doing a non ancestor query with a sort by key, will my result be ordered by entity groups?

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

Answers (2)

Nick Johnson
Nick Johnson

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

Jimmy Kane
Jimmy Kane

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

Related Questions