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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description Boolean
applyCaps()
If true, collection caps will be applied to the database at start up.default MorphiaConfig
applyCaps(Boolean value)
Updates this configuration with a new value and returns a new instance.Boolean
applyDocumentValidations()
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.Boolean
applyIndexes()
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>
codecProvider()
Deprecated, for removal: This API element is subject to removal in a future version.this configuration entry will be updated to use SPI as with other customizationsdefault MorphiaConfig
codecProvider(CodecProvider value)
Updates this configuration with a new value and returns a new instance.@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
annotationdefault MorphiaConfig
collectionNaming(NamingStrategy value)
Updates this configuration with a new value and returns a new instance.String
database()
The database name that Morphia should use.default MorphiaConfig
database(String value)
Updates this configuration with a new value and returns a new instance.DateStorage
dateStorage()
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
discriminator()
The function to use when calculating the discriminator value for an entitydefault MorphiaConfig
discriminator(DiscriminatorFunction value)
Updates this configuration with a new value and returns a new instance.String
discriminatorKey()
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.Boolean
enablePolymorphicQueries()
Enable polymorphic queries.default MorphiaConfig
enablePolymorphicQueries(Boolean value)
Updates this configuration with a new value and returns a new instance.Boolean
ignoreFinals()
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
load(String path)
Parses and loads the configuration found at the given locationList<String>
packages()
A comma delimited list of packages that Morphia should map.default MorphiaConfig
packages(List<String> value)
Updates this configuration with a new value and returns a new instance.MapperOptions.PropertyDiscovery
propertyDiscovery()
Determines how properties are discovered.default MorphiaConfig
propertyDiscovery(MapperOptions.PropertyDiscovery value)
Updates this configuration with a new value and returns a new instance.@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
.default MorphiaConfig
propertyNaming(NamingStrategy value)
Updates this configuration with a new value and returns a new instance.@WithConverter(QueryFactoryConverter.class) QueryFactory
queryFactory()
Specifies the query factory to use.default MorphiaConfig
queryFactory(QueryFactory value)
Updates this configuration with a new value and returns a new instance.Boolean
storeEmpties()
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.Boolean
storeNulls()
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.UuidRepresentation
uuidRepresentation()
Deprecated, for removal: This API element is subject to removal in a future version.This should be configured in the MongoClient given to Morphiadefault MorphiaConfig
uuidRepresentation(UuidRepresentation value)
Updates this configuration with a new value and returns a new instance.
-
-
-
Method Detail
-
load
static MorphiaConfig load()
Tries to load a configuration from the default location.- Returns:
- the loaded config
-
load
static MorphiaConfig load(String path)
Parses and loads the configuration found at the given location- Parameters:
path
- 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
default MorphiaConfig collectionNaming(NamingStrategy value)
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
@WithDefault("morphia") String 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
@WithDefault("false") Boolean applyCaps()
If true, collection caps will be applied to the database at start up.- Returns:
- true if the caps should be applied
-
applyCaps
default MorphiaConfig applyCaps(Boolean value)
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
@WithDefault("false") Boolean applyDocumentValidations()
If true, document validations will be enabled for entities/collections with validation mappings.- Returns:
- true if the validations should be applied
- See Also:
Validation
- MongoDB documentation
- core/document-validation/
-
applyDocumentValidations
default MorphiaConfig applyDocumentValidations(Boolean value)
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
@WithDefault("false") Boolean applyIndexes()
If true, mapped indexes will be applied to the database at start up.- Returns:
- true if the indexes should be applied
-
applyIndexes
default MorphiaConfig applyIndexes(Boolean value)
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
@Deprecated(since="2.4.0", forRemoval=true) @WithConverter(CodecProviderConverter.class) @WithConverter(CodecProviderConverter.class) Optional<CodecProvider> codecProvider()
Deprecated, for removal: This API element is subject to removal in a future version.this configuration entry will be updated to use SPI as with other customizationsSpecifies aCodecProvider
to supply user defined codecs that Morphia should use.- Returns:
- the user configured CodecProvider
- Since:
- 2.4
- See Also:
CodecProvider
-
codecProvider
default MorphiaConfig codecProvider(CodecProvider value)
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:
Entity
,NamingStrategy
-
database
default MorphiaConfig database(String value)
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
@WithDefault("utc") DateStorage dateStorage()
The date storage configuration Morphia should use for JSR 310 types.- Returns:
- the date storage configuration value
-
dateStorage
default MorphiaConfig dateStorage(DateStorage value)
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:
DiscriminatorFunction
-
discriminator
default MorphiaConfig discriminator(DiscriminatorFunction value)
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
@WithDefault("_t") String discriminatorKey()
The document field name to use when storing discriminator values- Returns:
- the discriminator property name
-
discriminatorKey
default MorphiaConfig discriminatorKey(String value)
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
@WithDefault("false") Boolean 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
default MorphiaConfig enablePolymorphicQueries(Boolean value)
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
@WithDefault("false") Boolean ignoreFinals()
Instructs Morphia to ignore final fields.- Returns:
- true if Morphia should ignore final fields
-
ignoreFinals
default MorphiaConfig ignoreFinals(Boolean value)
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
default MorphiaConfig 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
@WithDefault(".*") List<String> 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
default MorphiaConfig packages(List<String> value)
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) MapperOptions.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:
MapperOptions.PropertyDiscovery
-
propertyDiscovery
default MorphiaConfig propertyDiscovery(MapperOptions.PropertyDiscovery value)
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:
Property
,NamingStrategy
-
propertyNaming
default MorphiaConfig propertyNaming(NamingStrategy value)
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
default MorphiaConfig queryFactory(QueryFactory value)
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
@WithDefault("false") Boolean 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
default MorphiaConfig storeEmpties(Boolean value)
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
@WithDefault("false") Boolean storeNulls()
Instructs Morphia on how to handle null property values.- Returns:
- true if Morphia should store null values
-
storeNulls
default MorphiaConfig storeNulls(Boolean value)
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
-
uuidRepresentation
@WithDefault("standard") @Deprecated(forRemoval=true, since="2.4.0") UuidRepresentation uuidRepresentation()
Deprecated, for removal: This API element is subject to removal in a future version.This should be configured in the MongoClient given to Morphia- Returns:
- the UUID representation to use in the driver
-
uuidRepresentation
default MorphiaConfig uuidRepresentation(UuidRepresentation value)
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
-
-