Package dev.morphia.mapping.codec.pojo
Class EntityModelBuilder
- java.lang.Object
-
- dev.morphia.mapping.codec.pojo.EntityModelBuilder
-
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(Datastore datastore, A annotation, Class<T> clazz)
EntityModelBuilder(Datastore datastore, Class<?> type)
Create a builder
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addModel(FieldModelBuilder builder)
Adds a field to the modelSet<Annotation>
annotations()
protected Map<Class<? extends Annotation>,Annotation>
annotationsMap()
EntityModel
build()
Creates a new ClassModel instance based on the mapping data provided.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 serializingFieldModelBuilder
fieldModelByFieldName(String name)
Gets a field by its nameList<FieldModelBuilder>
fieldModels()
<A extends Annotation>
AgetAnnotation(Class<A> type)
protected String
getCollectionName()
protected Datastore
getDatastore()
Class<?>
getType()
The type of this modelboolean
hasAnnotation(Class<? extends Annotation> type)
String
idFieldName()
EntityModelBuilder
idFieldName(String name)
Sets the name of the id fieldList<EntityModel>
interfaces()
boolean
isDiscriminatorEnabled()
EntityModel
superclass()
-
-
-
Constructor Detail
-
EntityModelBuilder
public EntityModelBuilder(Datastore datastore, Class<?> type)
Create a builder- Parameters:
datastore
- the datastore to usetype
- the entity type
-
EntityModelBuilder
public EntityModelBuilder(Datastore datastore, A annotation, Class<T> clazz)
- Type Parameters:
T
- the class typeA
- the annotation type- Parameters:
datastore
- the datastoreannotation
- the annotationclazz
- the type
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Method Detail
-
addModel
public void addModel(FieldModelBuilder builder)
Adds a field to the model- Parameters:
builder
- the field to add
-
annotations
public Set<Annotation> annotations()
- Returns:
- the annotation on this model
-
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
-
fieldModelByFieldName
public FieldModelBuilder fieldModelByFieldName(String name) throws NoSuchElementException
Gets a field by its name- Parameters:
name
- the name- Returns:
- the field
- Throws:
NoSuchElementException
- if no value is present
-
fieldModels
public List<FieldModelBuilder> fieldModels()
- Returns:
- the fields on this model
-
getAnnotation
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
-
getType
public Class<?> getType()
The type of this model- Returns:
- the type
-
hasAnnotation
public boolean hasAnnotation(Class<? extends Annotation> type)
- Parameters:
type
- the annotation class- Returns:
- the annotation if it exists
-
idFieldName
public String idFieldName()
- Returns:
- the name of the id field
-
idFieldName
public EntityModelBuilder idFieldName(String name)
Sets the name of the id field- 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
-
superclass
public EntityModel superclass()
- Returns:
- the super class of this type or null
-
annotationsMap
protected Map<Class<? extends Annotation>,Annotation> annotationsMap()
-
getCollectionName
protected String getCollectionName()
-
getDatastore
protected Datastore getDatastore()
-
-