-
Notifications
You must be signed in to change notification settings - Fork 160
AnnotationReference
Jim Morrison edited this page Feb 5, 2024
·
5 revisions
@Cache(expirationSeconds=600)
@Entity(name="Emp")
@Index // or @Unindex sets default for fields in class; if neither specified, default is @Unindex
class Employee {
@Id long id;
@Parent Key<Company> employer;
@Unindex int vacationDays;
// field value WILL be serialized (eg, with GWT) but will NOT be persisted in the datastore
@Ignore int notPersistent;
// field value will NOT be serialized (eg, with GWT) but WILL be persisted in the datastore
transient int notSerialized;
// field getting renamed
@AlsoLoad("boss") Key<Employee> manager;
String firstName;
String lastName;
// we used to store fullName, now we store first and last separately
public void oldWay(@AlsoLoad("fullName") String fullName) {
String[] split = fullName.split(" ");
firstName = split[0];
lastName = split[1];
}
static class Office {
String building;
String room;
}
// Allows you to query for employess in a building by filtering on "offices.building"
Office[] offices;
// Whatever gets put here will be serialized out and back (and cannot be filtered)
@Serialize Object misc;
@OnLoad void onLoad() { /* do something after load */ }
@OnSave void onSave() { /* do something before persisting */ }
}- Required for all registered entity classes.
- Optionally specifies the name of a kind, ie
@Entity(name="Person")
- Must be placed on one and only one field of an @Entity class
- Field must be type
Long,long, orString - If used on type
Long, null values will be autogenerated on put()
- Placed on at most one field of type
Key - Defines the entity group parent for an entity
- Placed on subclasses of polymorphic types, both
@Entityand embedded - Exclusive with
@Entity - See Polymorphism.
- Placed on a field or class.
- When placed on a class, sets the default state for all fields of the class.
- Can take
Ifconditions which allow partial indexing. - @Index state is inherited by embedded classes and their fields, but can be overriden with @Unindex.
- Indexed fields cost more space and cpu time to store, but can be queried on.
- Translates to
Entity.setProperty()at the low-level api. - Unless otherwise specified, all classes default to @Unindex.
- Placed on a field or class.
- When placed on a class, sets the default state for all fields of the class.
- Can take
Ifconditions which allow partial indexing. - @Unindex state is inherited by embedded classes and their fields, but can be overridden with @Index.
- Unindexed fields consume less space and require less cpu time to store, but cannot be queried for.
- Translates to
Entity.setUnindexedProperty()at the low-level api.
- Placed on any field
- Makes the field opaque to storage in the datastore; the field will be ignored for both read and write.
- Placed on any field
- Field will be loaded from the datastore but won't be saved
- Can take
Ifconditions which allow some values to be saved and not others.
- Placed on any field
- Field will be saved to the datastore but will be ignored during load operations
- Placed on a field or the single parameter to a method
- Requires one value, the name of a property in the datastore to load into the field.
- Example:
@AlsoLoad("whatThisFieldUsedToBeCalled") - Causes the field to be loaded from an alternate name (alias) in the underlying datastore
- If placed on the parameter to a method that takes a single parameter, the method will be called with the datastore value
- Can be used on multiple fields; they will all receive the loaded value.
- Placed on an entity class
- Stores entity data in a write-through cache for faster read performance
- Allows you to specify the expiration of entities in the cache
- Placed on any entity field of Serializable type
- Causes the object graph at that point to be stored as a serialized Blob.
- You can optionally configure zipping and compression level.
- See the serializing documentation.
- Placed on any method that takes no parameters.
- Called after the POJO is populated with data.
- Can be specified on multiple methods in this class or any base class.
- Methods are called in declared order, with superclass methods first.
- See LifecycleCallbacks
- Placed on any method that takes no parameters.
- Called before the POJO is written to the datastore Entity.
- Can be specified on multiple methods in this class or any base class.
- Methods are called in declared order, with superclass methods first.
- See LifecycleCallbacks
- Placed on entity fields of type
Ref<?> - Causes the referenced entity to be loaded automatically
- Load groups can be specified to limit when loading occurs
- See Relationships
- TODO: This needs some explanation.
- See the javadocs for details.
- TODO: This needs some explanation.
- See the javadocs for details.
- TODO: This needs some explanation.
- See the javadocs for details.
- TODO: This needs some explanation.
- See the javadocs for details.
- Home
- Concepts
- User's Guide
- Examples
- API Javadoc
- Release Notes
- Best Practices
- Frequently Asked Questions
- Extensions
- Contributing To Objectify
- User's Guide (Objectify v4)
- User's Guide (Objectify v3)