JAVA-7334: Update 'Oracle Connection Pooling With Spring' article
This commit is contained in:
parent
2c837e030f
commit
e03662dd54
|
@ -146,7 +146,7 @@
|
||||||
<jdbi.version>3.9.1</jdbi.version>
|
<jdbi.version>3.9.1</jdbi.version>
|
||||||
<spring.boot.dependencies>2.1.8.RELEASE</spring.boot.dependencies>
|
<spring.boot.dependencies>2.1.8.RELEASE</spring.boot.dependencies>
|
||||||
<c3p0.version>0.9.5.2</c3p0.version>
|
<c3p0.version>0.9.5.2</c3p0.version>
|
||||||
<oracle-database.version>19.6.0.0</oracle-database.version>
|
<oracle-database.version>21.1.0.0</oracle-database.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -20,7 +20,8 @@ public class OracleConfiguration {
|
||||||
dataSource.setUser("books");
|
dataSource.setUser("books");
|
||||||
dataSource.setPassword("books");
|
dataSource.setPassword("books");
|
||||||
dataSource.setURL("jdbc:oracle:thin:@//localhost:11521/ORCLPDB1");
|
dataSource.setURL("jdbc:oracle:thin:@//localhost:11521/ORCLPDB1");
|
||||||
dataSource.setFastConnectionFailoverEnabled(true);
|
// Only with clients prior to v21
|
||||||
|
// dataSource.setFastConnectionFailoverEnabled(true);
|
||||||
dataSource.setImplicitCachingEnabled(true);
|
dataSource.setImplicitCachingEnabled(true);
|
||||||
// Only with clients prior to v11.2
|
// Only with clients prior to v11.2
|
||||||
// dataSource.setConnectionCachingEnabled(true);
|
// dataSource.setConnectionCachingEnabled(true);
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package com.baeldung.spring.oracle.pooling.configuration;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Profile;
|
|
||||||
|
|
||||||
import oracle.ucp.jdbc.PoolDataSource;
|
|
||||||
import oracle.ucp.jdbc.PoolDataSourceFactory;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@Profile("oracle-ucp")
|
|
||||||
public class OracleUCPConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DataSource dataSource() throws SQLException {
|
|
||||||
PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource();
|
|
||||||
dataSource.setUser("books");
|
|
||||||
dataSource.setPassword("books");
|
|
||||||
dataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
|
|
||||||
dataSource.setURL("jdbc:oracle:thin:@//localhost:11521/ORCLPDB1");
|
|
||||||
|
|
||||||
dataSource.setFastConnectionFailoverEnabled(true);
|
|
||||||
dataSource.setInitialPoolSize(5);
|
|
||||||
dataSource.setMinPoolSize(5);
|
|
||||||
dataSource.setMaxPoolSize(10);
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,6 +21,15 @@ spring.datasource.hikari.poolName=HikariPoolBooks
|
||||||
spring.datasource.tomcat.maxActive=15
|
spring.datasource.tomcat.maxActive=15
|
||||||
spring.datasource.tomcat.minIdle=5
|
spring.datasource.tomcat.minIdle=5
|
||||||
|
|
||||||
|
# UCP settings
|
||||||
|
#Note: These properties require JDBC version 21.0.0.0
|
||||||
|
spring.datasource.ucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
|
||||||
|
spring.datasource.ucp.sql-for-validate-connection=select * from dual
|
||||||
|
spring.datasource.ucp.connection-pool-name=UcpPoolBooks
|
||||||
|
spring.datasource.ucp.initial-pool-size=5
|
||||||
|
spring.datasource.ucp.min-pool-size=5
|
||||||
|
spring.datasource.ucp.max-pool-size=10
|
||||||
|
|
||||||
# JPA settings
|
# JPA settings
|
||||||
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
|
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
|
||||||
spring.jpa.hibernate.use-new-id-generator-mappings=false
|
spring.jpa.hibernate.use-new-id-generator-mappings=false
|
||||||
|
|
|
@ -9,11 +9,13 @@ import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
||||||
@ActiveProfiles({"oracle-pooling-basic", "oracle-ucp"})
|
@ActiveProfiles({"oracle-pooling-basic"})
|
||||||
|
@TestPropertySource(properties = "spring.datasource.type=oracle.ucp.jdbc.UCPDataSource")
|
||||||
public class SpringOraclePoolingApplicationOracleUCPLiveTest {
|
public class SpringOraclePoolingApplicationOracleUCPLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -21,7 +23,7 @@ public class SpringOraclePoolingApplicationOracleUCPLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenOracleUCPConfiguration_thenBuildsOraclePoolDataSource() {
|
public void givenOracleUCPConfiguration_thenBuildsOraclePoolDataSource() {
|
||||||
assertTrue(dataSource instanceof oracle.ucp.jdbc.PoolDataSource);
|
assertTrue(dataSource instanceof oracle.ucp.jdbc.UCPDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue