Package dev.morphia.mapping.codec.pojo
Class EntityModelBuilder
- java.lang.Object
-
- dev.morphia.mapping.codec.pojo.EntityModelBuilder
-
@MorphiaInternal public class EntityModelBuilder extends Object
Builder for EntityModels- 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.
-
-
Constructor Summary
Constructors Constructor Description EntityModelBuilder(Mapper mapper, Class<?> type)
Create a builder
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PropertyModelBuilder
addProperty()
Adds a property to the modelEntityModelBuilder
annotation(Annotation type)
Adds an annotationprotected Map<Class<? extends Annotation>,Annotation>
annotations()
EntityModel
build()
Creates a new ClassModel instance based on the mapping data provided.Set<Class<?>>
classHierarchy()
String
discriminator()
EntityModelBuilder
discriminator(String discriminator)
Sets the discriminatorString
discriminatorKey()
EntityModelBuilder
discriminatorKey(String key)
Sets the mapped key name to use when storing the discriminator valueEntityModelBuilder
enableDiscriminator(boolean enabled)
Enables or disables the use of a discriminator when serializing<A extends Annotation>
AgetAnnotation(Class<A> type)
protected String
getCollectionName()
TypeData<?>
getTypeData(Class<?> type, TypeData<?> suggested, Type genericType)
boolean
hasAnnotation(Class<? extends Annotation> type)
String
idPropertyName()
EntityModelBuilder
idPropertyName(String name)
Sets the name of the id propertyList<EntityModel>
interfaces()
boolean
isDiscriminatorEnabled()
PropertyModelBuilder
propertyModelByName(String name)
Gets a property by its nameList<PropertyModelBuilder>
propertyModels()
EntityModel
superclass()
Class<?>
targetType()
The target type of this modelEntityModelBuilder
targetType(Class<?> targetType)
The target type of this modelString
toString()
Class<?>
type()
The type of this modelString
versionPropertyName()
EntityModelBuilder
versionPropertyName(String name)
Sets the name of the version property
-
-
-
Method Detail
-
addProperty
public PropertyModelBuilder addProperty()
Adds a property to the model- Returns:
- the new PropertyModelBuilder
-
annotation
public EntityModelBuilder annotation(Annotation type)
Adds an annotation- Parameters:
type
- the annotation to add- Returns:
- this
- Since:
- 2.3
-
build
public EntityModel build()
Creates a new ClassModel instance based on the mapping data provided.- Returns:
- the new instance
-
discriminator
public EntityModelBuilder discriminator(String discriminator)
Sets the discriminator- Parameters:
discriminator
- the discriminator- Returns:
- this
-
discriminator
public String discriminator()
- Returns:
- the discriminator
-
discriminatorKey
public EntityModelBuilder discriminatorKey(String key)
Sets the mapped key name to use when storing the discriminator value- Parameters:
key
- the key to use- Returns:
- this
-
discriminatorKey
public String discriminatorKey()
- Returns:
- the discriminator key
-
enableDiscriminator
public EntityModelBuilder enableDiscriminator(boolean enabled)
Enables or disables the use of a discriminator when serializing- Parameters:
enabled
- true to enable the use of a discriminator- Returns:
- this
-
getAnnotation
@Nullable public <A extends Annotation> A getAnnotation(Class<A> type)
- Type Parameters:
A
- the annotation type- Parameters:
type
- the annotation class- Returns:
- the annotation or null if it doesn't exist
-
getTypeData
public TypeData<?> getTypeData(Class<?> type, TypeData<?> suggested, Type genericType)
- Parameters:
type
-suggested
-genericType
-- Returns:
- the type data for the model
-
hasAnnotation
public boolean hasAnnotation(Class<? extends Annotation> type)
- Parameters:
type
- the annotation class- Returns:
- the annotation if it exists
-
idPropertyName
public EntityModelBuilder idPropertyName(String name)
Sets the name of the id property- Parameters:
name
- the name- Returns:
- this
-
interfaces
public List<EntityModel> interfaces()
- Returns:
- the interfaces implemented by this model or its super types
-
isDiscriminatorEnabled
public boolean isDiscriminatorEnabled()
- Returns:
- true if the discriminator is enabled
-
propertyModelByName
public PropertyModelBuilder propertyModelByName(String name) throws NoSuchElementException
Gets a property by its name- Parameters:
name
- the name- Returns:
- the property
- Throws:
NoSuchElementException
- if no value is present
-
propertyModels
public List<PropertyModelBuilder> propertyModels()
- Returns:
- the properties on this model
-
superclass
@Nullable public EntityModel superclass()
- Returns:
- the super class of this type or null
-
targetType
public Class<?> targetType()
The target type of this model- Returns:
- the type
- Since:
- 2.3
-
targetType
public EntityModelBuilder targetType(Class<?> targetType)
The target type of this model- Parameters:
targetType
- the type- Returns:
- this
- Since:
- 2.3
-
type
public Class<?> type()
The type of this model- Returns:
- the type
-
versionPropertyName
@Nullable public String versionPropertyName()
- Returns:
- the name of the version property
-
versionPropertyName
public EntityModelBuilder versionPropertyName(String name)
Sets the name of the version property- Parameters:
name
- the name- Returns:
- this
-
annotations
protected Map<Class<? extends Annotation>,Annotation> annotations()
-
getCollectionName
protected String getCollectionName()
-
-