Class MappedField

  • Direct Known Subclasses:
    EphemeralMappedField

    public class MappedField
    extends java.lang.Object
    Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
      Adds the annotation, if it exists on the field.
      void addAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> clazz, java.lang.annotation.Annotation ann)
      Adds the annotation, if it exists on the field.
      static void addInterestingAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
      Adds an annotation for Morphia to retain when mapping.
      protected void discover​(Mapper mapper)
      Discovers interesting (that we care about) things about the field.
      protected void discoverType​(Mapper mapper)  
      <T extends java.lang.annotation.Annotation>
      T
      getAnnotation​(java.lang.Class<T> clazz)  
      java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.lang.annotation.Annotation> getAnnotations()  
      java.lang.Class getConcreteType()  
      java.lang.reflect.Constructor getCTor()  
      java.lang.Object getDbObjectValue​(com.mongodb.DBObject dbObj)  
      java.lang.Class getDeclaringClass()  
      java.lang.reflect.Field getField()  
      java.lang.Object getFieldValue​(java.lang.Object instance)
      Gets the value of the field mapped on the instance given.
      java.lang.String getFirstFieldName​(com.mongodb.DBObject dbObj)
      Gets the field name to use when converting from a DBObject
      java.lang.String getFullName()  
      java.lang.String getJavaFieldName()  
      java.util.List<java.lang.String> getLoadNames()  
      java.lang.Class getMapKeyClass()
      If the underlying java type is a map then it returns T from Map
      java.lang.String getMappedFieldName()  
      java.lang.String getNameToStore()  
      java.lang.Class getSubClass()
      If the java field is a list/array/map then the sub-type T is returned (ex.
      java.lang.reflect.Type getSubType()
      If the java field is a list/array/map then the sub-type T is returned (ex.
      java.lang.Class getType()  
      java.util.List<MappedField> getTypeParameters()  
      boolean hasAnnotation​(java.lang.Class ann)
      Indicates whether the annotation is present in the mapping (does not check the java field annotations, just the ones discovered)
      protected java.util.List<java.lang.String> inferLoadNames()  
      boolean isArray()  
      boolean isMap()  
      boolean isMultipleValues()  
      boolean isReference()  
      boolean isSet()  
      boolean isSingleValue()  
      boolean isTransient()  
      boolean isTypeMongoCompatible()  
      java.lang.annotation.Annotation putAnnotation​(java.lang.annotation.Annotation ann)
      Deprecated.
      unused
      void setFieldValue​(java.lang.Object instance, java.lang.Object value)
      Sets the value for the java field
      protected java.lang.Class toClass​(java.lang.reflect.Type t)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • addInterestingAnnotation

        public static void addInterestingAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
        Adds an annotation for Morphia to retain when mapping.
        Parameters:
        annotation - the type to retain
      • addAnnotation

        public void addAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
        Adds the annotation, if it exists on the field.
        Parameters:
        clazz - the annotation to add
      • addAnnotation

        public void addAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> clazz,
                                  java.lang.annotation.Annotation ann)
        Adds the annotation, if it exists on the field.
        Parameters:
        clazz - type of the annotation
        ann - the annotation
      • getAnnotation

        public <T extends java.lang.annotation.Annotation> T getAnnotation​(java.lang.Class<T> clazz)
        Type Parameters:
        T - the type of the annotation
        Parameters:
        clazz - the annotation to search for
        Returns:
        the annotation instance if it exists on this field
      • getAnnotations

        public java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.lang.annotation.Annotation> getAnnotations()
        Returns:
        the annotations found while mapping
      • getCTor

        public java.lang.reflect.Constructor getCTor()
        Returns:
        a constructor for the type represented by the field
      • getConcreteType

        public java.lang.Class getConcreteType()
        Returns:
        the concrete type of the MappedField
      • getDbObjectValue

        public java.lang.Object getDbObjectValue​(com.mongodb.DBObject dbObj)
        Parameters:
        dbObj - the DBObject get the value from
        Returns:
        the value from best mapping of this field
      • getDeclaringClass

        public java.lang.Class getDeclaringClass()
        Returns:
        the declaring class of the java field
      • getField

        public java.lang.reflect.Field getField()
        Returns:
        the underlying java field
      • getFieldValue

        public java.lang.Object getFieldValue​(java.lang.Object instance)
        Gets the value of the field mapped on the instance given.
        Parameters:
        instance - the instance to use
        Returns:
        the value stored in the java field
      • getFirstFieldName

        public java.lang.String getFirstFieldName​(com.mongodb.DBObject dbObj)
        Gets the field name to use when converting from a DBObject
        Parameters:
        dbObj - the DBObject to scan for alternate names
        Returns:
        the value of this field mapped from the DBObject
        See Also:
        AlsoLoad
      • getFullName

        public java.lang.String getFullName()
        Returns:
        the full name of the class plus java field name
      • getJavaFieldName

        public java.lang.String getJavaFieldName()
        Returns:
        the name of the java field, as declared on the class
      • getLoadNames

        public java.util.List<java.lang.String> getLoadNames()
        Returns:
        the name of the field's (key)name for mongodb, in order of loading.
      • inferLoadNames

        protected java.util.List<java.lang.String> inferLoadNames()
      • getMapKeyClass

        public java.lang.Class getMapKeyClass()
        If the underlying java type is a map then it returns T from Map
        Returns:
        the type of the map key
      • getNameToStore

        public java.lang.String getNameToStore()
        Returns:
        the name of the field's (key)name for mongodb
      • getSubClass

        public java.lang.Class getSubClass()
        If the java field is a list/array/map then the sub-type T is returned (ex. List, T[], Map
        Returns:
        the parameterized type of the field
      • getSubType

        public java.lang.reflect.Type getSubType()
        If the java field is a list/array/map then the sub-type T is returned (ex. List, T[], Map
        Returns:
        the parameterized type of the field
      • isTransient

        public boolean isTransient()
        Returns:
        true if this field is marked as transient
      • getType

        public java.lang.Class getType()
        Returns:
        the type of the underlying java field
      • getTypeParameters

        public java.util.List<MappedField> getTypeParameters()
        Returns:
        the type parameters defined on the field
      • hasAnnotation

        public boolean hasAnnotation​(java.lang.Class ann)
        Indicates whether the annotation is present in the mapping (does not check the java field annotations, just the ones discovered)
        Parameters:
        ann - the annotation to search for
        Returns:
        true if the annotation was found
      • isArray

        public boolean isArray()
        Returns:
        true if the MappedField is an array
      • isMap

        public boolean isMap()
        Returns:
        true if the MappedField is a Map
      • isMultipleValues

        public boolean isMultipleValues()
        Returns:
        true if this field is a container type such as a List, Map, Set, or array
      • isReference

        public boolean isReference()
        Returns:
        true if this field is a reference to a foreign document
        See Also:
        Reference, Key, DBRef
      • isSet

        public boolean isSet()
        Returns:
        true if the MappedField is a Set
      • isSingleValue

        public boolean isSingleValue()
        Returns:
        true if this field is not a container type such as a List, Map, Set, or array
      • isTypeMongoCompatible

        public boolean isTypeMongoCompatible()
        Returns:
        true if type is understood by MongoDB and the driver
      • putAnnotation

        @Deprecated
        public java.lang.annotation.Annotation putAnnotation​(java.lang.annotation.Annotation ann)
        Deprecated.
        unused
        Adds the annotation even if not on the declared class/field.
        Parameters:
        ann - the annotation to add
        Returns:
        ann the annotation
      • setFieldValue

        public void setFieldValue​(java.lang.Object instance,
                                  java.lang.Object value)
        Sets the value for the java field
        Parameters:
        instance - the instance to update
        value - the value to set
      • toString

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

        protected void discover​(Mapper mapper)
        Discovers interesting (that we care about) things about the field.
      • discoverType

        protected void discoverType​(Mapper mapper)
      • getMappedFieldName

        public java.lang.String getMappedFieldName()
        Returns:
        the name of the field's key-name for mongodb
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • toClass

        protected java.lang.Class toClass​(java.lang.reflect.Type t)