Example usage for org.springframework.jdbc.datasource DriverManagerDataSource getUsername

List of usage examples for org.springframework.jdbc.datasource DriverManagerDataSource getUsername

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource DriverManagerDataSource getUsername.

Prototype

@Nullable
public String getUsername() 

Source Link

Document

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

Usage

From source file:org.mifos.core.SystemInfo.java

public SystemInfo(ApplicationInformationDto applicationInformationDto,
        DriverManagerDataSource driverManagerDataSource) {
    LOG.info("Mifos Cheetah system information:");
    LOG.info("  Software:");
    LOG.info("    Build Id: " + applicationInformationDto.getBuildId());
    LOG.info("    SVN revision: " + applicationInformationDto.getSvnRevision());
    LOG.info("    Build Tag: " + applicationInformationDto.getBuildTag());
    LOG.info("  Data source:");
    LOG.info("    JDBC URL: " + driverManagerDataSource.getUrl());
    LOG.info("    Database username: " + driverManagerDataSource.getUsername());
}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGenerator.java

@Autowired
public void setDiseaseDevJdbcTemplate(final JdbcTemplate diseaseDevJdbcTemplate) {

    final DriverManagerDataSource dataSource = (DriverManagerDataSource) diseaseDevJdbcTemplate.getDataSource();
    final String username = dataSource.getUsername();
    if (isTestAccount(username))
        throw new IllegalArgumentException("Test account '" + username
                + "' is not permitted for database connection property 'diseaseDevJdbcTemplate'");

    this.diseaseDevJdbcTemplate = diseaseDevJdbcTemplate;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGenerator.java

@Autowired
public void setDccCommonDevJdbcTemplate(final JdbcTemplate dccCommonDevJdbcTemplate) {

    final DriverManagerDataSource dataSource = (DriverManagerDataSource) dccCommonDevJdbcTemplate
            .getDataSource();// w  w w  . j  a  v  a2  s.co  m
    final String username = dataSource.getUsername();
    if (isTestAccount(username))
        throw new IllegalArgumentException("Test account '" + username
                + "' is not permitted for database connection property 'dccCommonDevJdbcTemplate'");

    this.dccCommonDevJdbcTemplate = dccCommonDevJdbcTemplate;
}

From source file:org.finra.herd.service.impl.RelationalTableRegistrationHelperServiceImpl.java

/**
 * Retrieves a list of actual schema columns for the specified relational table. This method uses actual JDBC connection to retrieve a description of table
 * columns./*from  w  ww  .  j av  a2 s .com*/
 *
 * @param relationalStorageAttributesDto the relational storage attributes DTO
 * @param relationalSchemaName the name of the relational database schema
 * @param relationalTableName the name of the relational table
 *
 * @return the list of schema columns for the specified relational table
 */
List<SchemaColumn> retrieveRelationalTableColumnsImpl(
        RelationalStorageAttributesDto relationalStorageAttributesDto, String relationalSchemaName,
        String relationalTableName) {
    // Get the JDBC password value.
    String password = getPassword(relationalStorageAttributesDto);

    // Create and initialize a driver manager data source (a simple implementation of the standard JDBC interface).
    // We only support PostgreSQL database type.
    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
    driverManagerDataSource.setUrl(relationalStorageAttributesDto.getJdbcUrl());
    driverManagerDataSource.setUsername(relationalStorageAttributesDto.getJdbcUsername());
    driverManagerDataSource.setPassword(password);
    driverManagerDataSource.setDriverClassName(JdbcServiceImpl.DRIVER_POSTGRES);

    // Create an empty result list.
    List<SchemaColumn> schemaColumns = new ArrayList<>();

    // Connect to the database and retrieve the relational table columns.
    try (Connection connection = driverManagerDataSource.getConnection()) {
        DatabaseMetaData databaseMetaData = connection.getMetaData();

        // Check if the specified relational table exists in the database.
        try (ResultSet tables = databaseMetaData.getTables(null, relationalSchemaName, relationalTableName,
                null)) {
            Assert.isTrue(tables.next(), String.format(
                    "Relational table with \"%s\" name not found under \"%s\" schema at jdbc.url=\"%s\" for jdbc.username=\"%s\".",
                    relationalTableName, relationalSchemaName, driverManagerDataSource.getUrl(),
                    driverManagerDataSource.getUsername()));
        }

        // Retrieve the relational table columns.
        try (ResultSet columns = databaseMetaData.getColumns(null, relationalSchemaName, relationalTableName,
                null)) {
            while (columns.next()) {
                SchemaColumn schemaColumn = new SchemaColumn();
                schemaColumn.setName(columns.getString("COLUMN_NAME"));
                schemaColumn.setType(columns.getString("TYPE_NAME"));
                schemaColumn.setSize(columns.getString("COLUMN_SIZE"));
                schemaColumn.setRequired(columns.getInt("NULLABLE") == 0);
                schemaColumn.setDefaultValue(columns.getString("COLUMN_DEF"));
                schemaColumns.add(schemaColumn);
            }
        }
    } catch (SQLException e) {
        throw new IllegalArgumentException(String.format(
                "Failed to retrieve description of a relational table with \"%s\" name under \"%s\" schema "
                        + "at jdbc.url=\"%s\" using jdbc.username=\"%s\". Reason: %s",
                relationalTableName, relationalSchemaName, driverManagerDataSource.getUrl(),
                driverManagerDataSource.getUsername(), e.getMessage()), e);
    }

    return schemaColumns;
}