How does the appengine datastore (java - JDO) store and return data, i.e. is it FIFO or LIFO? If its FIFO or NEITHER, how can I make it LIFO?
I was just wondering if I store some data chronologically, will it be returned back in the order of most-recent to least-recent OR least-recent to most-recent? For e.g. If I input data in the following order: A[1], B开发者_Python百科[2], ...
, if I do a simple select
query of the table, will it return the list as {A, B, ...}
or {..., B, A}
? Assume that I haven't set any indexes i.e. indexing is automatically set by appengine. A critical part of my system's design depends on this information, so I want to confirm this information before I proceed. Any help will be highly appreciated. I need the data retrieval to be in LIFO format, how can I ensure this?
- FIFO - first in first out
- LIFO - last in first out
I'm pretty sure that the app engine datastore doesn't specify any guaranteed order, and that the persistence framework you use (JPA? JDO?) doesn't either. So if it's critical, then store a timestamp along with every data you insert, and add an order by
clause to your queries to make sure you retrieve the objects in the appropriate order.
If you don't specify a sort order, data will be returned sorted by key. If you haven't specified key names, the ordering of the keys will be by their numeric IDs, which are generally increasing but monotonicity is not guaranteed because of the way IDs are allocated among running instances. If you need to guarantee a specific ordering, store a timestamp and order on that property.
The default sort order for entities returned by App Engine - if you don't specify another one - is first by any inequality you've filtered on, then by key. If you want to order by date, you should include a date field and sort on it explicitly.
It's perfectly valid to filter on a field of an entity in a keys_only query.
精彩评论