Access container and server services from enterprise components

Setting up a server to test Data source

  1. In the Servers view, double-click the TitanServer server. The server editor opens.

  2. Select the Data source tab at the bottom of the editor.

  3. To test data sources at the node level, expand Node Settings. To test data sources at the server level, expand Server Settings.

    Expand Server Settings.

  4. A JDBC provider for DB2 and for Cloudscape will already be created for you (in the Server Settings section only). Before using the predefined JDBC provider, verify that the Class path field specified in the JDBC provider is the correct class path that contains the database driver. Select the JDBC provider from the JDBC provider list and click Edit to edit the JDBC class path.

  5. Define a data source and resource properties. Beside Data sources defined in the JDBC provider selected above list, click Add.

  6. Select the type of JDBC provider, for example Cloudscape JDBC Provider.

    JDBC Provider

    Select Version 5.0 data source and click Next.

  7. On the Modify Data source page, specify the details of the data source that you want to create. For more information about any of the fields on this wizard, select the field and then press F1.

    Name - TitanDS.

    JNDI name - jdbc/TitanDS.

    Select the Use this data source in container managed persistence (CMP) check box.

    Modify Data source

    Click Next.

  8. In the Resource Properties list table, select databaseName.

    In the Value field, type the following: c:/titandb.

    Modify Data source

  9. Click Finish. You associated a pooled database connection to a JNDI name that can be used by the application.

    Data source

Adding Datasource references to enterprise bean

You can add different types of references to an enterprise bean, including resource references.

To add resource references to an enterprise bean:

  1. In the J2EE Hierarchy view, right-click the desired EJB module and select Open With > Deployment Descriptor Editor from the pop-up menu.

  2. On the References page of the editor select the enterprise bean that you want to add a reference to (the referencing bean) - Ship, and click the Add button. The Add Reference wizard opens.

  3. Select the type of reference that you want to create (Resource reference), and click Next.


  4. Complete these fields:

    • Name - Specifies the name of the reference (jdbc/TitanDS).

    • Type - The expected type of the resource manager connection factory (javax.sql.DataSource).

    • Authentication - Specifies the authentication method (container or application) for the resource manager (Container).

    • Sharing Scope - Specifies whether connections can be shareable or unshareable. This option is available for J2EE 1.3-compliant application client modules (Shareable).

    • Description - Text that describes the reference (Titan application Data Source).

  5. Click Finish.


The reference is added to the bean that you selected and is displayed on the References page of the EJB deployment descriptor editor.

Add WebSphere Binding information (the JNDI (Java Naming and Directory Interface) name that the bean code uses to get a reference to a data source) - jdbc/TitanDS

WebSphere Binding information

The Data source reference is added to the ejb-jar.xml deployment descriptor:

<entity id="Ship">
	<resource-ref id="ResourceRef_1122305703058">
		<description>Titan application Data Source</description>

Defining JNDI bindings (CMP connection factory)

You can define JNDI bindings, or CMP connection factory bindings, for EJB 2.0 beans.

The CMP factory connection binding is a setting specific to WebSphere Application Server. See the WebSphere Application Server documentation for more detailed information about component-managed authentication and container-managed authentication.

To define CMP connection factory bindings:

  1. Switch to the J2EE perspective.

  2. In the J2EE Hierarchy view, right-click the desired EJB 2.0 module, and select Open With > Deployment Descriptor Editor from the pop-up menu.

  3. On the Overview page of the editor, in the WebSphere Bindings section, go to the CMP Connection Factory Binding section.

  4. Type a JNDI name - jdbc/TitanDS

  5. Select one of the following container authentication types:

    • Per_Connection_Factory - Select this option for component-managed authentication.

    • Container - Select this option for container-managed authentication.

JNDI name

Professional hosting     Belorussian informational portal         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide