Introduction to UML Data Modeling Using JDeveloper 9i
Background
With
increasingly complex systems, a clear and concise way of representing them
visually became more and more important. The Unified Modeling Language (UML) was
developed by Grady Booch, Jim Rumbaugh and Ivar Jacobson as a response to that
need. In an attempt to create a single system for modeling and documenting
information systems and business processes, the UML was created with an
underlying object-oriented analysis and design philosophy.
JDeveloper includes two modelers capable of creating class
diagrams and activity diagrams. This paper
The UML is now the standard for object-oriented design and development. However, you must keep in mind the fact that the UML was originally intended to support object-oriented programming (large C++ projects), and its best fit is with those types of systems. This is not to say that the UML cannot be used for other purposes. A number of years ago, Oracle created the Object Database Designer (ODD). Its function was to allow database designers to design and generate the then new Oracle8 object extensions. In that situation, class diagrams were used to support and generate items such as nested tables and V-arrays.
More recently, one of the authors has used UML class diagrams in conjunction with a business-rules based development approach to represent structural business rules and generate relational structures. Other companies have used UML class diagrams to directly generate relational database tables, converting classes to relational tables and class associations to foreign key constraints.
Despite these efforts, there is a significant voice in the
OO community that resists using UML for data modeling. Many believe that UML class diagrams should
not be used for data modeling. Clearly, class diagrams can be used for purposes
other than designing object-oriented programming classes. In particular, one
very useful purpose is the inclusion of UML in JDeveloper to graphically
represent BC4J entities and associations.
Author’s Note
This paper is aimed at those who have some experience with JDeveloper. If you are not familiar with workspaces and projects and cannot build a simple application using the JDeveloper wizards, much of the information contained in this paper will be hard to understand. It is intended as an overview of UML modeling and how it is used within JDeveloper.
You should download the latest version of JDeveloper 9i (as
of this writing the pre-production Release Candidate 2). Build a small
application using the wizards and read through the paper with the tool open in
front of you so you can try out the features as they are explained. Much of the
material in this paper
Using UML to Develop Systems
There are two broad purposes to which the UML can be applied. First, the UML is a conceptual modeling language where database designers can take their understanding of the design for a system and represent it
using one or more of the UML tools. The process of
translating these diagrams or UML documents into an actual system is the task
for the IT professional.
Second, the UML can be used as a graphical front-end for a
code or other system element generator tool. The tool’s designers can
explicitly define how each UML element
JDeveloper has four such translation mechanisms. One is
based on a UML Activity Diagrammer which allows you to make web pages interact.
The remaining three are associated with the Class Modeler and perform the
following functions:
·
Generate BC4J entities and associations
·
Generate UML classes
·
Generate physical tables in the database
Objects within these three contexts have very different
meanings and should not be regarded as the same constructs; therefore, each
Overview of the JDeveloper 9i Class Modeler
It is possible to create both Class Diagrams and Activity
Diagrams using the JDeveloper Class Modeler. The remainder of this paper will
discuss how to use the Class Modeler to create UML class diagrams.
The Component Palette
When you create a UML class diagram, the Class Diagram Component Palette shown in Figure 1 is accessible for adding elements to the diagram. All diagram elements can be edited by double clicking on them
Figure 1: JDeveloper 9i Component Palette
Icon functionality is as follows (moving from left to
right):
·
The first icon is for the pointer, which is used
to select items, as in most applications.
·
The Java Class icon allows you to add a Java
class to the diagram by clicking it and clicking on the diagram. Java Classes
are shown in pale yellow.
·
The Interface icon allows you to add an
interface to the diagram. By default, interfaces are shown in light bluish
purple.
·
The Entity Object icon allows you to add an
entity object to the diagram. By default, entity objects are shown in gray.
·
The Domain icon allows you to add a domain to
the diagram. By default, domains are shown in light pink.
·
The Package icon allows you to add a package to
the diagram. Packages are shown as a folder-shaped object in light orange by
default.
·
The Association 1 * icon allows you to associate
two objects with a 1-to-many relationship.
·
The Directed Association 1 to 1 icon allows you
to associate two objects with a 1-1 relationship.
·
The Directed Association 1 to * icon allows you
to associate two objects with a 1-many relationship.
·
The Directed Strong Aggregation icon indicates
that the class at the other end of the association is a part of and is owned by
the class identified by this association.
·
The Generalization icon (solid line arrow with
triangle head) indicates inheritance between the connected elements. The arrow head on the generalization line
points toward the generalization element and away from the specialization
element. Place the generalized element above its specialized element on the
diagram.
·
The Realization icon (dotted line arrow with
triangle head) is used to implement relationships in the UML to specify where a
(concrete) modeled Java class is used to implement a modeled Java interface.
·
The Dependency icon (dotted line arrow with
regular arrowhead) is used to indicate that changes to one element
·
The Note icon places a bright yellow area on the
diagram to allow you to add any information about the diagram to be viewed when
the diagram is opened. This has no automatic effect on objects.
·
The Constraint icon allows you to add a
restriction to a class or an association.
Constraints are shown in gray with a turned down corner. This has no
automatic effect on objects.
·
The Attachment icon allows you to attach a note
or constraint to another diagram element. This has no automatic effect on
objects.
Useful Techniques for Adding Elements to a Diagram
Entity objects can be added to a class diagram using one of
four methods:
1.
Drag the object directly from the Navigator onto the
Class Modeler diagram. This is the simplest method.
2.
You can create the entity object as you normally would
in the Navigator using one of the BC4J Wizards and then selecting Add to
Diagram from the right click menu on the class diagram. Use the Add to Diagram
dialog to expand the Business Components node and select the appropriate
package. Expand the package node to select the desired element(s) (association
or entity).
3.
You can expand the Connections, Database and Tables
nodes respectively in the Navigator and select and drag the desired tables onto
the diagram.
Note about selecting multiple items:
It
is possible to select multiple items using the Ctrl key but not the shift key.
You must select the first item without holding down the Ctrl key. Then hold
down the Ctrl key and select additional items. Do not let go of the mouse
button or the Ctrl key after selecting the last item. Drag the cursor over to
the diagram and release the mouse button. The mouse cursor
4. You can use the Component Palette. Select the Entity Object icon and click the diagram where you want it to appear. Doubleclick the entity object to open the Table and Entity Object Dialog. Create the entity by entering the information in the re-entrant Entity Object dialog. You can attach to an existing table using the wizard, or you can fully specify an entity independent of the database and ultimately use the entity object to generate the physical table. However, the interface to support this is relatively rudimentary and not as convenient as the traditional way of creating tables.
5.
To add an elbow (equivalent to doglegs in Designer) in
a diagram, hold down the Shift key and click the line to be edited. Drag the
line to the desired position. To remove the elbow, hold down the Shift key and
drag the line back to the straight position.
Class Modeler Window Buttons
There are five tiny icons at the bottom of the diagram
window as shown in Figure 2.
Figure 2: Class Modeler Diagram Tools
·
Moving from left to right, the icon
functionality is as follows:
·
Zoom In (+ sign): Enlarges view of diagram
·
Zoom Out (- sign): Allows you to see more of the
diagram on the screen
·
Zoom to Selected: Fills the modeler window with
the selected object
·
Fit to Window:
Fits the entire diagram in the modeler window
·
Normal Size: Returns the diagram to its original
size for editing
The entire model window can be resized as you add elements.
Class Modeler Menu
There are several categories of selections you can make from
the Model menu when working with class diagrams.
·
The look of the model can be adjusted using the
Align, Distribute or Straighten Lines options. The Straighten Lines option is
particularly useful with complex models containing many objects and
associations between them.
·
Bring to Front, Send to Back and Minimize Pages
provide the standard Windows functionality for these operations.
·
The Visual Properties selection accesses the
Visual Properties dialog, which allows you to specify certain visual display
preferences for the diagram, enable the Automatically Resize Shapes feature,
and set the diagram Grid Size. More information about the visual properties can
be obtained by clicking the help button on this dialog.
·
Zoom controls what portion of the diagram is
visible on the screen at a given time.
·
Node View allows you to select between Iconic
and Symbolic format for your diagram elements.
·
Go to Source is used to access the Java code
editor for the diagram elements
·
Drill Down and Drill Up functionality is used
either for packages on a Class Diagram or with Activity Diagrams.
·
Add to Diagram allows you to access the Business
Components, Library Elements and Model Elements nodes to find the desired
objects to add to your diagram.
·
Show gives you two options. Show Related
Elements adds related elements and draws arrows from your existing Java classes
in the diagram. Show Implementation Files creates a modeled Java class from the
.java file that implements the entity object.
·
Generate has a number of options:
o
Java – Generates the Java code for the diagram
element
o
Java for Diagram – Generates the Java code for
all elements in the diagram simultaneously
o
Automatically Generate Java – When this option
is checked, elements are automatically generated as soon as they are added to
the diagram.
o
Business Components – Generates a selected
business component
o
Business Components for Diagram – Generates all
of the business components in the active diagram
o
Database Objects – Generates the Java code for
the selected database object in the active diagram
o
Database Objects for Diagram – Generates the
Java code for all database objects in the active diagram
o
E-Business Integration – Used only for the
Activity Modeler to visualize and generate the integration between E-Business
applications either within an Intranet system or over the Internet.
· Transform to Business Components (see Using the Class Modeler as an Analysis Tool Section below for explanation)
·
Publish Diagram - You can export any diagram
created in the Class Modeler to either a .jpg or .svg file using either the
menu selection Model|Publish Diagram or clicking on a blank space in the
diagram and selecting Publish Diagram… from the right-click menu.
Java classes can effectively be used to do logical modeling.
Until you generate the class, there is no associated code so you can quickly
and easily create classes and interfaces using the Component Palette and
manipulate them within the model. Later, if you choose to implement the model,
you can easily generate the Java classes.
Java classes can also be used to build BC4J entities in the
Class Modeler. You can do this by creating a Java class and adding the
appropriate entities and associations. When the logical model is correct, you
can multi-select all of the objects for which you want to create corresponding
objects in the BC4J layer. Each Java class
·
Model only – creates the BC4J entity and
associations but does not place them on the diagram. They
·
Same Diagram – creates the BC4J objects and
presents them on the same diagram
·
New Diagram – creates the objects and places
them by default on a new UML Class Diagram
Note: The menu option name “Transform to Business
Components” is misleading since you are not changing the existing Java classes
in to BC4J components but actually creating new entity objects and BC4J associations.
A BC4J project is really composed of two different primary
areas: entities and their associations as well as views and view links. The
JDeveloper Class Modeler
To create a BC4J diagram, you should first have a BC4J
project. Since the diagram exists within a BC4J project, the only objects you
When you create a UML Class Diagram, it must be in a
package.
Tip: Place your UML class diagrams in their own packages. If
you use an existing package, JDeveloper will place the package in two places in
the Navigator. As of this writing, elements that are added to the diagram will
appear under both packages with slightly different functionality.
Once you have generated the class, any modifications to the
diagram component immediately update the associated Java classes. You do not
need to regenerate a BC4J entity or association.
When you create a BC4J element in a diagram, JDeveloper
automatically creates the associated BC4J object and modifications to the
diagram elements are also made to the BC4J elements. However, the BC4J Java
classes are not automatically created if you create the BC4J element from the
Component Palette. If you use this
method, in order to create the associated Java class, you must select
Generate…Business Components from the right-click menu.
BC4J classes associated with generated Java classes will be
flagged with a rectangular icon in the upper left-hand corner of the class in
the model window.
Class Modeler Window for BC4J Diagrams
In the Class Modeler window, you can view each object in
either iconic or symbolic format by clicking the object and using the
right-click menu. Iconic format is more aesthetically pleasing but does not
show any information beyond the class name.
Symbolic format includes the attributes, methods, keywords
and constraints associated with the class. What appears with the class can be
manipulated using the Visual Properties window.
Color and font preferences can also be set using the Visual
Properties dialog. Just as in the BC4J Class Modeler, you can view objects in
either iconic or symbolic format.
In a BC4J diagram, it is possible to add BC4J Java classes
to the diagram. Also, if you have a project with both BC4J components and other
Java classes, these can be modeled on the same diagram. There are some
applications where you may choose to have Java classes and BC4J components in
the same project. The reason that this capability exists within JDeveloper is
because developers on the Oracle Applications team wanted to take advantage of
this functionality. A full discussion of this topic is beyond the scope of this
paper.
BC4J Associations
BC4J associations (between BC4J entities) can be created in
UML diagrams in the same ways as adding BC4J classes described above. As
previously mentioned, selecting Add to Diagram from the entity right-click menu
is one method. If you add entities to the diagram that are already associated,
the associations
If you drag tables from the database that are already
associated because of existing foreign key constraints, the association
Once the association is represented on the diagram, you can
double click it to open the tabbed Association dialog and specify or modify the
association. If you create the associations between BC4J entity classes using
the Component Palette, JDeveloper creates a BC4J association between the two
classes. The name of the association in the diagram acts as the name of the
BC4J association.
(Association Roles
The association roles (words at the ends of the association
line) act as the names of the accessor if you choose to expose them. Accessors
are exposed by using a directed association. You can modify which accessors are
exposed (show the association as directed) by double clicking the association
line in the diagram to access the Association dialog. On the Association
Properties tab, you can use the Expose Accessor checkboxes to make the
association directed.
Composition, Generalization and Realization
You may choose to use composition rather than simple
association to improve the readability of your diagram but the only effect this
has is that you can implement Cascade Delete, which is not available otherwise.
You are allowed to place generalizations or dependencies
between BC4J classes but this
Notes and Constraints
You can also add notes and constraints to your model using
the icons on the Component Palette. Constraints may be attached to other
objects using a dependency line. These are purely descriptive elements that
have no impact on the logical components.
Class Modeler for Java Elements
The JDeveloper 9i Class Modeler is a Java class modeler. In
addition to modeling BC4J classes, it can also be used to manage Java classes,
packages and interfaces. When using the Class Modeler on BC4J objects, there
are various things you can do in UML some of which have an effect on your code
while others do not.
Java Classes
You can actually create a Java class on the diagram using
the Class Modeler. However, this does not immediately create the Java class
itself. It only creates a modeled representation of the Java class. Just as
with the BC4J entity class, it
The underlying Java class code is not created until you
explicitly generate the UML diagram Java class. However, once generated, the
diagram and the class are then linked. Any modifications to the diagram
When you create a Java class using the Modeler, the class is
simply created as a public class (two lines of code) and placed in the
appropriate package. Once the class is created, it can be manipulated like any
other class using the Class Editor accessed by clicking on a class in the
diagram and selecting Class Editor from the right-click menu.
Even though you can create classes directly in the Modeler,
it is usually better to create them in the Navigator by selecting new class
from the right-click menu and using the New Class dialog to specify the Name,
Package and other elements. Once created this way, it can easily be added to
the diagram by selecting Add to Diagram from the right-click menu and the
desired class from the Model Elements node.
Note: If you select a class to add to the diagram that is
already in the diagram, it
There are two methods for adding classes to a diagram.
First, they can be created using the Component Palette. Second, if the class
already exists in your project, you can select the class in the Navigator,
click the desired diagram area and select Add to Diagram from the right-click
menu. You can then use the Add to Diagram Dialog to make additional
specifications.
Note: Classes, packages and interfaces found under the Model
Elements node in the Navigator can be added to the diagram using the Add to
Diagram dialog.
If you add a class that is an extension of another class on
the diagram, the generalization line connecting the two classes
Interfaces
You can also create Java interfaces using the Modeler. You
can create a stub for an interface by stereotyping a class as an interface and
then generating the Java as a second step. Interestingly, there is no obvious
way other than this to create an interface in JDeveloper. This can only be done
using the Modeler. In the Navigator, the easiest way to create an interface is
to create a Java class and manually change the code to make it into an
interface.
Realizations
Realizations connect Java classes to interfaces and are
shown as a triangle with a dotted line. The triangle points to the interface.
The effect on the code is that, in the associated Java class, it modifies the
Java class so that it implements the interface.
Note: If you convert the Java interface to a class, the
realization line will automatically change to a generalization. The underlying
code will be modified to show that the first class extends the second class. Similarly,
if you convert a Java class to an interface, the generalization line will be
changed to a realization line with the appropriate code modifications.
Packages
You can also create packages using the Component Palette of
the Class Modeler. Packages are created immediately when the diagram element is
created and do not need to be generated. Packages are usually created when you
create other objects such as workspaces, projects and classes. As with other
elements, packages can be added directly to the diagram by selecting Add to
Diagram from the diagram right-click menu and selecting the desired package
from the list. There is no node view for packages. However, you can change the
colors and fonts using the Visual Properties dialog.
When classes and packages are added to the diagram, there is
no visual representation showing what classes belong to which packages. Java
classes do not show up in the Navigator to indicate the package in which they
reside. However, there is nothing to prevent you from using the dependency
arrow in the diagram to represent that inclusion. Drawing a dependency arrow
between the class and the package does not have any impact on the class or the
package.
Tip: There are a number of diagramming operations you can
use that have no affect on your application but can be used purely for
documentation purposes to make the diagram clearer. If you are unsure of
whether your diagram change has impacted your code, before making the change,
first Save All so that all model and BC4J elements are not in italics in the
Navigator. Make the change to the diagram and look to see if any elements in
the Navigator other than the affected diagram elements appear in italics,
indicating that they have been modified.
Packages and Class Modeler Diagrams
Packages are logical collections of elements that usually
appear in the Navigator with their associated objects. For example, when you
create a BC4J project, the BC4J elements appear within the BC4J package node.
However, in an application project, typically you do not see the package. When
you create a UML diagram in either a BC4J or application project, JDeveloper
displays the name of the diagram under the node for the package in which the
diagram resides. When BC4J elements are displayed in the Navigator, they are
shown within a package with a special icon If you build a UML diagram in a
project without BC4J components, the package
You may therefore have two package nodes referencing the
same package. These packages may also show the classes that belong to them. For
example, in a BC4J project, using package “mypackage1”, only a single package
Figure 3: JDeveloper Navigator showing dual package structure
As you add BC4J elements to the diagram, the associated BC4J
classes
In your application project, you
The Class Modeler section includes a tabbed Java Class
dialog that is only available once a class had been placed in a UML class
diagram. The Java Class dialog shown in Figure 3 is accessed by double clicking
the class name under the package node in the application project. The
multi-tabbed Java class dialog allows you to modify the attributes, operations,
realizations and Javadoc associated with the class.
Figure 3: Java Class dialog
The tabs are fairly self-explanatory. Each tab also includes
a Help button to explain each of the options available. By examining the
underlying code, you can view the results of any modifications made in the
dialog. Because of the dual package representation of classes and BC4J objects,
you may want to suppress the additional display.
It is possible to change the way in which the Navigator is
organized and displayed by selecting a project and selecting Project|Show Categories from the Menu
or the Show Categories icon in the Navigator toolbar.
Associations
Associations between classes
If you have a directed association between two classes,
there
If the association on the side with the arrowhead has a
cardinality of 0..1 or 1 (meaning that at most one object can be pointed to),
then the variable created is a simple public variable. If the cardinality is *
or 1..*, an array variable is created.
The name on the end of the association (role in UML) is used
to specify the name of the variable. Therefore, you must have a role specified
to have a directional association. If you make the association bi-directional
(arrows on both sides), then both classes
Specialized Associations
Compositions (aggregations and strong aggregations) are
treated in the same way as associations. The composition symbol has no effect
on the generated code.
Associations (directional or otherwise), when either of the
objects being connected to is an interface, act exactly as if they were
connecting to regular Java classes.
A generalization between two Java classes
About the Author
Dr.