Skip to content

Commit 0a60d81

Browse files
author
Nirmala Sundarappa
committed
Re-organizing the code samples
1 parent 03b33fe commit 0a60d81

File tree

7 files changed

+637
-0
lines changed

7 files changed

+637
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Connection Management Samples in JDBC using UCP, Universal Connection Pool
2+
3+
Brief descriptions of connection management related code samples.
4+
5+
|Author | Date |
6+
|-------|------|
7+
|nirmala.sundarappa|06/14/16|
8+
9+
10+
==============================================================================
11+
Creating a connection is an expensive database operation which
12+
involves several background operations such as network communication, reading
13+
connection strings, authentication, transaction enlistment, foreground process
14+
creation and memory allocation. Each of these processes contributes to the
15+
amount of time and resources taken to create a connection object. Repeated
16+
connection creation and destruction will significantly impact Java application
17+
scalability.
18+
19+
"Connection Management" code samples explain various ways of connecting to an
20+
Oracle Database and explain use-cases to be considered while choosing the
21+
connection management strategy. The section below provides more details on
22+
specific connection management strategy.
23+
24+
----
25+
## InternalT2Driver.sql & InternalT2Driver.java:
26+
The server-side Type 2 (T2S) driver (aka KPRB driver) is for Java in the
27+
database. It uses database session directly for accessing local data.
28+
T2S driver is used for better performance because it cuts network traffic
29+
between the Java code and the RDBMS SQL engine.
30+
31+
## InternalT4Driver.sql & InternalT4Driver.java:
32+
The server side Type 4(T4S) driver (aka thin/T4 driver) is used for code
33+
running Java in database session needing access to another session either on
34+
the same RDBMS instance/server or on a remote RDBMS instance/server.
35+
36+
## DataSourceSample.java:
37+
This sample shows how to connect to a simple DataSource
38+
(oracle.jdbc.pool.OracleDataSource) and how to set connection related
39+
properties such as `defaultRowPrefetch`, `defaultBatchValue` etc.,
40+
41+
## ProxySessionSample.java and ProxySessionSample.sql:
42+
This sample shows connecting to the Oracle Database using Proxy
43+
authentication or N-tier authentication. Proxy authentication is the
44+
process of using a middle tier for user authentication. Proxy connections
45+
can be created using any one of the following options.
46+
(a) USER NAME: Done by supplying the user name or the password or both.
47+
(b) DISTINGUISHED NAME: This is a global name in lieu of the password of
48+
the user being proxied for.
49+
(c) CERTIFICATE:More encrypted way of passing the credentials of the user,
50+
who is to be proxied, to the database.
51+
52+
## DRCPSample.java:
53+
DRCP can be used with or without a client side connection pool.
54+
Either UCP or any other third party connection pool (eg., C3P0) can be used as
55+
client side pool. Note that, when UCP is used, it takes care of attaching and
56+
releasing server connections. There is no need to explicitly call
57+
`attachServerConnection()`/`detachServerConnection()` with UCP.
58+
59+
----
60+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0"?>
2+
3+
<!--
4+
Copyright (c) 2017, 2016, Oracle and/or its affiliates. All rights reserved.
5+
6+
NAME
7+
build.xml - For compiling and running connection management samples
8+
9+
DESCRIPTION
10+
Use this build.xml for compiling and running connection
11+
management related code samples.
12+
-->
13+
<project name="OracleJdbcSamples" default="compile">
14+
<description>Build and run Oracle Jdbc Samples</description>
15+
16+
17+
<property environment="env" />
18+
<property name="ORACLE_HOME" value="${env.ORACLE_HOME}" />
19+
<property name="JDK8" location="${ORACLE_HOME}/jdk8" />
20+
<property name="jdk.javac" location="${JDK8}/bin/javac" />
21+
<property name="jdk.java" location="${JDK8}/bin/java" />
22+
<property name="jdk.jar" location="${JDK8}/bin/jar" />
23+
24+
25+
<!-- ///////////////////// classpath /////////////////////////// -->
26+
<path id="java.classpath">
27+
<pathelement path="lib/ojdbc7.jar" />
28+
<pathelement path="lib/ucp.jar" />
29+
<pathelement path="lib/ons.jar" />
30+
<pathelement location="classes/" />
31+
</path>
32+
33+
<!-- ///////////////////////////////////////////////////////////// -->
34+
<!-- TARGETS -->
35+
<!-- ///////////////////////////////////////////////////////////// -->
36+
<target name="compile">
37+
<mkdir dir="classes"/>
38+
<!-- ////////////////// Compile java file //////////////// -->
39+
<javac srcdir="src" destdir="classes" debug="yes" includeantruntime="false" fork="yes" executable="${jdk.javac}">
40+
<classpath refid="java.classpath" />
41+
<include name="**/*.java" />
42+
</javac>
43+
44+
</target>
45+
46+
<target name="clean">
47+
<delete>
48+
<fileset dir="classes" includes="*"/>
49+
</delete>
50+
</target>
51+
52+
<target name="run" depends="compile">
53+
<java classname="${class.file.name}" fork="true" jvm="${jdk.java}" >
54+
<classpath refid="java.classpath" />
55+
<arg value="${arg.one}" />
56+
</java>
57+
</target>
58+
59+
<echo> Connection Management Samples: Commands to Run </echo>
60+
<echo> ============================================== </echo>
61+
<echo> (1) ant DataSourceSample </echo>
62+
<echo> (2) ant ProxySessionSample </echo>
63+
<echo> (5) ant DRCPSample </echo>
64+
<echo> ============================================== </echo>
65+
66+
<target name="DataSourceSample" description="Run a sample that exhibits the usage of DataSource with and without properties"> <antcall target="run">
67+
<param name="class.file.name" value="DataSourceSample" />
68+
</antcall>
69+
</target>
70+
71+
<target name="ProxySessionSample" description="Run a proxy session sample">
72+
<antcall target="run">
73+
<param name="class.file.name" value="ProxySessionSample" />
74+
</antcall>
75+
</target>
76+
77+
<target name="DRCPSample" description="Run a sample that shows how to use DRCP"> <antcall target="run">
78+
<param name="class.file.name" value="DRCPSample" />
79+
</antcall>
80+
</target>
81+
</project>
82+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Connection Management Samples in JDBC using UCP, Universal Connection Pool
2+
3+
Brief descriptions of connection management related code samples.
4+
5+
|Author | Date |
6+
|-------|------|
7+
|nirmala.sundarappa|06/14/16|
8+
9+
10+
==============================================================================
11+
Creating a connection is an expensive database operation which
12+
involves several background operations such as network communication, reading
13+
connection strings, authentication, transaction enlistment, foreground process
14+
creation and memory allocation. Each of these processes contributes to the
15+
amount of time and resources taken to create a connection object. Repeated
16+
connection creation and destruction will significantly impact Java application
17+
scalability.
18+
19+
"Connection Management" code samples explain various ways of connecting to an
20+
Oracle Database and explain use-cases to be considered while choosing the
21+
connection management strategy. The section below provides more details on
22+
specific connection management strategy.
23+
24+
============================================================================
25+
## UCPSample.java:
26+
Universal Connection Pool (UCP) is a client side connection pool. UCP
27+
furnishes a rich set of features to support scalability in single database
28+
instance as well as built-in features to support high-availability and
29+
scalability in RAC and Active Data Guard environments. UCP along with RAC,
30+
RAC One and ADG is a tested and certified combination for handling database
31+
failovers. Refer to this sample for using UCP and setting UCP properties
32+
such as `minPoolSize`, `maxPoolSize`, etc.
33+
34+
## UCPWithTimeoutProperties.java:
35+
UCP furnishes a set of TimeOut properties which can be used to tune
36+
performance. The sample demonstrates using some of UCP's important Timeout
37+
properties, such as `InactivityTimeout`, `AbandonedConnectionTimeout`,
38+
`TimeToLiveTimeout`, and `connectionWaitTimeout`. Each one of the UCP timeout
39+
property can be run independently. Refer to the sample for more details.
40+
41+
## UCPWebSessionAffinitySample.java:
42+
Web-Session Affinity is a scalability feature of UCP in RAC and Active Data
43+
Guard environment which attempts to allocate connections from the same RAC
44+
instance during the life of a Web application. UCP tries to do a best try
45+
effort, but, there is no guarantee to get a connection to the same instance.
46+
UCP Web-Session Affinity is used in applications which expect short lived
47+
connections to any database instance.
48+
49+
## UCPConnectionLabelingSample.java:
50+
Connection Labelling allows applications to set custom states ("labels")
51+
then retrieve connections based on these pre-set states thereby avoiding the
52+
cost of resetting these states. The sample uses applyConnectionLabel() to
53+
apply a connection label and retrieves a connection using getConnection(label)
54+
by specifying the created label.
55+
56+
## UCPConnectionHarvestingSample.java:
57+
UCP's Connection Harvesting allows UCP to pro-actively reclaim borrowed
58+
connections based on pool requirements at run-time, while still giving
59+
applications control over which borrowed connections should not be reclaimed.
60+
The sample uses registerConnectionHarvestingCallback to register a connection
61+
harvesting callback.
62+
63+
## UCPWithDRCPSample.java:
64+
Database Resident Connection Pool (DRCP) is the server side connection pool.
65+
DRCP should be used in a scenario when there are a number of middle tiers but
66+
the number of active connections is fairly less than the number of open
67+
connections.
68+
DRCP when used along with and Universal Connection Pool(UCP) as the client
69+
side connection pool improves the performance. The sample shows UCP with DRCP
70+
in action. The purpose of the client-side pooling mechanism is to maintain the
71+
connections to Connection Broker. Client-side connection pools must attach and
72+
detach connections to the connection broker through `attachServerConnection()`
73+
and `detachServerConnection()`. DRCP should be used in a scenario when there are
74+
a number of middle tiers but the number of active connections is fairly less
75+
than the number of open connections.
76+
77+
============================================================================
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?xml version="1.0"?>
2+
3+
<!--
4+
Copyright (c) 2017, 2016, Oracle and/or its affiliates. All rights reserved.
5+
6+
NAME
7+
build.xml - For compiling and running connection management samples
8+
9+
DESCRIPTION
10+
Use this build.xml for compiling and running connection
11+
management related code samples.
12+
-->
13+
14+
<project name="OracleJdbcSamples" default="compile">
15+
<description>Build and run Oracle Jdbc Samples</description>
16+
17+
<property environment="env" />
18+
<property name="ORACLE_HOME" value="${env.ORACLE_HOME}" />
19+
<property name="JDK8" location="${ORACLE_HOME}/jdk8" />
20+
<property name="jdk.javac" location="${JDK8}/bin/javac" />
21+
<property name="jdk.java" location="${JDK8}/bin/java" />
22+
<property name="jdk.jar" location="${JDK8}/bin/jar" />
23+
24+
<!-- ///////////////////// classpath /////////////////////////// -->
25+
<path id="java.classpath">
26+
<pathelement path="lib/ojdbc7.jar" />
27+
<pathelement path="lib/ucp.jar" />
28+
<pathelement path="lib/ons.jar" />
29+
<pathelement location="classes/" />
30+
</path>
31+
32+
<!-- ///////////////////////////////////////////////////////////// -->
33+
<!-- TARGETS -->
34+
<!-- ///////////////////////////////////////////////////////////// -->
35+
<target name="compile">
36+
<mkdir dir="classes"/>
37+
<!-- ////////////////// Compile java file //////////////// -->
38+
<javac srcdir="src" destdir="classes" debug="yes" includeantruntime="false" fork="yes" executable="${jdk.javac}">
39+
<classpath refid="java.classpath" />
40+
<include name="**/*.java" />
41+
</javac>
42+
43+
</target>
44+
45+
<target name="clean">
46+
<delete>
47+
<fileset dir="classes" includes="*"/>
48+
</delete>
49+
</target>
50+
51+
<target name="run" depends="compile">
52+
<java classname="${class.file.name}" fork="true" jvm="${jdk.java}" >
53+
<classpath refid="java.classpath" />
54+
<arg value="${arg.one}" />
55+
</java>
56+
</target>
57+
58+
<echo> Connection Management Samples: Commands to Run </echo>
59+
<echo> ============================================== </echo>
60+
<echo> (1) ant UCPSample </echo>
61+
<echo> (2) ant UCPInactiveConnectionTimeout </echo>
62+
<echo> (3) ant UCPConnectionWaitTimeout </echo>
63+
<echo> (4) ant UCPAbandonedConnectionTimeout </echo>
64+
<echo> (5) ant UCPAbandonedConnectionTimeout </echo>
65+
<echo> (6) ant UCPTimeToLiveConnectionTimeout </echo>
66+
<echo> (7) ant UCPConnectionHarvestingSample </echo>
67+
<echo> (8) ant UCPConnectionLabelingSample </echo>
68+
<echo> (9) ant UCPWebSessionAffinitySample </echo>
69+
<echo> (10) ant UCPWithDRCPSample </echo>
70+
<echo> ============================================== </echo>
71+
72+
<target name="UCPSample" description="Run a sample that exhibits the use Universal Connection Pool (UCP) "> <antcall target="run">
73+
<param name="class.file.name" value="UCPSample" />
74+
</antcall>
75+
</target>
76+
77+
78+
<target name="UCPWithDRCPSample" description="Run a sample that exhibits the use DRCP "> <antcall target="run">
79+
<param name="class.file.name" value="UCPWithDRCPSample" />
80+
</antcall>
81+
</target>
82+
83+
84+
<target name="UCPWithTimeoutProperties" description="Run a sample that exhibits different UCP timeout properties "> <antcall target="run">
85+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
86+
</antcall>
87+
</target>
88+
89+
<target name="UCPTimeToLiveConnectionTimeout" description="Run a sample that exhibits UCP's TimeToLiveConnectionTimeout property">
90+
<antcall target="run">
91+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
92+
<param name="arg.one" value="runTimeToLive" />
93+
</antcall>
94+
</target>
95+
96+
97+
<target name="UCPAbandonedConnectionTimeout" description="Run a sample that exhibits UCP's AbandonedConnectionTimeout property"> <antcall target="run">
98+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
99+
<param name="arg.one" value="runAbandonedTimeout" />
100+
</antcall>
101+
</target>
102+
103+
104+
<target name="UCPInactiveConnectionTimeout" description="Run a sample that exhibits UCP's InactiveConnectionTimeout property"> <antcall target="run">
105+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
106+
<param name="arg.one" value="runInactiveTimeout" />
107+
</antcall>
108+
</target>
109+
110+
111+
<target name="UCPConnectionWaitTimeout" description="Run a sample that exhibits UCP's ConnectionWaitTimeout property"> <antcall target="run">
112+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
113+
<param name="arg.one" value="runConnectionWaitTimeout" />
114+
</antcall>
115+
</target>
116+
117+
<target name="UCPConnectionHarvestingSample" description="Run a sample that exhibits Connection Harvesting feature of UCP"> <antcall target="run">
118+
<param name="class.file.name" value="UCPConnectionHarvestingSample" />
119+
</antcall>
120+
</target>
121+
122+
<target name="UCPConnectionLabelingSample" description="Run a sample that exhibits Connection Labeling feature of UCP"> <antcall target="run">
123+
<param name="class.file.name" value="UCPConnectionLabelingSample" />
124+
</antcall>
125+
</target>
126+
127+
<target name="UCPWebSessionAffinitySample" description="Run a sample that exhibits the use of Web Session Affinity"> <antcall target="run">
128+
<param name="class.file.name" value="UCPWebSessionAffinitySample" />
129+
</antcall>
130+
</target>
131+
132+
</project>
133+

0 commit comments

Comments
 (0)