One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only...
-
Upload
shonda-dorothy-dennis -
Category
Documents
-
view
220 -
download
0
Transcript of One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only...
![Page 1: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/1.jpg)
One-to-One Relationship
Branch Manager1 1
Each branch has a single manager
Each manager manages only one branch
Sue JamesCentral
HeadOffice Tony Dunn
HighStreet Ann Bond
10.1
![Page 2: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/2.jpg)
Implement with a Reference
Branch Manager
myManager
Sue JamesCentral
reference
10.2
![Page 3: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/3.jpg)
Inverse Reference
Branch Manager
myManager
Branch Manager
myBranch
myManager is the inverse reference of myBranch
myBranch is the inverse reference of myManager
10.3
![Page 4: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/4.jpg)
Update Mode
Sue JamesCentral
A reference is set manually in a method
Sue JamesCentral
JADE automatically sets inverse reference
or
or10.4
![Page 5: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/5.jpg)
Referential Integrity
// Suppose mgr1 is Sue James, not currently managing a branch // Suppose mgr2 is Tony Dunn, not currently managing a branch // Suppose br is Central branch, currently without a manager
br.myManager := mgr1; // Manually sets Central's myManager reference to Sue James // Automatically Sue James' myBranch reference set to Central
br.myManager := mgr2; // Manually sets Central's myManager reference to Tony Dunn // Automatically Sue James' myBranch reference set to null // Automatically Tony Dunn's myBranch reference set to Central
delete br; // Manually deletes the Central branch // Automatically Tony Dunn's myBranch reference is set to null
// Suppose mgr1 is Sue James, not currently managing a branch // Suppose mgr2 is Tony Dunn, not currently managing a branch // Suppose br is Central branch, currently without a manager
br.myManager := mgr1; // Manually sets Central's myManager reference to Sue James // Automatically Sue James' myBranch reference set to Central
br.myManager := mgr2; // Manually sets Central's myManager reference to Tony Dunn // Automatically Sue James' myBranch reference set to null // Automatically Tony Dunn's myBranch reference set to Central
delete br; // Manually deletes the Central branch // Automatically Tony Dunn's myBranch reference is set to null
10.5
![Page 6: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/6.jpg)
PersistentTransient
TransientPersistent A persistent object, visible in all nodes, may not
reference a transient object, visible in only one node.
Allow Transient to Persistent Reference
PersistentPersistent
TransientTransient
A transient object may reference a persistent object provided the inverse is not maintained.
An object can reference another object with the same lifetime.
10.6
![Page 7: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/7.jpg)
Relationship Type
PeerPeer
Object is deleted Peer not affected
or
or
ChildParent
Parent is deleted Child is deleted
Child is deleted Parent not affected
10.7
![Page 8: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/8.jpg)
One-to-Many Relationship
Branch Customer1
Each branch has many customers
Each customer belongs to exactly one branch
G.Brown
Central V.Clark
C.Smith
D.Jones
HighStreet
T.Watson
10.8
![Page 9: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/9.jpg)
Implement with a Collection
Branch Customer
allCustomers
exclusive collection
G.Brown
V.Clark
C.Smith
Central
10.9
![Page 10: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/10.jpg)
Inverse Reference
Branch Customer
allCustomers
Branch Customer
myBranch
allCustomers is the inverse reference of myBranch
myBranch is the inverse reference of allCustomers
10.10
![Page 11: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/11.jpg)
Referential Integrity
// Suppose br1 is the Central branch // Suppose br2 is the HighStreet branch // Each branch has a dictionary of customers keyed on ID number // Suppose cust is C.Smith, a customer who is not with any branch
cust.myBranch := br1; // Manually sets the customer's myBranch reference to Central // Automatically adds C.Smith to Central's allCustomers
cust.myBranch := br2; // Manually sets the C.Smith's myBranch reference to HighStreet // Automatically removes C.Smith from Central's allCustomers // Automatically adds C.Smith to HighStreet's allCustomers
cust.myID := '25485725'; // Manually changes C.Smith's key property (ID) // Automatically removes C.Smith from HighStreet's allCustomers // Automatically re-adds C.Smith into allCustomers with a new key
delete cust; // Manually deletes C.Smith // Automatically removes C.Smith from HighStreet's allCustomers
// Suppose br1 is the Central branch // Suppose br2 is the HighStreet branch // Each branch has a dictionary of customers keyed on ID number // Suppose cust is C.Smith, a customer who is not with any branch
cust.myBranch := br1; // Manually sets the customer's myBranch reference to Central // Automatically adds C.Smith to Central's allCustomers
cust.myBranch := br2; // Manually sets the C.Smith's myBranch reference to HighStreet // Automatically removes C.Smith from Central's allCustomers // Automatically adds C.Smith to HighStreet's allCustomers
cust.myID := '25485725'; // Manually changes C.Smith's key property (ID) // Automatically removes C.Smith from HighStreet's allCustomers // Automatically re-adds C.Smith into allCustomers with a new key
delete cust; // Manually deletes C.Smith // Automatically removes C.Smith from HighStreet's allCustomers
10.11
![Page 12: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/12.jpg)
Many-to-Many Relationship
Employee Skill
Each employee has many skills
Each skill is possessed by many employees
F. Mills
DomesticCurrency
J. Wood
ForeignCurrency
MortgageSelling
10.12
![Page 13: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/13.jpg)
Implement with Collections
Employee Skill
allSkills
Employee Skill
allEmployees
allSkills is the inverse reference of allEmployees
allEmployees is the inverse reference of allSkills
10.13
![Page 14: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/14.jpg)
Multiple Inverses
Bank Customer1
allCustomersByAccount myBank
First relationship between Bank and Customer
When a customer’s myBank reference is set manually,the customer is automatically added to both collections
Bank Customer1
allCustomersByName myBank
Second relationship between Bank and Customer
10.14
![Page 15: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/15.jpg)
Conditional Inverses
Branch BankAccount1
allBankAccountsallChequeAccountsallSavingsAccounts
myBranch
SavingsAccountChequeAccount
Three relationships are defined between Branch and BankAccount
Manually setting myBranch for a cheque accountautomatically adds the account to
allBankAccounts and allChequeAccounts
Manually setting myBranch for a savings accountautomatically adds the account to
allBankAccounts and allSavingsAccounts
10.15
![Page 16: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/16.jpg)
Challenge #20
CustomerByLastName 1 Customer
myBank
Bank
allCustomersByLastName
ChequeAccountByNumber 1 BankAccount
myBank
Bank
allChequeAccountsByNumber
SavingsAccountByNumber BankAccount
myBank
Bank
allSavingsAccountsByNumber
1
BankAccountByNumber Customer
allBankAccountsByNumber
1 BankAccount
myCustomer
• Add dictionary classes with duplicate keys not allowed
• Define relationships with collections automatically maintained
10.16
![Page 17: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/17.jpg)
Challenge #21
• Modify ChequeAccount::setPropertiesOnCreate method
• Modify SavingsAccount::setPropertiesOnCreate method
• Modify Customer::setPropertiesOnCreate method
• Code a JadeScript::createCustomerWithBankAccounts method
• Execute the JadeScript and inspect the new objects
10.17
![Page 18: One-to-One Relationship Branch Manager 11 Each branch has a single manager Each manager manages only one branch Sue JamesCentralHeadOfficeTony DunnHighStreetAnn.](https://reader035.fdocuments.in/reader035/viewer/2022062408/56649f265503460f94c3d42c/html5/thumbnails/18.jpg)
Attributes before References
setPropertiesOnCreate(pAddress : String; pFirstNames : String; pLastName : String) updating;
begin self.myBank := app.myBank; self.address := pAddress; self.firstNames := pFirstNames; self.lastName := pLastName;end;
setPropertiesOnCreate(pAddress : String; pFirstNames : String; pLastName : String) updating;
begin self.myBank := app.myBank; self.address := pAddress; self.firstNames := pFirstNames; self.lastName := pLastName;end;
Why is this method inefficient?
10.18