Java Code Examples for io.micronaut.core.util.StringUtils#hasText()

The following examples show how to use io.micronaut.core.util.StringUtils#hasText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalculatedSettings.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the driver class name based on the configured value. If not
 * configured, determine the driver class name based on the URL. If the
 * URL is not configured, look for an embedded database driver on the
 * classpath.
 *
 * @return The calculated driver class name
 */
public String getDriverClassName() {
    final String driverClassName = basicJdbcConfiguration.getConfiguredDriverClassName();
    if (calculatedDriverClassName == null || StringUtils.hasText(driverClassName)) {
        if (StringUtils.hasText(driverClassName)) {
            if (!driverClassIsPresent(driverClassName)) {
                throw new ConfigurationException(String.format("Error configuring data source '%s'. The driver class '%s' was not found on the classpath", basicJdbcConfiguration.getName(), driverClassName));
            }
            calculatedDriverClassName = driverClassName;
        } else {
            final String url = basicJdbcConfiguration.getUrl();
            if (StringUtils.hasText(url)) {
                JdbcDatabaseManager.findDatabase(url).ifPresent(db ->
                    calculatedDriverClassName = db.getDriverClassName());
            }

            if (!StringUtils.hasText(calculatedDriverClassName) && embeddedDatabaseConnection.isPresent()) {
                calculatedDriverClassName = this.embeddedDatabaseConnection.get().getDriverClassName();
            }

            if (!StringUtils.hasText(calculatedDriverClassName)) {
                throw new ConfigurationException(String.format("Error configuring data source '%s'. No driver class name specified", basicJdbcConfiguration.getName()));
            }
        }
    }

    return calculatedDriverClassName;
}
 
Example 2
Source File: CalculatedSettings.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the URL based on the configured value. If the URL is
 * not configured, search for an embedded database driver on the
 * classpath and retrieve a default URL for it.
 *
 * @return The calculated URL
 */
public String getUrl() {
    final String url = basicJdbcConfiguration.getConfiguredUrl();
    if (calculatedUrl == null || StringUtils.hasText(url)) {
        calculatedUrl = url;
        if (!StringUtils.hasText(calculatedUrl) && embeddedDatabaseConnection.isPresent()) {
            calculatedUrl = embeddedDatabaseConnection.get().getUrl(basicJdbcConfiguration.getName());
        }
        if (!StringUtils.hasText(calculatedUrl)) {
            throw new ConfigurationException(String.format("Error configuring data source '%s'. No URL specified", basicJdbcConfiguration.getName()));
        }
    }

    return calculatedUrl;
}
 
Example 3
Source File: CalculatedSettings.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the username based on the configured value. If the
 * username is not configured and an embedded database driver is
 * on the classpath, return 'sa'.
 *
 * @return The calculated username
 */
public String getUsername() {
    final String username = basicJdbcConfiguration.getConfiguredUsername();
    if (calculatedUsername == null || StringUtils.hasText(username)) {
        calculatedUsername = username;
        if (!StringUtils.hasText(calculatedUsername) && JdbcDatabaseManager.isEmbedded(basicJdbcConfiguration.getDriverClassName())) {
            calculatedUsername = "sa";
        }
    }

    return calculatedUsername;
}
 
Example 4
Source File: CalculatedSettings.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the password based on the configured value. If the
 * password is not configured and an embedded database driver is
 * on the classpath, return an empty string.
 *
 * @return The calculated password
 */
public String getPassword() {
    final String password = basicJdbcConfiguration.getConfiguredPassword();
    if (calculatedPassword == null || StringUtils.hasText(password)) {
        calculatedPassword = password;
        if (!StringUtils.hasText(calculatedPassword) && JdbcDatabaseManager.isEmbedded(basicJdbcConfiguration.getDriverClassName())) {
            calculatedPassword = "";
        }
    }

    return calculatedPassword;
}
 
Example 5
Source File: CalculatedSettings.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the validation query based on the configured value. If the
 * validation query is not configured, search pre-defined databases for
 * a match based on the URL. If a match is found, return the defined
 * validation query for that database.
 *
 * @return The calculated validation query
 */
public String getValidationQuery() {
    final String validationQuery = basicJdbcConfiguration.getConfiguredValidationQuery();
    if (calculatedValidationQuery == null || StringUtils.hasText(validationQuery)) {
        calculatedValidationQuery = validationQuery;
        if (!StringUtils.hasText(calculatedValidationQuery)) {
            JdbcDatabaseManager.findDatabase(getUrl()).ifPresent(db ->
                calculatedValidationQuery = db.getValidationQuery());
        }
    }

    return calculatedValidationQuery;
}
 
Example 6
Source File: MicronautLockConfigurationExtractor.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
private Duration getValue(AnnotationValue<SchedulerLock> annotation, Duration defaultValue, String paramName) {
    String stringValueFromAnnotation = annotation.get(paramName, String.class).orElse("");
    if (StringUtils.hasText(stringValueFromAnnotation)) {
        return conversionService.convert(stringValueFromAnnotation, Duration.class)
            .orElseThrow(() -> new IllegalArgumentException("Invalid " + paramName + " value \"" + stringValueFromAnnotation + "\" - cannot parse into duration"));
    } else {
        return defaultValue;
    }
}
 
Example 7
Source File: FlywayConfigurationProperties.java    From micronaut-flyway with Apache License 2.0 2 votes vote down vote up
/**
 * Whether there is an alternative database configuration for the migration. By default Micronaut will use the
 * {@link javax.sql.DataSource} defined for the application but if both {@code url} and {@code user} are defined,
 * then those will be use for Flyway.
 *
 * @return true if there is an alternative database configuration
 */
public boolean hasAlternativeDatabaseConfiguration() {
    return StringUtils.hasText(this.getUrl());
}