Implement the Service Layer for Samples
In the service layer for this chapter, we will still use the contact application as the sample, like the one in
Chapter 16. However, the service layer and the data model will be a bit more complicated than the one
we developed in Chapter 16 in order to show you some web application features such as file upload
support. In this section, we will discuss the data model and the implementation of the service layer that
will be used throughout this chapter.
Data Model for Samples
For the data model in the samples in this chapter, we will use a very simple one, which contains only a
single CONTACT table for storing contact information. Listing 17-1 shows the script for schema creation
(schema.sql in the /src/main/resources folder).
Listing 17-1. Sample Database Schema
DROP TABLE IF EXISTS CONTACT;
CREATE TABLE CONTACT (
ID INT NOT NULL AUTO_INCREMENT
, FIRST_NAME VARCHAR(60) NOT NULL
, LAST_NAME VARCHAR(40) NOT NULL
, BIRTH_DATE DATE
, DESCRIPTION VARCHAR(2000)
, PHOTO BLOB
, VERSION INT NOT NULL DEFAULT 0
, UNIQUE UQ_CONTACT_1 (FIRST_NAME, LAST_NAME)
, PRIMARY KEY (ID)
);
As you can see, the CONTACT table stores only a few basic fields of a contact's information. One thing
worth mentioning is the PHOTO column, of the BLOB (binary large object) data type, which will be used to
store the photo of a contact using file upload. Listing 17-2 shows the testing data population script
(/src/main/resources/test-data.sql).
Listing 17-2. Sample Data Population Script
insert
into
contact
(first_name,
last_name,
birth_date)
values
('Clarence', 'Ho', '1980-07-30');
insert
into
contact
(first_name,
last_name,
birth_date)
values
('Scott', 'Tiger', '1990-11-02');
insert
into
contact
(first_name,
last_name,
birth_date)
values
('John', 'Smith', '1964-02-28');
insert
into
contact
(first_name,
last_name,
birth_date)
values
('Peter', 'Jackson', '1944-1-
10');
insert
into contact (first_name, last_name, birth_date) values ('Jacky', 'Chan', '1955-10-31');
insert
into contact (first_name, last_name, birth_date) values ('Susan', 'Boyle', '1970-05-06');
insert
into contact (first_name, last_name, birth_date) values ('Tinner', 'Turner', '1967-04-
30');
insert
into contact (first_name, last_name, birth_date) values ('Lotus', 'Notes', '1990-02-28');
insert
into contact (first_name, last_name, birth_date) values ('Henry', 'Dickson', '1997-06-
30');
insert
into contact (first_name, last_name, birth_date) values ('Sam', 'Davis', '2001-01-31');
insert
into contact (first_name, last_name, birth_date) values ('Max', 'Beckham', '2002-02-01');
insert
into contact (first_name, last_name, birth_date) values ('Paul', 'Simon', '2002-02-28');
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home