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
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Comparison is based on keystatic <T> Ref<T>
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
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.getKey()
Same as key() but conforms to JavaBeans conventions in case this is being processed by a JSON converter or expression language.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()
safe()
Obtain the entity value, throwing an exception if the entity was not found.toString()
Renders some info about the key
-
Field Details
-
key
The key associated with this ref
-
-
Constructor Details
-
Ref
protected Ref()For GWT serialization -
Ref
Create a Ref based on the key, with the specified session
-
-
Method Details
-
create
Key.create(Blah.class, id) is easier to type than new Key(Blah.class, id) -
create
Creates a Ref from a registered pojo entity -
key
- Returns:
- the key associated with this Ref
-
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
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
Same as key() but conforms to JavaBeans conventions in case this is being processed by a JSON converter or expression language. -
safe
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
Comparison is based on key- Specified by:
compareTo
in interfaceComparable<T>
-
equals
Equality comparison is based on key equivalence -
equivalent
Type-safe comparison for key equivalence -
equivalent
Type safe comparison for key equivalence -
hashCode
public int hashCode()Hash code is simply that of key -
toString
Renders some info about the key
-