Defining a Persistent Object Model
Figure 1-1 is a
Unified Modeling Language (UML) diagram of the classes and
interrelationships in the Media Mania object model. A Movie instance represents a particular movie.
Each actor who has played a role in at least one movie is represented by
an instance of Actor. The Role class represents the specific roles an
actor has played in a movie and thus represents a relationship between
Movie and Actor that includes an attribute (the name of
the role). Each movie has one or more roles. An actor may have played a
role in more than one movie or may have played multiple roles in a
single movie.
Figure 1-1. UML diagram of the Media Mania object model
We will place these persistent classes and the application
programs used to manage their instances in the Java com.mediamania.prototype package.
The Classes to Persist
We will make the Movie,
Actor, and Role classes persistent, so their instances
can be stored in a datastore. First we will examine the complete
source code for each of these classes. An import statement is included
for each class, so it is clear which package contains each class used
in the example.
Example 1-1 provides
the source code for the Movie
class. JDO is defined in the javax.jdo package. Notice that the class
does not require you to import any JDO-specific classes. Java
references and collections defined in the java.util package are used ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access