Package dev.morphia.mapping
Class Mapper
- java.lang.Object
-
- dev.morphia.mapping.Mapper
-
@MorphiaInternal public class Mapper extends Object
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Field Summary
Fields Modifier and Type Field Description static String
IGNORED_FIELDNAME
Special name that can never be used.static List<Class<? extends Annotation>>
LIFECYCLE_ANNOTATIONS
static List<Class<? extends Annotation>>
MAPPING_ANNOTATIONS
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addInterceptor(EntityListener<?> ei)
Deprecated, for removal: This API element is subject to removal in a future version.useEntityListeners
to define any lifecycle event listenersMapper
copy()
MongoCollection
enforceWriteConcern(MongoCollection collection, Class type)
Updates a collection to use a specific WriteConcernPropertyModel
findIdProperty(Class<?> type)
Class
getClass(String discriminator)
<T> Class<T>
getClass(Document document)
Gets the class as defined by any discriminator fieldList<EntityModel>
getClassesMappedToCollection(String collection)
Finds all the types mapped to a named collection<T> Class<T>
getClassFromCollection(String collection)
Looks up the class mapped to a named collection.MorphiaConfig
getConfig()
DiscriminatorLookup
getDiscriminatorLookup()
Object
getId(Object entity)
Gets the ID value for an entityList<EntityListener<?>>
getInterceptors()
Deprecated, for removal: This API element is subject to removal in a future version.<T> Key<T>
getKey(T entity)
Deprecated, for removal: This API element is subject to removal in a future version.<T> Key<T>
getKey(T entity, String collection)
Deprecated, for removal: This API element is subject to removal in a future version.List<EntityModel>
getMappedEntities()
WriteConcern
getWriteConcern(Class clazz)
Gets the write concern for entity or returns the default write concern for this datastoreboolean
hasInterceptors()
<T> boolean
isMappable(Class<T> type)
Checks if a type is mappable or notboolean
isMapped(Class c)
Checks to see if a Class has been mapped.EntityModel
register(EntityModel entityModel)
void
setOptions(MapperOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.no longer usedString
updateCollection(Key key)
Deprecated, for removal: This API element is subject to removal in a future version.void
updateQueryWithDiscriminators(EntityModel model, Document query)
Updates a query with any discriminators from subtypes if polymorphic queries are enabled
-
-
-
Field Detail
-
IGNORED_FIELDNAME
@MorphiaInternal public static final String IGNORED_FIELDNAME
Special name that can never be used. Used as default for some fields to indicate default state.- See Also:
- Constant Field Values
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
MAPPING_ANNOTATIONS
@MorphiaInternal public static final List<Class<? extends Annotation>> MAPPING_ANNOTATIONS
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
LIFECYCLE_ANNOTATIONS
@MorphiaInternal public static final List<Class<? extends Annotation>> LIFECYCLE_ANNOTATIONS
-
-
Method Detail
-
addInterceptor
@Deprecated(forRemoval=true, since="2.4.0") public void addInterceptor(EntityListener<?> ei)
Deprecated, for removal: This API element is subject to removal in a future version.useEntityListeners
to define any lifecycle event listenersAdds anEntityInterceptor
- Parameters:
ei
- the interceptor to add
-
copy
public Mapper copy()
-
enforceWriteConcern
public MongoCollection enforceWriteConcern(MongoCollection collection, Class type)
Updates a collection to use a specific WriteConcern- Parameters:
collection
- the collection to updatetype
- the entity type- Returns:
- the updated collection
-
findIdProperty
@MorphiaInternal public PropertyModel findIdProperty(Class<?> type)
- Parameters:
type
- the class- Returns:
- the id property model
- Since:
- 2.2
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getClass
@Nullable public <T> Class<T> getClass(Document document)
Gets the class as defined by any discriminator field- Type Parameters:
T
- the class type- Parameters:
document
- the document to check- Returns:
- the class reference. might be null
-
getClass
public Class getClass(String discriminator)
- Parameters:
discriminator
- the lookup value- Returns:
- the class mapped to this discrimiator value
-
getClassFromCollection
@MorphiaInternal public <T> Class<T> getClassFromCollection(String collection)
Looks up the class mapped to a named collection.- Type Parameters:
T
- the class type- Parameters:
collection
- the collection name- Returns:
- the Class mapped to this collection name
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getClassesMappedToCollection
@MorphiaInternal public List<EntityModel> getClassesMappedToCollection(String collection)
Finds all the types mapped to a named collection- Parameters:
collection
- the collection to check- Returns:
- the mapped types
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getDiscriminatorLookup
public DiscriminatorLookup getDiscriminatorLookup()
- Returns:
- the DiscriminatorLookup in use
-
getId
@Nullable public Object getId(@Nullable Object entity)
Gets the ID value for an entity- Parameters:
entity
- the entity to process- Returns:
- the ID value
-
getInterceptors
@Deprecated(forRemoval=true, since="2.4.0") public List<EntityListener<?>> getInterceptors()
Deprecated, for removal: This API element is subject to removal in a future version.Gets list ofEntityInterceptor
s- Returns:
- the Interceptors
-
getKey
@Nullable @Deprecated(since="2.0", forRemoval=true) public <T> Key<T> getKey(T entity)
Deprecated, for removal: This API element is subject to removal in a future version.Gets the Key for an entity- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to process- Returns:
- the Key
-
getKey
@Nullable @Deprecated(since="2.0", forRemoval=true) public <T> Key<T> getKey(T entity, String collection)
Deprecated, for removal: This API element is subject to removal in a future version.Gets the Key for an entity and a specific collection- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to processcollection
- the collection to use in the Key rather than the mapped collection as defined on the entity's class- Returns:
- the Key
-
getMappedEntities
public List<EntityModel> getMappedEntities()
- Returns:
- collection of EntityModels
-
getConfig
public MorphiaConfig getConfig()
- Returns:
- the options used by this Mapper
-
setOptions
@Deprecated(since="2.0", forRemoval=true) public void setOptions(MapperOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.no longer usedSets the options this Mapper should use- Parameters:
options
- the options to use
-
getWriteConcern
@Nullable public WriteConcern getWriteConcern(Class clazz)
Gets the write concern for entity or returns the default write concern for this datastore- Parameters:
clazz
- the class to use when looking up the WriteConcern- Returns:
- the write concern for the type
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
hasInterceptors
public boolean hasInterceptors()
- Returns:
- true if there are global interceptors defined
-
isMappable
public <T> boolean isMappable(Class<T> type)
Checks if a type is mappable or not- Type Parameters:
T
- the type- Parameters:
type
- the class to check- Returns:
- true if the type is mappable
-
isMapped
public boolean isMapped(Class c)
Checks to see if a Class has been mapped.- Parameters:
c
- the Class to check- Returns:
- true if the Class has been mapped
-
updateCollection
@Deprecated(since="2.0", forRemoval=true) public String updateCollection(Key key)
Deprecated, for removal: This API element is subject to removal in a future version.Updates the collection value on a Key with the mapped value on the Key's type Class- Parameters:
key
- the Key to update- Returns:
- the collection name on the Key
-
updateQueryWithDiscriminators
public void updateQueryWithDiscriminators(EntityModel model, Document query)
Updates a query with any discriminators from subtypes if polymorphic queries are enabled- Parameters:
model
- the query modelquery
- the query document
-
register
@MorphiaInternal public EntityModel register(EntityModel entityModel)
- Parameters:
entityModel
- the model to register- Returns:
- the model
- Since:
- 2.3
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-