Example usage for org.springframework.orm.jpa.vendor Database DEFAULT

List of usage examples for org.springframework.orm.jpa.vendor Database DEFAULT

Introduction

In this page you can find the example usage for org.springframework.orm.jpa.vendor Database DEFAULT.

Prototype

Database DEFAULT

To view the source code for org.springframework.orm.jpa.vendor Database DEFAULT.

Click Source Link

Usage

From source file:org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.java

/**
 * Return the most suitable {@link Database} for the given {@link DataSource}.
 * @param dataSource the source {@link DataSource}
 * @return the most suitable {@link Database}
 *//* w w  w . ja v a2 s. c  om*/
public static Database getDatabase(DataSource dataSource) {
    if (dataSource == null) {
        return Database.DEFAULT;
    }
    try {
        String url = 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;
}