diff --git a/database/starters/oracle-spring-boot-starter-samples/README.md b/database/starters/oracle-spring-boot-starter-samples/README.md index 0b95a8aa..60ba2c04 100644 --- a/database/starters/oracle-spring-boot-starter-samples/README.md +++ b/database/starters/oracle-spring-boot-starter-samples/README.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/README.md b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/README.md new file mode 100644 index 00000000..4510bee3 --- /dev/null +++ b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/README.md @@ -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="")))` 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:@?TNS_ADMIN= + username: ADMIN + 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 + + + com.oracle.database.spring + oracle-spring-boot-starter-ucp + + + com.oracle.database.spring + oracle-spring-boot-starter-wallet + + +``` diff --git a/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/pom.xml b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/pom.xml new file mode 100644 index 00000000..517a38ef --- /dev/null +++ b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/pom.xml @@ -0,0 +1,78 @@ + + + + + 4.0.0 + + oracle-spring-boot-starter-samples + com.oracle.database.spring + 24.3.0 + ../pom.xml + + + oracle-spring-boot-sample-wallet + 24.3.0 + + Oracle Spring Boot Starter - UCP using a Wallet + oracle-spring-boot-starter-samples-ucp-wallet + + + Oracle America, Inc. + https://www.oracle.com + + + + + Oracle + obaas_ww at oracle.com + Oracle America, Inc. + https://www.oracle.com + + + + + + The Universal Permissive License (UPL), Version 1.0 + https://oss.oracle.com/licenses/upl/ + repo + + + + + https://github.com/oracle/spring-cloud-oracle + scm:git:https://github.com/oracle/spring-cloud-oracle.git + scm:git:git@github.com:oracle/spring-cloud-oracle.git + + + + + com.oracle.database.spring + oracle-spring-boot-starter-ucp + ${project.version} + + + com.oracle.database.spring + oracle-spring-boot-starter-wallet + ${project.version} + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/java/com/oracle/database/spring/oraclespringbootsamplewallet/OracleSpringBootSampleWalletApplication.java b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/java/com/oracle/database/spring/oraclespringbootsamplewallet/OracleSpringBootSampleWalletApplication.java new file mode 100644 index 00000000..06e77652 --- /dev/null +++ b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/java/com/oracle/database/spring/oraclespringbootsamplewallet/OracleSpringBootSampleWalletApplication.java @@ -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); + } +} + diff --git a/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/resources/application.yaml b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/resources/application.yaml new file mode 100644 index 00000000..2a9728f9 --- /dev/null +++ b/database/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/resources/application.yaml @@ -0,0 +1,17 @@ +spring: + application: + name: oracle-spring-boot-samples-wallet + + # Datasource Configuration + datasource: + url: jdbc:oracle:thin:@?TNS_ADMIN= + username: ADMIN + 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 \ No newline at end of file diff --git a/database/starters/oracle-spring-boot-starter-samples/pom.xml b/database/starters/oracle-spring-boot-starter-samples/pom.xml index f8bbe9cd..60bcacd0 100644 --- a/database/starters/oracle-spring-boot-starter-samples/pom.xml +++ b/database/starters/oracle-spring-boot-starter-samples/pom.xml @@ -53,6 +53,7 @@ oracle-spring-boot-sample-json-duality oracle-spring-boot-sample-json-events oracle-spring-boot-sample-okafka + oracle-spring-boot-sample-wallet