JDBC and BEA WebLogic Server


BEA WebLogic Server provides services for JDBC. The J2EE services for JDBC are

  • Connection Pools

  • MultiPools

  • DataSources

  • TxDataSources

  • JDBC Data Source Factories

Each of these services are configured through the WebLogic Administration Console. A description of the service and how to configure and use the service is provided in the following sections.

Tip

Each field in the configuration form in the WebLogic Administration Console is preceded with a "?" character. Click on the "?" to view context sensitive help for the particular field.


Configuring and Using Connection Pools

Connection pooling provides a significant performance enhancement by maintaining a set of open database connections. These ready-to-use connections are made available by a connection pool, which saves the overhead of creating connections whenever an application wants to connect to the database. WebLogic Server can also load balance database connections by dynamically shrinking and increasing the number of connections in a connection pool to a database based upon peak and off-peak workload conditions.

The connections in the connection pool are accessed through a DataSource or TxDataSource. Through the DataSource, the application borrows a connection from the connection pool, uses it, and returns it to the connection pool by closing it.

Note

Connection pools use a type 2 or type 4 JDBC driver to create physical database connections.


To create a connection pool using the Administration Console, follow these steps:

  1. From the Administration Console, expand the JDBC node in the left pane.

  2. Click the Connection Pools node, which will display all the connection pools defined in your domain in the right pane.

  3. Click the Configure a New JDBC Connection Pool text link. A new page will display in the right pane (Configuration, General tab) allowing you to configure a new connection pool. The fields in the configuration form for a new connection pool are described in Table 13.8.

  4. Enter values in the Name , URL, Driver Classname, Properties, and Passwords attribute fields. These connection pool general attributes are described in Table 13.8.

    Table 13.8. The Connection Pool Fully Encapsulates the Configuration for the DriverManager

    Field Name

    Description

    Name:

    Any name of your choosing as long as no other connection pools are using it.

    URL:

    This is the same URL that would be used as the parameter to getConnection() if you were directly using the DriverManager.

    Driver Classname:

    This is the same driver class name that would be used if you were directly creating the JDBC driver.

    Properties (key=value):

    This is used to specify the user for a password-protected database. The syntax is user= username . For example, the Oracle sample schema has a sample user named SCOTT; the property is user=SCOTT .

    Password:

    This is the password for the user given in the Properties field. For example, the password for SCOTT in the Oracle sample schema is tiger .

    Open String Password:

    If set, this value is used to override the password in the open string.

    For example, in order to create a connection pool named MyConnectionPool for the demo Pointbase database provided with WebLogic Server, you would enter the following values, as shown in Figure 13.4:

    Figure 13.4. Creating a connection pool for the demo Pointbase database.

    graphics/13fig04.jpg

    • Name = MyConnectionPool

    • URL = jdbc:pointbase:server://localhost/demo

    • Driver Classname = com.pointbase.jdbc.jdbcUniversalDriver

    • Properties = user=PBPUBLIC, password=PBPUBLIC

  5. Click Create to create a connection pool instance with the name you specified in the Name field. The new instance is added under the Connection Pools node in the left pane.

  6. Click the Configuration, Connections tab and change the attribute fields or accept the default values, as shown in Figure 13.5. The value for the Initial Capacity attribute must be at least 1 in order for WebLogic Server to establish a database connection when the server is started. Click Apply to save your changes.

    Figure 13.5. Setting the connection attributes for a connection pool.

    graphics/13fig05.jpg

  7. Click the Targets tab and assign the connection pool to your WebLogic servers or clusters, as shown in Figure 13.6. Click Apply to save your changes.

    Figure 13.6. Assigning a connection pool to the target WebLogic servers or clusters.

    graphics/13fig06.jpg

Once you have created your connection pool, you can have your database connections verified and monitored by WebLogic Server by setting the attributes in the Configuration, Testing tab of your connection pool in the Administration Console. Setting these attributes allows WebLogic Server to test a database connection with a test table in your database before and/or after assigning and releasing a database connection from the connection pool. Since this procedure will add a small delay in either serving a client requesting a database connection, or releasing a database connection back to the connection pool, you should use this option for development environments only.

The attributes for the Configuration, Testing tab, as shown in Figure 13.7, are:

Figure 13.7. Enabling WebLogic Server to test your database connections in the connection pool.

graphics/13fig07.jpg

  • Test Table Name The name of the table used when testing a physical database connection.

  • Test Reserved Connections Enables WebLogic Server to test a connection before giving it to a requesting client.

  • Test Released Connections Enables WebLogic Server to test a connection before returning it to the connection pool.

The TestTableName must exist and be accessible to the database user for the connection. Also, it is important to note that the default SQL code used to test a connection is

 
 select count(*) from  TestTableName  

For this reason it is a good idea to set TestTableName to the name of a table that is known to have few rows, or even no rows, for example DUAL in Oracle, MEMBER in Microsoft SQL Server or USERS in Pointbase.

To monitor the status and activity of your connections using the Administration Console, follow these steps:

  1. Select your WebLogic Server from the left pane.

  2. Select the Services tab.

  3. Select the JDBC tab.

  4. Click the Monitor all Active Pools link.

Configuring and Using MultiPools

A MultiPool is a meta-pool, a pool of connection pools that provides load balancing or high availability for the connection pools which they contain.

MultiPools and Connection Pools are completely hidden from the application. As stated in the previous section, "Configuring and Using Connection Pools," the application locates a DataSource and uses the DataSource for the database connection. The DataSource or TxDataSource is configured to be a member of a connection pool, which can be configured to be members of a MultiPool. Hence, the application accesses the DataSource while the application server provides the high performance through the connection pool configured for that DataSource. The load-balancing or high-availability of the connection pool is provided through the MultiPool configured for that connection pool.

To create a MultiPool using the Administration Console, follow these steps:

Note

In order to create a MultiPool you must have a connection pool already configured.


  1. From the Administration Console, click to expand the JDBC node.

  2. Click the MultiPools node, which will display the MultiPools defined in your domain.

  3. Click the Configure a New JDBC MultiPool text link. A new page displays in the right pane showing the Configuration, General tab associated with configuring a new MultiPool, as shown in Figure 13.8.

    Figure 13.8. Using the Administration Console to create a MultiPool.

    graphics/13fig08.jpg

  4. In the Configuration, General tab enter values associated with the attributes described in Table 13.9.

    Table 13.9. The Attributes to Create a MultiPool

    Field Name

    Description

    Name:

    Any name of your choosing as long as no other MultiPools are using it.

    Algorithm Type

    The algorithm type is selected as either High-Availability or Load-Balancing . The High-Availability algorithm organizes the connection pools as an ordered list. When a connection is requested , the pools are searched in order until an available DataSource is located. If no connections are available, an exception is thrown. The Load-Balancing algorithm distributes the connections evenly across the connection pools.

  5. Click Create to create a MultiPool instance which will be added under the MultiPools node in the left pane.

  6. From the Configuration, Pools tab select the connection pools from the Pool List in the Available column that you want to assign to your MultiPool.

  7. Click Apply to save your changes.

Configuring and Using Data Sources

The DataSource is an enhancement to JDBC and is provided in the JDBC Optional Package. DataSources provide access to connection pools to establish database connectivity, and therefore must be created for each individual connection pool you have defined.

For further information on Data Sources see , "Managing Java Transactions Using JTA," p. 527 .


Create and configure DataSources through the WebLogic Administration Console by following these steps:

  1. In the left pane of the Administration Console, click to expand the JDBC node.

  2. Click the Data Sources node. The Data Sources table displays in the right pane showing all the data sources defined in your domain.

  3. Click the Configure a New JDBC Data Source text link. A new page displays in the right pane showing the Configuration tab for creating a new DataSource, as shown in Figure 13.9.

    Figure 13.9. Creating a DataSource using the Administration Console.

    graphics/13fig09.jpg

  4. Enter values in the Name, JNDI Name, and Pool Name attribute fields, and at a minimum accept the default values for the other attributes. A description of the attributes associated with creating a new DataSource are described in Table 13.10.

    Table 13.10. The Administration Console Attributes for Creating a New DataSource

    Field Name

    Description

    Name:

    Any name of your choosing as long as no other data sources are using it.

    JNDI Name:

    This is the name that the application will lookup using JNDI to get this data source.

    Pool Name:

    This is the name of a JDBC connection pool that is associated with this TxDataSource .

    Row Prefetch Enabled: (check box)

    This option is used to improve performance by allowing WebLogic Server to prefetch multiple rows for a ResultSet.

    Row Prefetch Size:

    This is the number of rows that will be prefetched for a ResultSet. The default value is 48, the minimum is 2, and the maximum is 65536. It is not recommended to exceed 100 for the prefetch size because additional performance is rarely achieved above this level.

    Stream Chunk Size:

    This is the number of bytes that WebLogic Server will read from a data stream for methods such as getBinaryStream() . The default value is 256, the minimum is 1, and the maximum is 65536.

  5. Click Create to create a data source. The new data source will be added under the Data Sources node in the left pane.

  6. Click the Targets tab and select one or more target servers in the Available column to which you want to assign the data source.

  7. Click Apply to save your changes.

Configuring and Using TxDataSources

The TxDataSource is a DataSource that supports distributed transactions. Distributed transactions are the subject of Chapter 16, which also describes TxDataSource s and how to configure them.

Note

The TxDataSource may be configured to a connection pool through its Pool Name ; however, a TxDataSource must not be configured for a MultiPool.


For further information on TxDataSource s see "Managing Java Transactions Using JTA," p. 527 .


Configuring and Using JDBC DataSource Factories

The JDBC DataSource Factories are used by entity EJBs to produce database connections from a connection pool. To configure a JDBC DataSource Factory using the Administration Console, follow these steps:

  1. Set up a JDBC connection pool in the Administration Console, described earlier in the "Configuring and Using Connection Pools" section.

  2. In the left pane, click Services and expand JDBC.

  3. Select JDBC DataSource Factories and in the right pane click the Configure a New JDBC DataSource Factory text link. A new page displays in the right pane showing the Configuration tab for creating a new JDBC DataSource Factory, as shown in Figure 13.10.

    Figure 13.10. Creating a new JDBC DataSource Factory using the Administration Console.

    graphics/13fig10.jpg

  4. In the displayed Configuration tab, enter values for the Name, User Name, URL, Driver Class Name, and Factory Name attribute fields. These attributes are described in Table 13.11.

    Table 13.11. Configuring the JDBC DataSource Factories

    Field Name

    Description

    Name:

    Any name of your choosing as long as no other WebLogic server configurations are using it.

    User Name:

    The user name to connect to the database. This may be overridden by the user-name element in the deployment descriptor.

    URL:

    The URL to connect to the database. This may be overridden by the url element in the deployment descriptor.

    Driver Classname:

    The JDBC driver to connect to the database. This may be overridden by the driver-name element in the deployment descriptor.

    Factory Name:

    The name of this DataSource factory. This is the name that is referenced by the connection-factory element in weblogic-application.xml.

    Properties:

    The default properties to use for the database connection.

  5. Click Create to create the JDBC Data Source Factory. The new Data Source Factory will be added under the JDBC DataSource Node in the left pane.

For further information on JDBC DataSource Factories see Chapter 21, "Managing PersistenceEntity Beans," p. 655 .




BEA WebLogic Platform 7
BEA WebLogic Platform 7
ISBN: 0789727129
EAN: 2147483647
Year: 2003
Pages: 360

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net