Example usage for org.springframework.boot.autoconfigure.jdbc DataSourceProperties getDriverClassName

List of usage examples for org.springframework.boot.autoconfigure.jdbc DataSourceProperties getDriverClassName

Introduction

In this page you can find the example usage for org.springframework.boot.autoconfigure.jdbc DataSourceProperties getDriverClassName.

Prototype

public String getDriverClassName() 

Source Link

Document

Return the configured driver or null if none was configured.

Usage

From source file:com.thinkbiganalytics.db.PoolingDataSourceService.java

private static DataSource createDatasource(DataSourceProperties props) {
    DataSourceBuilder builder = DataSourceBuilder.create().url(props.getUrl()).username(props.getUser())
            .password(props.getPassword());
    if (StringUtils.isNotBlank(props.getDriverClassName())) {
        builder.driverClassName(props.getDriverClassName());
    }/*from   ww w .  j  av  a 2s.  com*/
    DataSource ds = builder.build();
    if (props.isTestOnBorrow() && StringUtils.isNotBlank(props.getValidationQuery())) {
        if (ds instanceof org.apache.tomcat.jdbc.pool.DataSource) {
            ((org.apache.tomcat.jdbc.pool.DataSource) ds).setTestOnBorrow(true);
            ((org.apache.tomcat.jdbc.pool.DataSource) ds).setValidationQuery(props.getValidationQuery());
        } else if (ds instanceof org.apache.commons.dbcp2.BasicDataSource) {
            ((org.apache.commons.dbcp2.BasicDataSource) ds).setValidationQuery(props.getValidationQuery());
            ((org.apache.commons.dbcp2.BasicDataSource) ds).setTestOnBorrow(true);
        } else if (ds instanceof org.apache.commons.dbcp.BasicDataSource) {
            ((org.apache.commons.dbcp.BasicDataSource) ds).setValidationQuery(props.getValidationQuery());
            ((org.apache.commons.dbcp.BasicDataSource) ds).setTestOnBorrow(true);
        }
    }
    return ds;
}

From source file:com.teradata.benchto.driver.jdbc.MultipleDataSourcesConfiguration.java

private DataSource createDataSource(DataSourceProperties properties) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(properties.getDriverClassName());
    dataSource.setUrl(properties.getUrl());
    dataSource.setUsername(properties.getUsername());
    dataSource.setPassword(properties.getPassword());
    return dataSource;
}

From source file:com.todo.backend.config.DatabaseConfiguration.java

@Bean(destroyMethod = "close")
public DataSource dataSource(DataSourceProperties dataSourceProperties, CustomProperties customProperties) {

    log.debug("Initializing datasource...");

    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    config.addDataSourceProperty("password",
            dataSourceProperties.getPassword() == null ? "" : dataSourceProperties.getPassword());

    // mysql specific
    config.addDataSourceProperty("cachePrepStmts", customProperties.getDatasource().isCachePrepStmts());
    config.addDataSourceProperty("prepStmtCacheSize", customProperties.getDatasource().getPrepStmtCacheSize());
    config.addDataSourceProperty("prepStmtCacheSqlLimit",
            customProperties.getDatasource().getPrepStmtCacheSqlLimit());
    config.addDataSourceProperty("useServerPrepStmts", customProperties.getDatasource().isUseServerPrepStmts());

    return new HikariDataSource(config);
}