Package dev.morphia

Class 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
      protected Key()
      For GWT serialization
        Key​(java.lang.Class<? extends T> type, java.lang.String collection, byte[] idBytes)
      Create a key with an id
        Key​(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
      int compareTo​(Key<T> other)  
      boolean equals​(java.lang.Object obj)  
      java.lang.String getCollection()  
      java.lang.Object getId()  
      java.lang.Class<? extends T> getType()  
      int hashCode()  
      void setCollection​(java.lang.String collection)
      Sets the collection name.
      void setType​(java.lang.Class<? extends T> clazz)
      Sets the type of the entity for this Key
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 entity
        collection - the collection in which the entity lives
        id - 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 entity
        collection - the collection in which the entity lives
        idBytes - the value of the entity's ID
    • Method Detail

      • compareTo

        public int compareTo​(Key<T> other)
        Specified by:
        compareTo in interface java.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:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object