DataSources

A DataSource is an intermediary between a JDBC application and the connection pool. A JDBC application requires a DataSource and JNDI to obtain a database connection. Each DataSource is linked to a distinct DataSource object. This DataSource object can be implemented as a DataSource class, depending on the type of support it offers.

More than one DataSource can be linked to a single connection pool. Hence, DataSources may or may not be transaction enabled. This can be decided at the time of creation of the DataSource.

Creating a DataSource Using the WebLogic Administration Console

To create a DataSource, follow these steps:

  1. Click the DataSource link below the MultiPool link in the Administration Console.

  2. Click Configure a New JDBC Data Source. You will see a screen like that shown in Figure 7.21.

    Figure 7.21. The WebLogic administration screen to configure a new DataSource.

    graphics/07fig21.jpg

Explanations of the tabs you see on the console are provided next.

The Configuration tab offers the following options:

  • Name (required) Name your DataSource in the first property.

  • JNDI Name (required) Each DataSource is bound to a JNDI. For the JNDI Name property, you need to enter the JNDI name to which you want to bind your DataSource. When a client obtains a connection using DataSources, this property value will be used to look up the DataSource object. The method of lookup using DriverManager.getConnection() or Driver.connect() is deprecated; lookup using the DataSource name is now favored. When the lookup is performed, a javax.sql.DataSource object is returned. The default value is null.

  • Pool Name (required) Enter the pool name to which you wish to link your DataSource. When you perform a getConnection() on this DataSource, connections from the connection pool named here are returned. The default value is null.

  • Row Prefetch Enabled (optional) This check box, as its name clearly states, determines whether prefetching of rows is allowed. When a client makes a database selection, row prefetch enables the server to prefetch a number of rows of the result set and cache them. If an external client does a JDBC access through WebLogic Server, this property, if enabled, improves the performance to a great extent. If the client and the WebLogic Server are positioned in the same JVM, then this attribute is ignored by the server. The default value is for this property to be disabled.

  • Row Prefetch Size (required if row prefetch is enabled) This property value comes into the picture only if row prefetch is enabled. Here, you can specify the number of rows that must be prefetched. The minimum value is 2, the maximum value is 65,536, and the default value is 48.

  • Stream Chunk Size (optional) A getBinaryStream() operation using a DataSource will return a data stream in chunks of bytes of the size specified in this parameter. The minimum value is 1, the maximum value is 65,536, and the default value is 256.

The Targets tab, as shown in Figure 7.22, shows a list of WebLogic Servers available and the one for which this DataSource is enabled. It also consists of a list of clusters, if any are available, to connect to this DataSource.

Figure 7.22. The Targets tab of the WebLogic Administration Console for DataSource configuration.

graphics/07fig22.jpg

The last tab, Notes, is optional and is simply for user-supplied information. The default value is null, and it can contain only alphanumeric strings.

Following is a code snippet for using a DataSource. You need to import the relevant JNDI packages to use a DataSource in your Java application:

 Context ctx = new InitialContext();  javax.sql.DataSource ds= (javax.sql.DataSource) ctx.lookup (dataSource); conn = ds.getConnection(); 


Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

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