blob: 9e6a6880d88aa30cfe63477e6d63171127c4bf15 [file] [log] [blame]
package org.eclipse.openk.contactbasedata.config;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
import java.sql.SQLException;
@Log4j2
@Configuration
@ConditionalOnProperty(
value="spring.datasource.enable-oracle-configuration",
havingValue = "true",
matchIfMissing = false)
public class OracleConfig {
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${oracle.ucp.minPoolSize}")
private String minPoolSize;
@Value("${oracle.ucp.maxPoolSize}")
private String maxPoolSize;
@Value("${spring.datasource.driver-class-name:oracle.jdbc.pool.OracleDataSource}")
private String driverClassName;
@SneakyThrows
@Bean(name = "OracleUniversalConnectionPool")
@Primary
public DataSource getDataSource() {
PoolDataSource pds = null;
try {
pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName(driverClassName);
pds.setURL(url);
pds.setUser(username);
pds.setPassword(password);
pds.setMinPoolSize(Integer.valueOf(minPoolSize));
pds.setInitialPoolSize(10);
pds.setMaxPoolSize(Integer.valueOf(maxPoolSize));
} catch (SQLException ea) {
log.error("Error connecting to the database: " + ea.getMessage());
}
return pds;
}
}