generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...s/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
76 changes: 76 additions & 0 deletions
76
...base/starters/oracle-spring-boot-starter-samples/oracle-spring-boot-sample-wallet/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
andytael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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> |
54 changes: 54 additions & 0 deletions
54
...database/spring/oraclespringbootsamplewallet/OracleSpringBootSampleWalletApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.oracle.database.spring.oraclespringbootsamplewallet; | ||
andytael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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); | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
...boot-starter-samples/oracle-spring-boot-sample-wallet/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPen -> Open
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed