![]() |
![]() |
|
|
The DBMS Adapter
This section contains information on the following subjects:
Introduction to the DBMS Adapter
The DBMS adapter is a J2EE-compliant adapter built with the ADK. It provides a concrete example for adapter providers of how one might use the ADK to construct an adapter. A relational database was used as the EIS of an adapter because it allows adapter providers to focus on the adapter/ADK specifics, rather than become bogged-down in understanding a particular proprietary EIS.
The DBMS adapter gives you (developers and business analysts) a concrete example of an adapter, including a JSP-based GUI, to help you understand the possibilities that are at your disposal using the ADK to build adapters. If you are a business analyst, you might enjoy running through the interface to get a better understanding of an "application view", "service", and "event" as shown in How the DBMS Adapter Works.
If you are an adapter developer, you will also want to review How the DBMS Adapter Was Developed and How the DBMS Adapter Design-Time GUI was Developed the code, and Javadoc to gain insight into how you can extend and use the classes of the ADK to build a J2EE-compliant adapter.
The DBMS adapter satisfies the following requirements:
How the DBMS Adapter Works
This section provides you with an opportunity to see how the DBMS adapter works before you start developing one of your own. If you are a business analyst, you might enjoy running through the interface to get a feel for how the adapter works. The example in this section shows how to create a service that inserts a customer in the underlying database, and then demonstrates how an event is generated to notify others that this action has taken place.
This section contains information on the following subjects:
Before You Begin
Make sure the following tasks have been performed before you try to access the DBMS adapter:
Accessing the DBMS Adapter
To access the DBMS adapter:
http://<HOSTNAME>:7001/wlai
A Tour of the DBMS Adapter
This section provides you with a short tour through the DBMS Adapter. Before you begin, you need to open the DBMS adapter Application View Console - Logon page on your browser. For information about accessing the DBMS adapter, see Accessing the DBMS Adapter.
Figure E-2 Application View Console - Logon
Figure E-3 Application View Management Console
For detailed information about application views and about defining application views, see Defining an Application View in Using Application Integration.
Figure E-4 Define New Application View Page
The name should describe the set of functions performed by this application. Each application view name must be unique to its adapter. Valid characters are anything except `.', `#', `\', `+', `&', `,', `'', `"", and a space.
Figure E-5 Configure Connection Parameters Page
You can use the browse link to browse the DBMS adapter database schemas and tables and specify the database table CUSTOMER_TABLE.
To add a service:
Figure E-7 Add Service Page
Figure E-8 Browse DBMS Page
Figure E-9 Browse DBMS Table Types Page
Figure E-10 DBMS Browse Tables Page
Figure E-11 Browse DBMS for Table Page
This window is included in the tour to introduce you to the functionality and it is not necessary to select any text for this exercise.
Insert into APP.CUSTOMER_TABLE (FIRSTNAME, LASTNAME, DOB) VALUES ([FIRSTNAME VARCHAR], [LASTNAME VARCHAR], [DOB DATE])
For additional information about adding services, see Defining an Application View in the Using Application Integration.
You can use the Browse DBMS link to browse the DBMS database schemas and tables and to specify the database table. Then you can automatically populate the field with the selected table name.
To add an event:
Figure E-12 Add Event Page
Figure E-13 Browse DBMS Tables Page
Figure E-14 Add Event Page
Figure E-15 Application View Administration Page for AppViewTest
After verifying the application view parameters, click Continue. The Deploy Application View to Server page displays.
Figure E-16 Display Application View to Server Page
To deploy the application view:
http://localhost:7001/DbmsEventRouter/EventRouter
Minimum Pool Size - 1
Maximum Pool Size - 10
Target Fraction of Maximum Pool Size - 0.7
Allow Pool to Shrink - checked
Figure E-17 Application View Security Page
To set permissions for the application view:
Figure E-18 Summary for Application View Page
Figure E-19 Test Event Page
Figure E-20 Test Service Page
Figure E-21 Test Result Page
How the DBMS Adapter Was Developed
This section describes each interface used to develop the DBMS adapter. The ADK provides many of the necessary implementations required by a Java Connector Architecture-compliant adapter; however, since some interfaces cannot be fully implemented until the EIS and its environment are defined, the DBMS adapter was created to illustrate the detail-specific or concrete implementation of the abstract classes provided in the ADK.
The process of creating the DBMS adapter is comprised of the following steps:
Development Reference Documentation
You can review the Javadoc and code for the methods defined in the steps that follow in this section to see how the implementations provided by the ADK were leveraged. You can find the Javadoc for this implementation in:
WLI_HOME/adapters/dbms/docs/api/index.html
You can find the code listing for this package in:
WLI_HOME/adapters/dbms/src/com/bea/adapter/dbms/spi
Note: WLI_HOME is the drive or home directory where WebLogic Integration is installed.
Step 1: Development Considerations
The Adapter Setup Worksheet (see Adapter Setup Worksheet,) is available to help adapter developers identify and collect critical information about an adapter they are developing before they begin coding. For the DBMS adapter, the worksheet questions are answered as follows:
Note: Questions preceded by an asterisk (*) are required to use the GenerateAdapterTemplate utility.
SQLServer or Oracle databases.
MSSQLServer 7.0 or Oracle 8.1.6
DBMS
BEA
None - Sample Only
BEA_WLS_DBMS_ADK
Yes
If so, then your adapter needs to support services.
Yes
JDBC
Database URL, driver class, user name, password
Function name, executeUpdate, executeQuery
Yes, you can browse data structures.
If so, what information is needed to determine the input requirements for the service?
SQL
SQL
The input requirements would change depending on the SQL expression for the service
n/a
Yes
Yes
None. The DBMS adapter was built on the WebLogic Integration event generator using a pull mechanism.
Yes
Yes
Multiple
Step 2: Implementing the Server Provider Interface Package
To implement the DBMS adapter Server Provider Interface (SPI) and meet the J2EE-compliant SPI requirements, the classes in the ADK were extended to create the following concrete classes:
Table E-1 SPI Class Extensions
These classes provide connectivity to an EIS and establish a framework for event listening and request transmission, establish transaction demarcation, and allow management of a selected EIS.
ManagedConnectionFactoryImpl
The first step in implementing an SPI for the DBMS adapter was to implement the ManagedConnectionFactory interface. A ManagedConnectionFactory supports connection pooling by providing methods for matching and creating a ManagedConnection instance.
Basic Implementation
The ADK provides com.bea.adapter.spi.AbstractManagedConnection Factory, an implementation of the Java Connector Architecture interface javax.resource.spi.ManagedConnectionFactory. The DBMS adapter extends this class in com.bea.adapter.dbms.spi.ManagedConnectionFactoryImpl. Listing E-1 shows the derivation tree for ManagedConnectionFactoryImpl.
Listing E-1 com.bea.adapter.dbms.spi.ManagedConnectionFactoryImpl
javax.resource.spi.ManagedConnectionFactory
|
|-->com.bea.adapter.spi.AbstractManagedConnectionFactory
|
|-->com.bea.adapter.dbms.spi.ManagedConnectionFactoryImpl
Developers' Comments
The ManagedConnectionFactory is the central class of the Java Connector Architecture SPI package. The ADKs AbstractManagedConnectionFactory provides much of the required implementation for the methods declared in Sun MicroSystems' interface. To extend the ADKs AbstractManagedConnectionFactory for the DBMS adapter, the key createConnectionFactory() and createManagedConnection() methods were implemented. Overrides for equals(), hashcode(), checkState() were also written to provide specific behaviors for the databases supported by the DBMS adapter.
There are private attributes about which the superclass has no knowledge. When creating your adapters, you must provide setter/getter methods for these attributes. The abstract createConnectionFactory() method is implemented to provide an EIS-specific ConnectionFactory using the input parameters.
Additionally, createManagedConnection() is the main factory method of the class. It checks to see if the adapter is configured properly before doing anything else. It then implements methods of the superclass to get a connection and a password credential object. It then attempts to open a physical database connection; if this succeeds, it instantiates and returns a ManagedConnectionImpl (the DBMS adapter implementation of ManagedConnection), which is given the physical connection.
Other methods are getter/setter methods for member attributes.
ManagedConnectionImpl
A ManagedConnection instance represents a physical connection to the underlying EIS in a managed environment. ManagedConnection objects are pooled by the application server. For more information, read about how the ADK implements the AbstractManagedConnection instance in ManagedConnection.
Basic Implementation
The ADK provides com.bea.adapter.spi.AbstractManagedConnection, an implementation of the J2EE interface javax.resource.spi.ManagedConnection. The DBMS adapter extends this class in com.bea.adapter.dbms. spi.ManagedConnectionImpl. Listing E-2 shows the derivation tree for ManagedConnectionImpl.
Listing E-2 com.bea.adapter.dbms.spi.ManagedConnectionImpl
javax.resource.spi.ManagedConnection
|
|-->com.bea.adapter.spi.AbstractManagedConnection
|
|-->com.bea.adapter.dbms.spi.ManagedConnectionImpl
Developers' Comments
This class is well documented in the Javadoc comments since the ManagedConnection is a crucial part of the Java Connector Architecture SPI specification. You should focus on our implementation of the following methods:
The ping() method is used to check whether the physical database connection (not our cci.Connection) is still valid. If an exception occurs, ping() is very specific about checking the type so that a connection is not needlessly destroyed.
Other methods are EIS specific or are simply required setter/getters.
ConnectionMetaDataImpl
The ManagedConnectionMetaData interface provides information about the underlying EIS instance associated with a ManagedConnection instance. An application server uses this information to get run-time information about a connected EIS instance. For more information, read about how the ADK implements the AbstractConnectionMetaData instance in ManagedConnection.
Basic Implementation
The ADK provides com.bea.adapter.spi.AbstractConnectionMetaData, an implementation of the J2EE interface javax.resource.spi.ManagedConnection MetaData. The DBMS adapter extends this class in com.bea. adapter.dbms.spi.ConnectionMetaDataImpl. Listing E-3 shows the derivation tree for ConnectionMetaDataImpl.
Listing E-3 com.bea.adapter.dbms.spi.ConnectionMetaDataImpl
javax.resource.spi.ManagedConnectionMetaData
|
|-->com.bea.adapter.spi.AbstractConnectionMetaData
|
|-->com.bea.adapter.dbms.spi.ConnectionMetaDataImpl
Developers' Comments
The ADKs AbstractConnectionMetaData implements the following:
This implementation of the ConnectionMetaData class uses a DatabaseMetaData object. Since the ADK's abstract implementation was used, you must provide EIS-specific knowledge when implementing the abstract methods in this class.
LocalTransactionImpl
The LocalTransaction interface provides support for transactions that are managed internal to an EIS resource manager and do not require an external transaction manager. For more information, read about how the ADK implements the AbstractLocalTransaction instance in LocalTransaction.
Basic Implementation
The ADK provides com.bea.adapter.spi.AbstractLocalTransaction, an implementation of the J2EE interface javax.resource.spi.LocalTransaction. The DBMS adapter extends this class in com.bea.adapter.dbms. spi.LocalTransactionImpl. Listing E-4 shows the derivation tree for LocalTransactionImpl.
Listing E-4 com.bea.adapter.dbms.spi.LocalTransactionImpl
javax.resource.spi.LocalTransaction
|
|-->com.bea.adapter.spi.AbstractLocalTransaction
|
|-->com.bea.adapter.dbms.spi.LocalTransactionImpl
Developers' Comments
This class utilizes the ADKs abstract superclass which provides logging and event notification. The superclass implements both the CCI and SPI LocalTransaction interfaces provided by Sun. The DBMS adapter's concrete class implements the three abstract methods of the superclass:
Step 3: Implementing the Common Client Interface Package
To implement the DBMS adapter Common Client Interface (CCI) and meet the J2EE-compliant CCI requirements, ADK classes to create the following concrete classes were extended:
Table E-2 CCI Class Extensions
This concrete class... |
Extends this ADK class... |
---|---|
ConnectionImpl |
AbstractConnection |
InteractionImpl |
AbstractInteraction |
InteractionSpecImpl |
InteractionSpecImpl |
These classes provide connectivity to and access back-end systems. The client interface specifies the format of the request and response records for a given interaction with the EIS.
Note: Although implementing the CCI is optional in the Java Connector Architecture 1.0 specification, it is likely to be required in the future. For your reference, the DBMS adapter provides a complete implementation.
ConnectionImpl
A Connection represents an application-level handle that is used by a client to access the underlying physical connection. The actual physical connection associated with a Connection instance is represented by a ManagedConnection instance. For more information, read about how the ADK implements the AbstractConnection instance in Connection.
Basic Implementation
The ADK provides com.bea.adapter.cci.AbstractConnection, an implementation of the J2EE interface javax.resource.cci.Connection. The DBMS adapter in by implementing com.bea.adapter.dbms.cci. ConnectionImpl. Listing E-5 shows the derivation tree for ConnectionImpl.
Listing E-5 com.bea.adapter.dbms.cci.ConnectionImpl
javax.resource.cci.Connection
|
|-->com.bea.adapter.cci.AbstractConnection
|
|-->com.bea.adapter.dbms.cci.ConnectionImpl
Developers' Comments
The ConnectionImpl class is the DBMS adapter's concrete implementation of the javax.resource.cci.Connection interface. It extends the ADKs AbstractConnection class. The actual physical connection associated with a connection instance is represented by a ManagedConnection instance.
A client gets a connection instance by using the getConnection() method on a ConnectionFactory instance. A connection can be associated with zero or more interaction instances. The simplicity of this concrete class is a testament to the power of extending the ADK's base classes.
InteractionImpl
The Interaction enables a component to execute EIS functions. An interaction instance is created from a connection and is required to maintain its association with the Connection instance. For more information, read about how the ADK implements the AbstractInteraction instance in Interaction.
Basic Implementation
The ADK provides com.bea.adapter.cci.AbstractInteraction, an implementation of the J2EE interface javax.resource.cci.Interaction. The DBMS adapter extends this class in com.bea.adapter.dbms.cci. InteractionImpl. Listing E-6 shows the derivation tree for InteractionImpl.
Listing E-6 com.bea.adapter.dbms.cci.InteractionImpl
javax.resource.cci.Interaction
|
|-->com.bea.adapter.cci.AbstractInteraction
|
|-->com.bea.adapter.dbms.cci.InteractionImpl
Developers' Comments
This is the concrete implementation of the ADKs Interaction object. As expected, the methods are EIS-specific implementations of Java Connector Architecture/ADK required methods.
Both versions of the Java Connector Architecture's javax.resource.cci.InteractionExecute()method (the central method of this class) were implemented. The main logic for the execute() method has the following signature: public Record execute(InteractionSpec ispec, Record input). This method return the actual output record from the interaction, so it is the one that is called more often.
The second implementation is provided as a convenience method. This form of execute() has the following signature: public boolean execute(InteractionSpec ispec, Record input, Record output). The second implementation's logic returns a boolean, which indicates only the success or failure of the interaction.
InteractionSpecImpl
An InteractionSpecImpl holds properties for driving an interaction with an EIS instance. An InteractionSpec is used by an interaction to execute the specified function on an underlying EIS.
The CCI specification defines a set of standard properties for an InteractionSpec, but an InteractionSpec implementation is not required to support a standard property if that property does not apply to its underlying EIS.
The InteractionSpec implementation class must provide getter and setter methods for each of its supported properties. The getter and setter methods convention should be based on the Java Beans design pattern. For more information, read about how the ADK implements the InteractionSpecImpl instance in InteractionSpec.
Basic Implementation
The ADK provides com.bea.adapter.cci.InteractionSpecImpl, an implementation of the J2EE interface javax.resource.cci.InteractionSpec. The DBMS adapter extends this class in com.bea.adapter.dbms. cci.InteractionSpecImpl. Listing E-7 shows the derivation tree for InteractionSpecImpl.
Listing E-7 com.bea.adapter.dbms.cci.InteractionSpecImpl
javax.resource.cci.InteractionSpec
|
|-->com.bea.adapter.cci.InteractionSpecImpl
|
|-->com.bea.adapter.dbms.cci.InteractionSpecImpl
Developers' Comments
An implementation class for InteractionSpec interface is required to implement the java.io.Serializable interface. InteractionSpec extends the ADK InteractionSpec in order to add setter/getter methods for the String attribute m_sql. The getter/setter methods should be based on the Java Beans design pattern as specified in the Java Connector Architecture 1.0 specification.
Step 4: Implementing the Event Package
This package contains only one class: the DBMS adapter EventGeneratorWorker. It does the work for the event generator for the DBMS adapter.
EventGenerator
The EventGenerator class implements the following interfaces:
Basic Implementation
The DBMS adapter event generator extends the ADK's AbstractPullEventGenerator because a database cannot "push" information to the event generator; you therefore need to "pull" or actually "poll" the database for changes about which you are interested in being notified. Listing E-8 shows the derivation tree for EventGenerator.
Listing E-8 EventGenerator
com.bea.adapter.event.AbstractEventGenerator
|
|-->com.bea.adapter.event.AbstractPullEventGenerator
|
|-->com.bea.adapter.dbms.event.DbmsEventGeneratorWorker
Developers' Comments
This concrete implementation of the ADK's AbstractPullEventGenerator implements the abstract methods:
It also overrides the following methods:
These methods are EIS specific and are used to identify an event within the context of the EIS while interacting with the database to create and remove event definitions and events. Additionally, these methods create and remove the actual triggers on the database that are fired when an event occurs.
The key method of the class is postEvents(). It creates the IEvent objects of the data taken from rows in the EVENT table of the database. This method takes an IEventRouter as an argument. After creating an IEvent using the IEventDefinition object's createDefaultEvent() method, it populates the event data, and the event is propagated to the router by calling router.postEvent(event). Once the event is sent to the router, the method deletes the row of event data from the database.
The method setupNewTypes()creates new event definitions, making sure that the appropriate trigger is created for the database. For each event definition, the method creates a trigger information object that describes the catalog, schema, table, triggerType, and trigger key that the event definition represents. A map of trigger keys is kept so that triggers are not redundantly added to the database. If the map doesn't contain the new key, the trigger text for the database is generated.
The method removeDeadTypes() also creates a trigger information object; however, it also checks if one or more event types match it. All event definitions that match this trigger are removed from the map, and then the trigger is removed from the database.
Step 5: Deploying the DBMS Adapter
After implementing the SPI, CCI and event interfaces, deploy the adapter. To deploy the adapter, use the procedures outlined in this section:
Before You Begin
Before deploying the adapter into WebLogic Integration, do the following:
Step 5a: Update the ra.xml File
The DBMS adapter provides the ra.xml file in the adapter's .rar file (META-INF/ra.xml). Since the DBMS adapter extends the AbstactManagedConnectionFactory class, the following properties were provided in the ra.xml file:
The DBMS adapter requires these additional declarations:
Property |
Example |
---|---|
UserName |
The username for DBMS adapter login. |
Password |
The password for username. |
DataSourceName |
The name of the JDBC connection pool. |
You can view the complete ra.xml file for the DBMS adapter in:
WLI_HOME/adapters/dbms/src/rar/META-INF/
Step 5b: Create the .rar File
Class files, logging configuration, and message bundle(s) should be bundled into a .jar file, which should then be bundled along with META-INF/ra.xml into the .rar file. The Ant build.xml file demonstrates how to properly construct this .rar file.
Step 5c: Build the .jar and .ear Files
To build the .jar and .ear files, use this procedure:
Step 5d: Create and Deploy the .ear File
To create and deploy the .ear file, thus deploying the DBMS adapter, use this procedure:
Listing E-9 Declaring the DBMS Adapter's .ear File
<!-- This deploys the EAR file -->
<Application Deployed="true" Name="BEA_WLS_DBMS_ADK" Path="WLI_HOME/adapters/dbms/lib/BEA_WLS_DBMS_ADK.ear">
<ConnectorComponent Name="BEA_WLS_DBMS_ADK" Targets="myserver"
URI="BEA_WLS_DBMS_ADK.rar"/>
<WebAppComponent Name="DbmsEventRouter" Targets="myserver"
URI="BEA_WLS_DBMS_ADK_EventRouter.war"/>
<WebAppComponent Name="BEA_WLS_DBMS_ADK_Web" Targets="myserver"
URI="BEA_WLS_DBMS_ADK_Web.war"/>
</Application>
Note: Replace WLI_HOME with the correct path to the WebLogic Integration root directory for your environment.
http://localhost:7001/console
http://localhost:7001/wlai
The Application View Console - Logon is displayed.
How the DBMS Adapter Design-Time GUI was Developed
The design-time GUI is the user interface that allows the user to create application views, add services and events and deploy the adapter if it is hosted in the WebLogic Integration. This section discusses some specific design time issues that were considered during the development of the DBMS adapter.
The process of creating the DBMS adapter design-time GUI is comprised of the following steps:
Step 1: Development Considerations
Some of the important development considerations regarding the design-time GUI for the DBMS adapter included:
Step 2: Determine Necessary Java Server Pages
The DBMS adapter uses the ADKs Java Server Pages (JSPs) for a design-time GUI; however, additional JSPs have been added to provide adapter-specific functionality. A description of the additional JSPs is in Table :
Step 3: Create the Message Bundle
To support the internationalization of all text labels, messages and exceptions, the DBMS adapter uses a message bundle based on a text property file. The property file uses copied name value pairs from the BEA_WLS_SAMPLE_ADK property file, and new entries were added for properties specific to the DBMS adapter.
The message bundle for the DBMS adapter is contained in WLI_HOME/adapters/dbms/src directory, which was installed with the ADK. Please refer to BEA_WLS_DBMS_ADK.properties in the directory above.
For additional instructions on creating a message bundle, refer to the JavaSoft tutorial on internationalization at:
http://java.sun.com/docs/books/tutorial/i18n/index.html
Step 4: Implementing the Design-time GUI
To implement the design-time GUI, you need to create a DesignTimeRequestHandler class. This class accepts user input from a form and provides methods to perform a design-time action. For more information on the DesignTimeRequestHandler, see Step 4: Implementing the Design-Time GUI.
The DBMS adapter public class DesignTimeRequestHandler extends AbstractDesignTimeRequestHandler and it provides the methods shown in Table :
Table E-5 Methods for the DBMS Adapter Design-time GUI
Step 5: Writing Java Server Pages
The following issues are relevant for the DBMS adapter, and you may encounter them as you develop your own adapter.
Custom JSP Tags
The Java Server Pages are displayed within the display.jsp; thus display.jsp is the first .jsp that needs to be written. The ADK provides a library of custom JSP tags, which are used extensively throughout the Java server pages of the ADK and DBMS adapter. They provide the ability to add validation, to save field values when the user clicks away, and a number of other features.
Save an Object's State
You may also need to save an object's state as you write the JSPs. There are a number of ways to save an object's state when building your adapter using the ADK. The AbstractDesignTimeRequestHandler maintains an ApplicationViewDescriptor of the application view being edited. This is often the best place to save state. Calls to the handler are fast and efficient.
You can also ask the AbstractDesignTimeRequestHandler for a Manager Bean, using its convenience methods: getApplicationViewManager(); getSchemaManager(); and getNamespaceManager(), to retrieve information from the repository about an application view. This is more time-consuming but may be necessary on occasion. Since it is a JSP, you can also use the session object, although everything put in the session must explicitly implement the java.io.serializable interface.
Write the WEB-INF/web.xml Web Application Deployment Descriptor
Write the WEB-INF/web.xml Web application deployment descriptor. In most cases, you should use the adapter's web.xml file as a starting point and modify the necessary components to fit your needs. To see the web.xml file for this adapter, go to:
WLI_HOME/adapters/dbms/src/war/WEB-INF/web.xml
For detailed information, see the BEA WebLogic Server product documentation at:
http://www.oracle.com/technology/documentation/index.html
![]() |
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|