From 030f8eec7a906718b1cf133a1a649e49783a3e5f Mon Sep 17 00:00:00 2001 From: juarezjuniorgithub Date: Fri, 23 Feb 2024 12:10:28 +0000 Subject: [PATCH 1/5] Code sample - 23c JDBC Reactive Extensions --- java/jdbc-reactive-extensions-intro/pom.xml | 79 +++++++++++ .../SQLStatementWithAsynchronousJDBC.java | 126 ++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 java/jdbc-reactive-extensions-intro/pom.xml create mode 100644 java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java diff --git a/java/jdbc-reactive-extensions-intro/pom.xml b/java/jdbc-reactive-extensions-intro/pom.xml new file mode 100644 index 00000000..a085372f --- /dev/null +++ b/java/jdbc-reactive-extensions-intro/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + com.oracle.jdbc.reactive + jdbc-reactive-extensions-intro + 1.0-SNAPSHOT + + jdbc-reactive-extensions-intro + Introduction to JDBC Reactive Extensions with the Oracle Database 23c Free — Developer Release + https://juarezjunior.medium.com/introduction-to-jdbc-reactive-extensions-with-the-oracle-database-23c-free-developer-release-b5a64ac5d194/ + + + UTF-8 + 17 + 17 + + + + + com.oracle.database.jdbc + ojdbc11-production + 23.2.0.0 + pom + + + junit + junit + 3.8.1 + + + + + + + + maven-clean-plugin + 3.1.0 + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + + diff --git a/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java b/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java new file mode 100644 index 00000000..2fe4d6c7 --- /dev/null +++ b/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java @@ -0,0 +1,126 @@ +/* + Copyright (c) 2024, Oracle and/or its affiliates. + + This software is dual-licensed to you under the Universal Permissive License + (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License + 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose + either license. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.oracle.jdbc.reactive; + +import java.sql.SQLException; +import java.util.concurrent.Flow; + +import oracle.jdbc.OracleConnection; +import oracle.jdbc.OraclePreparedStatement; +import oracle.jdbc.pool.OracleDataSource; + +public class SQLStatementWithAsynchronousJDBC { + + private OracleDataSource ods = null; + private OracleConnection conn = null; + + public SQLStatementWithAsynchronousJDBC() { + try { + ods = new OracleDataSource(); + // jdbc:oracle:thin@[hostname]:[port]/[DB service/name] + ods.setURL("jdbc:oracle:thin@[hostname]:[port]/[DB service/name"); + ods.setUser("[Username]"); + ods.setPassword("[Password]"); + + conn = (OracleConnection) ods.getConnection(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + SQLStatementWithAsynchronousJDBC asyncSQL = new SQLStatementWithAsynchronousJDBC(); + try { + // Execute a SQL DDL statement to create a database table + // asynchronously + asyncSQL.createTable(asyncSQL.getConn()); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * Asynchronously creates a new table by executing a DDL SQL statement + * + * @param connection Connection to a database where the table is created + * @return A Publisher that emits the result of executing DDL SQL + * @throws SQLException If a database access error occurs before the DDL SQL can + * be executed + */ + private Flow.Publisher createTable(OracleConnection connection) throws SQLException { + + OraclePreparedStatement createTableStatement = (OraclePreparedStatement) connection + .prepareStatement("CREATE TABLE employee_names (" + "id NUMBER PRIMARY KEY, " + + "first_name VARCHAR(50), " + "last_name VARCHAR2(50))"); + + Flow.Publisher createTablePublisher = createTableStatement.unwrap(OraclePreparedStatement.class) + .executeAsyncOracle(); + + createTablePublisher.subscribe( + + // This subscriber will close the PreparedStatement + new Flow.Subscriber() { + public void onSubscribe(Flow.Subscription subscription) { + subscription.request(1L); + } + + public void onNext(Boolean item) { + } + + public void onError(Throwable throwable) { + closeStatement(); + } + + public void onComplete() { + closeStatement(); + } + + void closeStatement() { + try { + createTableStatement.close(); + } catch (SQLException closeException) { + closeException.printStackTrace(); + ; + } + } + }); + + return createTablePublisher; + } + + public OracleDataSource getOds() { + return ods; + } + + public void setOds(OracleDataSource ods) { + this.ods = ods; + } + + public OracleConnection getConn() { + return conn; + } + + public void setConn(OracleConnection conn) { + this.conn = conn; + } + +} \ No newline at end of file From c08d92bce84bd729c88869ca92883bcdd485c4fc Mon Sep 17 00:00:00 2001 From: juarezjuniorgithub Date: Fri, 10 May 2024 13:39:21 +0100 Subject: [PATCH 2/5] code sample adjustments --- java/jdbc-reactive-extensions-intro/pom.xml | 135 +++++++++--------- .../SQLStatementWithAsynchronousJDBC.java | 4 +- 2 files changed, 72 insertions(+), 67 deletions(-) diff --git a/java/jdbc-reactive-extensions-intro/pom.xml b/java/jdbc-reactive-extensions-intro/pom.xml index a085372f..500ded51 100644 --- a/java/jdbc-reactive-extensions-intro/pom.xml +++ b/java/jdbc-reactive-extensions-intro/pom.xml @@ -1,79 +1,84 @@ - - 4.0.0 + + 4.0.0 - com.oracle.jdbc.reactive - jdbc-reactive-extensions-intro - 1.0-SNAPSHOT + com.oracle.jdbc.reactive + jdbc-reactive-extensions-intro + 1.0-SNAPSHOT - jdbc-reactive-extensions-intro - Introduction to JDBC Reactive Extensions with the Oracle Database 23c Free — Developer Release - https://juarezjunior.medium.com/introduction-to-jdbc-reactive-extensions-with-the-oracle-database-23c-free-developer-release-b5a64ac5d194/ + jdbc-reactive-extensions-intro + Introduction to JDBC Reactive Extensions with the Oracle + Database 23c Free — Developer Release + + https://juarezjunior.medium.com/introduction-to-jdbc-reactive-extensions-with-the-oracle-database-23c-free-developer-release-b5a64ac5d194/ - - UTF-8 - 17 - 17 - + + UTF-8 + 17 + 17 + - - + + com.oracle.database.jdbc ojdbc11-production 23.2.0.0 pom - - junit - junit - 3.8.1 - - + + junit + junit + 3.8.1 + + - - - - - maven-clean-plugin - 3.1.0 - - - maven-site-plugin - 3.7.1 - - - maven-project-info-reports-plugin - 3.0.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - - + + + + + maven-clean-plugin + 3.1.0 + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + diff --git a/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java b/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java index 2fe4d6c7..18f73606 100644 --- a/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java +++ b/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java @@ -69,8 +69,8 @@ public static void main(String[] args) { private Flow.Publisher createTable(OracleConnection connection) throws SQLException { OraclePreparedStatement createTableStatement = (OraclePreparedStatement) connection - .prepareStatement("CREATE TABLE employee_names (" + "id NUMBER PRIMARY KEY, " - + "first_name VARCHAR(50), " + "last_name VARCHAR2(50))"); + .prepareStatement("CREATE TABLE employee_names (" + "id NUMBER PRIMARY KEY, " + "first_name VARCHAR(50), " + + "last_name VARCHAR2(50))"); Flow.Publisher createTablePublisher = createTableStatement.unwrap(OraclePreparedStatement.class) .executeAsyncOracle(); From e14599fc22e973891adf7ebaa61f309b378872d4 Mon Sep 17 00:00:00 2001 From: juarezjuniorgithub Date: Wed, 19 Jun 2024 01:21:19 +0100 Subject: [PATCH 3/5] code sample adjustments --- java/jdbc-reactive-extensions-intro/pom.xml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/java/jdbc-reactive-extensions-intro/pom.xml b/java/jdbc-reactive-extensions-intro/pom.xml index 500ded51..438b8ed1 100644 --- a/java/jdbc-reactive-extensions-intro/pom.xml +++ b/java/jdbc-reactive-extensions-intro/pom.xml @@ -17,22 +17,17 @@ UTF-8 - 17 - 17 + 21 + 21 com.oracle.database.jdbc ojdbc11-production - 23.2.0.0 + 23.4.0.24.05 pom - - junit - junit - 3.8.1 - From 3401ead46354e60a67f6760013c69c5c3dae2bce Mon Sep 17 00:00:00 2001 From: juarezjuniorgithub Date: Mon, 1 Jul 2024 19:14:35 +0100 Subject: [PATCH 4/5] code sample adjustments --- java/jdbc-reactive-extensions-intro/pom.xml | 136 +++++++-------- .../SQLStatementWithAsynchronousJDBC.java | 155 +++++++----------- 2 files changed, 131 insertions(+), 160 deletions(-) diff --git a/java/jdbc-reactive-extensions-intro/pom.xml b/java/jdbc-reactive-extensions-intro/pom.xml index 438b8ed1..b494146a 100644 --- a/java/jdbc-reactive-extensions-intro/pom.xml +++ b/java/jdbc-reactive-extensions-intro/pom.xml @@ -1,79 +1,79 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - com.oracle.jdbc.reactive - jdbc-reactive-extensions-intro - 1.0-SNAPSHOT + com.oracle.jdbc.reactive + jdbc-reactive-extensions-intro + 1.0-SNAPSHOT - jdbc-reactive-extensions-intro - Introduction to JDBC Reactive Extensions with the Oracle - Database 23c Free — Developer Release - - https://juarezjunior.medium.com/introduction-to-jdbc-reactive-extensions-with-the-oracle-database-23c-free-developer-release-b5a64ac5d194/ + jdbc-reactive-extensions-intro + Introduction to JDBC Reactive Extensions with the Oracle + Database 23c Free — Developer Release + + https://juarezjunior.medium.com/introduction-to-jdbc-reactive-extensions-with-the-oracle-database-23c-free-developer-release-b5a64ac5d194/ - - UTF-8 - 21 - 21 - + + UTF-8 + 21 + 21 + - - - com.oracle.database.jdbc - ojdbc11-production - 23.4.0.24.05 - pom - - + + + com.oracle.database.jdbc + ojdbc11-production + 23.4.0.24.05 + pom + + - - - - - maven-clean-plugin - 3.1.0 - - - maven-site-plugin - 3.7.1 - - - maven-project-info-reports-plugin - 3.0.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - - + + + maven-clean-plugin + 3.1.0 + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + diff --git a/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java b/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java index 18f73606..9748b905 100644 --- a/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java +++ b/java/jdbc-reactive-extensions-intro/src/main/java/com/oracle/jdbc/reactive/SQLStatementWithAsynchronousJDBC.java @@ -30,97 +30,68 @@ public class SQLStatementWithAsynchronousJDBC { - private OracleDataSource ods = null; - private OracleConnection conn = null; - - public SQLStatementWithAsynchronousJDBC() { - try { - ods = new OracleDataSource(); - // jdbc:oracle:thin@[hostname]:[port]/[DB service/name] - ods.setURL("jdbc:oracle:thin@[hostname]:[port]/[DB service/name"); - ods.setUser("[Username]"); - ods.setPassword("[Password]"); - - conn = (OracleConnection) ods.getConnection(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { - SQLStatementWithAsynchronousJDBC asyncSQL = new SQLStatementWithAsynchronousJDBC(); - try { - // Execute a SQL DDL statement to create a database table - // asynchronously - asyncSQL.createTable(asyncSQL.getConn()); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - /** - * Asynchronously creates a new table by executing a DDL SQL statement - * - * @param connection Connection to a database where the table is created - * @return A Publisher that emits the result of executing DDL SQL - * @throws SQLException If a database access error occurs before the DDL SQL can - * be executed - */ - private Flow.Publisher createTable(OracleConnection connection) throws SQLException { - - OraclePreparedStatement createTableStatement = (OraclePreparedStatement) connection - .prepareStatement("CREATE TABLE employee_names (" + "id NUMBER PRIMARY KEY, " + "first_name VARCHAR(50), " - + "last_name VARCHAR2(50))"); - - Flow.Publisher createTablePublisher = createTableStatement.unwrap(OraclePreparedStatement.class) - .executeAsyncOracle(); - - createTablePublisher.subscribe( - - // This subscriber will close the PreparedStatement - new Flow.Subscriber() { - public void onSubscribe(Flow.Subscription subscription) { - subscription.request(1L); - } - - public void onNext(Boolean item) { - } - - public void onError(Throwable throwable) { - closeStatement(); - } - - public void onComplete() { - closeStatement(); - } - - void closeStatement() { - try { - createTableStatement.close(); - } catch (SQLException closeException) { - closeException.printStackTrace(); - ; - } - } - }); - - return createTablePublisher; - } - - public OracleDataSource getOds() { - return ods; - } - - public void setOds(OracleDataSource ods) { - this.ods = ods; - } - - public OracleConnection getConn() { - return conn; - } - - public void setConn(OracleConnection conn) { - this.conn = conn; - } + public static void main(String[] args) throws SQLException { + OracleDataSource ods = new OracleDataSource(); + // jdbc:oracle:thin@[hostname]:[port]/[DB service/name] + ods.setURL("jdbc:oracle:thin@[hostname]:[port]/[DB service/name"); + ods.setUser("[Username]"); + ods.setPassword("[Password]"); + OracleConnection conn = (OracleConnection) ods.getConnection(); + SQLStatementWithAsynchronousJDBC asyncSQL = new SQLStatementWithAsynchronousJDBC(); + // Execute a SQL DDL statement to create a database table + // asynchronously + asyncSQL.createTable(conn); + } + + /** + * Asynchronously creates a new table by executing a DDL SQL statement + * + * @param connection + * Connection to a database where the table is created + * @return A Publisher that emits the result of executing DDL SQL + * @throws SQLException + * If a database access error occurs before the DDL SQL can be + * executed + */ + private Flow.Publisher createTable(OracleConnection connection) + throws SQLException { + + OraclePreparedStatement createTableStatement = (OraclePreparedStatement) connection + .prepareStatement( + "CREATE TABLE employee_names (" + "id NUMBER PRIMARY KEY, " + + "first_name VARCHAR(50), " + "last_name VARCHAR2(50))"); + + Flow.Publisher createTablePublisher = createTableStatement + .unwrap(OraclePreparedStatement.class).executeAsyncOracle(); + + createTablePublisher.subscribe( + // This subscriber will close the PreparedStatement + new Flow.Subscriber() { + public void onSubscribe(Flow.Subscription subscription) { + subscription.request(1L); + } + + public void onNext(Boolean item) { + } + + public void onError(Throwable throwable) { + closeStatement(); + } + + public void onComplete() { + closeStatement(); + } + + void closeStatement() { + try { + createTableStatement.close(); + } catch (SQLException closeException) { + closeException.printStackTrace(); + } + } + }); + + return createTablePublisher; + } } \ No newline at end of file From 3f3d95134f413141662ad7546472de3c3e8d38c5 Mon Sep 17 00:00:00 2001 From: juarezjuniorgithub Date: Mon, 4 Nov 2024 10:51:07 +0000 Subject: [PATCH 5/5] changed to make the explanation release-agnostic --- java/jdbc-reactive-extensions-intro/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/jdbc-reactive-extensions-intro/pom.xml b/java/jdbc-reactive-extensions-intro/pom.xml index b494146a..02d46333 100644 --- a/java/jdbc-reactive-extensions-intro/pom.xml +++ b/java/jdbc-reactive-extensions-intro/pom.xml @@ -11,7 +11,7 @@ jdbc-reactive-extensions-intro Introduction to JDBC Reactive Extensions with the Oracle - Database 23c Free — Developer Release + Database https://juarezjunior.medium.com/introduction-to-jdbc-reactive-extensions-with-the-oracle-database-23c-free-developer-release-b5a64ac5d194/