views:

21

answers:

1

Hi,

I have a rather large class stored in the datastore, for example a User class with lots of fields (I'm using java, omitting all decorations below example for clarity):

@PersistenceCapable
class User {

    private String username;
    private String city;
    private String state;
    private String country;
    private String favColor;
}

For some user queries, I only need the favColor property, but right now I'm doing this:

SELECT FROM " + User.class.getName() + " WHERE username == 'bob'

which should deserialize all of the entity properties. Is it possible to do something instead like:

SELECT username, favColor FROM " + User.class.getName() + " WHERE username == 'bob'

and then in this case, all of the returned User instances will only spend time deserializing the username and favColor properties, and not the city/state/country properties? If so, then I suppose all the other properties will be null (in the case of objects) or 0 for int/long/float?

Thank you

+1  A: 

No, this isn't possible with the App Engine datastore; your entire entity is stored in a protocol buffer and must be deserialized together.

If you have really large properties that aren't often needed, it's probably a good idea to put these in a separate model, although if you're really talking about just 3 strings it's almost certainly not worth the effort.

Wooble
Argh I'm confused, I'm reading this (http://code.google.com/appengine/docs/java/datastore/relationships.html): "Child objects are loaded from the datastore when they are accessed for the first time. If you do not access the child object on a parent object, the entity for the child object is never loaded. If you want to load the child, you can either "touch" it before closing the PersistenceManager (e.g. by calling getContactInfo() in the above example) or explicitly add the child field to the default fetch group so it's retrieved and loaded with the parent."
Couldn't fit all in above comment - so we can't explicitly do the SELECT field syntax, but we can get a similar effect by following the rule above and structuring our classes smartly? Thanks!