Skip to content

Commit 4fe59aa

Browse files
author
Nirmala Sundarappa
committed
Checking in files into JDBC and UCP files.
1 parent 2234941 commit 4fe59aa

File tree

9 files changed

+1304
-0
lines changed

9 files changed

+1304
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
*.class
3+
*.jar
4+
classes/

java/jdbc/Readme.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
## UCPSample.java:
53+
Universal Connection Pool (UCP) is a client side connection pool. UCP
54+
furnishes a rich set of features to support scalability in single database
55+
instance as well as built-in features to support high-availability and
56+
scalability in RAC and Active Data Guard environments. UCP along with RAC,
57+
RAC One and ADG is a tested and certified combination for handling database
58+
failovers. Refer to this sample for using UCP and setting UCP properties
59+
such as `minPoolSize`, `maxPoolSize`, etc.
60+
61+
## UCPWithTimeoutProperties.java:
62+
UCP furnishes a set of TimeOut properties which can be used to tune
63+
performance. The sample demonstrates using some of UCP's important Timeout
64+
properties, such as `InactivityTimeout`, `AbandonedConnectionTimeout`,
65+
`TimeToLiveTimeout`, and `connectionWaitTimeout`. Each one of the UCP timeout
66+
property can be run independently. Refer to the sample for more details.
67+
68+
## UCPWebSessionAffinitySample.java:
69+
Web-Session Affinity is a scalability feature of UCP in RAC and Active Data
70+
Guard environment which attempts to allocate connections from the same RAC
71+
instance during the life of a Web application. UCP tries to do a best try
72+
effort, but, there is no guarantee to get a connection to the same instance.
73+
UCP Web-Session Affinity is used in applications which expect short lived
74+
connections to any database instance.
75+
76+
## UCPConnectionLabelingSample.java:
77+
Connection Labelling allows applications to set custom states ("labels")
78+
then retrieve connections based on these pre-set states thereby avoiding the
79+
cost of resetting these states. The sample uses `applyConnectionLabel()` to
80+
apply a connection label and retrieves a connection using `getConnection(label)`
81+
by specifying the created label.
82+
83+
## UCPConnectionHarvestingSample.java:
84+
UCP's Connection Harvesting allows UCP to pro-actively reclaim borrowed
85+
connections based on pool requirements at run-time, while still giving
86+
applications control over which borrowed connections should not be reclaimed.
87+
The sample uses `registerConnectionHarvestingCallback` to register a connection
88+
harvesting callback.
89+
90+
## UCPWithDRCPSample.java:
91+
Database Resident Connection Pool (DRCP) is the server side connection pool.
92+
DRCP should be used in a scenario when there are a number of middle tiers but
93+
the number of active connections is fairly less than the number of open
94+
connections.
95+
DRCP when used along with and Universal Connection Pool(UCP) as the client
96+
side connection pool improves the performance. The sample shows UCP with DRCP
97+
in action. The purpose of the client-side pooling mechanism is to maintain the
98+
connections to Connection Broker. Client-side connection pools must attach and
99+
detach connections to the connection broker through `attachServerConnection()`
100+
and `detachServerConnection()`. DRCP should be used in a scenario when there are
101+
a number of middle tiers but the number of active connections is fairly less
102+
than the number of open connections.
103+
104+
## DRCPSample.java:
105+
DRCP can be used with or without a client side connection pool.
106+
Either UCP or any other third party connection pool (eg., C3P0) can be used as
107+
client side pool. Note that, when UCP is used, it takes care of attaching and
108+
releasing server connections. There is no need to explicitly call
109+
`attachServerConnection()`/`detachServerConnection()` with UCP.
110+
111+
============================================================================
112+
113+

java/jdbc/build.xml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?xml version="1.0"?>
2+
3+
<!--
4+
Copyright (c) 2015, 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+
MODIFIED (MM/DD/YY)
14+
nbsundar 01/14/16 - update
15+
nbsundar 02/16/15 - Creation
16+
17+
-->
18+
<project name="OracleJdbcSamples" default="compile">
19+
<description>Build and run Oracle Jdbc Samples</description>
20+
21+
22+
<property environment="env" />
23+
<property name="ORACLE_HOME" value="${env.ORACLE_HOME}" />
24+
<property name="JDK8" location="${ORACLE_HOME}/jdk8" />
25+
<property name="jdk.javac" location="${JDK8}/bin/javac" />
26+
<property name="jdk.java" location="${JDK8}/bin/java" />
27+
<property name="jdk.jar" location="${JDK8}/bin/jar" />
28+
29+
30+
<!-- ///////////////////// classpath /////////////////////////// -->
31+
<path id="java.classpath">
32+
<pathelement path="lib/ojdbc7.jar" />
33+
<pathelement path="lib/ucp.jar" />
34+
<pathelement path="lib/ons.jar" />
35+
<pathelement location="classes/" />
36+
</path>
37+
38+
<!-- ///////////////////////////////////////////////////////////// -->
39+
<!-- TARGETS -->
40+
<!-- ///////////////////////////////////////////////////////////// -->
41+
<target name="compile">
42+
<mkdir dir="classes"/>
43+
<!-- ////////////////// Compile java file //////////////// -->
44+
<javac srcdir="src" destdir="classes" debug="yes" includeantruntime="false" fork="yes" executable="${jdk.javac}">
45+
<classpath refid="java.classpath" />
46+
<include name="**/*.java" />
47+
<exclude name="**/.ade_path/*.java" />
48+
</javac>
49+
50+
</target>
51+
52+
<target name="clean">
53+
<delete>
54+
<fileset dir="classes" includes="*"/>
55+
</delete>
56+
</target>
57+
58+
<target name="run" depends="compile">
59+
<java classname="${class.file.name}" fork="true" jvm="${jdk.java}" >
60+
<classpath refid="java.classpath" />
61+
<arg value="${arg.one}" />
62+
</java>
63+
</target>
64+
65+
<echo> Connection Management Samples: Commands to Run </echo>
66+
<echo> ============================================== </echo>
67+
<echo> (1) ant DataSourceSample </echo>
68+
<echo> (2) ant ProxySessionSample </echo>
69+
<echo> (3) ant UCPSample </echo>
70+
<echo> (4) ant UCPWithDRCPSample </echo>
71+
<echo> (5) ant DRCPSample </echo>
72+
<echo> (6) ant UCPInactiveConnectionTimeout </echo>
73+
<echo> (7) ant UCPConnectionWaitTimeout </echo>
74+
<echo> (8) ant UCPAbandonedConnectionTimeout </echo>
75+
<echo> (9) ant UCPAbandonedConnectionTimeout </echo>
76+
<echo> (10) ant UCPTimeToLiveConnectionTimeout </echo>
77+
<echo> (11) ant UCPConnectionHarvestingSample </echo>
78+
<echo> (12) ant UCPConnectionLabelingSample </echo>
79+
<echo> (13) ant UCPWebSessionAffinitySample </echo>
80+
<echo> ============================================== </echo>
81+
82+
<target name="DataSourceSample" description="Run a sample that exhibits the usage of DataSource with and without properties"> <antcall target="run">
83+
<param name="class.file.name" value="DataSourceSample" />
84+
</antcall>
85+
</target>
86+
87+
<target name="ProxySessionSample" description="Run a proxy session sample">
88+
<antcall target="run">
89+
<param name="class.file.name" value="ProxySessionSample" />
90+
</antcall>
91+
</target>
92+
93+
94+
<target name="UCPSample" description="Run a sample that exhibits the use Universal Connection Pool (UCP) "> <antcall target="run">
95+
<param name="class.file.name" value="UCPSample" />
96+
</antcall>
97+
</target>
98+
99+
100+
<target name="UCPWithDRCPSample" description="Run a sample that exhibits the use DRCP "> <antcall target="run">
101+
<param name="class.file.name" value="UCPWithDRCPSample" />
102+
</antcall>
103+
</target>
104+
105+
106+
<target name="UCPWithTimeoutProperties" description="Run a sample that exhibits different UCP timeout properties "> <antcall target="run">
107+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
108+
</antcall>
109+
</target>
110+
111+
<target name="UCPTimeToLiveConnectionTimeout" description="Run a sample that exhibits UCP's TimeToLiveConnectionTimeout property">
112+
<antcall target="run">
113+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
114+
<param name="arg.one" value="runTimeToLive" />
115+
</antcall>
116+
</target>
117+
118+
119+
<target name="UCPAbandonedConnectionTimeout" description="Run a sample that exhibits UCP's AbandonedConnectionTimeout property"> <antcall target="run">
120+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
121+
<param name="arg.one" value="runAbandonedTimeout" />
122+
</antcall>
123+
</target>
124+
125+
126+
<target name="UCPInactiveConnectionTimeout" description="Run a sample that exhibits UCP's InactiveConnectionTimeout property"> <antcall target="run">
127+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
128+
<param name="arg.one" value="runInactiveTimeout" />
129+
</antcall>
130+
</target>
131+
132+
133+
<target name="UCPConnectionWaitTimeout" description="Run a sample that exhibits UCP's ConnectionWaitTimeout property"> <antcall target="run">
134+
<param name="class.file.name" value="UCPWithTimeoutProperties" />
135+
<param name="arg.one" value="runConnectionWaitTimeout" />
136+
</antcall>
137+
</target>
138+
139+
<target name="DRCPSample" description="Run a sample that shows how to use DRCP"> <antcall target="run">
140+
<param name="class.file.name" value="DRCPSample" />
141+
</antcall>
142+
</target>
143+
144+
<target name="UCPConnectionHarvestingSample" description="Run a sample that exhibits Connection Harvesting feature of UCP"> <antcall target="run">
145+
<param name="class.file.name" value="UCPConnectionHarvestingSample" />
146+
</antcall>
147+
</target>
148+
149+
<target name="UCPConnectionLabelingSample" description="Run a sample that exhibits Connection Labeling feature of UCP"> <antcall target="run">
150+
<param name="class.file.name" value="UCPConnectionLabelingSample" />
151+
</antcall>
152+
</target>
153+
154+
<target name="UCPWebSessionAffinitySample" description="Run a sample that exhibits the use of Web Session Affinity"> <antcall target="run">
155+
<param name="class.file.name" value="UCPWebSessionAffinitySample" />
156+
</antcall>
157+
</target>
158+
159+
</project>
160+

0 commit comments

Comments
 (0)