Developing Enterprise Java Applications Using DB2 UDB, Version 7.2


Java application development for Web servers

There are several tools provided with UDE Version 7.2 which provide Web enablement support. VisualAge for Java, Version 3.5 is an integrated development environment (IDE) that enables you to build, test, and deploy Java applications to WebSphere Application Server and DB2 Universal Database. WebSphere Studio is a suite of tools that brings all aspects of Web site development into a common interface. WebSphere Application Server Standard Edition version 3.5 provides a robust deployment environment for e-business applications. Its components let you build and deploy personalized, dynamic Web content quickly and easily.

VisualAge for Java, Professional Edition

VisualAge for Java, Professional Edition Version 3.5 (provided with UDE Version 7.2) contains features and performance improvements that make it easier than ever to create scalable, hardworking e-business applications. Tight integration with IBM WebSphere Application Server, WebSphere Studio, and DB2 Universal Database reduces development time and improves productivity, while providing easier, secure access to enterprise data.

IBM Data Access JavaBeans(TM), an optional installable feature of VisualAge for Java, allows application developers to easily access JDBC-enabled relational databases. The IBM Data Access JavaBeans, found in the com.ibm.db package, include classes to simplify access to relational databases and provide the following enhanced features:

Caching of query results
SQL query results can be retrieved all at once and placed into a cache. The application or servlet can move forward and backward through the cache or jump directly to any result row in the cache. Contrast this to facilities in the java.sql package, in which rows are retrieved from the database one at a time, in the forward direction only, and a newly retrieved row overlays the last retrieved row unless additional code is written to expand functionality. For large result sets, the IBM Data Access JavaBeans provide ways to retrieve and manage packets, which are subsets of the complete result set.

Updates through the results cache
The servlet can use standard Java methods to change, add, or delete rows in the result cache. Changes to the cache can be propagated to the underlying relational table.

Query parameter support
The base SQL query is defined as a Java String, with parameters replacing some of the actual values. When the query is run, the IBM Data Access JavaBeans provide a way to replace the parameters with values made available at run time. For example, the parameter values might be submitted by a user on an HTML form.

Metadata support
A StatementMetaData object contains the base SQL query. Higher levels of metadata can be added to the object to help pass parameters into the query and work with the returned results. When the query is run, the parameters are automatically converted between Java datatypes and the corresponding SQL datatypes.

VisualAge for Java, Enterprise Edition

VisualAge for Java, Enterprise Edition Version 3.5 (not provided with UDE Version 7.2) enables you to build, test, and deploy Java applications within a single environment. In addition to its visual programming features, VisualAge for Java provides wizards to lead you quickly through many tasks, including the creation of applets, servlets, and applications. It also enables you to import existing code and export code, as required, from the underlying file system.

VisualAge for Java provides an SQLj Tool that implements the SQLj standard, enabling you to simplify database access. The translator component is integrated into the IDE, enabling you to import, translate, and edit SQLj files. The run-time environment is an installable feature that is added to your workspace. The original SQLj source files are maintained in your project resources directory, as are the profiles. The VisualAge for Java SQLj Tool creates profiles in your project resources directory.

Persistence management

The Persistence Builder is a feature of VisualAge for Java that generates a layer of code that implements all of the JDBC access calls necessary to insert, update, or retrieve the data for an object from the database. The Persistence Builder is a productivity tool that simplifies many of the challenges when developing database applications. If the application was developed using object modeling, the Persistence Builder Schema Browser can be used to generate the necessary tables to persist the objects, known as top-down mapping. If the database exists then the Schema Browser can be used to reverse-engineer the tables into objects, known as bottom-up mapping. The third technique is called outside-in or "meet in the middle," as each model is maintained and adaptive changes are made within the object model or the relational model. Using the VisualAge for Java Persistence Builder can improve programmer efficiency and separate the data model and the object model. WebSphere Application Servers can provide connection pooling for DB2 UDB database connections, while the persistence builder code can be generated to utilize the connection pool instead of directly connecting to the database. Used primarily in the development of EJBs, the Persistence Builder can also provide links between object associations and transactions using the equivalent constraints and transactions in DB2.

Debugging

VisualAge for Java provides several tools for developing JavaServer Pages(TM) (JSPs). The Servlet Launcher allows you to start a Web server, open your Web browser, and launch a servlet. The JSP Execution Monitor allows you to monitor the execution of JSP source, generated servlets, and HTML source as it is generated. VisualAge for Java also allows you to set breakpoints within servlet code, dynamically update the servlet at breakpoints, and continue running the servlet with the incorporated changes .

The IBM WebSphere Test Environment is an optional installable feature of VisualAge for Java. This feature allows you to run servlets and Enterprise JavaBeans(TM) (EJBs) within the VisualAge for Java environment prior to deployment to WebSphere Application Servers. The environment provides a servlet engine and the required services for EJB applications. Since this test environment is provided within the IDE, breakpoints can be set in servlets or JSPs and a client application or browser can be invoked to test all aspects of the server-side Java programs. The remote debugger can be used to set breakpoints in EJBs that are executing within an EJB Server such as WebSphere Application Server.

Using the DB2 Stored Procedure Builder (SPB) and the VisualAge remote debugger, you can remotely debug a stored procedure installed on a DB2 server. To debug a stored procedure, run the stored procedure in debug mode. You are not required to debug the stored procedures from within an application program. You can test your stored procedure separately from the calling application program.

Using the Debug Properties notebook in SPB, you can change, add, or remove debug records in the stored procedures debug table. If you are a database administrator and you created the selected stored procedure, you can grant database authorization to other users to debug the stored procedure.

WebSphere Studio

WebSphere Studio Version 3.5 is a suite of tools that brings all aspects of Web site development into a common interface. The WebSphere Studio makes it easier than ever to cooperatively create, assemble, publish, and maintain dynamic Web applications. Content authors, graphic artists, programmers, and Web masters are able to work on the same projects, each having access to the files they need. The Studio is composed of the Workbench, the Page Designer, the Remote Debugger, and wizards, and it comes with trial copies of companion Web development products, such as Macromedia Flash, Fireworks, Freehand, and Director. WebSphere Studio enables you to do everything you need to create interactive Web sites that support your advanced business functions, including the following:

The Studio Workbench helps you manage and maintain your Web site applications and files and provides the following capabilities and features:

The Studio Page Designer provides a visual design environment that enables you to create JSP, Java servlets, and other Java-based Web tools. For example, you can use the visual environment to drag and drop JavaBeans into JSP applications. The Studio Page Designer can also be used to create Dynamic Hyper Text Markup Language (DHTML) and HTML pages and includes the capability to easily edit and toggle between the HTML or DHTML source and the browser view. The Studio Remote Debugger provides source-level debugging of JSP files and Java servlets within the Studio environment.

WebSphere Application Server

The WebSphere Application Server combines the portability of server-side business applications with the performance and manageability of Java technologies to offer a comprehensive platform for designing Java-based Web applications. It enables powerful interactions with enterprise databases and transaction systems.

Figure 3. WebSphere Application Server


WebSphere Application Server

Application servers extend the capabilities of a Web server to handle application requests. Given an application comprised of HTML pages, servlets, and enterprise beans, the application server makes the following exchange possible:

  1. A user at a Web browser on the public Internet visits a company Web site. The user requests use of an application that provides access to data in a database.
  2. The user request flows to the Web server.
  3. The Web server determines that the request involves an application containing servlets and enterprise beans. It forwards the request to IBM WebSphere Application Server.
  4. The IBM WebSphere Application Server product forwards the request to one of its application servers on which the application is running.
  5. The application processes the user request.
  6. The application server collaborates with the Web server to return the results to the user's Web browser.

The WebSphere Application Server provides a servlet engine that implements the Java Servlet API 2.1. It includes its own packages that extend and add to the Java Servlet API, and leverage JDK 1.2 across all supported operating systems. The extensions and additions make it easier to manage session state, create personalized Web pages, generate better servlet error reports, and access databases.

The Application Server supports JSPs, a powerful approach to dynamic Web page content. One of the advantages of JSPs is that they enable you to effectively separate the HTML coding from the business logic in your Web pages. The IBM extensions to the JSP specification include HTML-like JSP tags that make it easy for HTML authors to add the power of Java to their Web pages.

Connection pooling

Connection pooling support is provided with WebSphere Application Server. Connection pooling enables you to control and reduce the resources used by your Web-based applications. Web-based applications accessing data servers incur higher and less predictable overhead than non-Web applications, because Web users connect and disconnect frequently. Often, more resources are spent connecting and disconnecting than are spent during the interactions themselves.

Connection pooling spreads the connection overhead across several user requests by establishing a pool of connections which servlets can use. After the initial resources are spent to produce the connections in the pool, additional connect/disconnect overhead is insignificant because the existing connections are reused repeatedly.

Connection pooling as provided by WebSphere Application Server specifies how relational data servers are accessed by a servlet using the new JDBC 2.0 Standard Extension APIs. This is the new model. Servlets running under WebSphere Application Server Version 3.x can be coded to make efficient use of data server connection resources.

Connection pooling advantages

Each time a resource attempts to access a database, it must connect to that database. A database connection incurs overhead - it requires resources to create the connection, maintain it, and then release it when it is no longer required. The overhead is particularly high for Web-based applications because of the frequency of connection and disconnection. User interactions are typically short, due to the transient nature of Web browsing. Because Internet requests can arrive from virtually anywhere, usage volumes can be large and difficult to predict. To address the problem, WebSphere Application Server establishes a pool of database connections that is shared by applications on application servers.

Connection pooling lets the administrator control and reduce the resources used by Web-based applications, spreading the connection overhead across several user requests. Connection pooling can also improve the response times of Web-based applications.

When a user makes a request over the Web to a resource, the resource accesses a data source. Because the data source locates and uses an existing connection from the pool, the user request does not incur the overhead of creating a new connection.

Each connection is associated with a particular user request. When the request is satisfied and the response is returned to the user, the data source returns the connection to the connection pool for reuse. Again, the overhead of a disconnect is avoided.

Each user request incurs a fraction of the cost of connecting or disconnecting. After the initial resources are used to produce the connections in the pool, additional overhead is insignificant because the existing connections are reused.

How WebSphere Application Server manages connection pools

WebSphere Application Server establishes and maintains pools of connections as specified by the administrator. Once the connections are established, they are distributed in response to user requests, and then perform housekeeping operations to maintain a balance between available connections and the demand for connections. This ensures that an existing connection is available when a servlet or application server needs one.

For example, the connection pool periodically identifies idle or orphaned connections. It terminates idle connections and returns orphaned connections to the connection pool. This means fewer connections are available (and fewer resources are used) when demand for connections is low. An idle connection is one that has not been used for the amount of time specified in the Idle Timeout property of the data source. A connection is orphaned when its owning servlet or application server terminates or does not respond.

WebSphere Standard Edition

The WebSphere Application Server, Standard Edition Version 3.5 (provided with UDE Version 7.2) is a component of the WebSphere Studio. InstantDB is the default database used for WebSphere Standard Edition repository. However, DB2 Universal Database can be configured to be WebSphere's administrative server repository. You can run the DB2 server on the same machine as WebSphere Application Server or on a different Web server.

WebSphere Advanced Edition

The WebSphere Application Server Advanced Edition (not provided with UDE Version 7.2) builds on the Standard Application Server, as it requires a database for operation. DB2 Universal Database is provided with the WebSphere Application Server Advanced Edition Version 3.5, to be used as the administrative server repository. It introduces server capabilities for applications built to the EJB Specification from Sun Microsystems, which provides support for integrating Web applications to non-Web business systems.

The EJB server is the application server of WebSphere Application Server's three tier architecture. It connects the client tier of Java servlets, applets, applications, and JSPs with the resource management tier, the data source.

There are two types of enterprise beans: session beans and entity beans. Session beans encapsulate temporary data associated with a particular client. Entity beans encapsulate permanent data that is stored in a data source. The persistence service ensures that the data associated with entity beans is properly synchronized with their corresponding data in the data source. To accomplish this task, the persistence service works with the transaction service to insert, update, extract, and remove data from the data source at the appropriate times.

There are two types of entity beans: those with container-managed persistence (CMP) and those with bean-managed persistence (BMP). In entity beans with CMP, the persistence service handles nearly all of the tasks required to manage persistent data. CMP entity beans can be implemented using DB2 UDB (including DB2 for OS/390) as the persistent data store. In entity beans with BMP, the bean itself handles most of the tasks required to manage persistent data.


[ Top of Page | Previous Page | Next Page | Table of Contents ]