Search in sources :

Example 1 with DatabaseDriver

use of org.springframework.boot.jdbc.DatabaseDriver in project spring-boot by spring-projects.

the class DatabaseLookup method getDatabase.

/**
	 * Return the most suitable {@link Database} for the given {@link DataSource}.
	 * @param dataSource the source {@link DataSource}
	 * @return the most suitable {@link Database}
	 */
public static Database getDatabase(DataSource dataSource) {
    if (dataSource == null) {
        return Database.DEFAULT;
    }
    try {
        String url = (String) JdbcUtils.extractDatabaseMetaData(dataSource, "getURL");
        DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(url);
        Database database = LOOKUP.get(driver);
        if (database != null) {
            return database;
        }
    } catch (MetaDataAccessException ex) {
        logger.warn("Unable to determine jdbc url from datasource", ex);
    }
    return Database.DEFAULT;
}
Also used : MetaDataAccessException(org.springframework.jdbc.support.MetaDataAccessException) Database(org.springframework.orm.jpa.vendor.Database) DatabaseDriver(org.springframework.boot.jdbc.DatabaseDriver)

Example 2 with DatabaseDriver

use of org.springframework.boot.jdbc.DatabaseDriver in project spring-boot by spring-projects.

the class AbstractDatabaseInitializer method getDatabaseName.

protected String getDatabaseName() {
    try {
        String productName = JdbcUtils.commonDatabaseName(JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString());
        DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
        if (databaseDriver == DatabaseDriver.UNKNOWN) {
            throw new IllegalStateException("Unable to detect database type");
        }
        return databaseDriver.getId();
    } catch (MetaDataAccessException ex) {
        throw new IllegalStateException("Unable to detect database type", ex);
    }
}
Also used : MetaDataAccessException(org.springframework.jdbc.support.MetaDataAccessException) DatabaseDriver(org.springframework.boot.jdbc.DatabaseDriver)

Example 3 with DatabaseDriver

use of org.springframework.boot.jdbc.DatabaseDriver in project spring-boot by spring-projects.

the class DataSourceHealthIndicator method getValidationQuery.

protected String getValidationQuery(String product) {
    String query = this.query;
    if (!StringUtils.hasText(query)) {
        DatabaseDriver specific = DatabaseDriver.fromProductName(product);
        query = specific.getValidationQuery();
    }
    if (!StringUtils.hasText(query)) {
        query = DEFAULT_QUERY;
    }
    return query;
}
Also used : DatabaseDriver(org.springframework.boot.jdbc.DatabaseDriver)

Aggregations

DatabaseDriver (org.springframework.boot.jdbc.DatabaseDriver)3 MetaDataAccessException (org.springframework.jdbc.support.MetaDataAccessException)2 Database (org.springframework.orm.jpa.vendor.Database)1