Datasheet
class has two attributes that would need to be mapped to a relational database table for permanent stor-
age. The title and artist fields can be mapped to a schema like the following:
create table CD (
ID int not null primary key auto_increment,
title varchar(256),
artist varchar(256)
);
The ID field is used to create unique rows in the database. Each title and artist field holds the appropri-
ate value from the CD object. This is an example of a one-to-one mapping between the class and the
database. Figure 1.1 shows the appropriate UML diagram to accompany the class and the resulting
database table.
Figure 1.1
From a database standpoint, consider a CD object instantiated using the following constructor:
new CD("Grace Under Pressure", "Rush");
When the object is mapped to the database table defined earlier, the values in the database might look
like this:
+----+--------------------------+-------+
| ID | Title | Artist|
+----+--------------------------+-------+
| 1 | Grace Under Pressure | Rush |
+----+--------------------------+-------+
For any additional CD objects that are instantiated, new rows are created in the database; the ID column
maintains their uniqueness.
Typically, the classes you’re dealing with in a production application will include more than just simple
attributes. Consider the following CD class:
public class CD implements Serializable {
String title;
String artist;
<<class model>>
CD
CD
-title : String
-artist : String
+getTitle : String
+getArtist : String
+getTitle()
+getArtist()
<<Physical Data Model>>
ID : int
title : varchar(256)
artist : varchar(256)
4
Chapter 1
03_576771_c01.qxd 9/1/04 12:09 PM Page 4










