Class PropertyModel


  • @MorphiaInternal
    public final class PropertyModel
    extends Object
    Represents a field on a class and stores various metadata such as generic parameters.
    Since:
    2.0
    Developer note.
    This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    • Method Detail

      • normalize

        @MorphiaInternal
        public static Class<?> normalize​(TypeData<?> typeData)
        Gets the parameterized type of a TypeData
        Parameters:
        typeData - the type to normalize
        Returns:
        the unwrapped type
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getAccessor

        public PropertyAccessor<? super Object> getAccessor()
        Returns:
        the accessor to use when accessing this field
      • getAnnotation

        @Nullable
        public <A extends Annotation> A getAnnotation​(Class<A> type)
        Find an annotation of a specific type or null if not found.
        Type Parameters:
        A - the class type
        Parameters:
        type - the annotation type to find
        Returns:
        the annotation instance or null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getDocumentValue

        public Object getDocumentValue​(Document document)
        Parameters:
        document - the Document get the value from
        Returns:
        the value from first mapping of this field
      • getEntityModel

        public EntityModel getEntityModel()
        Returns:
        the entity model owner of this field
        Since:
        2.1
      • getFullName

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

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

        public String getMappedName()
        Returns:
        the mapped name for the model
      • getName

        public String getName()
        Returns:
        the field name for the model
      • getNormalizedType

        public Class<?> getNormalizedType()
        Gets the parameterized type of a List or the key type of a Map, e.g.
        Returns:
        the unwrapped type
      • getType

        public Class<?> getType()
        Returns:
        the type of this field
      • getTypeData

        public TypeData<?> getTypeData()
        Returns:
        the type data for the field
      • getValue

        @Nullable
        public Object getValue​(Object instance)
        Gets the value of the property mapped on the instance given.
        Parameters:
        instance - the instance to use
        Returns:
        the value stored in the property
      • hasAnnotation

        public boolean hasAnnotation​(Class<? extends Annotation> type)
        Indicates whether the annotation is present in the mapping (does not check the java field annotations, just the ones discovered)
        Parameters:
        type - the annotation to search for
        Returns:
        true if the annotation was found
      • specializeCodec

        @Nullable
        public Codec<?> specializeCodec​(Datastore datastore)
        Parameters:
        datastore -
        Returns:
        the custom codec to use if set or null
      • 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
      • isScalarValue

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

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

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

        public void setValue​(Object instance,
                             @Nullable
                             Object value)
        Sets the value for the java field
        Parameters:
        instance - the instance to update
        value - the value to set
      • shouldSerialize

        public boolean shouldSerialize​(@Nullable
                                       Object value)
        Checks a value against the configured rules for serialization
        Parameters:
        value - the value to check
        Returns:
        true if the given value should be serialized