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

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

Introduction

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

Prototype

public String getUrl() 

Source Link

Document

Return the configured url 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 w  w  w  .j a  va 2 s  .co  m
    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:oauth2.OAuth2Application.java

/**
 * Log database URL to verify which database we use.
 *//*from w w  w.j a  va  2 s .  co m*/
@Autowired(required = false)
public void setDataSourceProperties(DataSourceProperties properties) {
    LOGGER.info("Use database {}", properties.getUrl());
}

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