Java Code Examples for org.springframework.boot.jdbc.DatabaseDriver

The following examples show how to use org.springframework.boot.jdbc.DatabaseDriver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 获取当前使用数据库类型
 */
private static String getDatabaseName(DataSource dataSource) {
    try {
        String productName = JdbcUtils.
                commonDatabaseName(JdbcUtils.extractDatabaseMetaData(
                        dataSource, "getDatabaseProductName"
                ).toString());
        DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
        if (databaseDriver == DatabaseDriver.UNKNOWN) {
            throw new IllegalStateException("Unable to detect database type");
        }
        return databaseDriver.getId();
    } catch (MetaDataAccessException ex) {
        throw new IllegalStateException("Unable to detect database type", ex);
    }
}
 
Example 2
@Override
public void customize(FluentConfiguration configuration) {
	// boot's flyway auto-config doesn't allow to define callbacks per
	// vendor id, so essentially customizing those here.
	DataSource dataSource = configuration.getDataSource();
	DatabaseDriver databaseDriver = getDatabaseDriver(dataSource);
	logger.info("Customizing flyway config, detected DatabaseDriver as {}.", databaseDriver);
	if (databaseDriver == DatabaseDriver.POSTGRESQL) {
		configuration.callbacks(new PostgresBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.MYSQL || databaseDriver == DatabaseDriver.MARIADB) {
		configuration.callbacks(new MysqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.SQLSERVER) {
		configuration.callbacks(new MsSqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.ORACLE) {
		configuration.callbacks(new OracleBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.DB2) {
		configuration.callbacks(new Db2BeforeBaseline());
	}
}
 
Example 3
@Override
public void customize(FluentConfiguration configuration) {
	// boot's flyway auto-config doesn't allow to define callbacks per
	// vendor id, so essentially customizing those here.
	DataSource dataSource = configuration.getDataSource();
	DatabaseDriver databaseDriver = getDatabaseDriver(dataSource);
	if (databaseDriver == DatabaseDriver.POSTGRESQL) {
		configuration.callbacks(new PostgresBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.MYSQL || databaseDriver == DatabaseDriver.MARIADB) {
		configuration.callbacks(new MysqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.SQLSERVER) {
		configuration.callbacks(new MsSqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.ORACLE) {
		configuration.callbacks(new OracleBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.DB2) {
		configuration.callbacks(new Db2BeforeBaseline());
	}
}
 
Example 4
private DatabaseDriver getDatabaseDriver(DataSource dataSource) {
	// copied from boot's flyway auto-config to get matching db vendor id
	try {
		String url = JdbcUtils.extractDatabaseMetaData(dataSource, "getURL");
		return DatabaseDriver.fromJdbcUrl(url);
	}
	catch (MetaDataAccessException ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 5
Source Project: teiid-spring-boot   Source File: XADataSourceBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public String dataSourceClassName() {
    String className = this.properties.get("dataSourceClassName");
    if (!StringUtils.hasLength(className)) {
        String url = this.properties.get("url");
        className = DatabaseDriver.fromJdbcUrl(url).getXaDataSourceClassName();
    }
    return className;
}
 
Example 6
private DatabaseDriver getDatabaseDriver(DataSource dataSource) {
	// copied from boot's flyway auto-config to get matching db vendor id
	try {
		String url = JdbcUtils.extractDatabaseMetaData(dataSource, "getURL");
		return DatabaseDriver.fromJdbcUrl(url);
	}
	catch (MetaDataAccessException ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 7
Source Project: sample-boot-micro   Source File: OrmDataSourceProperties.java    License: MIT License 4 votes vote down vote up
private String driverClassName() {
    if (StringUtils.hasText(driverClassName)) {
        return driverClassName;
    }
    return DatabaseDriver.fromJdbcUrl(url).getDriverClassName();
}
 
Example 8
Source Project: sample-boot-micro   Source File: OrmDataSourceProperties.java    License: MIT License 4 votes vote down vote up
private String validationQuery() {
    if (StringUtils.hasText(validationQuery)) {
        return validationQuery;
    }
    return DatabaseDriver.fromJdbcUrl(url).getValidationQuery();
}