Skip to content

Commit 5dc808f

Browse files
authored
Merge branch 'master' into dependabot/maven/12g/JavaExample/maven/org.eclipse.jetty-jetty-server-9.4.51.v20230217
2 parents 224cbda + 8a72e09 commit 5dc808f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1704
-314
lines changed

JdbcExamples/README.md

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# JDBC and JSON in Oracle Database 21c+
1+
# JDBC and JSON in Oracle Database 23c
22

33
This directory contains examples of how to store and access JSON type values in Oracle Database from a Java program.
44

5-
* [emp.CreateTable](src/main/java/emp/CreateTable.java) - Creates the employee table `emp` used by all the examples.
6-
* [emp.Insert](src/main/java/emp/Insert.java) - Inserts three JSON values into the `emp` table.
7-
* [emp.GetAll](src/main/java/emp/GetAll.java) - Gets all the JSON values from the `emp` table.
8-
* [emp.Filter](src/main/java/emp/Filter.java) - Selects employees from the `emp` table where the salary attribute is greater than 30,000.
9-
* [emp.Filter2](src/main/java/emp/Filter2.java) - Selects employees from the `emp` table that have the `created` attribute.
10-
* [emp.Update](src/main/java/emp/Update.java) - Updates an employee record using whole document replacement.
11-
* [emp.UpdateMerge](src/main/java/emp/UpdateMerge.java) - Performs a partial update using JSON_MERGEPATCH().
12-
* [emp.UpdateTransform](src/main/java/emp/UpdateTransform.java) - Performs a partial update using JSON_TRANSFORM().
13-
* [emp.JSONP](src/main/java/emp/JSONP.java) - Inserts and retrieves a value using [JSON-P (javax.json)](https://javaee.github.io/jsonp/) interfaces.
14-
* [emp.JSONB](src/main/java/emp/JSONB.java) - Stores and retrieves a plain/custom Java object as JSON using [JSON-B (javax.json.bind)](https://javaee.github.io/jsonb-spec/).
15-
* [emp.Jackson](src/main/java/emp/Jackson.java) - Encodes JSON from an external source, in this case a Jackson parser, as Oracle binary JSON and inserts it into the table.
16-
* [emp.BinaryJson](src/main/java/emp/BinaryJson.java) - Encodes JSON text as Oracle binary JSON, stores it in a file, and then reads it back again.
17-
* [emp.RunAll](src/main/java/emp/RunAll.java) - Runs all the examples at once.
18-
* [emp.DropTable](src/main/java/emp/DropTable.java) - Drops the table used by the examples.
5+
* [movie.CreateTable](src/main/java/movie/CreateTable.java) - Creates the movie table `movie` used by all the examples.
6+
* [movie.Insert](src/main/java/movie/Insert.java) - Inserts three JSON values into the `movie` table.
7+
* [movie.GetAll](src/main/java/movie/GetAll.java) - Gets all the JSON values from the `movie` table.
8+
* [movie.Filter](src/main/java/movie/Filter.java) - Selects movies from the `movie` table where the salary attribute is greater than 30,000.
9+
* [movie.Filter2](src/main/java/movie/Filter2.java) - Selects movies from the `movie` table that have the `created` attribute.
10+
* [movie.Update](src/main/java/movie/Update.java) - Updates an movie record using whole document replacement.
11+
* [movie.UpdateMerge](src/main/java/movie/UpdateMerge.java) - Performs a partial update using JSON_MERGEPATCH().
12+
* [movie.UpdateTransform](src/main/java/movie/UpdateTransform.java) - Performs a partial update using JSON_TRANSFORM().
13+
* [movie.JSONP](src/main/java/movie/JSONP.java) - Inserts and retrieves a value using [JSON-P (javax.json)](https://javaee.github.io/jsonp/) interfaces.
14+
* [movie.JSONB](src/main/java/movie/JSONB.java) - Stores and retrieves a plain/custom Java object as JSON using [JSON-B (javax.json.bind)](https://javaee.github.io/jsonb-spec/).
15+
* [movie.Jackson](src/main/java/movie/Jackson.java) - Encodes JSON from an external source, in this case a Jackson parser, as Oracle binary JSON and inserts it into the table.
16+
* [movie.BinaryJson](src/main/java/movie/BinaryJson.java) - Encodes JSON text as Oracle binary JSON, stores it in a file, and then reads it back again.
17+
* [movie.RunAll](src/main/java/movie/RunAll.java) - Runs all the examples at once.
18+
* [movie.DropTable](src/main/java/movie/DropTable.java) - Drops the table used by the examples.
1919

2020
See also:
2121
* Documentation: [The API for JSON type in Oracle Database (oracle.sql.json)](https://javadoc.io/static/com.oracle.database.jdbc/ojdbc8/21.4.0.0/oracle/sql/json/package-summary.html#package.description)
@@ -29,34 +29,9 @@ Need help, talk to us on Slack:
2929

3030
### Create a database
3131

32-
These steps show how to create an always-free Autonomous Database but any 21c or later version of Oracle Database will also work.
33-
34-
1. Create a free cloud account:<br/>
35-
[https://www.oracle.com/cloud/free/](https://www.oracle.com/cloud/free/).
36-
37-
_It will ask for a credit card for identification purposes. Your card will not be charged unless you manually choose to upgrade out of the free-tier limits._
38-
39-
2. Sign-in to the cloud console and click on **Autonomous JSON Database** under **Oracle Database**. <br/>
40-
<img src="../MongoExamples/img/one.png" width="500px"/>
41-
42-
3. Click **Create Autonomous Database**. When creating the database, ensure that
43-
- Workload type **Transaction Processing** or **JSON** is selected
44-
- **Always Free** is selected
45-
- Version **21c** (or later) is selected
46-
- **IMPORTANT**: 21c is required to run these examples. At the time of this writing, Autonomous 21c is only available in the Always Free Tier and is restricted to the regions (IAD - US East, PHX - US West, LHR - UK South, and FRA - Germany Central). If 21c is not available in your Cloud region, you can alternatively use [Oracle Database XE](https://www.oracle.com/database/technologies/xe-downloads.html) to run the database locally.
47-
48-
<img src="img/workload.png" width="500px"/>
49-
50-
- Select "Secure access from allowed IPs and VCNs only" and add your current IP address. This makes it so access is only allowed from your current IP address. It also makes it so that Mutual TLS encryption is not required (you don't have to download the database wallet).
51-
<img src="img/acl.png" width="500px"/>
52-
53-
4. Once the database is created, click on **DB Connection**
54-
55-
<kbd><img src="img/con1.png" width="500px"/></kbd>
56-
57-
Select TLS and copy the connection string by clicking "Copy". Use "tp" for transactional or operational workloads.
58-
59-
<kbd><img src="img/con2.png" width="500px" style="border: 1px solid black;"/></kbd>
32+
These examples should be run against Oracle Database 23c.
33+
See:
34+
[https://www.oracle.com/database/free/get-started/](https://www.oracle.com/database/free/get-started/)
6035

6136
### Setup the examples
6237

@@ -82,34 +57,23 @@ These steps show how to create an always-free Autonomous Database but any 21c or
8257
8358
```
8459
mvn -q exec:java \
85-
-Dexec.mainClass="emp.RunAll" \
86-
-Dexec.args='jdbc:oracle:thin:ADMIN/[PASSWORD]@[CONNECTION STRING]'
87-
```
88-
But replace the following values with your own:
89-
- Replace [PASSWORD] with the ``ADMIN`` password you specified when you created the database
90-
- Replace [CONNECTION STRING] with the string you copied above in step 4.
91-
92-
The actual command might look something like this:
93-
94-
```
95-
mvn -q exec:java \
96-
-Dexec.mainClass="emp.RunAll" \
97-
-Dexec.args='jdbc:oracle:thin:ADMIN/SecurePassword123!@(description=(retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.us-ashburn-1.oraclecloud.com))(connect_data=(service_name=tx8s4whxjz2u232_demo_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)(ssl_server_cert_dn="CN=adwc.uscom-east-1.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))'
60+
-Dexec.mainClass="movie.RunAll" \
61+
-Dexec.args='jdbc:oracle:thin:user/password@//localhost:1521/freepdb1'
9862
```
9963
10064
2. Drop the table used by the examples:
10165
10266
```
10367
mvn -q exec:java \
104-
-Dexec.mainClass="emp.DropTable" \
105-
-Dexec.args='jdbc:oracle:thin:ADMIN/SecurePassword123!@(description=(retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.us-ashburn-1.oraclecloud.com))(connect_data=(service_name=tx8s4whxjz2u232_demo_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)(ssl_server_cert_dn="CN=adwc.uscom-east-1.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))'
68+
-Dexec.mainClass="movie.DropTable" \
69+
-Dexec.args='jdbc:oracle:thin:user/password@//localhost:1521/freepdb1'
10670
10771
```
10872
10973
3. You can also run specific examples, one at a time:
11074
11175
```
11276
mvn -q exec:java \
113-
-Dexec.mainClass="emp.CreateTable" \
114-
-Dexec.args='jdbc:oracle:thin:ADMIN/SecurePassword123!@(description=(retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.us-ashburn-1.oraclecloud.com))(connect_data=(service_name=tx8s4whxjz2u232_demo_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)(ssl_server_cert_dn="CN=adwc.uscom-east-1.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))'
77+
-Dexec.mainClass="movie.CreateTable" \
78+
-Dexec.args='jdbc:oracle:thin:user/password@//localhost:1521/freepdb1'
11579
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<factorypath>
2+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-starter-data-jdbc/3.1.2/spring-boot-starter-data-jdbc-3.1.2.jar" enabled="true" runInBatchMode="false"/>
3+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-starter-jdbc/3.1.2/spring-boot-starter-jdbc-3.1.2.jar" enabled="true" runInBatchMode="false"/>
4+
<factorypathentry kind="VARJAR" id="M2_REPO/com/zaxxer/HikariCP/5.0.1/HikariCP-5.0.1.jar" enabled="true" runInBatchMode="false"/>
5+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-jdbc/6.0.11/spring-jdbc-6.0.11.jar" enabled="true" runInBatchMode="false"/>
6+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/data/spring-data-jdbc/3.1.2/spring-data-jdbc-3.1.2.jar" enabled="true" runInBatchMode="false"/>
7+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/data/spring-data-relational/3.1.2/spring-data-relational-3.1.2.jar" enabled="true" runInBatchMode="false"/>
8+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/data/spring-data-commons/3.1.2/spring-data-commons-3.1.2.jar" enabled="true" runInBatchMode="false"/>
9+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-tx/6.0.11/spring-tx-6.0.11.jar" enabled="true" runInBatchMode="false"/>
10+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-context/6.0.11/spring-context-6.0.11.jar" enabled="true" runInBatchMode="false"/>
11+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-aop/6.0.11/spring-aop-6.0.11.jar" enabled="true" runInBatchMode="false"/>
12+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-expression/6.0.11/spring-expression-6.0.11.jar" enabled="true" runInBatchMode="false"/>
13+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-beans/6.0.11/spring-beans-6.0.11.jar" enabled="true" runInBatchMode="false"/>
14+
<factorypathentry kind="VARJAR" id="M2_REPO/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar" enabled="true" runInBatchMode="false"/>
15+
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.28/lombok-1.18.28.jar" enabled="true" runInBatchMode="false"/>
16+
<factorypathentry kind="VARJAR" id="M2_REPO/com/oracle/database/jdbc/ojdbc8/23.0.0.0/ojdbc8-23.0.0.0.jar" enabled="true" runInBatchMode="false"/>
17+
<factorypathentry kind="VARJAR" id="M2_REPO/com/oracle/database/jdbc/ucp/23.0.0.0/ucp-23.0.0.0.jar" enabled="true" runInBatchMode="false"/>
18+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-starter-test/3.1.2/spring-boot-starter-test-3.1.2.jar" enabled="true" runInBatchMode="false"/>
19+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-starter/3.1.2/spring-boot-starter-3.1.2.jar" enabled="true" runInBatchMode="false"/>
20+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot/3.1.2/spring-boot-3.1.2.jar" enabled="true" runInBatchMode="false"/>
21+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-autoconfigure/3.1.2/spring-boot-autoconfigure-3.1.2.jar" enabled="true" runInBatchMode="false"/>
22+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-starter-logging/3.1.2/spring-boot-starter-logging-3.1.2.jar" enabled="true" runInBatchMode="false"/>
23+
<factorypathentry kind="VARJAR" id="M2_REPO/ch/qos/logback/logback-classic/1.4.8/logback-classic-1.4.8.jar" enabled="true" runInBatchMode="false"/>
24+
<factorypathentry kind="VARJAR" id="M2_REPO/ch/qos/logback/logback-core/1.4.8/logback-core-1.4.8.jar" enabled="true" runInBatchMode="false"/>
25+
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/logging/log4j/log4j-to-slf4j/2.20.0/log4j-to-slf4j-2.20.0.jar" enabled="true" runInBatchMode="false"/>
26+
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/logging/log4j/log4j-api/2.20.0/log4j-api-2.20.0.jar" enabled="true" runInBatchMode="false"/>
27+
<factorypathentry kind="VARJAR" id="M2_REPO/org/slf4j/jul-to-slf4j/2.0.7/jul-to-slf4j-2.0.7.jar" enabled="true" runInBatchMode="false"/>
28+
<factorypathentry kind="VARJAR" id="M2_REPO/jakarta/annotation/jakarta.annotation-api/2.1.1/jakarta.annotation-api-2.1.1.jar" enabled="true" runInBatchMode="false"/>
29+
<factorypathentry kind="VARJAR" id="M2_REPO/org/yaml/snakeyaml/1.33/snakeyaml-1.33.jar" enabled="true" runInBatchMode="false"/>
30+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-test/3.1.2/spring-boot-test-3.1.2.jar" enabled="true" runInBatchMode="false"/>
31+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-test-autoconfigure/3.1.2/spring-boot-test-autoconfigure-3.1.2.jar" enabled="true" runInBatchMode="false"/>
32+
<factorypathentry kind="VARJAR" id="M2_REPO/com/jayway/jsonpath/json-path/2.8.0/json-path-2.8.0.jar" enabled="true" runInBatchMode="false"/>
33+
<factorypathentry kind="VARJAR" id="M2_REPO/jakarta/xml/bind/jakarta.xml.bind-api/4.0.0/jakarta.xml.bind-api-4.0.0.jar" enabled="true" runInBatchMode="false"/>
34+
<factorypathentry kind="VARJAR" id="M2_REPO/jakarta/activation/jakarta.activation-api/2.1.2/jakarta.activation-api-2.1.2.jar" enabled="true" runInBatchMode="false"/>
35+
<factorypathentry kind="VARJAR" id="M2_REPO/net/minidev/json-smart/2.4.11/json-smart-2.4.11.jar" enabled="true" runInBatchMode="false"/>
36+
<factorypathentry kind="VARJAR" id="M2_REPO/net/minidev/accessors-smart/2.4.11/accessors-smart-2.4.11.jar" enabled="true" runInBatchMode="false"/>
37+
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/asm/asm/9.3/asm-9.3.jar" enabled="true" runInBatchMode="false"/>
38+
<factorypathentry kind="VARJAR" id="M2_REPO/org/assertj/assertj-core/3.24.2/assertj-core-3.24.2.jar" enabled="true" runInBatchMode="false"/>
39+
<factorypathentry kind="VARJAR" id="M2_REPO/net/bytebuddy/byte-buddy/1.14.5/byte-buddy-1.14.5.jar" enabled="true" runInBatchMode="false"/>
40+
<factorypathentry kind="VARJAR" id="M2_REPO/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar" enabled="true" runInBatchMode="false"/>
41+
<factorypathentry kind="VARJAR" id="M2_REPO/org/junit/jupiter/junit-jupiter/5.9.3/junit-jupiter-5.9.3.jar" enabled="true" runInBatchMode="false"/>
42+
<factorypathentry kind="VARJAR" id="M2_REPO/org/junit/jupiter/junit-jupiter-api/5.9.3/junit-jupiter-api-5.9.3.jar" enabled="true" runInBatchMode="false"/>
43+
<factorypathentry kind="VARJAR" id="M2_REPO/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar" enabled="true" runInBatchMode="false"/>
44+
<factorypathentry kind="VARJAR" id="M2_REPO/org/junit/platform/junit-platform-commons/1.9.3/junit-platform-commons-1.9.3.jar" enabled="true" runInBatchMode="false"/>
45+
<factorypathentry kind="VARJAR" id="M2_REPO/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar" enabled="true" runInBatchMode="false"/>
46+
<factorypathentry kind="VARJAR" id="M2_REPO/org/junit/jupiter/junit-jupiter-params/5.9.3/junit-jupiter-params-5.9.3.jar" enabled="true" runInBatchMode="false"/>
47+
<factorypathentry kind="VARJAR" id="M2_REPO/org/junit/jupiter/junit-jupiter-engine/5.9.3/junit-jupiter-engine-5.9.3.jar" enabled="true" runInBatchMode="false"/>
48+
<factorypathentry kind="VARJAR" id="M2_REPO/org/junit/platform/junit-platform-engine/1.9.3/junit-platform-engine-1.9.3.jar" enabled="true" runInBatchMode="false"/>
49+
<factorypathentry kind="VARJAR" id="M2_REPO/org/mockito/mockito-core/5.3.1/mockito-core-5.3.1.jar" enabled="true" runInBatchMode="false"/>
50+
<factorypathentry kind="VARJAR" id="M2_REPO/net/bytebuddy/byte-buddy-agent/1.14.5/byte-buddy-agent-1.14.5.jar" enabled="true" runInBatchMode="false"/>
51+
<factorypathentry kind="VARJAR" id="M2_REPO/org/objenesis/objenesis/3.3/objenesis-3.3.jar" enabled="true" runInBatchMode="false"/>
52+
<factorypathentry kind="VARJAR" id="M2_REPO/org/mockito/mockito-junit-jupiter/5.3.1/mockito-junit-jupiter-5.3.1.jar" enabled="true" runInBatchMode="false"/>
53+
<factorypathentry kind="VARJAR" id="M2_REPO/org/skyscreamer/jsonassert/1.5.1/jsonassert-1.5.1.jar" enabled="true" runInBatchMode="false"/>
54+
<factorypathentry kind="VARJAR" id="M2_REPO/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar" enabled="true" runInBatchMode="false"/>
55+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-core/6.0.11/spring-core-6.0.11.jar" enabled="true" runInBatchMode="false"/>
56+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-jcl/6.0.11/spring-jcl-6.0.11.jar" enabled="true" runInBatchMode="false"/>
57+
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-test/6.0.11/spring-test-6.0.11.jar" enabled="true" runInBatchMode="false"/>
58+
<factorypathentry kind="VARJAR" id="M2_REPO/org/xmlunit/xmlunit-core/2.9.1/xmlunit-core-2.9.1.jar" enabled="true" runInBatchMode="false"/>
59+
<factorypathentry kind="VARJAR" id="M2_REPO/jakarta/json/jakarta.json-api/1.1.6/jakarta.json-api-1.1.6.jar" enabled="true" runInBatchMode="false"/>
60+
<factorypathentry kind="VARJAR" id="M2_REPO/org/glassfish/jakarta.json/1.1.6/jakarta.json-1.1.6.jar" enabled="true" runInBatchMode="false"/>
61+
</factorypath>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This directory contains a Spring Data JDBC example that uses JSON in Oracle Database to persist a sub-object.
2+
3+
The following table:
4+
5+
```
6+
create table movie (
7+
id number default movieidsequence.NEXTVAL primary key,
8+
name varchar2(100),
9+
details JSON
10+
)
11+
```
12+
Stores instances of the class [Movie](src/main/java/movie/springjdbc/model/Movie.java).
13+
The nested class [MovieDetails](src/main/java/movie/springjdbc/model/MovieDetails.java)
14+
is stored within the details column as JSON.
15+
16+
JSON-B (jakarta.json.bind) is used to automatically convert the MovieDetails instances directly to from OSON in [Config.java](src/main/java/movie/springjdbc/Config.java).

0 commit comments

Comments
 (0)