Package dev.morphia
Class Key<T>
- java.lang.Object
-
- dev.morphia.Key<T>
-
- Type Parameters:
T- The type of the entity
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Key<T>>
public class Key<T> extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<Key<T>>
The key object; this class is take from the app-engine datastore (mostly) implementation. It is also Serializable and GWT-safe, enabling your entity objects to be used for GWT RPC should you so desire.
You may use normal DBRef objects as relationships in your entities if you desire neither type safety nor GWT-ability.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedKey()For GWT serializationKey(java.lang.Class<? extends T> type, java.lang.String collection, byte[] idBytes)Create a key with an idKey(java.lang.Class<? extends T> type, java.lang.String collection, java.lang.Object id)Create a key with an id
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Key<T> other)booleanequals(java.lang.Object obj)java.lang.StringgetCollection()java.lang.ObjectgetId()java.lang.Class<? extends T>getType()inthashCode()voidsetCollection(java.lang.String collection)Sets the collection name.voidsetType(java.lang.Class<? extends T> clazz)Sets the type of the entity for this Keyjava.lang.StringtoString()
-
-
-
Constructor Detail
-
Key
protected Key()
For GWT serialization
-
Key
public Key(java.lang.Class<? extends T> type, java.lang.String collection, java.lang.Object id)
Create a key with an id- Parameters:
type- the type of the entitycollection- the collection in which the entity livesid- the value of the entity's ID
-
Key
public Key(java.lang.Class<? extends T> type, java.lang.String collection, byte[] idBytes)
Create a key with an id- Parameters:
type- the type of the entitycollection- the collection in which the entity livesidBytes- the value of the entity's ID
-
-
Method Detail
-
compareTo
public int compareTo(Key<T> other)
- Specified by:
compareToin interfacejava.lang.Comparable<T>
-
getCollection
public java.lang.String getCollection()
- Returns:
- the collection name.
-
setCollection
public void setCollection(java.lang.String collection)
Sets the collection name.- Parameters:
collection- the collection to use
-
getId
public java.lang.Object getId()
- Returns:
- the id associated with this key.
-
getType
public java.lang.Class<? extends T> getType()
- Returns:
- type of the entity
-
setType
public void setType(java.lang.Class<? extends T> clazz)
Sets the type of the entity for this Key- Parameters:
clazz- the type to use
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-