Package org.bson.codecs.pojo
Class ClassModelBuilder<T>
- java.lang.Object
-
- org.bson.codecs.pojo.ClassModelBuilder<T>
-
- Type Parameters:
T
- The type of the class the ClassModel represents
public class ClassModelBuilder<T> extends Object
A builder for programmatically creatingClassModels
.- Since:
- 3.5
- See Also:
ClassModel
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassModelBuilder<T>
annotations(List<Annotation> annotations)
Sets the annotations for the modelClassModel<T>
build()
Creates a new ClassModel instance based on the mapping data provided.ClassModelBuilder<T>
conventions(List<Convention> conventions)
Sets the conventions to apply to the modelClassModelBuilder<T>
discriminator(String discriminator)
Sets the discriminator to be used when storing instances of the modeled typeClassModelBuilder<T>
discriminatorKey(String discriminatorKey)
Sets the discriminator key to be used when storing instances of the modeled typeClassModelBuilder<T>
enableDiscriminator(boolean discriminatorEnabled)
Enables or disables the use of a discriminator when serializingList<Annotation>
getAnnotations()
List<Convention>
getConventions()
String
getDiscriminator()
String
getDiscriminatorKey()
String
getIdPropertyName()
InstanceCreatorFactory<T>
getInstanceCreatorFactory()
PropertyModelBuilder<?>
getProperty(String propertyName)
Gets a property by the property name.List<PropertyModelBuilder<?>>
getPropertyModelBuilders()
Class<T>
getType()
ClassModelBuilder<T>
idPropertyName(String idPropertyName)
Designates a property as the_id
property for this type.ClassModelBuilder<T>
instanceCreatorFactory(InstanceCreatorFactory<T> instanceCreatorFactory)
Sets the InstanceCreatorFactory for the ClassModelboolean
removeProperty(String propertyName)
Remove a property from the builderString
toString()
ClassModelBuilder<T>
type(Class<T> type)
Sets the type of the modelBoolean
useDiscriminator()
-
-
-
Method Detail
-
instanceCreatorFactory
public ClassModelBuilder<T> instanceCreatorFactory(InstanceCreatorFactory<T> instanceCreatorFactory)
Sets the InstanceCreatorFactory for the ClassModel- Parameters:
instanceCreatorFactory
- the InstanceCreatorFactory- Returns:
- this
-
getInstanceCreatorFactory
public InstanceCreatorFactory<T> getInstanceCreatorFactory()
- Returns:
- the InstanceCreatorFactory for the ClassModel
-
type
public ClassModelBuilder<T> type(Class<T> type)
Sets the type of the model- Parameters:
type
- the type of the class- Returns:
- the builder to configure the class being modeled
-
conventions
public ClassModelBuilder<T> conventions(List<Convention> conventions)
Sets the conventions to apply to the model- Parameters:
conventions
- a list of conventions- Returns:
- this
-
getConventions
public List<Convention> getConventions()
- Returns:
- the conventions o apply to the model
-
annotations
public ClassModelBuilder<T> annotations(List<Annotation> annotations)
Sets the annotations for the model- Parameters:
annotations
- a list of annotations- Returns:
- this
-
getAnnotations
public List<Annotation> getAnnotations()
- Returns:
- the annotations on the modeled type if set or null
-
discriminator
public ClassModelBuilder<T> discriminator(String discriminator)
Sets the discriminator to be used when storing instances of the modeled type- Parameters:
discriminator
- the discriminator value- Returns:
- this
-
getDiscriminator
public String getDiscriminator()
- Returns:
- the discriminator to be used when storing instances of the modeled type or null if not set
-
discriminatorKey
public ClassModelBuilder<T> discriminatorKey(String discriminatorKey)
Sets the discriminator key to be used when storing instances of the modeled type- Parameters:
discriminatorKey
- the discriminator key value- Returns:
- this
-
getDiscriminatorKey
public String getDiscriminatorKey()
- Returns:
- the discriminator key to be used when storing instances of the modeled type or null if not set
-
enableDiscriminator
public ClassModelBuilder<T> enableDiscriminator(boolean discriminatorEnabled)
Enables or disables the use of a discriminator when serializing- Parameters:
discriminatorEnabled
- true to enable the use of a discriminator- Returns:
- this
-
useDiscriminator
public Boolean useDiscriminator()
- Returns:
- true if a discriminator should be used when serializing, otherwise false
-
idPropertyName
public ClassModelBuilder<T> idPropertyName(String idPropertyName)
Designates a property as the_id
property for this type. If another property is currently marked as the_id
property, that setting is cleared in favor of the named property.- Parameters:
idPropertyName
- the property name to use for the_id
property, a null value removes the set idPropertyName.- Returns:
- this
-
getIdPropertyName
public String getIdPropertyName()
- Returns:
- the designated
_id
property name for this type or null if not set
-
removeProperty
public boolean removeProperty(String propertyName)
Remove a property from the builder- Parameters:
propertyName
- the actual property name in the POJO and not thedocumentPropertyName
.- Returns:
- returns true if the property matched and was removed
-
getProperty
public PropertyModelBuilder<?> getProperty(String propertyName)
Gets a property by the property name.- Parameters:
propertyName
- the name of the property to find.- Returns:
- the property or null if the property is not found
-
getPropertyModelBuilders
public List<PropertyModelBuilder<?>> getPropertyModelBuilders()
- Returns:
- the properties on the modeled type
-
build
public ClassModel<T> build()
Creates a new ClassModel instance based on the mapping data provided.- Returns:
- the new instance
-
-