CSCE 431 Lecture 13

From Notes
Jump to navigation Jump to search

« previous | Tuesday, February 25, 2014 | next »


Exam next week over everything up through Design Patterns


Relational Databases

Models to Persistent Data

city { name : string(30) , state : string(2) , population : int }

Table might be okay without an ID attribute:

  • name seldom changes
  • however, there are 9 cities named "Springfield Township, PA"

Data Questions

  • is 30 chars enough? (no)
  • 32-bit integers is plenty for humans and pets.


1-* Assocation

We could add a one-to-many association with a table of countries:

Add country foreign key column to city table that references the primary key of the country table

Now 32-bit int for population of country is marginal (range between ± 2 G)

1-1 Assocaition

Every country has exactly one piece of map information

store foreign key on map info row (unidirectional)

store foreign keys on both tables (bidirectional)


Inheritance

Vertical Mapping

Create table for base class and create tables with new fields

  • con: slow response times
  • pro: easy to add subtypes and new fields to the base class
Horizontal Mapping

Replicate all base attributes on all subtypes

  • pro: less fragmented data → less access time.


Other Database Systems: OODBMS, NoSQL

more direct mapping between model and data

Joins not needed:

  • access through pointers

OODBMS uses same definitions as OO language constructs.


Final Thoughts

  • consistency is important
  • use tools (ORM tools)

Avoid replication:

  • edit in one space, generated to other spaces.
  • replication begets synchronization issues: data will get out of sync.


Summary

  • Model Transformations: improve compliance of design model with design goal
  • Forward Engineering: consistent transformation of models to code
  • Refactoring: "Preserve semantics, improve readability and modifiability"
  • Reverse Engineering: "extract [actual] design from code"