views:

74

answers:

1

I just need to change order of items in a (previously persisted) ordered collection...

I tried simply passing the re-arranged collection to a setter: after committing a transaction the collection is gone.
Then I tried to clear() the existing collection and addAll() afterwards: clear() makes persistent manager to mark all the elements as deleted. (But obviously I would like to be able to work with the collection items in the very transaction.)

(The collection is not in a default fetch group, so I tried the above also with the named fetch group added into the fetch plan. No luck.)

This must be the most stupid question, but I ran out of ideas and I'm stuck here two days already. I swear I googled. :(

+1  A: 

The order of the data is set in an index. Unfortunately, the functionality to delete or reset the index is not currently there (http://stackoverflow.com/questions/2465195/how-to-delete-indexes-in-google-app-engine-java.

It may be possible to dynamically change the index, however. Take a look at http://rahulswackyworld.blogspot.com/2010/03/dynamic-indexes-with-google-app-engine.html.

Matthew Flynn
Thank you. As long as it helps it will have to do, even though it sounds kinda weird that no one needed to change order of items in a collection.I'm using Java though, and given the linked solution works with Python it might not be that easy for me to implement. So, I was just thinking, do you think it makes even any sense to delete the parent object and re-create it with the collection-property re-arranged? (Other than that it would remain unchanged, identical key including.)
Jaroslav Záruba
That might do it. Theoretically, it's an awful idea, but practically, it would probably work. The problem seems to be that google-data-store over simplifies collection relations and doesn't give an obvious way to vary the query that reads them (you should be able to use an order by in a query to get the collection in a given order, but this doesn't auto-wire nicely.
Matthew Flynn
Yes, awful, I agree. I won't go that way anyways. Well, given I can't get official word from Google on this I think you gave me the answer.Thanks for your time, Matthew.
Jaroslav Záruba