Java Code Examples for io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier#connectionPoolConfiguration()

The following examples show how to use io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier#connectionPoolConfiguration() . 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
Source File: AgroalDataSourceFactory.java    From kumuluzee with MIT License 5 votes vote down vote up
public static AgroalDataSource createDataSource(DataSourceConfig dsc, boolean jtaPresent) {
    AgroalDataSourceConfigurationSupplier dataSourceConfig = new AgroalDataSourceConfigurationSupplier();

    AgroalConnectionPoolConfigurationSupplier poolConfig = dataSourceConfig.connectionPoolConfiguration();

    AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfig = poolConfig.connectionFactoryConfiguration();

    if (!jtaPresent) {
        dataSourceConfig.dataSourceImplementation(DataSourceImplementation.HIKARI);
    } else {
        poolConfig.transactionIntegration( JtaProvider.getInstance().getTransactionIntegration() );
    }

    if (!StringUtils.isNullOrEmpty( dsc.getDriverClass() )) {
        connectionFactoryConfig.connectionProviderClassName(dsc.getDriverClass());
    } else if (!StringUtils.isNullOrEmpty( dsc.getDataSourceClass( ))) {
        connectionFactoryConfig.connectionProviderClassName(dsc.getDataSourceClass());
    }

    if (!StringUtils.isNullOrEmpty( dsc.getConnectionUrl() )) {
        connectionFactoryConfig.jdbcUrl(dsc.getConnectionUrl());
    }

    setDatabaseCredentials(connectionFactoryConfig, dsc.getUsername(), dsc.getPassword());

    setConnectionPoolConfiguration(poolConfig, connectionFactoryConfig, dsc.getPool(), !jtaPresent);

    dsc.getProps().forEach(connectionFactoryConfig::jdbcProperty);

    try {
        return AgroalDataSource.from( dataSourceConfig );
    } catch (SQLException e) {
        throw new KumuluzServerException("Failed to create DataSource", e);
    }
}
 
Example 2
Source File: AgroalDataSourceFactory.java    From kumuluzee with MIT License 5 votes vote down vote up
public static AgroalDataSource createXaDataSource(XaDataSourceConfig xdsc, boolean jtaPresent) {
    AgroalDataSourceConfigurationSupplier xaDataSourceConfig = new AgroalDataSourceConfigurationSupplier();

    AgroalConnectionPoolConfigurationSupplier poolConfig = xaDataSourceConfig.connectionPoolConfiguration();

    AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfig = poolConfig.connectionFactoryConfiguration();

    if (jtaPresent) {
        poolConfig.transactionIntegration( JtaProvider.getInstance().getTransactionIntegration() );
    }

    if (!StringUtils.isNullOrEmpty( xdsc.getXaDatasourceClass() )) {
        connectionFactoryConfig.connectionProviderClassName( xdsc.getXaDatasourceClass() );
    }

    setDatabaseCredentials(connectionFactoryConfig, xdsc.getUsername(), xdsc.getPassword());

    setConnectionPoolConfiguration(poolConfig, connectionFactoryConfig, xdsc.getPool(), false);

    xdsc.getProps().forEach(connectionFactoryConfig::jdbcProperty);

    try {
        return AgroalDataSource.from( xaDataSourceConfig );
    } catch (SQLException e) {
        throw new KumuluzServerException("Failed to create XaDataSource", e);
    }
}