Example usage for org.springframework.boot.jdbc DatabaseDriver fromJdbcUrl

List of usage examples for org.springframework.boot.jdbc DatabaseDriver fromJdbcUrl

Introduction

In this page you can find the example usage for org.springframework.boot.jdbc DatabaseDriver fromJdbcUrl.

Prototype

public static DatabaseDriver fromJdbcUrl(String url) 

Source Link

Document

Find a DatabaseDriver for the given URL.

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}
 *//*from w  w w  .  jav  a2s.  co m*/
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;
}

From source file:org.springframework.boot.jdbc.DataSourceBuilder.java

private void maybeGetDriverClassName() {
    if (!this.properties.containsKey("driverClassName") && this.properties.containsKey("url")) {
        String url = this.properties.get("url");
        String driverClass = DatabaseDriver.fromJdbcUrl(url).getDriverClassName();
        this.properties.put("driverClassName", driverClass);
    }/* ww w . j  a va  2 s  . c o  m*/
}

From source file:org.springframework.cloud.dataflow.server.repository.support.DataflowRdbmsInitializer.java

private String getDatabaseType(DataSource dataSource) {
    Connection connection = null;

    try {/* w w  w  . j  a v  a  2  s  .  co m*/
        connection = dataSource.getConnection();
        return DatabaseDriver.fromJdbcUrl(connection.getMetaData().getURL()).getId();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to detect database type", ex);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                throw new IllegalStateException("Unable to detect database type", e);
            }
        }
    }
}