Class DatabaseDriverFeature

java.lang.Object
io.micronaut.starter.feature.testresources.EaseTestingFeature
io.micronaut.starter.feature.database.DatabaseDriverFeature
All Implemented Interfaces:
io.micronaut.core.naming.Described, io.micronaut.core.naming.Named, io.micronaut.core.order.Ordered, Feature, OneOfFeature, DatabaseDriverFeatureDependencies, TestResourcesAdditionalModulesProvider
Direct Known Subclasses:
H2, MySQLCompatibleFeature, Oracle, OracleCloudAutonomousDatabase, PostgreSQL, SQLServer

public abstract class DatabaseDriverFeature extends EaseTestingFeature implements OneOfFeature, DatabaseDriverFeatureDependencies, TestResourcesAdditionalModulesProvider
Abstract base class for database driver features.

Handles dependency management, configuration, and integration of JDBC, R2DBC, Hibernate, migration tools, and test resources for Micronaut projects. Provides helper methods for feature selection, dependency resolution, and implementation of database-specific logic.

  • Constructor Details

    • DatabaseDriverFeature

      public DatabaseDriverFeature()
    • DatabaseDriverFeature

      public DatabaseDriverFeature(JdbcFeature jdbcFeature, TestContainers testContainers, TestResources testResources)
  • Method Details

    • getFeatureClass

      public Class<?> getFeatureClass()
      Specified by:
      getFeatureClass in interface OneOfFeature
    • processSelectedFeatures

      public void processSelectedFeatures(FeatureContext featureContext)
      Description copied from interface: Feature
      If this method is called for a given feature then that feature was explicitly selected or was included by default as a result of DefaultFeature.shouldApply(io.micronaut.starter.options.Options, java.util.Set). This method can be implemented to allow features to modify the list of features that will apply to the project. The methods FeatureContext.addFeature(Feature) and FeatureContext.exclude(FeaturePredicate) are the primary ways to add and remove features from the context. FeatureContext.isPresent(Class) can be used to determine the existence of other features in order to make decisions.
      Specified by:
      processSelectedFeatures in interface Feature
      Overrides:
      processSelectedFeatures in class EaseTestingFeature
      Parameters:
      featureContext - The feature context
    • getCategory

      public String getCategory()
      Specified by:
      getCategory in interface Feature
      Returns:
      The Category to which the feature belongs to.
    • embedded

      public abstract boolean embedded()
    • getJdbcUrl

      public abstract String getJdbcUrl()
    • getR2dbcUrl

      public abstract String getR2dbcUrl()
    • getDriverClass

      public abstract String getDriverClass()
    • getDefaultUser

      public abstract String getDefaultUser()
    • getDefaultPassword

      public abstract String getDefaultPassword()
    • getDataDialect

      public abstract String getDataDialect()
    • getDbType

      @NonNull public @NonNull Optional<DbType> getDbType()
      Returns the database type if applicable.

      Subclasses may override this to provide a specific DbType. Ensure consistency with other database-related features.

      Returns:
      An Optional containing the DbType, or empty if not applicable.
    • getTestResourcesAdditionalModules

      @NonNull public @NonNull List<String> getTestResourcesAdditionalModules(@NonNull @NonNull GeneratorContext generatorContext)
      Specified by:
      getTestResourcesAdditionalModules in interface TestResourcesAdditionalModulesProvider
    • getTestResourcesDependencies

      @NonNull public @NonNull List<MavenCoordinate> getTestResourcesDependencies(@NonNull @NonNull GeneratorContext generatorContext)
      Specified by:
      getTestResourcesDependencies in interface TestResourcesAdditionalModulesProvider
    • getAdditionalConfig

      public Map<String,Object> getAdditionalConfig(GeneratorContext generatorContext)
      Provides additional configuration specific to the database driver feature.
      Parameters:
      generatorContext - the context of the project generation
      Returns:
      a map containing additional configuration properties; empty by default
    • apply

      public void apply(GeneratorContext generatorContext)
      Description copied from interface: Feature
      If this method is called for a given feature that means the feature was explicitly selected, included by default as a result of DefaultFeature.shouldApply(io.micronaut.starter.options.Options, java.util.Set), or added explicitly by another feature through FeatureContext.addFeature(Feature). At this point the feature list is set and cannot change.
      Specified by:
      apply in interface Feature
      Parameters:
      generatorContext - THe generator context
    • parseDependencies

      @NonNull protected @NonNull List<Dependency.Builder> parseDependencies(GeneratorContext generatorContext)
      Parses and returns a list of dependencies required for the database driver feature based on the provided GeneratorContext.

      The method considers various features such as R2DBC, Hibernate Reactive, and Migration to determine the necessary dependencies. It uses the GeneratorContext to check for the presence of specific features and accordingly adds the required dependencies to the list.

      Parameters:
      generatorContext - the context of the project generation
      Returns:
      a non-null list of Dependency.Builder objects representing the dependencies required for the database driver feature
    • dependenciesForHibernateReactive

      @NonNull protected @NonNull List<Dependency.Builder> dependenciesForHibernateReactive(@NonNull @NonNull GeneratorContext generatorContext)
      Returns a list of dependencies required for Hibernate Reactive based on the provided GeneratorContext.

      This method considers the presence of the Migration feature to determine whether to include the Java client dependency in addition to the Hibernate Reactive Java client dependency.

      Parameters:
      generatorContext - the context of the project generation, which is used to check for the presence of specific features
      Returns:
      a non-null list of Dependency.Builder objects representing the dependencies required for Hibernate Reactive