(cid:1)(cid:2)(cid:3)(cid:4)(cid:5)(cid:6)(cid:7)(cid:1)(cid:8)(cid:9)(cid:4)(cid:10)(cid:6)(cid:4)(cid:11) (cid:1)(cid:8)(cid:12)(cid:5)(cid:13)(cid:4)(cid:14) Johanna Wenny Rahayu La Trobe University, Australia David Taniar Monash University, Australia Eric Pardede La Trobe University, Australia (cid:15)(cid:16)(cid:17)(cid:18)(cid:19)(cid:8)(cid:4)(cid:20)(cid:20) (cid:19)(cid:21)(cid:2)(cid:13)(cid:9)(cid:20)(cid:22)(cid:4)(cid:8)(cid:18)(cid:23)(cid:24)(cid:18)(cid:9)(cid:10)(cid:10)(cid:23)(cid:25)(cid:12)(cid:6)(cid:9)(cid:25)(cid:4)(cid:18)(cid:20)(cid:5)(cid:22)(cid:23)(cid:13)(cid:12)(cid:8)(cid:13)(cid:26)(cid:18)(cid:12)(cid:10)(cid:11)(cid:18)(cid:27)(cid:8)(cid:23)(cid:24)(cid:4)(cid:20)(cid:20)(cid:9)(cid:23)(cid:10)(cid:12)(cid:13) (cid:9)(cid:10)(cid:24)(cid:23)(cid:8)(cid:28)(cid:12)(cid:6)(cid:9)(cid:23)(cid:10)(cid:18)(cid:6)(cid:4)(cid:5)(cid:22)(cid:10)(cid:23)(cid:13)(cid:23)(cid:29)(cid:26)(cid:18)(cid:6)(cid:9)(cid:6)(cid:13)(cid:4)(cid:20)(cid:18)(cid:9)(cid:10)(cid:18)(cid:6)(cid:22)(cid:4)(cid:18)(cid:5)(cid:26)(cid:2)(cid:4)(cid:8)(cid:12)(cid:29)(cid:4) Hershey • London • Melbourne • Singapore Acquisitions Editor: Renée Davies Development Editor: Kristin Roth Senior Managing Editor: Amanda Appicello Managing Editor: Jennifer Neidig Copy Editor: Shanelle Ramelb Typesetter: Cindy Consonery Cover Design: Lisa Tosheff Printed at: Yurchak Printing Inc. Published in the United States of America by IRM Press (an imprint of Idea Group Inc.) 701 E. Chocolate Avenue, Suite 200 Hershey PA 17033-1240 Tel: 717-533-8845 Fax: 717-533-8661 E-mail: [email protected] Web site: http://www.irm-press.com and in the United Kingdom by IRM Press (an imprint of Idea Group Inc.) 3 Henrietta Street Covent Garden London WC2E 8LU Tel: 44 20 7240 0856 Fax: 44 20 7379 3313 Web site: http://www.eurospan.co.uk Copyright © 2006 by Idea Group Inc. All rights reserved. No part of this book may be reproduced, stored or distributed in any form or by any means, electronic or mechanical, including photocopying, without written permission from the publisher. Product or company names used in this book are for identification purposes only. Inclusion of the names of the products or companies does not indicate a claim of ownership by IGI of the trademark or registered trademark. Library of Congress Cataloging-in-Publication Data Object-oriented Oracle / Wenny Rahayu, David Taniar and Eric Pardede, editors. p. cm. Summary: " The book covers comprehensive and fundamental aspects of the implementation of object-oriented modeling in a DBMS that was originated as a pure Relational Database, Oracle"-- Provided by publisher. Includes bibliographical references and index. ISBN 1-59140-810-5 (hardcover : alk. paper) -- ISBN 1-59140-607-2 (softcover : alk. paper) -- ISBN 1-59140-608-0 (ebook : alk. paper) 1. Oracle (Computer file) 2. Object-oriented methods (Computer science) I. Rahayu, Wenny, 1968- II. Taniar, David. III. Pardede, Eric, 1975- QA76.9.D26O23 2005 005.1'1--dc22 2005005340 British Cataloguing in Publication Data A Cataloguing in Publication record for this book is available from the British Library. All work contributed to this book is new, previously-unpublished material. The views expressed in this book are those of the authors, but not necessarily of the publisher. (cid:1)(cid:2)(cid:3)(cid:4)(cid:5)(cid:6)(cid:7)(cid:1)(cid:8)(cid:9)(cid:4)(cid:10)(cid:6)(cid:4)(cid:11) (cid:1)(cid:8)(cid:12)(cid:5)(cid:13)(cid:4)(cid:14) (cid:20)(cid:12)(cid:2)(cid:13)(cid:4)(cid:22)(cid:30)(cid:31)(cid:22)(cid:15)(cid:30)(cid:10)(cid:6)(cid:4)(cid:10)(cid:6) Preface ................................................................................................. viii Chapter I. Object-Relational Approaches............................................ 1 Object-Oriented Conceptual Model................................................ 1 Static Aspects of OOCM................................................................. 2 Objects and Classes.................................................................... 3 Inheritance Relationships .............................................................. 4 Association Relationships ............................................................. 6 Aggregation Hierarchies ............................................................... 7 Dynamic Aspects of OOCM.......................................................... 12 Generic Methods ....................................................................... 13 User-Defined Methods............................................................... 14 New Era of Object-Relational Approaches .................................. 15 OOCM Implemented on Relational Databases.......................... 16 Object Wrappers on Relational Systems.................................... 16 Extended Relational Systems...................................................... 17 Object-Oriented System and RDBMS Coexistence .................. 18 OODBMS and RDBMS Interoperation .................................... 19 Object-Relational Database System ............................................. 20 Case Study .................................................................................... 21 Summary....................................................................................... 23 References..................................................................................... 24 Chapter Problems......................................................................... 25 Chapter Solutions ......................................................................... 27 Chapter II. Object-Oriented Features in Oracle™............................ 31 Relational-Model Features ........................................................... 31 Object-Oriented Features............................................................. 34 Object Types and User-Defined Types...................................... 34 Collection Types ........................................................................ 35 Object Identifiers ....................................................................... 36 Relationships using Ref............................................................... 38 Cluster ....................................................................................... 39 Inheritance Relationships using Under........................................ 40 Encapsulation ............................................................................. 41 Summary....................................................................................... 47 References..................................................................................... 47 Chapter Problems......................................................................... 48 Chapter Solutions ......................................................................... 49 Chapter III. Using Object-Oriented Features.................................... 51 Using Inheritance Relationships ................................................... 51 Union Inheritance Implementation............................................... 52 Mutual-Exclusion Inheritance Implementation ............................. 54 Partition Inheritance Implementation........................................... 56 Multiple Inheritance Implementation ........................................... 57 Using Association Relationships................................................... 59 Creating an Association Relationship by a Primary-Key and Foreign-Key Relationship ............................................ 60 Creating an Association Relationship by Object References.......................................................................... 62 Primary Keys: Foreign Keys vs. Object References in an Association Relationship............................................................. 65 Using Aggregation Relationships ................................................. 67 Implementing Existence-Dependent Aggregation using the Clustering Technique........................................................... 67 Implementing Existence-Dependent Aggregation using the Nesting Technique .............................................................. 70 Implementing Existence-Independent Aggregation....................... 73 Case Study .................................................................................... 76 Summary....................................................................................... 81 References..................................................................................... 81 Chapter Problems......................................................................... 81 Chapter Solutions ......................................................................... 83 Chapter IV. Object-Oriented Methods .............................................. 89 Implementation of Encapsulation Using Stored Procedures or Functions and Grant Mechanisms ...................................... 90 Stored Procedures or Functions ................................................ 90 Grant.......................................................................................... 97 Implementation of Encapsulation Using Member Procedures or Functions............................................................................. 98 Case Study .................................................................................. 102 Summary..................................................................................... 107 References................................................................................... 108 Chapter Problems....................................................................... 108 Chapter Solutions ....................................................................... 111 Chapter V.Generic Methods............................................................. 114 Implementation of Methods in Inheritance Hierarchies ............. 115 Implementation of Methods in Union Inheritance......................116 Implementation of Methods in Mutual-Exclusion Inheritance................................................................................ 126 Implementation of Methods in Partition Inheritance.................. 133 Implementation of Methods in Multiple Inheritance.................. 135 Implementation of Methods in Association Relationships .......... 138 Implementation of Methods in Aggregation Relationships......... 142 Implementation of Methods in Aggregation Relationships Using the Clustering Technique......................................... 145 Implementation of Methods in Aggregation Relationships Using the Nesting Technique ............................................ 146 Case Study .................................................................................. 151 Summary..................................................................................... 159 Chapter Problems....................................................................... 159 Chapter Solutions ....................................................................... 163 Chapter VI. User-Defined Queries................................................... 170 User-Defined Queries in Inheritance Hierarchies....................... 170 Subclass Query........................................................................ 171 Superclass Query..................................................................... 172 User-Defined Queries in Association Relationships.................... 175 Referencing Query ................................................................... 175 Dereferencing Query................................................................ 177 User-Defined Queries in Aggregation Hierarchies..................... 178 Part Query............................................................................... 179 Whole Query........................................................................... 181 User-Defined Queries Using Multiple Collection Types............. 184 Varray Collection Type ............................................................ 184 Nested-Table Collection Type.................................................. 186 User-Defined Queries with Object References ........................... 187 VALUE ................................................................................... 188 DEREF.................................................................................... 190 IS DANGLING....................................................................... 190 Object Table vs. Object Attribute............................................... 191 Clustering Technique vs. Index-Organization Table .................. 193 Case Study .................................................................................. 194 Summary..................................................................................... 202 Chapter Problems....................................................................... 202 Chapter Solutions ....................................................................... 206 Chapter VII. University Case Study................................................. 210 Problem Description................................................................... 210 Problem Solution ........................................................................ 217 Campus_T Table...................................................................... 217 Faculty_T Class and Part Classes ........................................... 218 Building_T Class and Part Classes .......................................... 221 Degree_T Class ....................................................................... 224 Person_T Class, the Subclasses, and the Enrolls_In Table...... 227 Subject_T Class and Takes Table ........................................... 240 Sample Database Execution....................................................... 243 Generic Methods Sample......................................................... 243 User-Defined Methods Sample................................................ 247 Building Case Application .......................................................... 249 Summary..................................................................................... 275 Chapter VIII. Retailer Case Study................................................... 276 Problem Description................................................................... 276 Problem Solution ........................................................................ 282 Company_T Class and the Subclasses .................................... 284 Shareholders_T Class and Own_Shares Table ........................ 285 Management_T Class and the Subclasses................................ 288 Store_T Class and the Department_T Part Class.................... 290 Employee_T Class and the Subclasses .................................... 294 Maker_T Class........................................................................ 300 Item_T Class and Available_In Table....................................... 301 Customer_T Class ................................................................... 303 Transaction_T Class................................................................. 306 Building Tools Using Oracle™ Developer ................................ 307 Creating a Form Using the Data-Block Form ......................... 308 Creating a Form Using a Custom Form.................................. 315 Summary..................................................................................... 323 About the Authors.............................................................................. 324 Index................................................................................................... 326 viii (cid:23)(cid:8)(cid:4)(cid:31)(cid:12)(cid:5)(cid:4) Why This Book? Object orientation has now invaded traditional relational database-manage- ment systems. Oracle™ without exception has included object-oriented fea- tures in its system. SQL is now richer due to these additional features. How- ever, the object-oriented elements in Oracle™ will not be fully utilized without a proper database design. For example, a database application designed us- ing a traditional database modeling, such as entity-relationship (E/R) model- ing, will not be able to make use of most object-oriented features in Oracle™. This is simply due to the absence of object-oriented elements in the design. Even with a proper object-oriented design, without careful transformation from design to implementation, many of the object-oriented features will be lost. Object-Oriented Oracle™ addresses this need by not only explaining the new object-oriented features in Oracle™, but most importantly how these features can be fully utilized in database applications. We put a heavy empha- size on how an object-oriented conceptual model is implemented in Oracle™. This includes the static aspect of an object-oriented conceptual model, in- cluding the inheritance, association, and aggregation relationships, as well as the dynamic aspect covering generic object-oriented methods and user-de- fined queries. Just as we enjoyed writing this book, we hope that you will enjoy reading it, and most importantly gain valuable lessons from it. We trust that this book will give you a comprehensive insight into object-oriented Oracle™. ix Distinguishing Features Object-Oriented Oracle™ presents the right mix between theoretical and practical lessons on object-oriented features of Oracle™. In the theoretical part, it describes the foundation of object-oriented concepts and how they are used in the implementation. The importance of these con- cepts is invaluable because without this understanding, the new object-ori- ented features offered by Oracle™ will not be fully utilized. Therefore, these theoretical elements serve as the foundation of object orientation in Oracle™. In the practical part, the book contains two case studies (Chapters VII and VIII) that thoroughly explain the development of a database application using the object-oriented technology of Oracle™. The case studies start with the description of an application, followed by the appropriate object-oriented designs. The designs are then transformed for implementation in Oracle™. Each chapter also contains extensive examples and code. These examples and code will give readers a better understanding of how object-oriented elements are used in Oracle™. At the end of each chapter, a set of problems, together with their solutions, are given. These will be suitable exercises for the classroom. The solutions will be useful for both students and their teachers. Topical Coverage Object-Oriented Oracle™ contains eight chapters. Chapter I starts with object-relational approaches that cover the object-ori- ented conceptual model. There have been many approaches in amalgamating the object-oriented model with database systems, from which the new era of object-relational databases is born. Chapter II explains object-oriented features in Oracle™. These include the use of type and object in conjunction with table creation, varray, and nested table. These features, together with the ref relationships, index cluster, and the under clause for subtyping, change the whole concept of database model- ing. Chapter III describes how these object-oriented features should be properly used in Oracle™. This includes how the object-oriented conceptual model described in Chapter I is implemented using the features presented in Chapter