Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCP and Wallet sample #142

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ The JSON Relational Duality Views sample application demonstrates how to use the

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)

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.
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.

### [Oracle UCP using Wallet](./oracle-spring-boot-sample-wallet)

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 number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Oracle Spring Boot Sample UCP using Wallet

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.

## Wallet

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).
1. Unzip the Wallet ZIP file
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.

## Configure the application

Open the `application.yaml` file and modify the `url` and `password` parameter to reflect your environment.

```yaml
spring:
application:
name: ucp-wallet

# Datasource Configuration
datasource:
url: jdbc:oracle:thin:@<TNSNAMES_ORA_ENTRY>?TNS_ADMIN=<DIRECTORY_OF_UNZIPPED_WALLET>
username: ADMIN
password: <PASSWORD>
driver-class-name: oracle.jdbc.OracleDriver
type: oracle.ucp.jdbc.PoolDataSource
oracleucp:
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
connection-pool-name: UCPWalletConnectionPool
initial-pool-size: 15
min-pool-size: 10
max-pool-size: 30
```

## Run the sample application

To run the testapplication, execute the following command:

```shell
mvn clean spring-boot:run
```

The output of the test application should look similar to this.

```text
Datasource is : oracle.ucp.jdbc.PoolDataSourceImpl
Connection is : oracle.ucp.jdbc.proxy.oracle$1ucp$1jdbc$1proxy$1oracle$1ConnectionProxy$2oracle$1jdbc$1internal$1OracleConnection$$$Proxy@527fc8e
Hello World!
Oracle Database 23ai Enterprise Edition Release 23.0.0.0.0 - Production
Version 23.6.0.24.07
```

## Configure your project to use Oracle Spring Boot Starters for UCP and Wallet

To use Oracle Spring Boot Starters for UCP and Wallet from your Spring Boot application, add the following Maven dependency to your project:

```xml
<dependencies>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
</dependency>
</dependencies>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2024, Oracle and/or its affiliates. -->
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>oracle-spring-boot-starter-samples</artifactId>
<groupId>com.oracle.database.spring</groupId>
<version>24.3.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>oracle-spring-boot-sample-wallet</artifactId>
<version>24.3.0</version>

<name>Oracle Spring Boot Starter - UCP using a Wallet</name>
<description>oracle-spring-boot-starter-samples-ucp-wallet</description>

<organization>
<name>Oracle America, Inc.</name>
<url>https://www.oracle.com</url>
</organization>

<developers>
<developer>
<name>Oracle</name>
<email>obaas_ww at oracle.com</email>
<organization>Oracle America, Inc.</organization>
<organizationUrl>https://www.oracle.com</organizationUrl>
</developer>
</developers>

<licenses>
<license>
<name>The Universal Permissive License (UPL), Version 1.0</name>
<url>https://oss.oracle.com/licenses/upl/</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/oracle/spring-cloud-oracle</url>
<connection>scm:git:https://github.com/oracle/spring-cloud-oracle.git</connection>
<developerConnection>scm:git:[email protected]:oracle/spring-cloud-oracle.git</developerConnection>
</scm>

<dependencies>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
package com.oracle.database.spring.oraclespringbootsamplewallet;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@SpringBootApplication
public class OracleSpringBootSampleWalletApplication {

final DataSource dataSource;

public OracleSpringBootSampleWalletApplication(DataSource dataSource) {
this.dataSource = dataSource;
}

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
try {
System.out.println("Datasource is : " + dataSource.getClass().getName());
Connection connection = dataSource.getConnection();
System.out.println("Connection is : " + connection);

PreparedStatement stmt = connection.prepareStatement("SELECT 'Hello World!' FROM dual");
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}

stmt = connection.prepareStatement("SELECT BANNER_FULL FROM V$VERSION");
resultSet = stmt.executeQuery();
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
};
}

public static void main(String[] args) {
SpringApplication.run(OracleSpringBootSampleWalletApplication.class, args);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:
application:
name: oracle-spring-boot-samples-wallet

# Datasource Configuration
datasource:
url: jdbc:oracle:thin:@<TNSNAMES_ORA_ENTRY>?TNS_ADMIN=<DIRECTORY_OF_UNZIPPED_WALLET>
username: ADMIN
password: <PASSWORD>
driver-class-name: oracle.jdbc.OracleDriver
type: oracle.ucp.jdbc.PoolDataSource
oracleucp:
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
connection-pool-name: UCPWalletConnectionPool
initial-pool-size: 15
min-pool-size: 10
max-pool-size: 30
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<module>oracle-spring-boot-sample-json-duality</module>
<module>oracle-spring-boot-sample-json-events</module>
<module>oracle-spring-boot-sample-okafka</module>
<module>oracle-spring-boot-sample-wallet</module>
</modules>

<build>
Expand Down
Loading