Skip to content

Commit daba436

Browse files
committed
2 parents ad47f50 + 5618a1c commit daba436

File tree

25 files changed

+327
-153
lines changed

25 files changed

+327
-153
lines changed

java/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Java based examples
2-
This repository stores examples that demonstrate various concepts to assist Java and JavaScript developers in designing Java database applications (i.e., accessing and processing data from the Oracle Database), leveraging the Java Database Connectivity (JDBC) API, the Univeral Java Connection Pool (UCP), the embedded Java VM (OJVM), Java 8 Nashorn, and JAX-WS.
2+
This repository stores examples that demonstrate various concepts to assist Java and JavaScript developers in designing database applications (i.e., accessing the Oracle Database and peocessing data), leveraging the Java Database Connectivity (JDBC) API, the Univeral Java Connection Pool (UCP), the embedded Java VM (OJVM), Java 8 Nashorn, and JAX-WS (the Web Services Callout utility).
33

4-
The examples let you run client-side database bound Java or JavaScript code either on HotSpot JDK/JRE (or other JVMs) or server-side Java or JavaScript directly in the database leveraging the embedded JVM (a.k.a. OJVM and Java 8 Nashorn engine). In addition, OJVM allows invoking remote SOAP or REST Web Services from within your database session (using SQL, PL/SQL or Java).
4+
The examples let you run client-side Java or JavaScript code either on HotSpot JDK/JRE (or other JVMs) or server-side Java or JavaScript directly in the database leveraging the embedded JVM (a.k.a. OJVM and Java 8 Nashorn engine). In addition, OJVM allows invoking remote SOAP or REST Web Services from within your database session (using SQL, PL/SQL or Java).
55

66
## What's in Oracle database 12c Release 2 for Java Developers?
77
* **Java 8**: Java 8 in JDBC/UCP and OJVM; JDBC 4.2

java/jdbc/Readme.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# JDBC based examples
2-
The Oracle JDBC driver is used for connecting and processing data in the Oracle Database. It is fully compliant with the latest JDBC specifications. The JDBC standard defines the `java.sql` interfaces.
2+
The Oracle JDBC drivers allow Java applications to connect and process data in the Oracle Database. These are fully compliant with the latest JDBC specifications which defines the standard `java.sql` interfaces.
33

4-
**The JDBC Thin driver or Type 4 driver** is a pure Java driver which communicates with the database server using Oracle Net Services. Oracle furnishes also the type 2 JDBc-OCI driver however, JDBC-Thin is the most used and recommended driver type. Java applications simply need to have **ojdbc8.jar** (for JDK8) in their classpath.
4+
**Type 4 and type 2 drivers** The Oracle database furnishes a type 4 driver a.k.a. JDBC-Thin and a type 2 driver a.k.a. JDBC-OCI however, JDBC-Thin is the most used and recommended driver type. Java applications simply need to have **ojdbc8.jar** (for JDK/JRE 8) in their classpath.
55

6-
The JDBC THin driver allows connecting to the Oracle Database Cloud Services including: the Oracle Database Service **(DBCS)**, the Oracle Exadata Express Cloud Service **(EECS)**, and the Oracle Database Service on Bare Metal **(BMCS)**.
7-
Please refer to [JDBC and Oracle Database Service on Cloud](http://www.oracle.com/technetwork/database/application-development/jdbc/documentation/index.html) for detailed instructions.
6+
**Cloud Database Services** The JDBC Thin driver allows connecting to the various Oracle Database Cloud Services including: the Oracle Database Service **(DBCS)**, the Oracle Exadata Express Cloud Service **(EECS)**, and the Oracle Database Service on Bare Metal **(BMCS)**. Please refer to [JDBC and Oracle Database Service on Cloud](http://www.oracle.com/technetwork/database/application-development/jdbc/documentation/index.html) for detailed instructions.
7+
8+
**Prerequisite - JDBC Tutorial** The examples in this folder assume a basic knowledge of JDBC [See the JDBC Java Tutorial]( https://docs.oracle.com/javase/tutorial/jdbc/index.html)
89

910
# What's New in JDBC in 12.2 ?
1011

java/ojvm/CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Copyright (c) Oracle and/or its affiliates. All rights reserved.
2+
3+
Oracle requires that contributors to all of its open-source projects sign the
4+
<a href="http://www.oracle.com/technetwork/community/oca-486395.html">Oracle Contributor Agreement (OCA)</a>.

java/ucp/Readme.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
# Universal Connection Pool (UCP)
2-
Oracle Universal Connection Pool (UCP) is a feature rich Java connection pool tightly integrated with all Oracle database configurations, providing high availability, scalability and work load balancing; To use UCP, Java applications or containers must have **ucp.jar** in their class path along with **ojdbc8.jar** (for JDK8).
2+
The Oracle Universal Connection Pool (UCP) is a feature rich Java connection pool tightly integrated with all Oracle database configurations and architectures, providing high availability, scalability and load balancing for Java applications.
3+
To use UCP, Java applications or containers must have **ucp.jar** in their class path along with **ojdbc8.jar** (for JDK or JRE 8).
34

4-
# What's new in 12.2 ?
5+
## What's new in 12.2 ?
56

6-
* **New Java Standards**: Java SE 8 and JDBC 4.2 are supported by UCP (ucp.jar)
7-
* **New Performance features**: UCP redesign of thread handling using Multi-dimension Search Tree, Configurable connection health check frequency (UCP)
8-
* **New Scalability features**: Shared Pool for Multitenant Database (UCP), Shared Pool for Sharded database (UCP), Sharding APIs for UCP
9-
* **New High Availability features**: FAN and ONS are auto-enabled in UCP, Application Continuity for XA Datasources, Transaction Guard for XA Datasource
10-
* **New Manageability features**: UCP XML configuration file
7+
* **New Java Standards**: Support for Java SE 8 and JDBC 4.2
8+
* **New Performance features**: UCP redesign for faster pool operations using Wait-Free technique, Multi-dimensionnal KD-Tree
9+
search, and configurable connection health check frequency
10+
* **New Scalability features**: Shared Pool for Multitenant Database, Shared Pool for Sharded database, Sharding APIs
11+
* **New High Availability features**: Fast Application Notification (FAN) and Oracle Notification Services (ONS) are auto-enabled,
12+
Application Continuity for XA Datasources, and Transaction Guard for XA Datasource
13+
* **New Manageability features**: XML configuration file
1114

12-
# Downloads
15+
## Downloads
1316

1417
[Oracle Database 12.2.0.1 UCP Download Page](http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html)
1518

16-
# Javadoc
19+
## Javadoc
1720

1821
[12.2 Online UCP Javadoc](http://docs.oracle.com/database/122/JJUAR/toc.htm)
1922

20-
# Documentation
23+
## Documentation
2124

2225
[12.2 UCP Developer's Guide](https://docs.oracle.com/database/122/JJUCP/toc.htm)
2326

24-
# White Papers
27+
## White Papers
2528

2629
* [Performance, Scalability, Availability, Security, and Manageability with JDBC and UCP in 12.2](http://www.oracle.com/technetwork/database/application-development/jdbc/jdbcanducp122-3628966.pdf)
2730

2831
* [Connection Management Strategies for Java Applications using JDBC and UCP](http://www.oracle.com/technetwork/database/application-development/jdbc-ucp-conn-mgmt-strategies-3045654.pdf)
2932

30-
# Other Resources
33+
* [What's in Oracle database 12c Release 2 for Java & JavaScript Developers?](http://bit.ly/2orH5jf)
34+
35+
## Other Resources
3136

3237
* [UCP and Oracle Database Service on Cloud](http://www.oracle.com/technetwork/database/application-development/jdbc/documentation/index.html)
3338

java/ucp/SharedPoolCodeSample.xml

Lines changed: 27 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,27 @@
1-
import java.sql.Connection;
2-
import java.sql.ResultSet;
3-
import java.sql.SQLException;
4-
import java.sql.Statement;
5-
6-
import oracle.ucp.jdbc.PoolDataSource;
7-
import oracle.ucp.jdbc.PoolDataSourceFactory;
8-
9-
/**
10-
* This sample code demonstrates the functionality of Multi-tenant shared pools.
11-
* With the use of shared pools now it is possible for more than one tenant
12-
* datasources to share a common pool provided they are connecting to the same
13-
* database with a single url. To use shared pool functionality, all the tenant
14-
* datasources accessing shared pools should be defined in UCP XML configuration
15-
* file along with the pool properties. The code example shows how to get a
16-
* connection from a shared pool defined in xml.
17-
*
18-
* The shared pool defined in sample XML config file has only one connection and
19-
* both the tenant datasources -tenat1_ds and tenant2_ds are reusing the same
20-
* connection to get the employee data from respective employee tables
21-
* (tenant1_emp and tenant2_emp) present in tenant1 PDB and tenant2 PDB.
22-
*
23-
*
24-
*/
25-
public class SharedPoolCodeSample {
26-
// UCP XML config file location URI
27-
private static final String xmlFileURI = "file:/test/ucp/config/SharedPoolCodeSample.xml";
28-
29-
public static void main(String[] args) throws Exception {
30-
System.out.println("Multi-Tenant shared pool configuration using XML");
31-
32-
// Java system property to specify the location of UCP XML configuration
33-
// file which has shared pool, datasource properties defined in it.
34-
System.setProperty("oracle.ucp.jdbc.xmlConfigFile", xmlFileURI);
35-
36-
// The xml file used in this code example defines a connection pool with
37-
// connection-pool-name -"pool1" and two tenant datasources with
38-
// datasource-name as "tenant1_ds" and "tenant2_ds" which are using this
39-
// shared pool.
40-
41-
// Get the datasource instance named as "tenant1_ds" in XML config file
42-
PoolDataSource tenant1_DS = PoolDataSourceFactory
43-
.getPoolDataSource("tenant1_ds");
44-
45-
// Get a connection using tenant1 datasource
46-
Connection tenant1Conn = tenant1_DS.getConnection();
47-
48-
// Run a query on the connection obtained using tenant1 datasource i.e.
49-
// tenant1_ds
50-
runQueryOnTenant1(tenant1Conn);
51-
52-
// return tenant1 connection to the pool
53-
tenant1Conn.close();
54-
55-
// Get the datasource instance named as "tenant2_ds" in XML config file
56-
PoolDataSource tenant2_DS = PoolDataSourceFactory
57-
.getPoolDataSource("tenant2_ds");
58-
59-
// Get a connection using tenant2 datasource
60-
Connection tenant2Conn = tenant2_DS.getConnection();
61-
62-
// Run a query on the connection obtained using tenant2 datasource i.e.
63-
// tenant2_ds
64-
runQueryOnTenant2(tenant2Conn);
65-
66-
// return tenant2 connection to the pool
67-
tenant2Conn.close();
68-
69-
}
70-
71-
/**
72-
* Runs a query on the tenant1 table i.e. tenant1_emp to get the employee details
73-
* using the given connection.
74-
*/
75-
private static void runQueryOnTenant1(Connection tenant1Conn) {
76-
try {
77-
String sql = "SELECT empno,ename FROM tenant1_emp";
78-
Statement st = tenant1Conn.createStatement();
79-
ResultSet rs = st.executeQuery(sql);
80-
System.out.println("Teant1 Employee Details :");
81-
while (rs.next()) {
82-
System.out.println("Employee ID = " + rs.getInt("empno")
83-
+ " Employee Name = " + rs.getString("ename"));
84-
}
85-
rs.close();
86-
st.close();
87-
88-
} catch (SQLException e) {
89-
e.printStackTrace();
90-
}
91-
92-
}
93-
94-
/**
95-
* Runs a query on the tenant2 table i.e. tenant2_emp to get the employee details
96-
* using the given connection.
97-
*/
98-
private static void runQueryOnTenant2(Connection tenant2Conn) {
99-
try {
100-
String sql = "SELECT empno,ename FROM tenant2_emp";
101-
Statement st = tenant2Conn.createStatement();
102-
ResultSet rs = st.executeQuery(sql);
103-
System.out.println("Teant2 Employee Details :");
104-
while (rs.next()) {
105-
System.out.println("Employee ID = " + rs.getInt("empno")
106-
+ " Employee Name = " + rs.getString("ename"));
107-
}
108-
rs.close();
109-
st.close();
110-
111-
} catch (SQLException e) {
112-
e.printStackTrace();
113-
}
114-
115-
}
116-
117-
}
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ucp-properties>
3+
<connection-pool
4+
connection-pool-name="pool1"
5+
connection-factory-class-name="oracle.jdbc.pool.OracleDataSource"
6+
url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<host_name>)(PORT=<port_number>))(CONNECT_DATA=(SERVICE_NAME=cdb_root_app_service_name)))"
7+
user="c##common_user"
8+
password="password"
9+
initial-pool-size="1"
10+
min-pool-size="1"
11+
max-pool-size="1"
12+
shared="true" >
13+
14+
<connection-property name="oracle.jdbc.ReadTimeout" value="20000"/>
15+
<connection-property name="oracle.net.OUTBOUND_CONNECT_TIMEOUT" value="20000"/>
16+
17+
<data-source
18+
data-source-name="tenant1_ds"
19+
service="pdb1_app_service_name"
20+
description="tenant1 data source"
21+
/>
22+
<data-source data-source-name="tenant2_ds"
23+
service="pdb2_app_service_name"
24+
description="tenant2 data source"
25+
/>
26+
</connection-pool>
27+
</ucp-properties>

javascript/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# JavaScript based examples
2-
This folder stores JavaScript based examples for Oracle Database; including JavaScript on the JVM using the Nashorn engine, and Node.js.
1+
# JavaScript Examples
2+
3+
This directory contains Oracle Database JavaScript examples for:
4+
5+
- JavaScript on the JVM using the Nashorn engine (Hotspot JDk or JRE, other Java SE 8 compliant VMs, OJVM).
6+
- node-oracledb for Node.js, allowing you to write mid-tier and networking applications in JavaScript.

javascript/nashorn/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Nashorn allows interoperability between Java and JavaScript, therefore, the SQL
77

88
[A reprint of my blog post](https://blogs.oracle.com/nashorn/entry/javascript_stored_procedures_and_node)
99

10+
[Nashorn jsr223 engine notes](https://wiki.openjdk.java.net/display/Nashorn/Nashorn+jsr223+engine+notes)
11+
1012
[Documentation](http://bit.ly/2nstiYQ)
1113

1214
[White paper](http://bit.ly/2orH5jf) What's in Oracle database 12c Release 2 for Java & JavaScript Developers?

javascript/nashorn/hello.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
function hello()
22
{
33
/*
4-
*This is a sample Javascript file that prints "Hello World".
4+
* This is a sample Javascript file that prints "Hello World".
5+
*
6+
* As indicated, your database user must have been granted the DBJAVASCRIPT role
7+
* Before invoking it, you must load it into your database user schema
8+
* loadjava –v –r –u hr/hr hello.js
9+
* then call hello.js from SQL*Plus
10+
* SQL> @hello.sql
511
*/
612
var hellow = "Hello World";
713
return hellow;
814
}
915
var output = hello();
10-
print(output);
16+
print(output);

javascript/nashorn/hello.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
REM
22
REM Script for running hello.js in the database
33
REM
4-
SQL>set serveroutput on
5-
SQL>call dbms_java.set_output(20000);
6-
SQL>call dbms_javascript.run("hello.js");
7-
4+
set serveroutput on
5+
call dbms_java.set_output(20000);
6+
call dbms_javascript.run("hello.js");
7+

optimizer/new_synopses/07_defaultmx.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ PL/SQL procedure successfully completed.
100100
Elapsed: 00:00:00.11
101101
SQL>
102102
SQL> --
103-
SQL> -- The partitioned table has old-style synopses
103+
SQL> -- The partitioned table has new-style synopses
104104
SQL> --
105105
SQL> exec dbms_stats.set_table_prefs(null,'t1', 'approximate_ndv_algorithm', 'hyperloglog')
106106

0 commit comments

Comments
 (0)