15 Copyright © 2005, Oracle. All rights reserved. Container-Managed Relationships (CMRs)

Slides:



Advertisements
Similar presentations
Advanced SQL Topics Edward Wu.
Advertisements

1
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
Communicating in J2EE.
19 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Developing Web Services.
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
1 Copyright © 2005, Oracle. All rights reserved. Introduction.
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
16 Copyright © 2005, Oracle. All rights reserved. Developing Message-Driven Beans.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
16 Copyright © 2005, Oracle. All rights reserved. Using JDBC to Access the Database.
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
J2EE Overview.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
17 Copyright © 2005, Oracle. All rights reserved. Deploying Applications by Using Java Web Start.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Create an Application Title 1A - Adult Chapter 3.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Information Systems Today: Managing in the Digital World
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
PP Test Review Sections 6-1 to 6-6
EU market situation for eggs and poultry Management Committee 20 October 2011.
11 Copyright © Oracle Corporation, All rights reserved. Managing Tables.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Displaying Data from Multiple Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
VOORBLAD.
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
Sample Service Screenshots Enterprise Cloud Service 11.3.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 12 View Design and Integration.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
Presentation transcript:

15 Copyright © 2005, Oracle. All rights reserved. Container-Managed Relationships (CMRs)

15-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Define relationships between entity beans Determine the cardinality and direction of a relationship Identify various elements of the deployment descriptor that define the relationship Develop CMR entity beans

15-3 Copyright © 2005, Oracle. All rights reserved. Relationships

15-4 Copyright © 2005, Oracle. All rights reserved. Implementing Relationships Data manipulation in the beans may involve a more complex data model, with a relationship between entity beans. The important aspects of a relationship are: –Cardinality: Number of data instances that can participate in a relationship –Direction: Direction in which a relationship is navigated

15-5 Copyright © 2005, Oracle. All rights reserved. Cardinality and Direction of Relationships Cardinality: –One-to-one –One-to-many or many-to-one –Many-to-many Directionality: –Unidirectional –Bidirectional

15-6 Copyright © 2005, Oracle. All rights reserved. Cardinality and Direction of Relationships

15-7 Copyright © 2005, Oracle. All rights reserved. One-to-One Relationships The phone_num column is the foreign key in the EMP entity that is referencing the PHONE entity. Each employee has only one phone number and each phone number belongs to only one employee Smith100 phone_numnameemp_id MCI servicearea_codephone_num EMP PHONE

15-8 Copyright © 2005, Oracle. All rights reserved. One-to-Many Relationships Each department exists in only one location identified by location_id, whereas each location can contain many departments (1:M). …Seattle1700 … citylocation_id DEPARTMENTS LOCATIONS 1700Administration10 location_iddepartment_namedepartment_id 1700Purchasing30

15-9 Copyright © 2005, Oracle. All rights reserved. Many-to-Many Relationships Each employee may be assigned many jobs and each job may be assigned to many employees. SA_REP176A1 job_idemployee_idassign_pk ASSIGNMENTS EMPLOYEES Jonathon176 Nameemployee_id JOBS_HISTORY...SA_REP...job_id

15-10 Copyright © 2005, Oracle. All rights reserved. Oracle TopLink Oracle TopLink run-time framework: Facilitates data integration with enterprise applications Facilitates rapid development, deployment, and execution of all persistence-related aspects of any Java application SQL Rows Java application JDBC TopLink

15-11 Copyright © 2005, Oracle. All rights reserved. TopLink: Integration of J2EE Applications with Data Sources at Run Time DB2 SQL server EIS Oracle XML Data mapping and integration EJBs Servlets/JSPs J2EE Application Server

15-12 Copyright © 2005, Oracle. All rights reserved. TopLink: Integrated with Oracle JDeveloper 10g

15-13 Copyright © 2005, Oracle. All rights reserved. Implementing Relationships Relationship restrictions: –Define only for CMP 2.0 entity beans –Declare related CMP beans in one deployment descriptor –Use only local interfaces to define the relationship Define abstract get() and set() accessor methods in the bean class for each relationship field In the deployment descriptor, define: –Name of each relationship –Cardinality and direction for each relationship –One section for each side of a bidirectional relationship –Cascade delete operations on one side of the relationship

15-14 Copyright © 2005, Oracle. All rights reserved. Defining Abstract Accessor Methods Name: – get and set –Example: getDepartment(), setEmployees(EmpLocal emp) Return type: –Local interface of the target bean for single object retrieval –Collection or set of local interface objects for multiple object retrieval Location where it is defined: –Only in the source bean for unidirectional relationship –In both beans for bidirectional relationship

15-15 Copyright © 2005, Oracle. All rights reserved. Accessor Methods in 1:1 Relationships For bidirectional relationships, define abstract get() and set() accessor methods for CMR fields in both the abstract bean classes. public abstract class Emp implements EntityBean {... public abstract PhoneLocal getPhone_PhoneNo(); public abstract void setPhone_PhoneNo(PhoneLocal p);... public abstract class Phone implements EntityBean {... public abstract EmpLocal getEmp_EmployeeID(); public abstract void setEmp_EmployeeID(EmpLocal e);...

15-16 Copyright © 2005, Oracle. All rights reserved. Accessor Methods in 1:M Relationships public abstract class DepartmentsBean implements EntityBean {... public abstract LocationsLocal getLocations_locationId(); public abstract void setLocations_locationId (LocationsLocal locations_locationId);... public abstract class LocationsBean implements EntityBean {... public abstract Collection getDepartments_locationId(); public abstract void setDepartments_locationId(Collection departments_locationId);...

15-17 Copyright © 2005, Oracle. All rights reserved. Checking Relationship Mappings in JDeveloper

15-18 Copyright © 2005, Oracle. All rights reserved. Accessor Methods in M:N Relationships public abstract class EmployeesBean implements EntityBean {... public abstract Collection getJobHistory_employeeId(); public abstract void setJobHistory_employeeId (Collection jobHistory_employeeId);... } public abstract class JobHistoryBean implements EntityBean {... public abstract Collection getEmployees_employeeId(); public abstract void setEmployees_employeeId (Collection employees_employeeId);... }

15-19 Copyright © 2005, Oracle. All rights reserved. Implementing a Relationship in the Deployment Descriptor

15-20 Copyright © 2005, Oracle. All rights reserved. Implementing a Relationship in the Deployment Descriptor

15-21 Copyright © 2005, Oracle. All rights reserved. Implementing 1:1 Relationships... EMP-PHONE Emp-has-Phone One Emp Phone PhoneLocal... Emp to Phone

15-22 Copyright © 2005, Oracle. All rights reserved. Implementing 1:1 Relationships... Phone-has-Emp One Phone Emp EmpLocal... Phone to Emp

15-23 Copyright © 2005, Oracle. All rights reserved. Implementing 1:M Relationships Departments-Locations Locations-has- departments_locationId One Locations departments_locationId java.util.Collection... Departments to Locations

15-24 Copyright © 2005, Oracle. All rights reserved. Implementing 1:M Relationships... Departments-owned-by- locations_locationId Many Departments locations_locationId... Locations to Departments

15-25 Copyright © 2005, Oracle. All rights reserved. Implementing M:N Relationships... JobHistory – Employees JobHistory-has-employees_employeeId Many JobHistory employees_employeeId java.util.Collection...

15-26 Copyright © 2005, Oracle. All rights reserved. Implementing M:N Relationships Employees-has-jobHistory_employeeId Many Employees jobHistory_employeeId java.util.Collection

15-27 Copyright © 2005, Oracle. All rights reserved. Mapping Relationship Fields to Database Accept default mapping provided by container (specify relationship fields in ejb-jar.xml) Explicitly map the fields to existing table columns in orion-ejb-jar.xml

15-28 Copyright © 2005, Oracle. All rights reserved. Default Mapping of Relationship Fields Database: Specified in data-sources.xml Each table in relationship: Same as for CMP entity Columns in each table: Based on, which represents a bean in the relationship For each of an entity, the container creates a foreign key to the primary key of the related entity: –In the source bean table for one-to-one mapping –In a container-generated association table for one- to-many and many-to-many relationships User-defined or automatically generated primary key

15-29 Copyright © 2005, Oracle. All rights reserved. Default Mapping of Relationship Fields

15-30 Copyright © 2005, Oracle. All rights reserved. Explicit Mapping of Relationship Fields 1.Deploy your application with only the ejb- jar.xml elements configured. 2.Copy the container-created orion-ejb-jar.xml file to your development environment. 3.Modify the element in the orion-ejb-jar.xml file to use the database table and columns that you specify. 4.Rearchive and redeploy your application.

15-31 Copyright © 2005, Oracle. All rights reserved. Using JDeveloper to Create CMR Beans Using JDeveloper, you can create a container- managed relationship between entity beans in the following ways: Create CMP beans from tables and generate default relationships between entities. Use the EJB Module Editor to specify the relationship or use TopLink Mapping Editor. Create an EJB Diagram for CMP beans and generate default relationships.

15-32 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Determine the cardinality and direction of a relationship Define and implement relationships between CMR entity beans

15-33 Copyright © 2005, Oracle. All rights reserved. Practice 15: Overview This practice covers creating a one-to-many relationship between the Employees and Departments entity beans.

15-34 Copyright © 2005, Oracle. All rights reserved.

15-35 Copyright © 2005, Oracle. All rights reserved.

15-36 Copyright © 2005, Oracle. All rights reserved.

15-37 Copyright © 2005, Oracle. All rights reserved.

15-38 Copyright © 2005, Oracle. All rights reserved.