Files   Prepare   Run   Troubleshooting   Related Topics 

About the Example

This example demonstrates how to use cached, filtered, and sorted rowsets. A RowSet is an extension of a Java ResultSet. Like a result set, a rowset is a Java object that holds tabular data. However, a rowset adds significant flexibility to result set features and reduces or eliminates some result set limitations. Cached rowsets are disconnected rowsets. That is, they do not maintain a connection to a database. Instead, they reconnect only when making database changes or when repopulating the database with data.

In this example, a rowset is used to hold patient data to display on a Web page. The user can search for patient records and then sort the results. Using a rowset to hold the data rather than a result set minimizes the number of database round trips required to filter and sort the data, and improves application performance.

This example demonstrates how to:

Workflow

When you run this example, a Web page opens in a browser. The workflow of the Web pages proceeds as follows:

  1. RowSetServlet acts as the entry point. It calls PatientSessionEJB.
  2. PatientSessionEJB creates a CachedRowSet on the server side and populates it with data from the Pointbase demo database.
  3. The user enters search criteria in the browser.
  4. The servlet sets the filter on the rowset and displays filtered results in Patients.jsp.
  5. If the user searches again for other data, the servlet resets the filter on the rowset and redisplays the data in Patients.jsp. There is no need to query the database because the data is already available in the cached rowset.
  6. If the user re-sorts the data displayed in Patients.jsp, the servlet sets the sort criteria on the rowset. The sorted data is then redisplayed in Patients.jsp.
  7. If the user edits data, when the changes are submitted, the servlet calls the EJB and passes the updated rowset. The EJB calls acceptChanges to update the database and then repopulates the rowset with updated data from the database.

As you work through the example, the corresponding rowset XML is written to the server window to help you understand what is happening behind the scenes and to demonstrate the printRowSetXML(rs) method.


Files Used in the Example

Directory Location:

BEA_HOME/wlserver_10.3/samples/server/examples/src/examples/jdbc/rowsets

(where BEA_HOME is the directory containing your WebLogic Server installation)

File

Click source files to view code.

Description

application.xml Standard descriptor file for the Enterprise application.
build.xml Ant build script for building and running the example and for recreating database tables, if necessary.
Confirmation.jsp JSP page that displays a confirmation message in your browser after data changes are successfully made to the database.
Edit.jsp JSP page that enables you to edit data in the cached rowset. When submitting changes, the changes are immediately propagated to the database through PatientSessionEJB. In many cases, it is more efficient to synchronize data changes with the database after all changes have been made. In this example, the design was kept simple and data changes are made to the database immediately.
Error.jsp JSP page that displays an error message in your browser if data changes are not successfully made to the database.
ExamplesFooter.jsp Common footer used in JSP pages in this example.
ExamplesHeader.jsp Common header used in JSP pages in this example.
Patients.jsp JSP page that displays a list of patients who match search criteria in your browser. The list is generated from a filtered rowset.
PatientSessionEJB.java EJB that gets the data from the database and stores it as a cached rowset. When data changes are made, this EJB synchronizes the rowset changes with the database.
RowSetsServlet.java Servlet that coordinates the work of the example, including calling the proper JSP pages and setting the sorter and filter on the rowset in PatienSessionEJB.
Search.jsp Starting page in your browser in which you enter search criteria used to filter the data displayed in Patients.jsp.
SearchPredicate.java Implements the javax.sql.rowset.Predicate interface. The example uses this class to create a Predicate object and uses the object to set the filter on the filtered rowset. Specifically, the predicate compares a case-insensitive string to a case-insensitive column value.
table.ddl SQL script files used with the ant db.setup.pointbase command. This script drops and recreates tables in the PointBase demo database that are used in this example.
web.xml Web application deployment descriptor.
weblogic-application.xml WebLogic-specific descriptor file for the Enterprise application. The Enterprise application in this example does not require WebLogic-specific settings in this file.
weblogic.xml WebLogic-specific descriptor file for the Web application.

Prepare the Example

Prerequisites

Before working with this example:

  1. Install WebLogic Server, including the examples.
  2. Start the Examples server.
  3. Set up your environment.

This example uses tables in the PointBase demo database. The database should already contain the necessary tables and sample data. However, if you need refresh the tables in the demo database, execute the following command from the shell where you set your environment:

ant db.setup.pointbase

This command uses the build.xml and table.ddl files, located in the SAMPLES_HOME\server\examples\src\examples\jdbc\rowsets directory, to drop, recreate, and repopulate tables in the PointBase demo database used by the example.

Configure WebLogic Server

The example uses JDBC connections from the examples-demoXA JDBC data source in the wl_server domain. You can view the data source configuration in the Administration Console:

  1. Open the Administration Console.
  2. In the Domain Structure tree, expand Services > JDBC and click Data Sources.
  3. In the Data Sources list, click examples-demoXA.

If you need to configure the examples-demoXA data source, see Configure JDBC Data Sources for instructions.

Build and Deploy the Example

To build and deploy the example:

  1. In the shell where you set your environment, change to the example directory:

    cd SAMPLES_HOME\server\examples\src\examples\jdbc\rowsets

    where SAMPLES_HOME refers to the main WebLogic Server samples directory, such as c:\bea\wlserver_10.3\samples.
  2. Execute the following command:

    ant build

    The build command creates and organizes a split development EAR (for more information, see Creating WebLogic Server Applications), and compiles the EAR containing the patient session EJB and the Web application.

    This command compiles the example files:
    	  
    clean:
    
    prepare.example:
        [mkdir] Created dir: C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar
        [mkdir] Created dir: C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\META-INF
        [mkdir] Created dir: C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsEjb
        [mkdir] Created dir: C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar
        [mkdir] Created dir: C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF
        [mkdir] Created dir: C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsEjb\examples\jdbc\rowsets
    
    copy.files:
         [copy] Copying 2 files to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\META-INF
         [copy] Copying 8 files to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar
         [copy] Copying 2 files to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF\src\examples\jdbc\rowsets
         [copy] Copying 1 file to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF
         [copy] Copying 1 file to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF
         [copy] Copying 1 file to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF
         [copy] Copying 1 file to C:\bea\wlserver_10.3\samples\server\examples\src\examples\jdbc\rowsets\jdbcRowSetsEar\jdbcRowSetsEjb\examples\jdbc\rowsets
    
    build.ear:
         [copy] Copying 1 file to C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF\lib
       [ejbgen] EJBGen 10.3
    
       [ejbgen]  Creating C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb\examples\jdbc\rowsets\PatientSessionHome.java
       [ejbgen]  Creating C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb\examples\jdbc\rowsets\PatientSession.java
       [ejbgen]  Creating C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb\\ejb-jar.xml
       [ejbgen]  Creating C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb\\weblogic-ejb-jar.xml
       [ejbgen]  Creating C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb\ejbgen-build.xml
         [move] Moving 2 files to C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb\META-INF
        [javac] Compiling 3 source files to C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsEjb
        [javac] Compiling 2 source files to C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar\jdbcRowSetsWar\WEB-INF\classes
       [wlappc]     
       [wlappc]     
    
    build:
    
    BUILD SUCCESSFUL	  
    	  
    	  
  3. Execute the following command from the shell where you set your environment:

    ant deploy

    This command deploys the jdbcRowSetsEAR on the wl_server domain of your WebLogic Server installation using the wldeploy ant task. You should see the following output:
    deploy:
     [wldeploy] weblogic.Deployer -noexit -source C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar -adminurl t3://localhost:7001 -user weblogic -password ******** -deploy
     [wldeploy] weblogic.Deployer invoked with options:  -noexit -source C:\bea\wlserver_10.3\samples\server\examples\build\jdbcRowSetsEar -adminurl t3://localhost:7001 -user weblogic -deploy
     [wldeploy]     
     [wldeploy] Task 0 initiated: [Deployer:149026]deploy application jdbcRowSetsEar on examplesServer.
     [wldeploy] Task 0 completed: [Deployer:149026]deploy application jdbcRowSetsEar on examplesServer.
     [wldeploy] Target state: deploy completed on Server examplesServer
     [wldeploy]
    
    BUILD SUCCESSFUL  
      

Run the Example

  1. Complete the steps in the "Prepare the Example" section.
  2. Execute the following command from the shell where you set your environment:

    ant run

    This command runs the example.

    A browser window will open. In the browser , you can search for records of patients with last names that contain a letter or string of letters that you specify. Depending on what you search for, the patient records displayed can be any of the following rows:

    First Name

    Middle Name

    Last Name

    Date of Birth

    SSN

    E-Mail

    Phone

    Gender

    Fred I Winner 1965-03-26 123456789fred@golf.com4151234564 Male
    Larry J Parrot 1959-02-13 777777777 larry@bball.com4151234564 Male
    Charlie E Florida 1973-10-29 444444444 charlie@star.com4151234564 Male
    Gabrielle H Spiker 1971-08-17333333333 volley@ball.com4151234564 Female
    Page A Trout 1972-02-18 888888888 page@fish.com4151234564 Male

    When results are displayed, you can sort the results by Last Name or by Social Security Number (SSN). You can also edit a record by clicking Edit.

Troubleshooting


Related Topics

(Internet connection required.)


Copyright © 1996, 2008, Oracle and/or its affiliates. All Rights Reserved.