Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
This tutorial project manages an employee database for your company. The system tracks each employee's name, address, and telephone number. The system also tracks employees' current projects, managers, and contract period.
This section includes information on the following topics:
The tutorial uses the Java source files in the <TUTORIAL_HOME>\src
directory, and JSP in the <TUTORIAL_HOME>\jsp
directory. Source files are divided into two packages:
You are encouraged to experiment with these Java source files and JSP. Using the <TUTORIAL_HOME>\build
script (see "Step 3: Packaging for Deployment") you can easily compile your changes and recreate deployment artifacts.
The Java classes in the examples.servletjsp.model
package represent the domain objects used in the tutorial application.
Figure 16-1 illustrates the object model for this tutorial.
Java source files in this package include the following:
Employee
–Represents both full-time ACME employees and temporary contractors working on ACME projects. It includes the employees' personal information as well as references to their home addresses and telephone numbers.
Address
–Represents the employee's home address. The class contains country, street, city, province, and postal code information.
PhoneNumber
–Contains the telephone number(s) for each employee and contractor (number, area code, and type information). The class also includes a reference to the employee who owns the telephone number.
EmploymentPeriod
–Defines the contract term for contractors and the hire date for ACME employees. Each Employee
class has an EmploymentPeriod
.
ResponsibilityList
–Each Employee has a collection of text that describes the employee's job.
Project
–Maintains information about a particular project and the people working on it. The Project
class contains two subclasses: LargeProject
and SmallProject
. Each Employee
can be involved in more than one project.
TeamLeader
–Each Project can have a team leader (the Employee
responsible for the project).
Manager
–Each Employee
may have a manager and a collection of managed employees.
The Java classes in the examples.servletjsp
package are instances of HttpServlet
responsible for handling HTTP requests. They do the work of the application.
All application classes extend JSPDemoServlet.java
. This base class is responsible for acquiring a TopLink session at run time with JSPDemoServlet
method getSession
and also provides implementations for two frequently used TopLink queries:
JSPDemoServlet
method readEmployee(String ID)
allows derived classes to read an Employee
from the database for viewing only.
JSPDemoServlet
method readEmployee(String ID, UnitOfWork unitOfWork)
allows derived classes to read an Employee
from the database within the transactional context of a TopLink UnitOfWork
.
Examine the application classes to see how TopLink API is used to handle persistence operations within the tutorial application.
The employee management system stores the employee data in the following database tables:
The column types listed here are generic; the actual column types depend on the database used.
Table 16-10 describes how each object model class (see "Object Model Classes") relates to these database tables.
Before building this tutorial application, create and populate the following tables in your database (see "Creating and Populating Database Tables").
Table 16-1 ADDRESS Table
Column Name | Column Type | Details |
---|---|---|
ADDRESS_ID |
NUMERIC(15) |
Primary key |
CITY |
VARCHAR(80) |
|
COUNTRY |
VARCHAR(80) |
|
P_CODE |
VARCHAR(20) |
|
PROVINCE |
VARCHAR(80) |
|
STREET |
VARCHAR(80) |
Table 16-2 EMPLOYEE Table
Column Name | Column Type | Details |
---|---|---|
ADDR_ID |
NUMERIC(15) |
FK reference to ADDRESS.ADDRESS_ID |
EMP_ID |
NUMERIC(15) |
Primary key FK reference to SALARY.EMP_ID |
END_DATE |
DATE |
|
END_TIME |
TIME |
|
F_NAME |
VARCHAR(40) |
|
GENDER |
CHAR(1) |
|
L_NAME |
VARCHAR(40) |
|
MANAGER_ID |
NUMERIC(15) |
FK reference to EMPLOYEE.EMP_ID |
START_DATE |
DATE |
|
START_TIME |
TIME |
|
VERSION |
NUMERIC(15) |
Table 16-3 LPROJECT Table
Column Name | Column Type | Details |
---|---|---|
BUDGET |
NUMERIC(10,2) |
|
MILESTONE |
DATE |
|
PROJ_ID |
NUMERIC(15) |
Primary key |
Table 16-4 PHONE Table
Column Name | Column Type | Details |
---|---|---|
AREA_CODE |
CHAR(3) |
|
P_NUMBER |
CHAR(7) |
|
TYPE |
VARCHAR(15) |
Primary key |
EMP_ID |
NUMERIC(15) |
Primary key FK reference to EMPLOYEE.EMP_ID |
Table 16-5 PROJ_EMP Relation Table Between PROJECT and EMPLOYEE
Column Name | Column Type | Details |
---|---|---|
EMP_ID |
NUMERIC(15) |
Primary key FK reference to EMPLOYEE.EMP_ID |
PROJ_ID |
NUMERIC(15) |
Primary key FK reference to PROJECT.PROJ_ID |
Table 16-6 PROJECT Table
Column Name | Column Type | Details |
---|---|---|
DESCRIP |
VARCHAR(200) |
|
LEADER_ID |
NUMERIC(15) |
FK reference to EMPLOYEE.EMP_ID |
PROJ_ID |
NUMERIC(15) |
Primary key |
PROJ_NAME |
VARCHAR(30) |
|
PROJ_TYPE |
CHAR(1) |
|
VERSION |
NUMERIC(15) |
Table 16-7 RESPONS Table
Column name | Column type | Details |
---|---|---|
DESCRIP |
VARCHAR(200) |
|
EMP_ID |
NUMERIC(15) |
Primary key FK reference to EMPLOYEE.EMP_ID |
Table 16-8 SALARY Table
Column Name | Column Type | Details |
---|---|---|
EMP_ID |
NUMERIC(15) |
Primary key |
SALARY |
NUMERIC(22) |
Table 16-9 SEQUENCE Table
Column Name | Column Type | Details |
---|---|---|
SEQ_COUNT |
NUMERIC(38) |
|
SEQ_NAME |
VARCHAR(50) |
Table 16-10 Relationships Between Classes and Database Table
Database Table and Column | Java Class and Attribute | Database Type | Java Type |
---|---|---|---|
EMPLOYEE |
|
||
EMP_ID |
|
NUMERIC(15) |
BigDecimal |
F_NAME |
|
VARCHAR(40) |
String |
L_NAME |
|
VARCHAR(40) |
String |
ADDR_ID |
|
NUMERIC(15) |
Address |
Not applicable |
|
Not applicable |
Vector |
GENDER |
|
CHAR(1) |
String |
START_TIME |
|
TIME |
Time |
END_TIME |
|
TIME |
Time |
MANAGER_ID |
|
NUMERIC(15) |
Employee |
Not applicable |
|
Not applicable |
Vector |
Not applicable |
|
Not applicable |
Vector |
see Employment Period |
|
Not applicable |
EmploymentPeriod |
SALARY |
|
||
EMP_ID |
Not applicable |
NUMERIC(15) |
Not applicable |
SALARY |
|
NUMERIC(10) |
int |
EMPLOYEE |
|
||
START_DATE |
|
DATE |
Date |
END_DATE |
|
DATE |
Date |
RESPONS |
|
||
EMP_ID |
Not applicable |
NUMERIC(15) |
Not applicable |
DESCRIP |
|
VARCHAR(200) |
String |
PROJECT |
|
||
PROJ_ID |
|
NUMERIC(15) |
BigDecimal |
DESCRIP |
|
VARCHAR(200) |
String |
LEADER_ID |
|
NUMERIC(15) |
Employee |
PROJ_NAME |
|
VARCHAR(30) |
String |
PROJ_TYPE |
Not applicable |
CHAR(1) |
Not applicable |
VERSION |
Not applicable |
NUMERIC(15) |
Not applicable |
LPROJECT |
|
||
PROJ_ID |
Not applicable |
NUMERIC(15) |
Not applicable |
BUDGET |
|
NUMERIC(10,2) |
double |
MILESTONE |
|
TIMESTAMP |
TimeStamp |
ADDRESS |
|
||
ADDRESS_ID |
|
NUMERIC(15) |
BigDecimal |
COUNTRY |
|
VARCHAR(80) |
String |
STREET |
|
VARCHAR(80) |
String |
CITY |
|
VARCHAR(80) |
String |
PROVINCE |
|
VARCHAR(80) |
String |
P_CODE |
|
VARCHAR(20) |
String |
PHONE |
|
||
AREA_CODE |
|
CHAR(3) |
String |
P_NUMBER |
|
CHAR(7) |
String |
EMP_ID |
|
NUMERIC(15) |
Employee |
TYPE |
|
VARCHAR(15) |
String |
PROJ_EMP |
*Relation Table* |
||
PROJ_ID |
Not applicable |
NUMERIC(15) |
Not applicable |
EMP_ID |
Not applicable |
NUMERIC(15) |
Not applicable |
The TopLink_Tutorial.zip
file contains a dbscripts.zip
file that provides SQL scripts that you can use to create and populate the database tables used in the tutorial:
UnZIP the <TUTORIAL_HOME>\dbscripts.zip
file.
This file contains two SQL scripts: createTables.sql
and populateTables.sql
.
Execute the createTables.sql
script.
For example, using sqlplus
:
C:>sqlplus scott/tiger SQL> @createTables.sql
The tables required for this tutorial are created.
Note: For information on how to create database tables using TopLink Workbench, see "Creating New Tables" |
Execute the populateTables.sql
script.
For example, using sqlplus
:
C:>sqlplus scott/tiger SQL> @populateTables.sql
The tables are populated with the sample data required for this tutorial.