You'll need an index no matter what, as if you did this, you'd need Key
descending. Note that this may not be exact insert order but it'll be pretty
close. This seems to save an index, though, as doing it another way requires
both ascending and descending indexes.

On Wed, Jul 21, 2010 at 5:52 AM, Mark <[email protected]> wrote:

> Hi,
>
> I'm creating records of a user's actions. When I fetch these records,
> I only ever want them sorted in reverse chronological ordering (the
> order they were inserted into the datastore). Does app engine by
> default return records in this order? I'm trying to avoid having to
> keep an extra index on timestamp to reduce the number of indexes I
> use. Example (in java):
>
>    class Action {
>        @PrimaryKey
>        @Extension(vendorName="datanucleus", key="gae.encoded-pk",
> value="true")
>        private String usernameOwner;
>
>        @Persistent
>        long timestamp;
>    }
>
>    public void userActionPerformed(PersistenceManager pm) {
>        pm.makePersistent(new Foo("myusername",
> System.currentTimeMillis());
>    }
>
>    public void getRecords(String username) {
>        String stmt = "SELECT FROM " + Action.class.getName() + "
> WHERE usernameOwner = '" + username + "'";
>        Query q = pm.newQuery(stmt);
>        q.setOrdering("timestamp desc"); // want to avoid this.
>
>        return (List<VRec>)q.execute();
>    }
>
>    // desired html: //
>    You performed a foo action on July 21 at 4:22pm!
>    You performed a boo action on July 21 at 3:21pm!
>    You performed a goo action on July 19 at 9:42pm!
>    ...
>
> so, it would be great if I don't have to index on the timestamp - just
> get the records back in the order I inserted them - possible?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
Blog: http://googleappengine.blogspot.com
Twitter: http://twitter.com/app_engine
Reddit: http://www.reddit.com/r/appengine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to