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 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

        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 the Entity annotation

        Possible 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

        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 using Property.

        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

        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