76 Chapter 5 / Item Description Template5.1.5 Examples The item description template occurs frequently.. Figure 5.3 Item description: SQL query.. SELECT ID.itemDescriptionID, ID.name FRO
Trang 176 Chapter 5 / Item Description Template
5.1.5 Examples
The item description template occurs frequently Of all the templates, it is the one you will find most often
Figure 5.6 shows the nucleus of a model for motor vehicles VehicleModel corresponds
to ItemDescription and PhysicalVehicle corresponds to Item Physical vehicles are items
with individual identification numbers In contrast, vehicle models refer to the year and make, such as 1986 Ford Escort and 1989 Mazda 626 Customer repair records refer to phys-ical vehicles, while design documents describe vehicle models
The library loan model in Figure 5.7 further demonstrates the template A LibraryItem
is something that a library offers for borrowing A LibraryItemCopy is a physical copy of a
LibraryItem For example, a library may list The Grapes of Wrath in its card catalog (a
Li-braryItem) and have five copies of the book available (LibraryItemCopies).
Figure 5.3 Item description: SQL query Find the description given an item
SELECT ID.itemDescriptionID, ID.name
FROM Item AS I
INNER JOIN ItemDescription AS ID
ON I.itemDescriptionID = ID.itemDescriptionID
WHERE I.itemID = :anItemID;
Figure 5.4 Item description: SQL query Find the items for a description
SELECT I.itemID, I.name
FROM Item AS I
INNER JOIN ItemDescription AS ID
ON I.itemDescriptionID = ID.itemDescriptionID
WHERE ID.itemDescriptionID = :anItemDescriptionID
ORDER BY I.name;
Figure 5.5 Item description: Populated tables
ItemDescription table
item
DescriptionID
name
Item table
item ID
DescriptionID
1 VIN 1032547698 11
2 VIN 5724916835 11
3 VIN 3761952953 11
4 VIN 1123581321 12
Trang 2Each category of LibraryItem (LibraryItemType) has a standard checkout period and number of renewals For example, children’s books may be checked out for a month, while adult books may be checked out for only two weeks
A LibraryItem may have multiple PendingRequests to borrow the next available copy.
In contrast, a LibraryItemCopy can have at most one Checkout at a time.
VehicleModel
name year
PhysicalVehicle
vehicleIdentificationNumber
Company
name address
RepairEvent
date vehicleMileage
1
1
1
*
*
*
manufacturer
Metadata
Data
description
Figure 5.6 Item description: Vehicle model
{ordered}
LibraryItem
name replacementCost
Author
name
LibraryItemType
name checkoutPeriod maxRenewalsPermitted finePerDayOverdue
libraryPatron
Person
name
address
phoneNumber
LibraryCard
expirationDate
Library
name
Checkout
checkoutDate finePaid
LibraryItemCopy
copyNumber
PendingRequest
requestDate
cardNumber
*
*
*
1
*
1
1
*
1
*
1 0 1
Figure 5.7 Item description: Library loan model
CheckoutItem
dueDate returnDate itemFine 1
*
Trang 378 Chapter 5 / Item Description Template
Figure 5.7 illustrates that there can be multiple levels of item description LibraryItem-Type is metadata with regard to LibraryItem And LibraryItem is metadata with regard to Li-braryItemCopy Thus Figure 5.7 applies the template twice I omitted color coding from this
diagram since there are three levels instead of two
In addition, some types cannot be classified as data or metadata For example, Person relates both to Checkout and PendingRequest It is not entirely clear if Person should be
treat-ed as data or metadata
Figure 5.8 shows another example, relating report definition to report execution
5.2 Homomorphism Template
5.2.1 UML Template
Figure 5.9 shows the UML template for homomorphism An analogy relates the item de-scription template on the left to the item dede-scription template on the right As with the pre-vious section, a shading convention differentiates metadata from data Light gray indicates metadata and white indicates data
Figure 5.8 Item description: Report model
ReportDefinition
name
ReportExecution
creationDatetime
Person
name 1
1
*
*
Metadata
Data
creator
*
*
*
*
0 1
*
Metadata
Data
<ItemDescription1>
<RelationshipDescription>
Figure 5.9 Homomorphism: UML template Use when there is an analogy
between item description templates
<Item1>
<Relationship>
<Item2>
<ItemDescription2>
Trang 45.2.2 IDEF1X Template
Figure 5.10 restates Figure 5.9 with the IDEF1X notation The following are foreign keys:
itemDescription1ID, itemDescription2ID, item1ID, and item2ID.
5.2.3 SQL Queries
The homomorphism template has the same queries as the item description template — find the description given an item and find the items for a description In addition a homomor-phism is important for constraining data as Figure 5.11 illustrates
Note that Figure 5.11 finds any data that violates the homomorphism constraint and could execute slowly due to the nested SQL inside the EXISTS clause In practice data would
Figure 5.10 Homomorphism: IDEF1X template
itemDescription1ID
ItemDescription1
item1ID
itemDescription1ID (FK)
Item1
itemDescription2ID
ItemDescription2
item2ID itemDescription2ID (FK)
Item2
RelationshipDescription
itemDescription1ID (FK) itemDescription2ID (FK)
Relationship
item1ID (FK) item2ID (FK) itemDescription1ID (FK) itemDescription2ID (FK)
Figure 5.11 Homomorphism: SQL query Find data that violates the
homomorphism constraint
SELECT R.item1ID, R.item2ID
FROM Relationship R
WHERE NOT EXISTS (
SELECT I1.item1ID, I2.item2ID
FROM Item1 AS I1
INNER JOIN ItemDescription1 AS ID1
ON I1.itemDescription1ID = ID1.itemDescription1ID INNER JOIN RelationshipDescription AS RD
ON ID1.itemDescription1ID = RD.itemDescription1ID INNER JOIN ItemDescription2 AS ID2
ON RD.itemDescription2ID = ID2.itemDescription2ID INNER JOIN Item2 AS I2
ON ID2.itemDescription2ID = I2.itemDescription2ID WHERE R.item1ID = I1.item1ID AND
R.item2ID = I2.item2ID );
Trang 580 Chapter 5 / Item Description Template
probably be checked as it is entered, either with SQL or programming code, and the checking would be more efficient
5.2.4 Sample Populated Tables
Figure 5.12 shows homomorphism tables populated with data The example is entirely con-trived and abstract, but it does indicate the mechanics of populating homomorphism tables The values of the IDs are arbitrary, but internally consistent
5.2.5 Examples
The homomorphism template is not as esoteric as it might seem Analogies between item de-scription templates do occasionally occur in practice You will construct better data models
if you recognize homomorphisms and show their symmetry in your model layout The flight model in Figure 5.13 has one homomorphism
An Airline offers PublishedFlights on a recurring basis The flightNumber uniquely identifies each PublishedFlight for an Airline Each PublishedFlight has one or more Pub-lishedFlightLegs, each from some origin Airport to a destination Airport.
An Airport has an IATA code and a name For example, some Airport names would be
Chicago O'Hare and Houston Hobby with IATA codes of ORD and HOU
An ActualFlightLeg is the flying of an Aircraft on a particular date corresponding to a PublishedFlightLeg A PublishedFlightLeg denotes the intent to provide service on a regular basis In contrast, an ActualFlightLeg is the actual provision of service on a particular date.
Figure 5.12 Homomorphism: Populated tables
ItemDescription1 table
itemDescription1ID name
Item1 table
item1ID name itemDescription1ID
ItemDescription2 table
itemDescription2ID name
Item2 table
item2ID name itemDescription2ID
RelationshipDescription table
item
Description1ID
item Description2ID
Relationship table
item 1ID
item 2ID
item Description1ID
item Description2ID