Getting Started with Enterprise JavaBeans™

G

Entity Beans

Tutorial Home Section Home Previous Section Next

Get

Get

The Rock Survey Database

     Now it's time to take a look at the database and tables that will store the Rock Survey data. For the tutorial, we'll use the Cloudscape database engine, which is included with the J2EE RI. To use a database within the J2EE environment, the following steps are necessary:

  1. A JDBC driver for the DBMS must be added to J2EE resources.

  2. The database to be used in an application must be created or available. The tutorial database will be named gsejbDB.

  3. A JDBC DataSource entry must be added to J2EE resources. The DataSource entry for gsejbDB will be jdbc/gsejbDB.

  4. The coded JNDI access and the real JNDI name must be reconciled. This step was actually done when the Alice application was deployed in Appendix C: About the Example Applications.

  5. Finally, the database engine (Cloudscape for the J2EE RI) must be started (see Appendix A: Installing and Running J2EE).

     Steps 1 and 3 are accomplished with the J2EE Administration Tool, j2eeadmin, which is discussed in the J2EE documentation under "J2EE SDK Tools" (see Resources). There is no standard for database creation, which is DBMS specific. For Cloudscape, step 1 is included in the J2EE RI as installed. Cloudscape database creation — step 2 — is an option (create=true) in the JDBC URL for the connection, so it will be handled in step 3. To perform step 3, start J2EE, then run j2eeadmin from the command line as follows:


j2eeadmin -addJdbcDatasource jdbc/gsejbDB jdbc:cloudscape:rmi:gsejbDB;create=true

     To ensure that the DataSource was added, use this command to see a list of the current DataSources:


j2eeadmin -listJdbcDatasource

     The Rock Survey tables are minimal, with no analytical decomposition or normalization, to avoid distraction from the main focus of the tutorial, which is EJB technology. You should note that the "design" is not very flexible and should not be used as a model for production tables.

Table EB-2. The table for storing survey data
Table Name: "SurveyBeanTable"
PK
Name
Type
Description
Yes
Type
VARCHAR
Survey type = "ROCK"
  SF INTEGER Single female count
  MF INTEGER Married female count
  SM INTEGER Single male count
  MM INTEGER Married male count
  USF INTEGER US female count
  NUSF INTEGER Non-US female count
  USM INTEGER US male count
  NUSM INTEGER Non-US male count
  Igneous INTEGER Igneous count
  Metamorphic INTEGER Metamorphic count
  Meteorite INTEGER Meteorite count
  Sedimentary INTEGER Sedimentary count
  InCountry INTEGER My Country count
  ExCountry INTEGER Another Country count
  Island INTEGER Island count
  OS INTEGER Outer Space count
  Total INTEGER Total rocks
  Pounds FLOAT Total rock weight


     The "SurveyBeanTable" table holds all survey results except for last name entries, and will contain exactly one row. The initial set of columns may appear confusing at first, but they just contain the breakdowns by gender, marital status, and residence. The other columns should be self-explanatory. For the Rock Survey example, the "SurveyBeanTable" table will be managed by an entity bean using CMP.

Table EB-3. The table for storing survey names
Table Name: SurveyNames
PK
Name
Type
Description
Yes
Type
VARCHAR
Survey type = "ROCK"
Yes
LastName
VARCHAR
Last name given for survey
 
Total
INTEGER
Count

     Last name data is kept in a separate table that contains a row with a count for each distinct last name. As we'll see in The Survey Results Application, the three most frequent last names are displayed along with the other results, so we need a way to track them. For the Rock Survey example, the SurveyNames table will be managed by an entity bean using BMP.



Tutorial Home Section Home Previous Section Next