From GAE's documentation, I can read this:
The entity's kind is derived from the simple name of the class (inner classes use the $ path without the package name).
which does not tell me how to store it, and this:
Here is an example of an embedded class. This example makes the embedded class an inner class of the data class that uses it; this is useful, but not required to make a class embeddable.
Why is it useful? What is the advantage of making the class "embedded"? How would I proceed if I do not need to "embed" it? I'm having a hard time understanding this last statement.
Let's say I have this class:
@PersistenceCapable
public class ChatHistory {
开发者_C百科 @PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private ArrayList<Message> messages;
// more fields and all the ChatHistory methods here
private class Message implements Comparable<Message>{ // <-- This one
public String timeStamp;
public String text;
// more fields and all the Message methods here
}
}
How would you store it?
The most obvious thing would be to make Message
into a static class (the idea of trying to persist non-static classes makes my head hurt) and to annotate it with @PersistenceCapable
. That will then cause it to be turned into its own table. You might be best advised to move it into its own file (and change it to 'package private') instead.
Objectify — a convenient datastore interface builded on top of GAE — defines @Embedded for this kind of situation. If you don't have look for this kind of tool yet, it seems to be a good opportunity. If you do and prefere the low-level API, I cannot help you any further.
精彩评论