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;
}
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);
}
}
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;
}
Aggregations