Chapter 6. Oracle Object-Relational Features

Oracle introduced most of its object-relational features in Oracle 8i. Of these features, object types are the most fundamental. Object types are user-defined types that correspond to classes in Java. They allow us to model data in the database the same way we do in our programs, using a set of attributes and methods for each object.

Designing a database to use object techniques is dramatically different from taking a relational approach. The most common technique in object-oriented design is composition, including classes within other classes, like Russian dolls, which is exactly the opposite approach for relational databases. The first step toward normalization is to "un-nest" the data and put aggregate or repeating types in separate tables.

Consider the design of the CD collection database. To conform to the first normal form, we made one table to hold information about each CD as a whole and another separate table. If we were to design a Java program that worked with our CD collection, we would likely have two classes, a CD class and a Song class, but they wouldn't be completely separate. The CD class would be related to the SONG class by aggregation: We'd probably include an array (or Vector) of type Song in our CD class.

Using Oracle's object-relational features, we can create a similar object in the database. We can create an object type that includes the songs for each CD in a nested table; each row in the CD table would include a table with the songs on that CD.

If we are writing an application in an object-oriented language such as Java and we are using the database to store our objects' data, it seems reasonable to mimic the structure of our objects in the database. This obviates the need for a separate layer to perform object-relational mapping. We'll see how this works in practice when we explore using JDBC together with Oracle's object-relational features.

The case for implementing methods, as opposed to data, in the database is not as compelling, however at least not when most of our code is already in Java classes on the client side. Nonetheless, there are cases when we might consider using this feature of Oracle's object types, so we'll examine methods, too.

Oracle introduced a few new object-relational features in Oracle 9i, most notably, inheritance. We'll examine these features briefly at the end of this chapter, but everything else in this chapter except for one or two instances, duly noted is applicable to both Oracle 8i and 9i.



Java Oracle Database Development
Java Oracle Database Development
ISBN: 0130462187
EAN: 2147483647
Year: 2002
Pages: 71

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net