Skip to content

Commit 6c6b761

Browse files
committed
2 parents fa8f25f + c8b04f7 commit 6c6b761

Some content is hidden

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

50 files changed

+3100
-132
lines changed

java/HRWebApp/tomcat-users.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<tomcat-users xmlns="http://tomcat.apache.org/xml"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
21+
version="1.0">
22+
<!--
23+
NOTE: By default, no user is included in the "manager-gui" role required
24+
to operate the "/manager/html" web application. If you wish to use this app,
25+
you must define such a user - the username and password are arbitrary. It is
26+
strongly recommended that you do NOT use one of the users in the commented out
27+
section below since they are intended for use with the examples web
28+
application.
29+
-->
30+
<!--
31+
NOTE: The sample user and role entries below are intended for use with the
32+
examples web application. They are wrapped in a comment and thus are ignored
33+
when reading this file. If you wish to configure these users for use with the
34+
examples web application, do not forget to remove the <!.. ..> that surrounds
35+
them. You will also need to set the passwords to something appropriate.
36+
-->
37+
<!--
38+
-->
39+
<role rolename="manager"/>
40+
<role rolename="staff"/>
41+
<user username="hradmin" password="welcome" roles="manager,staff"/>
42+
<user username="hrstaff" password="welcome" roles="staff"/>
43+
44+
45+
<role rolename="manager-gui"/>
46+
<user username="admin" password="welcome" roles="manager-gui"/>
47+
48+
</tomcat-users>

java/README.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# Java based examples
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).
3-
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).
5-
6-
## What's in Oracle database 12c Release 2 for Java Developers?
7-
* **Java 8**: Java 8 in JDBC/UCP and OJVM; JDBC 4.2
8-
* **JavaScript with Nashorn**: JDBC/UCP, OJVM
9-
* **Performance**: JIT (OJVM), Network Compression over WAN (JDBC), Configurable connection health check frequency (UCP), PL/SQL Callbace interface (JDBC)
10-
* **Scalability**: Shared Pool for Multi-Tenant Database (UCP), Shared Pool for Sharded database (UCP), Sharding Key APIs (JDBC, UCP), DRCP Proxy session sharing, DRCP support for multiple labels
11-
* **High-Availability**: Java APIs for FAN events (SimpleFan.jar), Planned Maintenance in the driver (JDBC), Application Continuity for XA Datasources, Transaction Guard for XA Datasource
12-
* **Security**: SSL v1.2 / TLS v 1.2 (JDBC)
13-
* **Manageability**: XMLconfiguration (UCP), Enable/disable/suspend/resume feature level logging (JDBC), MAX_THINK_TIME for Transactions in progress (DRCP), new statistics view and AWR reports
14-
* **Ease of Use** : Web Services Callout (OJVMWCU), Long Identifiers (OJVM), PL/SQL Boolean (JDBC), Debugger for OJVM (Java Debug Wire Protocol)
15-
16-
## [White paper](http://bit.ly/2orH5jf)
17-
## [See our OTN landing page for more information and resources](http://www.oracle.com/technetwork/database/application-development/java/overview/index.html)
1+
# Java based examples
2+
This is a repository of sample code that will demonstrate various concepts to assist Java developers in designing applications for accessing and processing data from the Oracle Database, leveraging Java Database Connectivity (JDBC), Univeral Connection Pool (UCP); or running Java code directly in the database leveraging the embedded JVM (a.k.a. OJVM).
3+
4+
# What's in Oracle database 12c Release 2 for Java Developers?
5+
* **Java 8**: Java 8 in JDBC/UCP and OJVM; JDBC 4.2
6+
* **Performance**: JIT (OJVM), Network Compression over WAN (JDBC), Configurable connection health check frequency (UCP), PL/SQL Callbace interface (JDBC)
7+
* **Scalability**: Shared Pool for Multi-Tenant Database (UCP), Shared Pool for Sharded database (UCP), Sharding Key APIs (JDBC, UCP), DRCP Proxy session sharing, DRCP support for multiple labels
8+
* **High-Availability**: Java APIs for FAN events (SimpleFan.jar), Planned Maintenance in the driver (JDBC), Application Continuity for XA Datasources, Transaction Guard for XA Datasource
9+
* **Security**: SSL v1.2 / TLS v 1.2 (JDBC)
10+
* **Manageability**: XMLconfiguration (UCP), Enable/disable/suspend/resume feature level logging (JDBC), MAX_THINK_TIME for Transactions in progress (DRCP), new statistics view and AWR reports
11+
* **Ease of Use** : Web Services Callout (OJCM), Long Identifiers (OJVM), PL/SQL Boolean (JDBC), Debugger for OJVM (Java Debug Wire Protocol)
12+
13+
# [White paper](http://bit.ly/2orH5jf)
14+
# [See our OTN landing page for more information and resources](http://www.oracle.com/technetwork/database/application-development/java/overview/index.html)

java/jdbc/ConnectionManagementSamples/DRCPSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ or clients. DRCP pools database server processes and sessions (the
1414
client releases it.
1515
1616
DRCP can be used with any third party client-side connection pool such as
17-
DBCP, C3PO etc., Third party client side connection pools must attach and
17+
DBCP, C3PO, etc. Third party client side connection pools must attach and
1818
detach connections explicitly to the connection broker through
1919
attachServerConnection() and detachServerConnection(). They should also
2020
set Connection Class as shown in the sample.

java/jdbc/ConnectionManagementSamples/InternalT4Driver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static public void printEmployees(Connection connection) throws SQLException {
6767
Statement statement = null;
6868
try {
6969
statement = connection.createStatement();
70-
resultSet = statement.executeQuery("SELECT employee_id, first_name FROM"+
70+
resultSet = statement.executeQuery("SELECT employee_id, first_name FROM "+
7171
"employees order by employee_id");
7272
while (resultSet.next()) {
7373
System.out.println("Emp no: " + resultSet.getInt(1) + " Emp name: "

java/ojvm/JSON-Tables.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
REM
2+
REM DDL for creating a table for the JSON Collection (and documents)
3+
REM for use by testSODA.java and testSODA.js
4+
REM
5+
CREATE TABLE MyFirstJSONCollection (
6+
ID varchar2(255) not null,
7+
CREATED_ON timestamp,
8+
LAST_MODIFIED timestamp,
9+
VERSION varchar2)255) not null,
10+
JSON_DOCUMENT BLOB
11+
)
12+
;

java/ojvm/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# OJVM based examples
2-
This folder stores Java based examples for the embedded JVM of the Oracle Database (a.k.a. OJVM). We are referring to plain Java code
3-
with embedded SQL statements, similar to client JDBC code.
4-
5-
The motivations for running Java code directly in the database include:
6-
* reusing Java code, Java libraries, and Java skills (developers) for database modules written in Java thereby allowing the same
7-
language across the mid-tier and the database-tier. The embedded JVM (a.k.a. OJVM also allows JavaScript (see our examples), Scala
8-
(see [Igor Racic's examples](http://www.igorandsons.com/)). I also described in [chapter 5 of my book](https://www.amazon.com/dp/1555583296), how to run run Jython, Jacl, Scheme, and Groovy in the database
9-
* the other key reason for running Java directly in the database is performance; really? Yes, even if HotSpot or external JVMs run
10-
pure Java sligthly faster than OJVM (but no one runs pure Java code i.e., Fibonnaci computation in the database), running Java in
11-
the database cuts the network traffic incurred by the steps involved in processing SQL statements (i.e., parse, and/or bind, and/or
12-
execute, and fetches).
13-
You can see for yourself with the Trimlob and Workers examples (running both inside and outside the database).
14-
15-
* OJVM allows calling out external SOAP and REST Web Services. [See the landing page for more details](http://www.oracle.com/technetwork/database/database-083829.html)
16-
17-
## [Documentation](http://docs.oracle.com/database/122/JJDEV/toc.htm)
18-
19-
## [What's in Oracle database 12c Release 2 for Java & JavaScript Developers?](http://bit.ly/2orH5jf)
20-
## [OTN Landing page](http://www.oracle.com/technetwork/database/application-development/java-db/overview/index.html)
21-
## [Community Forum](https://community.oracle.com/community/database/developer-tools/jvm)
1+
# Java in the Database (OJVM) examples
2+
This folder stores Java based examples for the embedded JVM of the Oracle Database (a.k.a. OJVM). We are referring to plain Java code
3+
with embedded SQL statements, similar to client JDBC code.
4+
5+
The motivations for running Java code directly in the database include:
6+
* reusing Java code, Java libraries, and Java skills (developers) for database modules written in Java thereby allowing the same
7+
language across the mid-tier and the database-tier. The embedded JVM (a.k.a. OJVM also allows JavaScript (see our examples), Scala
8+
(see [Igor Racic's examples](http://www.igorandsons.com/)). I also described in [chapter 5 of my book](https://www.amazon.com/dp/1555583296), how to run run Jython, Jacl, Scheme, and Groovy in the database
9+
* the other key reason for running Java directly in the database is performance; really? Yes, even if HotSpot or external JVMs run
10+
pure Java sligthly faster than OJVM (but no one runs pure Java code i.e., Fibonnaci computation in the database), running Java in
11+
the database cuts the network traffic incurred by the steps involved in processing SQL statements (i.e., parse, and/or bind, and/or
12+
execute, and fetches).
13+
You can see for yourself with the TrimBlog and Workers examples (running both inside and outside the database).
14+
15+
In addition, for JSON collections and documents, you can also use the fluent Java API using SODA for Java. See SODA.md and testSODA.java for a complete example.
16+
17+
[Documentation](http://docs.oracle.com/database/122/JJDEV/toc.htm)
18+
19+
[What's in Oracle database 12c Release 2 for Java & JavaScript Developers?](http://bit.ly/2orH5jf)
20+
21+
[Community Forum](https://community.oracle.com/community/database/developer-tools/jvm)

java/ojvm/SODA.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SODA for Java in the Database (OJVM)
2+
3+
[SODA for Java](https://github.com/oracle/soda-for-java) is Oracle's fluent Java API for accessing JSON collections and documents without any knowledge of SQL.
4+
See [Getting started with SODA for Java](https://github.com/oracle/soda-for-java/blob/master/doc/Getting-started-example.md) for more details on running testSODA.java with a client JVM (JDK or JRE).
5+
The goal of this write up is to furnish the steps for running testSODA.java in OJVM and manipulate the JSON collection directly in the database session without moving data around.
6+
7+
**Requirements to run SODA with Java in the database**
8+
9+
(i) Download the [latest orajsoda.jar](https://github.com/oracle/soda-for-java/releases) currently orajsoda-1.0.4.jar
10+
11+
(ii) Upload orasoda.jar in your database schema
12+
13+
loadjava -r -v -u hr/hr orajsoda-1.0.4.jar
14+
15+
(iii) Load the [latest javax.json-1.0.4.jar](https://mvnrepository.com/artifact/org.glassfish/javax.json/1.0.4)
16+
17+
loadjava -r -v -u hr/hr javax.json-1.0.4.jar
18+
19+
**Prep testSODA.java for OJVM**
20+
21+
(i) Get (copy/paste) testSODA.java from [Getting started with SODA for Java](https://github.com/oracle/soda-for-java/blob/master/doc/Getting-started-example.md)
22+
23+
(ii) Replace the URL in the connect string with the OJVM server-side connect URL
24+
25+
Replace "jdbc:oracle:thin:@//hostName:port/serviceName"
26+
With "jdbc:default:connection"
27+
28+
The furnished testSODA.java on this page already has the change
29+
30+
(iii) load the updated testSODA.java in your schema using
31+
32+
loadjava -r -v -user hr/hr testSODA.java
33+
34+
(iv) Create a SQL wrapper for invoking the main method
35+
36+
create or replace procedure testSODA as
37+
language java name 'testSODA.main(java.lang.String[])';
38+
39+
(v) Invoke the wrapper of the main method and display the output
40+
41+
set serveroutput on
42+
call dbms_java.set_output(2000);
43+
call testSODA();
44+
45+
The furnished testSODA.sql performs the steps (v) and (vi).
46+
47+
From a database SQLPLUS session, issue the following call
48+
49+
sqlplus hr/hr @testSODA.sql
50+
51+
You should see the following output
52+
53+
* Retrieving the first document by its key *
54+
55+
{ "name" : "Alex", "friends" : "50" }
56+
57+
* Retrieving documents representing users with at least 300 friends *
58+
59+
{ "name" : "Mia", "friends" : "300" }
60+
{ "name" : "Gloria", "friends" : "399" }
61+

java/ojvm/InternalT2Driver.java renamed to java/ojvm/ServersideConnect.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
database.
1010
1111
Step 1: Connect to SQLPLUS using the database USER/PASSWORD.
12-
Make sure to have InternalT2Driver.sql accessible on the
12+
Make sure to have ServersideConnect.sql accessible on the
1313
client side to execute.
14-
Step 2: Run the SQL file after connecting to DB "@InternalT2Driver.sql"
14+
Step 2: Run the SQL file after connecting to DB "@ServersideConnect.sql"
1515
1616
NOTES
1717
Use JDK 1.6 and above
@@ -28,17 +28,18 @@
2828
import oracle.jdbc.pool.OracleDataSource;
2929

3030

31-
public class InternalT2Driver {
31+
public class ServersideConnect {
3232

3333
static public void jrun() throws SQLException {
34-
// For testing InternalT2Driver
34+
// For testing ServersideConnect
3535
// test("jdbc:oracle:kprb:@");
36-
test("jdbc:default:connection");
37-
}
38-
/*
36+
method1("jdbc:default:connection");
37+
method2();
38+
}
39+
/*
3940
* Shows using the server side Type 2 driver a.k.a KPRB driver
4041
*/
41-
static public void test(String url) throws SQLException {
42+
static public void method1(String url) throws SQLException {
4243
Connection connection = null;
4344
try {
4445
System.out.println("Connecting to URL " + url);
@@ -51,18 +52,28 @@ static public void test(String url) throws SQLException {
5152
// Perform database operation
5253
printEmployees(connection);
5354

55+
} catch (SQLException e) {
56+
e.printStackTrace();
57+
}
58+
}
59+
60+
61+
/*
62+
* Method to show that a connection is obtained without specifying the URL.
63+
* This method uses the default connection to establish the connection.
64+
*/
65+
66+
static public void method2() throws SQLException {
67+
Connection connection = null;
5468
// Method 2: Using defaultConnection() method
5569
OracleDriver ora = new OracleDriver();
5670
connection = ora.defaultConnection();
5771
System.out.println("Method 2: Getting Default Connection "
5872
+ "using OracleDriver");
5973
// Perform database operation
6074
printEmployees(connection);
61-
}
62-
finally {
63-
if (connection != null) connection.close();
64-
}
65-
}
75+
}
76+
/*
6677
6778
/*
6879
* Displays employee_id and first_name from the employees table.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Rem InternalT2Driver.sql
1+
Rem ServersideConnect.sql
22
Rem
3-
Rem Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3+
Rem Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
44
Rem
55
Rem NAME
6-
Rem InternalT2Driver.sql
6+
Rem ServersideConnect.sql
77
Rem
88
Rem DESCRIPTION
99
Rem SQL for invoking the method which gets a server side connection to
@@ -13,25 +13,25 @@ Rem MODIFIED (MM/DD/YY)
1313
Rem nbsundar 03/23/15 - Created
1414
Rem kmensah 03/23/15 - Contributor
1515

16-
rem Reads the content of the Java source from InternalT2Driver.java
16+
rem Reads the content of the Java source from ServersideConnect.java
1717
rem then compiles it
1818
connect hr/hr
19-
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED InternalT2Driver_src AS
20-
@ InternalT2Driver.java
19+
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED ServersideConnect_src AS
20+
@ ServersideConnect.java
2121
/
2222

2323
show error
2424

2525
rem A wrapper (a.k.a. Call Spec), to invoke Java
2626
rem function in the database from SQL, PL/SQL, and client applications
27-
CREATE OR REPLACE PROCEDURE InternalT2Driver_proc AS
28-
LANGUAGE JAVA NAME 'InternalT2Driver.jrun ()';
27+
CREATE OR REPLACE PROCEDURE ServersideConnect_proc AS
28+
LANGUAGE JAVA NAME 'ServersideConnect.jrun ()';
2929
/
3030

3131
rem Running the sample
3232
connect hr/hr
3333
SET SERVEROUTPUT ON SIZE 10000
3434
CALL dbms_java.set_output (10000);
3535

36-
execute InternalT2Driver_proc;
36+
execute ServersideConnect_proc;
3737

0 commit comments

Comments
 (0)