© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 1 Associations Library Container Members Container Database.

Slides:



Advertisements
Similar presentations
Data Structures: A Pseudocode Approach with C
Advertisements

Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
Accounting System Design
ODMG Standard: Object Model1 OBJECT-ORIENTED DATABASE SYSTEMS ODMG Standard: Object Model Susan D. Urban and Suzanne W. Dietrich Department of Computer.
Databases Revision.
Introduction to Structured Query Language (SQL)
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
1 SYSTEMS DESIGN Pertemuan 13 s.d 20 Matakuliah: A0554/Analisa dan Perancangan Sistem Informasi Akuntansi Tahun: 2006.
Introduction to Structured Query Language (SQL)
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design Copyright 2000 © John Wiley & Sons, Inc. All rights reserved. Slide 1 Data.
1 of 5 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2006 Microsoft Corporation.
1 ODB Design Handling Associations in ODL M. Akhtar Ali School of Informatics.
Database Relationships Objective 5.01 Understand database tables used in business.
EER vs. UML Terminology EER Diagram Entity Type Entity Attribute
1 ODB Design: Handling Associations and Inheritance in ODL M. Akhtar Ali School of Informatics.
Chapter 5 UNDERSTANDING AND DESIGNING ACCOUNTING DATA.
Database Relationships Objective 5.01 Understand database tables used in business.
IST Databases and DBMSs Todd S. Bacastow January 2005.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Access 2002 Advanced Report Design.
Data Modelling – ERD Entity Relationship Diagram’s Entity Relationship Diagrams and how to create them. 1.
TM 7-1 Copyright © 1999 Addison Wesley Longman, Inc. Physical Database Design.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 9 – Building Links,
Optimize Your Object Model Paul Dayan – Sales Engineer.
1 Part 2: EJB Persistency Jianguo Lu. 2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
Chapter 2 Database Environment. Agenda Three-Level ANSI-SPARC Architecture Database Languages Data Models Functions of DBMS Components of DBMS Data Dictionary.
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Learners Support Publications Classes and Objects.
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
5 Copyright © 2004, Oracle. All rights reserved. Creating a Master-Detail Form.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 19 Data Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Data Structures A data structure.
Chapter 10 Designing the Files and Databases. SAD/CHAPTER 102 Learning Objectives Discuss the conversion from a logical data model to a physical database.
Build a database III: Build relationships for a new Access database Overview: You can relate This course teaches you how to build relationships between.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Copyright © 2006, Infinite Campus, Inc. All rights reserved. Behavior Letters & Referrals.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
Session 1 Module 1: Introduction to Data Integrity
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
Database Relationships Objective 5.01 Understand database tables used in business.
1 Information System Analysis Topic-3. 2 Entity Relationship Diagram \ Definition An entity-relationship (ER) diagram is a specialized graphic that illustrates.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Database Planning Database Design Normalization.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Microsoft ® Office 2007 PowerPoint Lecture to Accompany.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Storage and File Organization
Logical Database Design and the Rational Model
Compiler Construction (CS-636)
MIS 322 – Enterprise Business Process Analysis
CIS 155 Table Relationship
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
Chapter 9 Designing Databases
© 2011 Pearson Education, Inc. Publishing as Prentice Hall
Systems Analysis and Design
Presentation transcript:

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 1 Associations Library Container Members Container Database

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 2 Objectives In this section you will  Learn about the attributes of associations: Directionality Cardinality  Learn how to define an association  Learn how to add or delete associations

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 3 What is an Association?  An association is a typed relationship between two objects  To allow an association between objects, you must define an association link in each object’s class definition  Associations are used to link objects together

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 4 Associations in the Library Object Model Book Loan Patron patron loans[] previousBook activeBook activeLoanpreviousLoans[]

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 5 Unidirectional Associations  A unidirectional association is one in which only one class defines an association link to another class For example, there is only one Library to serve many Patrons Library Patron

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 6 Bidirectional Associations  Bidirectional associations are those in which each class instance has an association link to the other class  They guarantee referential integrity: prevents dangling references  They support two-way access paths For example, each patron has many loans and each loan can be tracked back to a patron Patron Loan

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 7 Cardinality in Associations  An association has two ends  Each end can connect to one or many objects, depending on how the association is defined in the database schema  Objectivity/DB associations support four categories of cardinality: 1:1one-to-one 1:mone-to-many m:1many-to-one n:mmany-to-many

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 8 Defining Association Links AB 1 toB one-to-one unidirectional AB 1 m toB[] toA one-to-many bidirectional AB n m toB[] toA[] many-to-many bidirectional class A : public ooObj { ooRef(B) toB; }; class B : public ooObj { }; class A : public ooObj { ooRef(B) toB[] toA; }; class B : public ooObj { ooRef(A) toA toB[]; }; class A : public ooObj { ooRef(B) toB[] toA[]; }; class B : public ooObj { ooRef(A) toA[] toB[]; };

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 9 Using Associations  The DDL Processor generates several methods (member functions) for every association link declared in a class  You use these member functions to access the related objects and establish association links  Set as many associations to a basic object as possible at the same time so that storage is allocated contiguously

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 10 Generated Member Functions: the to-one association  The DDL Processor automatically generates the member functions below for one-to-one and many-to-one associations  Association member functions are defined on an object, not on a handle class Book : public ooObj { ooRef(Loan) activeLoan activeBook; }; ooStatus Book::set_activeLoan(ooHandle(Loan)& objH); ooStatus Book::del_activeLoan(); ooStatus Book::activeLoan(ooHandle(Loan)& objH, ooMode mode); ooBoolean Book::exist_activeLoan (const ooHandle(Loan)& objH); DDL

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 11 Generated Member Functions: the to-many association  The DDL Processor automatically generates the member functions below for one-to-many and many-to-many associations class Book: public ooObj { ooRef(Loan) previousLoans[] previousBook; }; ooStatus Book::add_previousLoans(ooHandle(Loan)& newObjH); ooStatus Book ::sub_ previousLoans(ooHandle(Loan)& objH); ooStatus Book ::del_previousLoans(); ooStatus Book ::previousLoans(ooItr(Loan)&, ooMode); ooBoolean Book ::exist_previousLoans (const ooHandle(Loan)& objH); DDL

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 12 The Unidirectional To-One Association  No methods are automatically generated for a simple ooRef data member. I.e.  This data member is assigned to other ooRef/ooHandle values using the assignment operator  Technically, it is not an “association” unless it has special propagate semantics (explained later) class A : public ooObj { ooRef(B) toB; }; class B : public ooObj { };

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 13 Member Functions Examples // For the current book, set an active loan link bookH -> set_activeLoan(loanH); // For the current patron, delete all loans patronH -> del_loans(); // Check if the current book has the active loan bookH -> exist_activeLoan(loanH); // For the current book, add a previous loan link bookH -> add_previousLoans(loanH); // Delete the current loan from the patron patronH -> sub_loans(loanH); // Initialize the handle to the active loan object bookH -> activeLoan(loanH); or loanH = bookH->activeLoan();

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers Define Associations in your Object Model (diagrams) 2. Enter the definition in the DDL files 3. Build your application 4. Run your application, which a. Retrieves or creates two objects that are persistent b. Calls the association member functions which connect the link: Class::set_assocName() for a one-ended link Class::add_assocName() for a many-ended link Summary: Steps to Use Associations

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 15 How Associations are Stored class A : public ooObj { public: ooRef(B) toB []; ooRef(C) toC []; }; Object A 1 of Class A toC toC toB Assoc. ID OID System Default Association Array (VArray) 4 bytes8 bytes C1 C2 B To follow a specific association on an object, all entries in the system default association array are scanned until the desired association is found (i.e., linearly compare each entry in the VArray)

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 16 Optimizing Associations  Associations can be optimized for size by using short OIDs  Associations can be optimized for speed and size by using inline associations Improved traversal performance  Each inline to-many association is placed in a separate array (to-many) instead of the default association array  Inline association links are created by adding a property to your DDL file association definition

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 17 Long and Short Inline Association Links  A long inline association link uses an Object Identifier (OID) to refer to the associated object  A short inline association link uses a short OID to refer to the associated object  A short inline association link is used in the same way as a long inline association link, but uses less storage space (only four bytes, rather than eight) to maintain the association, resulting in better runtime performance  When using short association links, objects being linked must be in the same container

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 18 Defining & Storing Inline Associations toB toC toC Assoc. link name OID 4 bytes8 bytes B1 C1 C2 System Default Association Array class A : public ooObj { public: ooRef(B) toB toA; ooRef(C) toC []; ooRef(D) toD; inline ooRef(E) toE []; inline ooShortRef(F) toF; inline ooShortRef(G) toG [];... } E1 E2 E3 8 bytes OID bytes Short OID G1 G2 Pointer to System Default Association Array Embedded Short Inline Assocaition toF System overhead Pointer to Array for Inline Association Line toE Pointer to Array for Inline Association Link toG Embedded ooRef toD bytes Object A 1 of class A

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 19 Accessing Inline Association Links  The member functions for accessing inline association links are generated by the DDL processor and placed in a C++ header file  The member functions are the same as those for accessing non-inline association links  Application programs must be relinked, but not recompiled, when the change is made

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 20 Composite Objects & Propagation  Composite objects allow you to treat a group of associated objects as if they are a single object  Composite objects are built using Associations that have propagation semantics  Propagation causes each object in the composite object to be opened, operated on by the specified function, and then closed  Propagation is an atomic operation on a group of objects

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 21 Effects of Propagation on Deleting Objects  Delete operations can be propagated  All objects to be deleted are first identified and then deleted as a group  All bidirectional associations are automatically adjusted to reflect deletions B A A2A2 C If you delete object “B”, all objects pointed at by B with delete propagate will be cleaned up as well

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 22 Propagation Syntax  When you define an association link, specify the operation to propagate to other objects using the assocLink behavior specifier: assocLink : propOp(propagate {, propOp(propagate)})  Example: class Book: public ooObj { public: ooRef(Loan) previousLoans[] previousBook:delete(propagate); }... ooDelete(bookH);//deletes all related Loans

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 23 Associations Summary  An association is a typed relationship between two objects  There are two types of associations: unidirectional and bidirectional  Associations can connect to one or many objects  Associations can be optimized by using long and short inline properties  Delete propagation semantics can be added to association links to affect composite objects

© Copyright 1999, Objectivity, Inc., All Rights Reserved Objectivity/DB for C++ Developers - 24 Associations Lab In this lab you will create associations between a Loan and a Book and a Patron. You will: Add the new Loan class Define the association links Set/remove association links Build the LMS and populate it with Books, Patrons, Loans Browse the federated database and traverse the associations Database: Lab5 Default Container Book objects Library Container Members Container Patron objects LOM Loan objects