Package dev.morphia.config
Interface MorphiaConfig
@MorphiaExperimental
@ConfigMapping(prefix="morphia")
public interface MorphiaConfig
Please note that there is every expectation that this format/naming is stable. However, based on usage feedback prior to 3.0 some
tweaks might be made to improve the experience. As of 3.0, the experimental label will be dropped and the format fixed for the
existing configuration values.
- Since:
- 2.4
Developer note.
This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
Method Summary
Modifier and TypeMethodDescriptionIf true, collection caps will be applied to the database at start up.default MorphiaConfig
Updates this configuration with a new value and returns a new instance.If true, document validations will be enabled for entities/collections with validation mappings.default MorphiaConfig
applyDocumentValidations
(Boolean value) Updates this configuration with a new value and returns a new instance.If true, mapped indexes will be applied to the database at start up.default MorphiaConfig
applyIndexes
(Boolean value) Updates this configuration with a new value and returns a new instance.@WithConverter(CodecProviderConverter.class) Optional<CodecProvider>
Specifies aCodecProvider
to supply user defined codecs that Morphia should use.default MorphiaConfig
codecProvider
(CodecProvider value) Updates this configuration with a new value and returns a new instance.@WithConverter(NamingStrategyConverter.class) NamingStrategy
Sets the naming strategy to be used when generating collection names for entities if name is not explicitly given in theEntity
annotationdefault MorphiaConfig
collectionNaming
(NamingStrategy value) Updates this configuration with a new value and returns a new instance.database()
The database name that Morphia should use.default MorphiaConfig
Updates this configuration with a new value and returns a new instance.The date storage configuration Morphia should use for JSR 310 types.default MorphiaConfig
dateStorage
(DateStorage value) Updates this configuration with a new value and returns a new instance.@WithConverter(DiscriminatorFunctionConverter.class) DiscriminatorFunction
The function to use when calculating the discriminator value for an entitydefault MorphiaConfig
Updates this configuration with a new value and returns a new instance.The document field name to use when storing discriminator valuesdefault MorphiaConfig
discriminatorKey
(String value) Updates this configuration with a new value and returns a new instance.Enable polymorphic queries.default MorphiaConfig
enablePolymorphicQueries
(Boolean value) Updates this configuration with a new value and returns a new instance.Instructs Morphia to ignore final fields.default MorphiaConfig
ignoreFinals
(Boolean value) Updates this configuration with a new value and returns a new instance.default MorphiaConfig
legacy()
Creates a new configuration based on the current one but updated to reflect the legacy configuration.static MorphiaConfig
load()
Tries to load a configuration from the default location.static MorphiaConfig
Parses and loads the configuration found at the given locationpackages()
A comma delimited list of packages that Morphia should map.default MorphiaConfig
Updates this configuration with a new value and returns a new instance.Determines how properties are discovered.default MorphiaConfig
Updates this configuration with a new value and returns a new instance.@WithConverter(NamingStrategyConverter.class) NamingStrategy
Defines the strategy to use when generating property names to document field names for storage in the database when not explicitly set usingProperty
.default MorphiaConfig
propertyNaming
(NamingStrategy value) Updates this configuration with a new value and returns a new instance.@WithConverter(QueryFactoryConverter.class) QueryFactory
Specifies the query factory to use.default MorphiaConfig
queryFactory
(QueryFactory value) Updates this configuration with a new value and returns a new instance.Instructs Morphia on how to handle empty Collections and Maps.default MorphiaConfig
storeEmpties
(Boolean value) Updates this configuration with a new value and returns a new instance.Instructs Morphia on how to handle null property values.default MorphiaConfig
storeNulls
(Boolean value) Updates this configuration with a new value and returns a new instance.default String
toConfigFormat
(boolean showComplete) Converts this instance in to the format needed for a configuration file
-
Method Details
-
load
Tries to load a configuration from the default location.- Returns:
- the loaded config
-
load
Parses and loads the configuration found at the given location- Parameters:
location
- the location of the configuration to load. This can be a file path, a classpath resource, a URL, etc.- Returns:
- the loaded configuration
- Since:
- 3.0
-
collectionNaming
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
database
The database name that Morphia should use. This entry is required to be present and is the only necessary configuration element you need to provide as all the other entries have discernible default values.- Returns:
- the database name to be used with this configuration
-
applyCaps
If true, collection caps will be applied to the database at start up.- Returns:
- true if the caps should be applied
-
applyCaps
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
applyDocumentValidations
If true, document validations will be enabled for entities/collections with validation mappings.- Returns:
- true if the validations should be applied
- See Also:
- MongoDB documentation
- core/document-validation/
-
applyDocumentValidations
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
applyIndexes
If true, mapped indexes will be applied to the database at start up.- Returns:
- true if the indexes should be applied
-
applyIndexes
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
codecProvider
@WithConverter(CodecProviderConverter.class) @WithConverter(CodecProviderConverter.class) Optional<CodecProvider> codecProvider()Specifies aCodecProvider
to supply user defined codecs that Morphia should use.- Returns:
- the user configured CodecProvider
- Since:
- 2.4
- See Also:
-
codecProvider
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
collectionNaming
@WithDefault("camelCase") @PossibleValues({"camelCase","identity","kebabCase","lowerCase","snakeCase","fqcn"}) @WithConverter(NamingStrategyConverter.class) @WithConverter(NamingStrategyConverter.class) NamingStrategy collectionNaming()Sets the naming strategy to be used when generating collection names for entities if name is not explicitly given in theEntity
annotationPossible values include the documented values below as well as the fully qualified class name of a user supplied strategy.
- Returns:
- the strategy to use
- See Also:
-
database
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
dateStorage
The date storage configuration Morphia should use for JSR 310 types.- Returns:
- the date storage configuration value
-
dateStorage
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
discriminator
@WithDefault("simpleName") @WithConverter(DiscriminatorFunctionConverter.class) @PossibleValues({"className","lowerClassName","lowerSimpleName","simpleName","fqcn"}) @WithConverter(DiscriminatorFunctionConverter.class) DiscriminatorFunction discriminator()The function to use when calculating the discriminator value for an entity- Returns:
- the function to use
- See Also:
-
discriminator
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
discriminatorKey
The document field name to use when storing discriminator values- Returns:
- the discriminator property name
-
discriminatorKey
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
enablePolymorphicQueries
Enable polymorphic queries. By default, Morphia will only query for the given type. However, in cases where subtypes are stored in the same location, enabling this feature will instruct Morphia to fetch any subtypes that satisfy the query elements.- Returns:
- true if polymorphic queries are enabled
-
enablePolymorphicQueries
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
ignoreFinals
Instructs Morphia to ignore final fields.- Returns:
- true if Morphia should ignore final fields
-
ignoreFinals
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
legacy
Creates a new configuration based on the current one but updated to reflect the legacy configuration. This configuration is not changed.- Returns:
- the update configuration
- Since:
- 3.0
-
packages
A comma delimited list of packages that Morphia should map. If subpackages of a specific package should also be mapped, simply add a '*' to the end of the package name. e.g., 'com.foo.bar.*'- Returns:
- the list of packages to scan for entities
-
packages
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
propertyDiscovery
@WithDefault("fields") @PossibleValues(value={"fields","methods"}, fqcn=false) PropertyDiscovery propertyDiscovery()Determines how properties are discovered. The traditional value is by scanning for fields which involves a bit more reflective work. Alternately, scanning can check for get/set method pairs to determine which class properties should be mapped.- Returns:
- the discovery method to use
- See Also:
-
propertyDiscovery
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
propertyNaming
@WithDefault("identity") @WithConverter(NamingStrategyConverter.class) @PossibleValues({"camelCase","identity","kebabCase","lowerCase","snakeCase","fqcn"}) @WithConverter(NamingStrategyConverter.class) NamingStrategy propertyNaming()Defines the strategy to use when generating property names to document field names for storage in the database when not explicitly set usingProperty
.Possible values include the documented values below as well as the fully qualified class name of a user supplied strategy.
- Returns:
- the naming strategy for properties unless explicitly set via @Property
- See Also:
-
propertyNaming
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
queryFactory
@WithConverter(QueryFactoryConverter.class) @WithDefault("dev.morphia.query.DefaultQueryFactory") @WithConverter(QueryFactoryConverter.class) QueryFactory queryFactory()Specifies the query factory to use. Typically, there is no need to set this value.- Returns:
- the query factory
-
queryFactory
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
storeEmpties
Instructs Morphia on how to handle empty Collections and Maps.- Returns:
- true if Morphia should store empty values for lists/maps/sets/arrays
-
storeEmpties
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
storeNulls
Instructs Morphia on how to handle null property values.- Returns:
- true if Morphia should store null values
-
storeNulls
Updates this configuration with a new value and returns a new instance. The original instance is unchanged.- Parameters:
value
- the new value- Returns:
- a new instance with the updated configuration
- Since:
- 3.0
-
toConfigFormat
Converts this instance in to the format needed for a configuration file- Parameters:
showComplete
- true if all the entries should be shown. If false, only those settings with non-default values will be listed- Returns:
- the config file contents
-