PB138: ERD and XPath
Let's start with ERD
Entity-relationship digram
- captures relations between entities in the system
- requires analytical thinking and some experience
- suggested reading: domain driven design (about OO system design)
Note: there are different forms of ERD but nowadays most are based on Class Diagram
PlantUML
for our lessons we will use PlanUML
@startuml
' hide the spot
hide circle
' avoid problems with angled crows feet
skinparam linetype ortho
entity "Entity01" as e01 {
*e1_id : number <<generated>>
--
*name : text
description : text
}
entity "Entity02" as e02 {
*e2_id : number <<generated>>
--
*e1_id : number <<FK>>
other_details : text
}
e01 ||..o{ e02
@enduml
PlantUML
install by
choco install plantuml
brew install plantuml
or
Entity
@startuml
entity Entity01 {
* identifying_attribute
--
* mandatory_attribute
optional_attribute
}
@enduml
Entity names are:
- singular
- pascal cased
Attribute names:
- snake cased
Relations
-
ring and dash → minimum zero, maximum one (optional)
-
dash and dash → minimum one, maximum one (mandatory)
-
ring and crow's foot → minimum zero, maximum many (opt)
-
dash and crow's foot → minimum one, maximum many (m)
@startuml
Entity01 }|..|| Entity02
Entity03 }o..o| Entity04
Entity05 ||--o{ Entity06
Entity07 |o--|| Entity08
@enduml
Relation 1:N
one to many
foreign key placed on many side
Relation M:N
many to many
there is a binding table with foreign keys pointing to both tables
someone create a composite primary key in the binding table
better is to put there auto generated key
Let's practice it
Test data
generate test data using Mockaroo
XPath
is used to select the right elements.
We will use it later in XSLT
Axes
child::book | Selects all book nodes that are children of the current node |
attribute::lang | Selects the lang attribute of the current node |
child::* | Selects all element children of the current node |
attribute::* | Selects all attributes of the current node |
child::text() | Selects all text node children of the current node |
child::node() | Selects all children of the current node |
descendant::book | Selects all book descendants of the current node |
ancestor::book | Selects all book ancestors of the current node |
ancestor-or-self::book | Selects all book ancestors of the current node - and the current as well if it is a book node |
child::*/child::price | Selects all price grandchildren of the current node |
Examples
/bookstore/book/price[text()]
/bookstore/book[1]/title
/bookstore/book[price>35]/price
Ok, that's it for today
PB138: Erd and XPath
By Lukáš Grolig
PB138: Erd and XPath
- 500