Package dev.morphia.mapping
Class EphemeralMappedField
- java.lang.Object
-
- dev.morphia.mapping.MappedField
-
- dev.morphia.mapping.EphemeralMappedField
-
public class EphemeralMappedField extends MappedField
This is a MappedField facade that allows us to convert and collect values to be gathered back in to a Map or Collection, e.g., rather than directly on a mapped entity. This are not mapped directly to a field on a class like MappedFields are.
-
-
Constructor Summary
Constructors Constructor Description EphemeralMappedField(java.lang.reflect.ParameterizedType t, MappedField mf, Mapper mapper)
Creates an EphemeralMappedField.EphemeralMappedField(java.lang.reflect.Type t, MappedField mf, Mapper mapper)
Creates an EphemeralMappedField.
-
Method Summary
All Methods Instance Methods Concrete 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.java.lang.Object
getDbObjectValue(com.mongodb.DBObject dbObj)
java.lang.Object
getFieldValue(java.lang.Object instance)
Gets the value of the field mapped on the instance given.java.lang.Class
getMapKeyClass()
If the underlying java type is a map then it returns T from Map<T,V>java.lang.String
getMappedFieldName()
java.lang.String
getNameToStore()
MappedField
getParent()
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.lang.Object
getValue()
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)boolean
isSingleValue()
void
setFieldValue(java.lang.Object instance, java.lang.Object val)
Sets the value for the java fieldjava.lang.String
toString()
-
Methods inherited from class dev.morphia.mapping.MappedField
addInterestingAnnotation, discover, discoverType, getAnnotation, getAnnotations, getConcreteType, getCTor, getDeclaringClass, getField, getFirstFieldName, getFullName, getJavaFieldName, getLoadNames, getTypeParameters, inferLoadNames, isArray, isMap, isMultipleValues, isReference, isSet, isTransient, isTypeMongoCompatible, putAnnotation, toClass
-
-
-
-
Constructor Detail
-
EphemeralMappedField
public EphemeralMappedField(java.lang.reflect.ParameterizedType t, MappedField mf, Mapper mapper)
Creates an EphemeralMappedField.- Parameters:
t
- the parameterized type of the fieldmf
- the parent MappedFieldmapper
- the Mapper to use
-
EphemeralMappedField
public EphemeralMappedField(java.lang.reflect.Type t, MappedField mf, Mapper mapper)
Creates an EphemeralMappedField.- Parameters:
t
- the type of the fieldmf
- the parent MappedFieldmapper
- the Mapper to use
-
-
Method Detail
-
addAnnotation
public void addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Description copied from class:MappedField
Adds the annotation, if it exists on the field.- Overrides:
addAnnotation
in classMappedField
- Parameters:
clazz
- the annotation to add
-
addAnnotation
public void addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> clazz, java.lang.annotation.Annotation ann)
Description copied from class:MappedField
Adds the annotation, if it exists on the field.- Overrides:
addAnnotation
in classMappedField
- Parameters:
clazz
- type of the annotationann
- the annotation
-
getDbObjectValue
public java.lang.Object getDbObjectValue(com.mongodb.DBObject dbObj)
- Overrides:
getDbObjectValue
in classMappedField
- Parameters:
dbObj
- the DBObject get the value from- Returns:
- the value from best mapping of this field
-
getFieldValue
public java.lang.Object getFieldValue(java.lang.Object instance)
Description copied from class:MappedField
Gets the value of the field mapped on the instance given.- Overrides:
getFieldValue
in classMappedField
- Parameters:
instance
- the instance to use- Returns:
- the value stored in the java field
-
getMapKeyClass
public java.lang.Class getMapKeyClass()
Description copied from class:MappedField
If the underlying java type is a map then it returns T from Map<T,V>- Overrides:
getMapKeyClass
in classMappedField
- Returns:
- the type of the map key
-
getNameToStore
public java.lang.String getNameToStore()
- Overrides:
getNameToStore
in classMappedField
- Returns:
- the name of the field's (key)name for mongodb
-
getSubClass
public java.lang.Class getSubClass()
Description copied from class:MappedField
If the java field is a list/array/map then the sub-type T is returned (ex. List<T>, T[], Map<?,T>- Overrides:
getSubClass
in classMappedField
- Returns:
- the parameterized type of the field
-
getSubType
public java.lang.reflect.Type getSubType()
Description copied from class:MappedField
If the java field is a list/array/map then the sub-type T is returned (ex. List<T>, T[], Map<?,T>- Overrides:
getSubType
in classMappedField
- Returns:
- the parameterized type of the field
-
getType
public java.lang.Class getType()
- Overrides:
getType
in classMappedField
- Returns:
- the type of the underlying java field
-
hasAnnotation
public boolean hasAnnotation(java.lang.Class ann)
Description copied from class:MappedField
Indicates whether the annotation is present in the mapping (does not check the java field annotations, just the ones discovered)- Overrides:
hasAnnotation
in classMappedField
- Parameters:
ann
- the annotation to search for- Returns:
- true if the annotation was found
-
isSingleValue
public boolean isSingleValue()
- Overrides:
isSingleValue
in classMappedField
- Returns:
- true if this field is not a container type such as a List, Map, Set, or array
-
setFieldValue
public void setFieldValue(java.lang.Object instance, java.lang.Object val)
Description copied from class:MappedField
Sets the value for the java field- Overrides:
setFieldValue
in classMappedField
- Parameters:
instance
- the instance to updateval
- the value to set
-
toString
public java.lang.String toString()
- Overrides:
toString
in classMappedField
-
getMappedFieldName
public java.lang.String getMappedFieldName()
- Overrides:
getMappedFieldName
in classMappedField
- Returns:
- the name of the field's key-name for mongodb
-
getParent
public MappedField getParent()
- Returns:
- the parent MappedField
-
getValue
public java.lang.Object getValue()
- Returns:
- the value of the field
-
-