Java Reference
In-Depth Information
To make the data persistent we choose to use a relational database, because
it allows immediate access to information given its key, and it supports asso-
ciations between product data. An alternative solution could be a file, the
main drawback being the lack of support for direct data access.
Decision point
How do we connect to and access the persistent storage?
The persistence layer of the supermarket system makes use of a set of
standard technologies to support independence from the DBMS. In par-
ticular we will use JDBC (see Sidebar 14.2) as the connectivity technology
and SQL as the data management language. In our implementation we will
use the Cloudscape DB, because it bundles with the J2EE distribution.
Decision point
What is the structure of the persistent data tier?
The structure of the data we want to store in the database has been
defined in the previous iterations. The database structure will follow the
same structure as the logical information presented in Figure 14.9.
Each class will be implemented as a separate table and the many-to-one
associations will be implemented with external keys on the many side (Date
2000).
14.7.3
Implementation
To build the database we can use an SQL script CreateTables.sql that con-
tains the commands to create the tables. For each table we define a primary
key that is a long integer. This file can be used from the Cloudscape inter-
active SQL environment (activated with the command cloudscape - isql ) with
the command run 'CreateTables.sql' .
CREATE TABLE item (
ID LONGINT CONSTRAINT pk_item PRIMARY KEY ,
name VARCHAR (30),
price DOUBLE PRECISION ,
quantity INT
);
CREATE TABLE customer (
ID LONGINT CONSTRAINT pk_customer PRIMARY KEY ,
name VARCHAR (30)
);
 
Search WWH ::




Custom Search