Class JdbcFeature

java.lang.Object
io.micronaut.starter.feature.database.jdbc.JdbcFeature
All Implemented Interfaces:
io.micronaut.core.naming.Described, io.micronaut.core.naming.Named, io.micronaut.core.order.Ordered, Feature, OneOfFeature, DatabaseDriverConfigurationFeature
Direct Known Subclasses:
Dbcp, Hikari, Tomcat, Ucp

public abstract class JdbcFeature extends Object implements OneOfFeature, DatabaseDriverConfigurationFeature
Abstract base feature for JDBC-related functionality.

This class provides common configuration keys and behavior for JDBC connection setup, including default database driver selection, configuration property keys, and integration with supported database types.

  • Field Details

    • PROPERTY_DATASOURCES_DEFAULT_DB_TYPE

      public static final String PROPERTY_DATASOURCES_DEFAULT_DB_TYPE
      See Also:
  • Constructor Details

  • Method Details

    • getOrder

      public int getOrder()
      Description copied from interface: Feature
      The order of a feature controls the order in which it applies. The order of a feature is important to ensure that any previous work done by other features that may be required is done. See FeaturePhase for a list of phases to choose from.
      Specified by:
      getOrder in interface Feature
      Specified by:
      getOrder in interface io.micronaut.core.order.Ordered
      Returns:
      The order of the feature
    • 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
      Parameters:
      featureContext - The feature context
    • getCategory

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

      public String getUrlKey()
      Description copied from interface: DatabaseDriverConfigurationFeature
      Returns the configuration property key for the database connection URL.
      Specified by:
      getUrlKey in interface DatabaseDriverConfigurationFeature
      Returns:
      the URL configuration key
    • getDriverKey

      public String getDriverKey()
      Description copied from interface: DatabaseDriverConfigurationFeature
      Returns the configuration property key for the database driver class name.
      Specified by:
      getDriverKey in interface DatabaseDriverConfigurationFeature
      Returns:
      the driver class name configuration key
    • getUsernameKey

      public String getUsernameKey()
      Description copied from interface: DatabaseDriverConfigurationFeature
      Returns the configuration property key for the database username.
      Specified by:
      getUsernameKey in interface DatabaseDriverConfigurationFeature
      Returns:
      the username configuration key
    • getPasswordKey

      public String getPasswordKey()
      Description copied from interface: DatabaseDriverConfigurationFeature
      Returns the configuration property key for the database password.
      Specified by:
      getPasswordKey in interface DatabaseDriverConfigurationFeature
      Returns:
      the password configuration key
    • addDatabaseConfigRecipe

      protected void addDatabaseConfigRecipe(GeneratorContext generatorContext, List<String> recipes)
      Adds a database configuration recipe to the list of recipes based on the features present in the GeneratorContext.

      The method checks for the presence of specific database features (e.g., PostgreSQL, MySQL, MariaDB, SQLServer, Oracle) in the GeneratorContext and adds the corresponding JDBC configuration recipe to the list. If none of the specific database features are present, it defaults to adding the H2 JDBC configuration recipe.

      Parameters:
      generatorContext - the context of the project generation, used to check for the presence of specific database features
      recipes - the list of recipes to which the database configuration recipe will be added