100 Creating an Internal Connection Pool

This chapter explains how to create TopLink internal connection pools.

This chapter includes the following sections:

100.1 Introduction to the Internal Connection Pool Creation

You can create internal connection pools (see Section 96.1.6.1, "Internal Connection Pools") only for server sessions. For more information, see Section 100.2, "Creating an Internal Connection Pool".

After you create an internal connection pool, you must configure its various options (see Chapter 101, "Configuring an Internal Connection Pool")

After you create and configure a sequence connection pool (see Section 96.1.6.4, "Sequence Connection Pools"), TopLink will use this pool whenever it needs to assign an identifier to a new object.

After you create and configure a named connection pool (see Section 96.1.6.5, "Application-Specific Connection Pools"), you use it in your application by passing in a ConnectionPolicy when you acquire a client session (see Section 90.4.4, "How to Acquire a Client Session that Uses a Named Connection Pool").

100.2 Creating an Internal Connection Pool

You can create an internal connection pool using Oracle JDeveloper, TopLink Workbench, or Java code.

100.2.1 How to Create an Internal Connection Pool Using TopLink Workbench

Before you create a connection pool, you must first create a server session (see Section 88.4, "Creating a Server Session").

To create a new TopLink internal connection pool, use this procedure:

  1. Select the server session in the Navigator in which you want to create a connection pool.

  2. Create New Sequence Connection Pool button
    Click the appropriate button on the toolbar to create the type of connection pool you want:

    • To create a named connection pool, select Create a New Named Connection Pool, enter a name, and then click OK.

    • To create a sequence connection pool, select Add the Sequence Connection Pool.

    • To create a write connection pool, select Add the Write Connection Pool.

    You can also create a new internal connection pool by right-clicking the server session configuration in the Navigator and selecting New > Named Connection Pool, Sequence Connection Pool, or Write Connection Pool from the menu.

100.2.2 How to Create an Internal Connection Pool Using Java

Using Java, you can create read, write, and named connection pools.

Example 100-1 shows how to create connection pools. Example 100-2 shows an optimized connection pool, using the same connection for both read and write operations.

Example 100-1 Creating Connection Pools

// Read
ConnectionPool pool = new ConnectionPool();
pool.setName("read");
pool.setLogin(login);
pool.setMaxNumberOfConnections(50);
pool.setMinNumberOfConnections(50);
serverSession.setReadConnectionPool(pool);

// Write
ConnectionPool pool = new ConnectionPool();
pool.setName("default");
pool.setLogin(login);
pool.setMaxNumberOfConnections(50);
pool.setMinNumberOfConnections(50);
serverSession.addConnectionPool(pool);

// Named
ConnectionPool pool = new ConnectionPool();
pool.setName("admin");
pool.setLogin(login);
pool.setMaxNumberOfConnections(2);
pool.setMinNumberOfConnections(2);
serverSession.addConnectionPool(pool);

You can also use a single connection pools for both read and write operations, when the read and write pools use the same login information. This method requires fewer connections

Example 100-2 Using a Single Pool for Read and Write

ConnectionPool pool = new ConnectionPool();
pool.setName("default");
pool.setLogin(login);
pool.setMaxNumberOfConnections(50);
pool.setMinNumberOfConnections(50);
serverSession.setReadConnectionPool(pool);
serverSession.addConnectionPool(pool);