Package com.googlecode.objectify
Class Ref<T>
- java.lang.Object
-
- com.googlecode.objectify.Ref<T>
-
- All Implemented Interfaces:
Serializable
,Comparable<Ref<T>>
public abstract class Ref<T> extends Object implements Serializable, Comparable<Ref<T>>
Ref> is a Key> which allows the entity value to be fetched directly.
Note that the methods might or might not throw runtime exceptions related to datastore operations; ConcurrentModificationException, DatastoreTimeoutException, DatastoreFailureException, and DatastoreNeedIndexException. Some Refs hide datastore operations that could throw these exceptions.
- Author:
- Jeff Schnitzer
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(Ref<T> o)
Comparison is based on keystatic <T> Ref<T>
create(Key<T> key)
Key.create(Blah.class, id) is easier to type than new Key(Blah.class, id) static <T> Ref<T>
create(T value)
Creates a Ref from a registered pojo entityboolean
equals(Object obj)
Equality comparison is based on key equivalenceboolean
equivalent(Key<T> other)
Type safe comparison for key equivalenceboolean
equivalent(Ref<T> other)
Type-safe comparison for key equivalenceabstract T
get()
Obtain the entity value associated with the key.Key<T>
getKey()
Same as key() but conforms to JavaBeans conventions in case this is being processed by a JSON converter or expression language.T
getValue()
This method exists to facilitate serialization via javabeans conventions.int
hashCode()
Hash code is simply that of keyabstract boolean
isLoaded()
If an entity has been loaded into the session or is otherwise available, this will return true.Key<T>
key()
T
safe()
Obtain the entity value, throwing an exception if the entity was not found.String
toString()
Renders some info about the key
-
-
-
Method Detail
-
create
public static <T> Ref<T> create(Key<T> key)
Key.create(Blah.class, id) is easier to type than new Key(Blah.class, id)
-
create
public static <T> Ref<T> create(T value)
Creates a Ref from a registered pojo entity
-
get
public abstract T get()
Obtain the entity value associated with the key. Will pull from session if present, otherwise will fetch from the datastore.- Returns:
- the entity referenced, or null if the entity was not found
-
isLoaded
public abstract boolean isLoaded()
If an entity has been loaded into the session or is otherwise available, this will return true. Calls to get() will not require a trip to backing store. Note that even when loaded, get() can still return null if there is no entity which corresponds to the key.- Returns:
- true if the value is in the session or otherwise immediately available; false if get() will require a trip to the datastore or memcache.
-
getValue
public final T getValue()
This method exists to facilitate serialization via javabeans conventions. Unlike get(), it will return null if isLoaded() is false.- Returns:
- the entity referenced, or null if either the entity was not found or isLoaded() is false.
-
getKey
public final Key<T> getKey()
Same as key() but conforms to JavaBeans conventions in case this is being processed by a JSON converter or expression language.
-
safe
public final T safe() throws NotFoundException
Obtain the entity value, throwing an exception if the entity was not found.- Returns:
- the entity referenced. Never returns null.
- Throws:
NotFoundException
- if the specified entity was not found
-
compareTo
public int compareTo(Ref<T> o)
Comparison is based on key- Specified by:
compareTo
in interfaceComparable<T>
-
equals
public boolean equals(Object obj)
Equality comparison is based on key equivalence
-
-