Skip to content

Commit dfff7dc

Browse files
authored
UCP and Wallet sample (#142)
1 parent 5a0eb99 commit dfff7dc

File tree

6 files changed

+225
-1
lines changed

6 files changed

+225
-1
lines changed

database/starters/oracle-spring-boot-starter-samples/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ The JSON Relational Duality Views sample application demonstrates how to use the
1414

1515
This sample application demonstrates how to use the Oracle Spring Boot Starter for the [Kafka Java Client for Oracle Database Transactional Event Queues](https://github.com/oracle/okafka)
1616

17-
Using an in-database message broker like Oracle Database Transactional Event Queues eliminates the need for external message brokers, reduces overall network traffic, simplifying your overall application architecture — and the Kafka Java Client for Oracle Database Transactional Event Queues library enables developers to create applications for Oracle Database Transactional Event Queues using familiar Kafka APIs for messaging.
17+
Using an in-database message broker like Oracle Database Transactional Event Queues eliminates the need for external message brokers, reduces overall network traffic, simplifying your overall application architecture — and the Kafka Java Client for Oracle Database Transactional Event Queues library enables developers to create applications for Oracle Database Transactional Event Queues using familiar Kafka APIs for messaging.
18+
19+
### [Oracle UCP using Wallet](./oracle-spring-boot-sample-wallet)
20+
21+
This sample application demonstrates how to connect to an Autonomous database using the Oracle Spring Boot Starter UCP and Oracle Spring Boot Starter Wallet all while using the best connection pooling library for Oracle Database with Spring Boot.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Oracle Spring Boot Sample UCP using Wallet
2+
3+
This sample application demonstrates how to connect to an Autonomous database using the Oracle Spring Boot Starter UCP, [UCP Documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/), and Oracle Spring Boot Starter Wallet, [Database Connection with Wallet](https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/connect-download-wallet.html), all while using the best connection pooling library for Oracle Database with Spring Boot.
4+
5+
## Wallet
6+
7+
1. Download the Wallet using the following [instructions](https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/connect-download-wallet.html#GUID-DED75E69-C303-409D-9128-5E10ADD47A35).
8+
1. Unzip the Wallet ZIP file
9+
1. Open the `sqlnet.ora` file and modify the line `WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="<DIRECTORY_OF_UNZIPPED_WALLET>")))` to make the `DIRECTORY` parameter point to the directory where you unzipped the wallet.
10+
11+
## Configure the application
12+
13+
Open the `application.yaml` file and modify the `url` and `password` parameter to reflect your environment.
14+
15+
```yaml
16+
spring:
17+
application:
18+
name: ucp-wallet
19+
20+
# Datasource Configuration
21+
datasource:
22+
url: jdbc:oracle:thin:@<TNSNAMES_ORA_ENTRY>?TNS_ADMIN=<DIRECTORY_OF_UNZIPPED_WALLET>
23+
username: ADMIN
24+
password: <PASSWORD>
25+
driver-class-name: oracle.jdbc.OracleDriver
26+
type: oracle.ucp.jdbc.PoolDataSource
27+
oracleucp:
28+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
29+
connection-pool-name: UCPWalletConnectionPool
30+
initial-pool-size: 15
31+
min-pool-size: 10
32+
max-pool-size: 30
33+
```
34+
35+
## Run the sample application
36+
37+
To run the testapplication, execute the following command:
38+
39+
```shell
40+
mvn clean spring-boot:run
41+
```
42+
43+
The output of the test application should look similar to this.
44+
45+
```text
46+
Datasource is : oracle.ucp.jdbc.PoolDataSourceImpl
47+
Connection is : oracle.ucp.jdbc.proxy.oracle$1ucp$1jdbc$1proxy$1oracle$1ConnectionProxy$2oracle$1jdbc$1internal$1OracleConnection$$$Proxy@527fc8e
48+
Hello World!
49+
Oracle Database 23ai Enterprise Edition Release 23.0.0.0.0 - Production
50+
Version 23.6.0.24.07
51+
```
52+
53+
## Configure your project to use Oracle Spring Boot Starters for UCP and Wallet
54+
55+
To use Oracle Spring Boot Starters for UCP and Wallet from your Spring Boot application, add the following Maven dependency to your project:
56+
57+
```xml
58+
<dependencies>
59+
<dependency>
60+
<groupId>com.oracle.database.spring</groupId>
61+
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.oracle.database.spring</groupId>
65+
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
66+
</dependency>
67+
</dependencies>
68+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Copyright (c) 2024, Oracle and/or its affiliates. -->
3+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. -->
4+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<artifactId>oracle-spring-boot-starter-samples</artifactId>
9+
<groupId>com.oracle.database.spring</groupId>
10+
<version>24.3.0</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>oracle-spring-boot-sample-wallet</artifactId>
15+
<version>24.3.0</version>
16+
17+
<name>Oracle Spring Boot Starter - UCP using a Wallet</name>
18+
<description>oracle-spring-boot-starter-samples-ucp-wallet</description>
19+
20+
<organization>
21+
<name>Oracle America, Inc.</name>
22+
<url>https://www.oracle.com</url>
23+
</organization>
24+
25+
<developers>
26+
<developer>
27+
<name>Oracle</name>
28+
<email>obaas_ww at oracle.com</email>
29+
<organization>Oracle America, Inc.</organization>
30+
<organizationUrl>https://www.oracle.com</organizationUrl>
31+
</developer>
32+
</developers>
33+
34+
<licenses>
35+
<license>
36+
<name>The Universal Permissive License (UPL), Version 1.0</name>
37+
<url>https://oss.oracle.com/licenses/upl/</url>
38+
<distribution>repo</distribution>
39+
</license>
40+
</licenses>
41+
42+
<scm>
43+
<url>https://github.com/oracle/spring-cloud-oracle</url>
44+
<connection>scm:git:https://github.com/oracle/spring-cloud-oracle.git</connection>
45+
<developerConnection>scm:git:[email protected]:oracle/spring-cloud-oracle.git</developerConnection>
46+
</scm>
47+
48+
<dependencies>
49+
<dependency>
50+
<groupId>com.oracle.database.spring</groupId>
51+
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
52+
<version>${project.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.oracle.database.spring</groupId>
56+
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
57+
<version>${project.version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-starter-jdbc</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter</artifactId>
66+
</dependency>
67+
</dependencies>
68+
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-maven-plugin</artifactId>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
78+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2024, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
package com.oracle.database.spring.oraclespringbootsamplewallet;
4+
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.ApplicationContext;
9+
import org.springframework.context.annotation.Bean;
10+
11+
import javax.sql.DataSource;
12+
import java.sql.Connection;
13+
import java.sql.PreparedStatement;
14+
import java.sql.ResultSet;
15+
import java.sql.SQLException;
16+
17+
@SpringBootApplication
18+
public class OracleSpringBootSampleWalletApplication {
19+
20+
final DataSource dataSource;
21+
22+
public OracleSpringBootSampleWalletApplication(DataSource dataSource) {
23+
this.dataSource = dataSource;
24+
}
25+
26+
@Bean
27+
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
28+
return args -> {
29+
try {
30+
System.out.println("Datasource is : " + dataSource.getClass().getName());
31+
Connection connection = dataSource.getConnection();
32+
System.out.println("Connection is : " + connection);
33+
34+
PreparedStatement stmt = connection.prepareStatement("SELECT 'Hello World!' FROM dual");
35+
ResultSet resultSet = stmt.executeQuery();
36+
while (resultSet.next()) {
37+
System.out.println(resultSet.getString(1));
38+
}
39+
40+
stmt = connection.prepareStatement("SELECT BANNER_FULL FROM V$VERSION");
41+
resultSet = stmt.executeQuery();
42+
while (resultSet.next()) {
43+
System.out.println(resultSet.getString(1));
44+
}
45+
connection.close();
46+
} catch (SQLException e) {
47+
e.printStackTrace();
48+
}
49+
};
50+
}
51+
52+
public static void main(String[] args) {
53+
SpringApplication.run(OracleSpringBootSampleWalletApplication.class, args);
54+
}
55+
}
56+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
spring:
2+
application:
3+
name: oracle-spring-boot-samples-wallet
4+
5+
# Datasource Configuration
6+
datasource:
7+
url: jdbc:oracle:thin:@<TNSNAMES_ORA_ENTRY>?TNS_ADMIN=<DIRECTORY_OF_UNZIPPED_WALLET>
8+
username: ADMIN
9+
password: <PASSWORD>
10+
driver-class-name: oracle.jdbc.OracleDriver
11+
type: oracle.ucp.jdbc.PoolDataSource
12+
oracleucp:
13+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
14+
connection-pool-name: UCPWalletConnectionPool
15+
initial-pool-size: 15
16+
min-pool-size: 10
17+
max-pool-size: 30

database/starters/oracle-spring-boot-starter-samples/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<module>oracle-spring-boot-sample-json-duality</module>
5454
<module>oracle-spring-boot-sample-json-events</module>
5555
<module>oracle-spring-boot-sample-okafka</module>
56+
<module>oracle-spring-boot-sample-wallet</module>
5657
</modules>
5758

5859
<build>

0 commit comments

Comments
 (0)