From c51ec276715ce0d7ba5a1087150098703435e56d Mon Sep 17 00:00:00 2001 From: Nirmala Sundarappa Date: Thu, 31 May 2018 15:18:01 -0700 Subject: [PATCH] Merge UCP with JDBC --- .../UCPWithDRCPSample.java | 0 .../ucp/ConnectionManagementSamples/Readme.md | 77 ----- .../UCPConnectionHarvestingSample.java | 304 ------------------ .../UCPConnectionLabelingSample.java | 259 --------------- .../ucp/ConnectionManagementSamples/build.xml | 133 -------- java/ucp/Readme.md | 48 --- java/ucp/Tomcat_Servlet/Readme.md | 29 -- java/ucp/Tomcat_Servlet/build.xml | 51 --- java/ucp/WebLogicServer_Servlet/Readme.md | 35 -- java/ucp/WebLogicServer_Servlet/build.xml | 51 --- 10 files changed, 987 deletions(-) rename java/jdbc/{BasicSamples => ConnectionSamples}/UCPWithDRCPSample.java (100%) delete mode 100644 java/ucp/ConnectionManagementSamples/Readme.md delete mode 100644 java/ucp/ConnectionManagementSamples/UCPConnectionHarvestingSample.java delete mode 100644 java/ucp/ConnectionManagementSamples/UCPConnectionLabelingSample.java delete mode 100644 java/ucp/ConnectionManagementSamples/build.xml delete mode 100644 java/ucp/Readme.md delete mode 100644 java/ucp/Tomcat_Servlet/Readme.md delete mode 100644 java/ucp/Tomcat_Servlet/build.xml delete mode 100644 java/ucp/WebLogicServer_Servlet/Readme.md delete mode 100644 java/ucp/WebLogicServer_Servlet/build.xml diff --git a/java/jdbc/BasicSamples/UCPWithDRCPSample.java b/java/jdbc/ConnectionSamples/UCPWithDRCPSample.java similarity index 100% rename from java/jdbc/BasicSamples/UCPWithDRCPSample.java rename to java/jdbc/ConnectionSamples/UCPWithDRCPSample.java diff --git a/java/ucp/ConnectionManagementSamples/Readme.md b/java/ucp/ConnectionManagementSamples/Readme.md deleted file mode 100644 index f0aee486..00000000 --- a/java/ucp/ConnectionManagementSamples/Readme.md +++ /dev/null @@ -1,77 +0,0 @@ -# Connection Management Samples in JDBC using UCP, Universal Connection Pool - -Brief descriptions of connection management related code samples. - -|Author | Date | -|-------|------| -|nirmala.sundarappa|06/14/16| - - -============================================================================== -Creating a connection is an expensive database operation which -involves several background operations such as network communication, reading -connection strings, authentication, transaction enlistment, foreground process -creation and memory allocation. Each of these processes contributes to the -amount of time and resources taken to create a connection object. Repeated -connection creation and destruction will significantly impact Java application -scalability. - -"Connection Management" code samples explain various ways of connecting to an -Oracle Database and explain use-cases to be considered while choosing the -connection management strategy. The section below provides more details on -specific connection management strategy. - -============================================================================ -## UCPSample.java: -Universal Connection Pool (UCP) is a client side connection pool. UCP -furnishes a rich set of features to support scalability in single database -instance as well as built-in features to support high-availability and -scalability in RAC and Active Data Guard environments. UCP along with RAC, -RAC One and ADG is a tested and certified combination for handling database -failovers. Refer to this sample for using UCP and setting UCP properties -such as `minPoolSize`, `maxPoolSize`, etc. - -## UCPWithTimeoutProperties.java: -UCP furnishes a set of TimeOut properties which can be used to tune -performance. The sample demonstrates using some of UCP's important Timeout -properties, such as `InactivityTimeout`, `AbandonedConnectionTimeout`, -`TimeToLiveTimeout`, and `connectionWaitTimeout`. Each one of the UCP timeout -property can be run independently. Refer to the sample for more details. - -## UCPWebSessionAffinitySample.java: -Web-Session Affinity is a scalability feature of UCP in RAC and Active Data -Guard environment which attempts to allocate connections from the same RAC -instance during the life of a Web application. UCP tries to do a best try -effort, but, there is no guarantee to get a connection to the same instance. -UCP Web-Session Affinity is used in applications which expect short lived -connections to any database instance. - -## UCPConnectionLabelingSample.java: -Connection Labelling allows applications to set custom states ("labels") -then retrieve connections based on these pre-set states thereby avoiding the -cost of resetting these states. The sample uses applyConnectionLabel() to -apply a connection label and retrieves a connection using getConnection(label) -by specifying the created label. - -## UCPConnectionHarvestingSample.java: -UCP's Connection Harvesting allows UCP to pro-actively reclaim borrowed -connections based on pool requirements at run-time, while still giving -applications control over which borrowed connections should not be reclaimed. -The sample uses registerConnectionHarvestingCallback to register a connection -harvesting callback. - -## UCPWithDRCPSample.java: -Database Resident Connection Pool (DRCP) is the server side connection pool. -DRCP should be used in a scenario when there are a number of middle tiers but -the number of active connections is fairly less than the number of open -connections. -DRCP when used along with and Universal Connection Pool(UCP) as the client -side connection pool improves the performance. The sample shows UCP with DRCP -in action. The purpose of the client-side pooling mechanism is to maintain the -connections to Connection Broker. Client-side connection pools must attach and -detach connections to the connection broker through `attachServerConnection()` -and `detachServerConnection()`. DRCP should be used in a scenario when there are -a number of middle tiers but the number of active connections is fairly less -than the number of open connections. - -============================================================================ diff --git a/java/ucp/ConnectionManagementSamples/UCPConnectionHarvestingSample.java b/java/ucp/ConnectionManagementSamples/UCPConnectionHarvestingSample.java deleted file mode 100644 index 0e20187f..00000000 --- a/java/ucp/ConnectionManagementSamples/UCPConnectionHarvestingSample.java +++ /dev/null @@ -1,304 +0,0 @@ -/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*/ -/* - DESCRIPTION - The Connection Harvesting feature ensures that the pool does not run out of - available connections by reclaiming borrowed connections on-demand. It is - useful when an application holds a connection from a pool for a long time - without releasing it. By setting the appropriate HarvestTriggerCount and - HarvestMaxCount, user instructs UCP to reclaim some or all of these - borrowed connections to ensure there are enough in the pool. - - Methods for connection harvesting include: - (1)setConnectionHarvestable(): on a per-connection basis, specifies whether - it is harvestable by the pool. The default is harvestable. - (2)setConnectionHarvestMaxCount(): Maximum number of connections that may be - harvested when harvesting occurs. - (3)setConnectionHarvestTriggerCount(): Specifies the available connection - threshold that triggers connection harvesting. - For example., if the harvest trigger count is set to 10, then harvesting is - triggered when the number of available connections in the pool drops to 10. - - Step 1: Enter the database details in this file. - DB_USER, DB_PASSWORD, DB_URL and CONN_FACTORY_CLASS_NAME are required - Step 2: Run the sample with "ant UCPConnectionHarvestingSample" - - NOTES - Use JDK 1.7 and above - - MODIFIED (MM/DD/YY) - nbsundar 03/09/15 - Creation (Contributor - tzhou) - */ -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -import oracle.ucp.ConnectionHarvestingCallback; -import oracle.ucp.jdbc.HarvestableConnection; -import oracle.ucp.jdbc.PoolDataSource; -import oracle.ucp.jdbc.PoolDataSourceFactory; - -public class UCPConnectionHarvestingSample { - final static String DB_URL= "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))"; - final static String DB_USER = "hr"; - final static String DB_PASSWORD = "hr"; - final static String CONN_FACTORY_CLASS_NAME = "oracle.jdbc.pool.OracleDataSource"; - - /* - * The sample demonstrates UCP's Connection Harvesting feature. - *(1)Set the connection pool properties. - * PoolSize=10 connections, HarvestMaxCount=2 and HarvestTriggerCount=5 - *(2)Run the sample with connection Harvesting. - * (2.1) Get 4 connections from UCP and perform a database operation - * (2.2) Get a 5th connection which triggers harvesting - * (2.3) Notice that conns[0] and conns[1] are reclaimed as part of - * harvesting based on LRU (Least Recently Used) algorithm. - * (2.4) Notice that number of available conns=7 and borrowed conns=3 - *(3) Run the sample without connection harvesting. - * (3.1) Get 4 connections from UCP and perform a database operation - * (3.2) Mark conns[0] and conns[1] as non-harvestable - * (3.3) Get a 5th connection which triggers harvesting - * (3.4) Notice that conns[2] and conns[3] are reclaimed as part of - * harvesting and conns[0] and conns[1] are not harvested or released - * (3.5) Notice that number of available connections=7 and borrowed conns= 3 - */ - public static void main(String args[]) throws Exception { - UCPConnectionHarvestingSample sample = new UCPConnectionHarvestingSample(); - sample.run(); - } - - /* - * Shows the outcomes with and without HarvestableConnection. - */ - void run() throws Exception { - PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); - pds.setConnectionFactoryClassName(CONN_FACTORY_CLASS_NAME); - pds.setUser(DB_USER); - pds.setPassword(DB_PASSWORD); - pds.setURL(DB_URL); - // Set UCP properties - pds.setConnectionPoolName("HarvestingSamplePool"); - pds.setInitialPoolSize(10); - pds.setMaxPoolSize(25); - - // Configure connection harvesting: - // Borrowed connections could be held for long thus causing connection pool - // to run out of available connections. Connection Harvesting helps in - // reclaiming borrowed connections thus ensuring at least some are - // always available. - pds.setConnectionHarvestTriggerCount(5); - pds.setConnectionHarvestMaxCount(2); - - // demonstrates HavestableConnection behaviour - runWithHarvestableConnection(pds); - // demonstrates Non-HarvestableConnection behaviour - runWithoutHarvestableConnection(pds); - } - - /* - * Displays how the harvestable connection works. - */ - void runWithHarvestableConnection(PoolDataSource pds) throws Exception { - System.out.println("## Run with Harvestable connections ##"); - System.out.println("Initial available connections: " - + pds.getAvailableConnectionsCount()); - - Connection[] conns = new Connection[5]; - TestConnectionHarvestingCallback[] cbks = new TestConnectionHarvestingCallback[10]; - - // First borrow 4 connections--conns[0] and conns[1] are least-recently used - for (int i = 0; i < 4; i++) { - conns[i] = pds.getConnection(); - cbks[i] = new TestConnectionHarvestingCallback(conns[i]); - // Registers a ConnectionHarvestingCallback with the this connection. - ((HarvestableConnection) conns[i]) - .registerConnectionHarvestingCallback(cbks[i]); - // Perform a database operation - doSQLWork(conns[i], 2); - } - - // Get another new connection to trigger harvesting - conns[4] = pds.getConnection(); - cbks[4] = new TestConnectionHarvestingCallback(conns[4]); - ((HarvestableConnection) conns[4]) - .registerConnectionHarvestingCallback(cbks[4]); - - System.out.println("Requested 5 connections ..."); - - System.out.println("Available connections: " - + pds.getAvailableConnectionsCount()); - System.out.println("Borrowed connections: " - + pds.getBorrowedConnectionsCount()); - System.out.println("Waiting for 30 secs to trigger harvesting"); - // Harvesting should happen - Thread.sleep(30000); - - // conns[0] and conns[1]'s physical connections should be "harvested" - // by the pool and these two logical connections should be closed - System.out.println("Checking on the five connections ..."); - System.out.println(" conns[0] should be closed --" + conns[0].isClosed()); - System.out.println(" conns[1] should be closed --" + conns[1].isClosed()); - System.out.println(" conns[2] should be open --" + !conns[2].isClosed()); - System.out.println(" conns[3] should be open --" + !conns[3].isClosed()); - System.out.println(" conns[4] should be open --" + !conns[4].isClosed()); - - System.out.println("Checking on the pool ..."); - System.out.println(" Available connections should be 7: " - + (pds.getAvailableConnectionsCount() == 7)); - System.out.println(" Borrowed connections should be 3: " - + (pds.getBorrowedConnectionsCount() == 3)); - - for (int i = 2; i < 5; i++) - conns[i].close(); - } - - /* - * The method displays first_name and last_name from employees table - */ - void runWithoutHarvestableConnection(PoolDataSource pds) throws Exception { - System.out.println("## Run without harvestable connections ##"); - System.out.println("Initial available connections: " - + pds.getAvailableConnectionsCount()); - - Connection[] conns = new Connection[5]; - TestConnectionHarvestingCallback[] cbks = new TestConnectionHarvestingCallback[10]; - - // First borrow 4 connections -- conns[0] and conns[1] are least-recently - // used - for (int i = 0; i < 4; i++) { - conns[i] = pds.getConnection(); - cbks[i] = new TestConnectionHarvestingCallback(conns[i]); - // Registers a ConnectionHarvestingCallback with the this connection. - ((HarvestableConnection) conns[i]) - .registerConnectionHarvestingCallback(cbks[i]); - // Perform a database operation - doSQLWork(conns[i], 2); - } - - // Assuming the application is doing critical work on conns[0] and conns[1] - // and doesn't want these 2 to be "harvested" automatically. - // Mark conns[0] and conns[1] as non-harvestable connections. - ((HarvestableConnection) conns[0]).setConnectionHarvestable(false); - ((HarvestableConnection) conns[1]).setConnectionHarvestable(false); - - // Get another connection to trigger harvesting - conns[4] = pds.getConnection(); - cbks[4] = new TestConnectionHarvestingCallback(conns[4]); - ((HarvestableConnection) conns[4]) - .registerConnectionHarvestingCallback(cbks[4]); - - System.out.println("Requested 5 connections ..."); - - System.out.println("Available connections: " - + pds.getAvailableConnectionsCount()); - System.out.println("Borrowed connections: " - + pds.getBorrowedConnectionsCount()); - - System.out.println("Waiting for 30 secs to trigger harvesting"); - // Harvesting should happen - Thread.sleep(30000); - - // conns[2] and conns[3]'s physical connections should be "harvested" - // by the pool and these two logical connections should be closed. - // conns[0] and conns[1]'s physical connections will not be "harvested". - System.out.println("Checking on the five connections ..."); - System.out.println(" conns[0] should be open --" + !conns[0].isClosed()); - System.out.println(" conns[1] should be open --" + !conns[1].isClosed()); - System.out.println(" conns[2] should be closed --" + conns[2].isClosed()); - System.out.println(" conns[3] should be closed --" + conns[3].isClosed()); - System.out.println(" conns[4] should be open --" + !conns[4].isClosed()); - - System.out.println("Checking on the pool ..."); - System.out.println(" Available connections should be 7: " - + (pds.getAvailableConnectionsCount() == 7)); - System.out.println(" Borrowed connections should be 3: " - + (pds.getBorrowedConnectionsCount() == 3)); - - conns[0].close(); - conns[1].close(); - conns[4].close(); - } - - /* - * Creates a EMP_TEST table and perform an insert, update and select database - * operations on the new table created. - */ - public static void doSQLWork(Connection conn, int loopstoRun) { - for (int i = 0; i < loopstoRun; i++) { - try { - conn.setAutoCommit(false); - // Prepare a statement to execute the SQL Queries. - Statement statement = conn.createStatement(); - - // Create table EMP_TEST - statement.executeUpdate("create table EMP_TEST(EMPLOYEEID NUMBER," - + "EMPLOYEENAME VARCHAR2 (20))"); - // Insert some records into table EMP_TEST - statement - .executeUpdate("insert into EMP_TEST values(1, 'Jennifer Jones')"); - statement - .executeUpdate("insert into EMP_TEST values(2, 'Alex Debouir')"); - - // update a record on EMP_TEST table. - statement - .executeUpdate("update EMP_TEST set EMPLOYEENAME='Alex Deborie'" - + " where EMPLOYEEID=2"); - // verify table EMP_TEST - ResultSet resultSet = statement.executeQuery("select * from EMP_TEST"); - while (resultSet.next()) { - // System.out.println(resultSet.getInt(1) + " " - // + resultSet.getString(2)); - } - // Close ResultSet and Statement - resultSet.close(); - statement.close(); - - resultSet = null; - statement = null; - } - catch (SQLException e) { - System.out.println("UCPConnectionHarvestingSample - " - + "doSQLWork()-SQLException occurred : " + e.getMessage()); - } - finally { - // Clean-up after everything - try (Statement statement = conn.createStatement()) { - statement.execute("drop table EMP_TEST"); - } - catch (SQLException e) { - System.out.println("UCPConnectionHarvestingSample - " - + "doSQLWork()- SQLException occurred : " + e.getMessage()); - } - } - } - } - - /* - * Sample connection harvesting callback implementation is shown here. Refer - * to ConnectionHarvestingCallback in UCP Javadoc for more details. - * (http://docs.oracle.com/database/121/JJUAR/toc.htm) - */ - class TestConnectionHarvestingCallback implements - ConnectionHarvestingCallback { - private Object objForCleanup = null; - - public TestConnectionHarvestingCallback(Object objForCleanup) { - this.objForCleanup = objForCleanup; - } - - public boolean cleanup() { - try { - doCleanup(objForCleanup); - } - catch (Exception exc) { - return false; - } - - return true; - } - - private void doCleanup(Object obj) throws Exception { - ((Connection) obj).close(); - } - } -} diff --git a/java/ucp/ConnectionManagementSamples/UCPConnectionLabelingSample.java b/java/ucp/ConnectionManagementSamples/UCPConnectionLabelingSample.java deleted file mode 100644 index 18cd5e98..00000000 --- a/java/ucp/ConnectionManagementSamples/UCPConnectionLabelingSample.java +++ /dev/null @@ -1,259 +0,0 @@ -/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*/ - -/* - DESCRIPTION - Connection Labeling is used when an application wants to request a - particular connection with the desired label from the connection pool. - - Connection Labeling enables an application to associate custom labels - to a connection. By associating labels with a connection, an application - can search and retrieve an already initialized connection from the pool - and avoid the time and cost of connection re-initialization. Connection - labeling also makes it faster to find/retrieve connections - with specific properties (specified through labels). - - Connection labeling is application-driven and requires two interfaces. - (a) oracle.ucp.jdbc.LabelableConnection: It is used to retrieve, apply - and remove connection labels. - (b) oracle.ucp.ConnectionLabelingCallback: used to create a labeling - callback that determines if a connection with a requested label - already exists. Refer to ConnectionLabelingCallback in UCP Javadoc - (http://docs.oracle.com/database/121/JJUAR/toc.htm) - - Step 1: Enter the database details in this file. - DB_USER, DB_PASSWORD, DB_URL and CONN_FACTORY_CLASS_NAME are required - Step 2: Run the sample with "ant UCPConnectionLabelingSample" - - NOTES - Use JDK 1.7 and above - - MODIFIED (MM/DD/YY) - nbsundar 12/15/15 - . - nbsundar 11/24/15 - update - nbsundar 03/09/15 - Creation (tzhou - Contributor) - */ -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Map; -import java.util.Set; -import java.util.Properties; - -import oracle.ucp.ConnectionLabelingCallback; -import oracle.ucp.jdbc.LabelableConnection; -import oracle.ucp.jdbc.PoolDataSource; -import oracle.ucp.jdbc.PoolDataSourceFactory; - -public class UCPConnectionLabelingSample { - final static String DB_URL= "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))"; - final static String DB_USER = "hr"; - final static String DB_PASSWORD = "hr"; - final static String CONN_FACTORY_CLASS_NAME = "oracle.jdbc.pool.OracleDataSource"; - - /* The sample demonstrates UCP's Connection Labeling feature. - *(1) Set up the connection pool: - * Initialize the pool with 2 connections (InitialPoolSize = 2) and - * register a labeling callback (TestConnectionLabelingCallback). - *(2) Run the sample for connection Labeling: - * (2.1) Get the 1st connection from UCP and label the connection - * (2.2) Request 2nd connection with the same label - * (2.3) Notice that the cost() method in TestConnectionLabelingCallback - * gets invoked on connections in the pool. The cost() method projects - * the cost of configuring connections considering label-matching - * differences. The pool uses this method to select a connection - * with the least reconfiguration cost. - * (2.4) If the pool finds a connection with cost 0, it returns the - * connection without calling configure(); for any connection with - * above-zero cost, the pool invokes configure() in the labeling - * callback, and then returns the connection to application. - * (2.5) The purpose of the configure() method is to bring the - * connection to the desired state, which could include both - * client-side and server-side actions. The method should also - * apply or remove labels from the connection. - */ - public static void main(String args[]) throws Exception { - UCPConnectionLabelingSample sample = new UCPConnectionLabelingSample(); - // Demonstrates Connection Labeling - sample.run(); - } - /* - * Shows UCP's Connection labeling feature. - */ - void run() throws Exception { - PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); - - pds.setConnectionFactoryClassName(CONN_FACTORY_CLASS_NAME); - pds.setUser(DB_USER); - pds.setPassword(DB_PASSWORD); - pds.setURL(DB_URL); - // Set UCP properties - pds.setConnectionPoolName("LabelingSamplePool"); - pds.setInitialPoolSize(2); - - // Register connection labeling callback - TestConnectionLabelingCallback cbk = new TestConnectionLabelingCallback(); - // Registers a connection labeling callback with the connection pool - pds.registerConnectionLabelingCallback(cbk); - - System.out.println("Initial available connection number: " - + pds.getAvailableConnectionsCount()); - - // Fresh connection from pool - System.out.println("Requesting a regular connection from pool ..."); - Connection conn1 = pds.getConnection(); - System.out.println("Available connection number: " - + pds.getAvailableConnectionsCount()); - - // Change the transaction isolation level of the conn1 to - // java.sql.Connection.TRANSACTION_SERIALIZABLE - conn1.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); - doSQLWork(conn1, 5); - - // Now apply a connection label to this connection - ((LabelableConnection) conn1).applyConnectionLabel("TRANSACTION_ISOLATION", - "8"); - - // Done with this connection for now, return it to pool - System.out.println("Returning labeled connection to pool ..."); - conn1.close(); - System.out.println("Available connection number: " - + pds.getAvailableConnectionsCount()); - - Thread.sleep(10000); - - // The application wants to use connection again - - // Preferred connection label - Properties label = new Properties(); - label.setProperty("TRANSACTION_ISOLATION", "8"); - - // Request connection with the preferred label - System.out.println("Requesting connection with preferred label ..."); - Connection conn2 = pds.getConnection(label); - System.out.println("Available connection number: " - + pds.getAvailableConnectionsCount()); - - System.out.println("Again returning labelled connection to pool ..."); - conn2.close(); - System.out.println("Available connection number: " - + pds.getAvailableConnectionsCount()); - } - - /* - * The method shows database operations. - * It creates a EMP_LIST table and will do an insert, update and select - * on the new table created. - */ - public static void doSQLWork(Connection conn, int loopstoRun) { - for (int i = 0; i < loopstoRun; i++) { - try { - conn.setAutoCommit(false); - // Prepare a statement to execute the SQL Queries. - Statement statement = conn.createStatement(); - - // Create table EMP_LIST - statement.executeUpdate("create table EMP_LIST(EMPLOYEEID NUMBER," - + "EMPLOYEENAME VARCHAR2 (20))"); - // Insert few records into table EMP_LIST - statement.executeUpdate("insert into EMP_LIST values(1, 'Jennifer Jones')"); - statement.executeUpdate("insert into EMP_LIST values(2, 'Alex Debouir')"); - - // Update a record on EMP_LIST table. - statement.executeUpdate("\n update EMP_LIST set EMPLOYEENAME='Alex Deborie'" - + " where EMPLOYEEID=2"); - - // Verify the contents of table EMP_LIST - ResultSet resultSet = statement.executeQuery("select * from EMP_LIST"); - while (resultSet.next()) { - // System.out.println(resultSet.getInt(1) + " " + resultSet.getString(2)); - } - // Close ResultSet and Statement - resultSet.close(); - statement.close(); - - resultSet = null; - statement = null; - } - catch (SQLException e) { - System.out.println("UCPConnectionLabelingSample - " - + "doSQLWork()-SQLException occurred : " + e.getMessage()); - } - finally { - // Clean-up after everything - try (Statement statement = conn.createStatement()) { - statement.execute("drop table EMP_LIST"); - } - catch (SQLException e) { - System.out.println("UCPConnectionLabelingSample - " - + "doSQLWork()- SQLException occurred : " + e.getMessage()); - } - } - } - } -} - -/* - * Sample labeling callback implementation. - */ -class TestConnectionLabelingCallback implements ConnectionLabelingCallback { - public TestConnectionLabelingCallback() { - } - /* - * Projects the cost of configuring connections considering - * label-matching differences. - */ - public int cost(Properties reqLabels, Properties currentLabels) { - // Case 1: exact match - if (reqLabels.equals(currentLabels)) { - System.out.println("## Exact match found!! ##"); - return 0; - } - - // Case 2: Partial match where some labels match with current labels - String iso1 = (String) reqLabels.get("TRANSACTION_ISOLATION"); - String iso2 = (String) currentLabels.get("TRANSACTION_ISOLATION"); - boolean match = (iso1 != null && iso2 != null && iso1 - .equalsIgnoreCase(iso2)); - Set rKeys = reqLabels.keySet(); - Set cKeys = currentLabels.keySet(); - if (match && rKeys.containsAll(cKeys)) { - System.out.println("## Partial match found!! ##"); - return 10; - } - // Case 3: No match - // Do not choose this connection. - System.out.println("## No match found!! ##"); - return Integer.MAX_VALUE; - } - - /* - * Configures the selected connection for a borrowing request before - * returning the connection to the application. - */ - public boolean configure(Properties reqLabels, Object conn) { - try { - String isoStr = (String) reqLabels.get("TRANSACTION_ISOLATION"); - ((Connection) conn).setTransactionIsolation(Integer.valueOf(isoStr)); - - LabelableConnection lconn = (LabelableConnection) conn; - - // Find the unmatched labels on this connection - Properties unmatchedLabels = lconn - .getUnmatchedConnectionLabels(reqLabels); - - // Apply each label in unmatchedLabels to connection - for (Map.Entry label : unmatchedLabels.entrySet()) { - String key = (String) label.getKey(); - String value = (String) label.getValue(); - lconn.applyConnectionLabel(key, value); - } - } - catch (Exception exc) { - return false; - } - return true; - } -} - - diff --git a/java/ucp/ConnectionManagementSamples/build.xml b/java/ucp/ConnectionManagementSamples/build.xml deleted file mode 100644 index 2ddeac03..00000000 --- a/java/ucp/ConnectionManagementSamples/build.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - Build and run Oracle Jdbc Samples - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Connection Management Samples: Commands to Run - ============================================== - (1) ant UCPSample - (2) ant UCPInactiveConnectionTimeout - (3) ant UCPConnectionWaitTimeout - (4) ant UCPAbandonedConnectionTimeout - (5) ant UCPAbandonedConnectionTimeout - (6) ant UCPTimeToLiveConnectionTimeout - (7) ant UCPConnectionHarvestingSample - (8) ant UCPConnectionLabelingSample - (9) ant UCPWebSessionAffinitySample - (10) ant UCPWithDRCPSample - ============================================== - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/ucp/Readme.md b/java/ucp/Readme.md deleted file mode 100644 index 3c8c44a7..00000000 --- a/java/ucp/Readme.md +++ /dev/null @@ -1,48 +0,0 @@ -# Universal Connection Pool (UCP) -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. -To use UCP, Java applications or containers must have **ucp.jar** in their class path along with **ojdbc8.jar** (for JDK or JRE 8). - -## What's new in 12.2 ? - -* **New Java Standards**: Support for Java SE 8 and JDBC 4.2 -* **New Performance features**: UCP redesign for faster pool operations using Wait-Free technique, Multi-dimensionnal KD-Tree - search, and configurable connection health check frequency -* **New Scalability features**: Shared Pool for Multitenant Database, Shared Pool for Sharded database, Sharding APIs -* **New High Availability features**: Fast Application Notification (FAN) and Oracle Notification Services (ONS) are auto-enabled, - Application Continuity for XA Datasources, and Transaction Guard for XA Datasource -* **New Manageability features**: XML configuration file - -## Downloads - -[Oracle Database 12.2.0.1 UCP Download Page](http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html) - -## Javadoc - -[12.2 Online UCP Javadoc](http://docs.oracle.com/database/122/JJUAR/toc.htm) - -## Documentation - -[12.2 UCP Developer's Guide](https://docs.oracle.com/database/122/JJUCP/toc.htm) - -## White Papers - -* [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) - -* [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) - -* [What's in Oracle database 12c Release 2 for Java & JavaScript Developers?](http://bit.ly/2orH5jf) - -## Other Resources - -* [UCP and Oracle Database Service on Cloud](http://www.oracle.com/technetwork/database/application-development/jdbc/documentation/index.html) - -* [UCP Landing Page and Other UCP Whitepapers](http://www.oracle.com/technetwork/database/application-development/jdbc/overview/index.html) - -* [Oracle JDBC & UCP Forum](https://community.oracle.com/community/java/database_connectivity/java_database_connectivity/) - - - - - - - diff --git a/java/ucp/Tomcat_Servlet/Readme.md b/java/ucp/Tomcat_Servlet/Readme.md deleted file mode 100644 index be783cb7..00000000 --- a/java/ucp/Tomcat_Servlet/Readme.md +++ /dev/null @@ -1,29 +0,0 @@ -# Tomcat Java Servlet -The Oracle JDBC drivers allow Java applications to connect and process data in the Oracle Database. **Apache Tomcat** is a Java application server for building and deploying Java Web applications. This repository has code samples for a Java Servlet that connects to the Oracle Database using the Oracle JDBC driver. We have furnished `build.xml` to compile the servlet and the `Readme.md` that has instructions to compile and deploy this servlet on Tomcat. If you have subscribed to any Oracle Database Service on Cloud such as DBCS, EECS, BMCS etc., follow these instructions to verify the database connectivity with Tomcat. - -# What you need to install? - -* **Apache Tomcat**: Download and install [Apache Tomcat](https://tomcat.apache.org/) -* **Apache Ant**: Make sure you have [Apache ANT](http://ant.apache.org/) to compile the source code -* **JDBC driver**: Download the latest JDBC driver [ojdbc8.jar from OTN](http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html) -* **Oracle Database**: You need to have a working Oracle Database with the credentials to verify the successful connection. Make sure either you have subscribed to Oracle Database Service on Cloud (DBCS, EECS, BMCS, ExaCS) or installed an Oracle Database on premise. - -# Steps to compile the Java Servlet - -* **Update build.xml**: Download the `build.xml` present in this repository. Update TOMCAT_HOME to point to the location where Tomcat is installed. -* **Create a Resource in context.xml**: Download the `context.xml` present in `META-INF` folder. Update the database URL, username, and password to point to your Oracle Database. Let us name this datasource as `orcljdbc_ds` -* **Update JDBCSample_Servlet**: Download the `JDBCSample_Servlet` from this repository. Update the method `getDataSource()` to use the correct Oracle datasource name. E.g.,`orcljdbc_ds` -* **JDBC driver**: Place the downloaded JDBC driver ojdbc8.jar in `WEB-INF/lib` folder. -* **Create the war file**: Go to the location where the `build.xml` is located. Execute the command `ant` that will compile and also create the `JDBCSample.war` file in the `dist` folder. - -# Steps to deploy and run the Java Servlet - -* **Deploy the WAR file**: Copy the `JDBCSample.war` file to TOMCAT_HOME/webapps/ and Start the Tomcat Server -* **Invoke the Servlet**: Invoke the servlet at `https://localhost:8080/JDBCSample/JDBCSample_Servlet` -* **Check the Results**: Check the results on the page and make sure that it prints driver information retrieved from the Oracle database. - - -# Other Resources - -* [Connecting Java Applications to Database Cloud Services](https://blogs.oracle.com/dev2dev/connecting-java-applications-to-database-cloud-services) -* [Using Java Containers with Exadata Express Cloud Service (EECS)](http://www.oracle.com/technetwork/database/application-development/jdbc/jdbc-eecontainers-cloud.html#tomcat) diff --git a/java/ucp/Tomcat_Servlet/build.xml b/java/ucp/Tomcat_Servlet/build.xml deleted file mode 100644 index 61262712..00000000 --- a/java/ucp/Tomcat_Servlet/build.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/ucp/WebLogicServer_Servlet/Readme.md b/java/ucp/WebLogicServer_Servlet/Readme.md deleted file mode 100644 index ef28555b..00000000 --- a/java/ucp/WebLogicServer_Servlet/Readme.md +++ /dev/null @@ -1,35 +0,0 @@ -# WebLogicServer Java Servlet -The Oracle JDBC drivers allow Java applications to connect and process data in the Oracle Database. Oracle WebLogic Server is the application server for building and deploying enterprise Java EE applications. This repository has code samples for a Java Servlet that connects to the Oracle Database using the Oracle JDBC driver. We have furnished `build.xml` to compile the servlet and the `Readme.md` that has instructions to compile and deploy this servlet on WebLogic Server. If you have subscribed to any Oracle Database Service on Cloud such as DBCS, EECS, BMCS etc., follow these instructions to verify the connectivity with WebLogic Server. - -# What you need to install? - -* **Web Logic Server v12.2.1.2**: Download and install the [WebLogic Server v12.2.1.2](http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html) -* **Apache Ant**: Make sure you have [Apache ANT](http://ant.apache.org/) to compile the source code -* **JDBC driver**: You can choose to use the JDBC driver (ojdbc7.jar) that is shipped with WebLogicServer v 12.2.1.2 or you can download and use the latest [ojdbc8.jar from OTN](http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html) -* **Oracle Database**: You need to have a working Oracle Database with the credentials to verify the successful connection. Make sure either you have subscribed to Oracle Database Service on Cloud (DBCS, EECS, BMCS, ExaCS) or installed an Oracle Database on premise. - -# Steps to compile the Java Servlet - -* **Update build.xml**: Download the `build.xml` present in this repository. Update WLS_HOME to point to the location where WebLogic Server is installed. -* **Create a Datasource in WebLogicServer**: Create an Oracle Datasource through the admin console. Refer to the blog for more details ["Create and Deploy a Java Servlet using WebLogic Server"](https://blogs.oracle.com/dev2dev/create-and-deploy-a-java-servlet-using-weblogic-server-wls). Let us name this datasource as `orcljdbc_ds` -* **Update JDBCSample_Servlet**: Download the `JDBCSample_Servlet` from this repository and Update the method `getDataSource()` to use the correct Oracle datasource name. E.g.,`orcljdbc_ds` created through admin console. -* **Create the war file**: Go to the location where the `build.xml` is located. Execute the command `ant` that will compile and also create the `JDBCSample.war` file in the `dist` folder. - -# Steps to deploy and run the Java Servlet - -* **Deploy the WAR file**: Start the WebLogic Server and open the admin console. Follow the steps in this [blog](https://blogs.oracle.com/dev2dev/create-and-deploy-a-java-servlet-using-weblogic-server-wls#step8) to deploy `JDBCSample.war` -* **Invoke the Servlet**: Invoke the servlet at `https://localhost:7001/JDBCSample/JDBCSample_Servlet` -* **Check the Results**: Check the results on the page and make sure that it prints driver information retrieved from the Oracle database. - -# Other Resources - -* [Create and Deploy a Java Servlet using WebLogic Server](https://blogs.oracle.com/dev2dev/create-and-deploy-a-java-servlet-using-weblogic-server-wls) -* [How to use the latest ojdbc8.jar in WebLogic Server?](http://www.oracle.com/technetwork/database/application-development/jdbc/jdbc-eecontainers-cloud.html#wls) -* [Using Java Containers with Exadata Express Cloud Service (EECS)](http://www.oracle.com/technetwork/database/application-development/jdbc/jdbc-eecontainers-cloud.html#wls) - - - - - - - diff --git a/java/ucp/WebLogicServer_Servlet/build.xml b/java/ucp/WebLogicServer_Servlet/build.xml deleted file mode 100644 index f3d63b3d..00000000 --- a/java/ucp/WebLogicServer_Servlet/build.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -