Example usage for org.springframework.jdbc.datasource SimpleDriverDataSource getUrl

List of usage examples for org.springframework.jdbc.datasource SimpleDriverDataSource getUrl

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource SimpleDriverDataSource getUrl.

Prototype

@Nullable
public String getUrl() 

Source Link

Document

Return the JDBC URL to use for connecting through the Driver.

Usage

From source file:org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.java

/**
 * Hook to initialize the embedded database.
 * <p>If the {@code generateUniqueDatabaseName} flag has been set to {@code true},
 * the current value of the {@linkplain #setDatabaseName database name} will
 * be overridden with an auto-generated name.
 * <p>Subclasses may call this method to force initialization; however,
 * this method should only be invoked once.
 * <p>After calling this method, {@link #getDataSource()} returns the
 * {@link DataSource} providing connectivity to the database.
 *//*  w w  w. j a  v a 2  s .  c  om*/
protected void initDatabase() {
    if (this.generateUniqueDatabaseName) {
        setDatabaseName(UUID.randomUUID().toString());
    }

    // Create the embedded database first
    if (this.databaseConfigurer == null) {
        this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL);
    }
    this.databaseConfigurer.configureConnectionProperties(this.dataSourceFactory.getConnectionProperties(),
            this.databaseName);
    this.dataSource = this.dataSourceFactory.getDataSource();

    if (logger.isInfoEnabled()) {
        if (this.dataSource instanceof SimpleDriverDataSource) {
            SimpleDriverDataSource simpleDriverDataSource = (SimpleDriverDataSource) this.dataSource;
            logger.info(String.format("Starting embedded database: url='%s', username='%s'",
                    simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
        } else {
            logger.info(String.format("Starting embedded database '%s'", this.databaseName));
        }
    }

    // Now populate the database
    if (this.databasePopulator != null) {
        try {
            DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource);
        } catch (RuntimeException ex) {
            // failed to populate, so leave it as not initialized
            shutdownDatabase();
            throw ex;
        }
    }
}