Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Understanding the Tutorial Project

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:

Source Files

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.

Object Model Classes

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.

Figure 16-1 Tutorial Object Model

Description of Figure 16-1 follows
Description of "Figure 16-1 Tutorial Object Model "

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.

Application Classes

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.

Data Model

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

Employee



    EMP_ID

    id

NUMERIC(15)

BigDecimal

    F_NAME

    firstName

VARCHAR(40)

String

    L_NAME

    lastName

VARCHAR(40)

String

    ADDR_ID

    address

NUMERIC(15)

Address

    Not applicable

    phoneNumbers

Not applicable

Vector

    GENDER

    gender

CHAR(1)

String

    START_TIME

    normalHours[0]

TIME

Time

    END_TIME

    normalHours[1]

TIME

Time

    MANAGER_ID

    manager

NUMERIC(15)

Employee

Not applicable

    managedEmployees

Not applicable

Vector

Not applicable

    projects

Not applicable

Vector

see Employment Period

    period

Not applicable

EmploymentPeriod

SALARY

Employee



    EMP_ID

Not applicable

NUMERIC(15)

Not applicable

    SALARY

    salary

NUMERIC(10)

int

EMPLOYEE

EmploymentPeriod



    START_DATE

    startDate

DATE

Date

    END_DATE

    endDate

DATE

Date

RESPONS

Employee



    EMP_ID

Not applicable

NUMERIC(15)

Not applicable

    DESCRIP

responsibilitiesList

VARCHAR(200)

String

    PROJECT

    LargeProject and SmallProject



    PROJ_ID    

id

NUMERIC(15)

BigDecimal

    DESCRIP

    description

VARCHAR(200)

String

    LEADER_ID

    teamLeader

NUMERIC(15)

Employee

    PROJ_NAME

    name

VARCHAR(30)

String

    PROJ_TYPE

Not applicable

CHAR(1)

Not applicable

    VERSION

Not applicable

NUMERIC(15)

Not applicable

LPROJECT

LargeProject



    PROJ_ID

Not applicable

NUMERIC(15)

Not applicable

    BUDGET

    budget

NUMERIC(10,2)

double

    MILESTONE

    milestoneVersion

TIMESTAMP

TimeStamp

ADDRESS

Address



    ADDRESS_ID

    id

NUMERIC(15)

BigDecimal

    COUNTRY

    country

VARCHAR(80)

String

    STREET

    street

VARCHAR(80)

String

    CITY

    city

VARCHAR(80)

String

    PROVINCE

    province

VARCHAR(80)

String

    P_CODE

    postalCode

VARCHAR(20)

String

PHONE

PhoneNumber



    AREA_CODE

    areaCode

CHAR(3)

String

    P_NUMBER

    number

CHAR(7)

String

    EMP_ID

    owner

NUMERIC(15)

Employee

    TYPE

    type

VARCHAR(15)

String

PROJ_EMP

*Relation Table*



    PROJ_ID

Not applicable

NUMERIC(15)

Not applicable

    EMP_ID

Not applicable

NUMERIC(15)

Not applicable


Creating and Populating Database Tables

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:

  1. UnZIP the <TUTORIAL_HOME>\dbscripts.zip file.

    This file contains two SQL scripts: createTables.sql and populateTables.sql.

  2. 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"

  3. 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.