|
| 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 | + |
0 commit comments