quartz/content/notes/17-data-access.md
Jet Hughes 8f5488706c update
2022-05-07 12:44:09 +12:00

2.5 KiB

title aliases tags sr-due sr-interval sr-ease
17-data-access
info201
lecture
2022-05-08 3 250

revision questions

Most infosystems require persistent data. e.g.,

  • save to file
  • save to database Some systems require several persistent data stores. e.g., multiple databases.

File based

doesn't scale well

  • demlimited text e.g., CSV TSV
    • easy to create and process
    • portable
    • lowest common denominator
  • structured text e.g., JSON, XML, YAML
    • many tools for querying and transforming data
    • portable also
  • Serialiased data Structures (usually binary)
    • more compact
    • easy to do
    • single user only
    • no automatic failure recovery
    • no querying
    • versioning issues
    • no standards
    • less portable

Databases

  • managed by DBMS
    • usually SQL based
    • also noSQL for unstructured big data
  • advantages
    • multi user support
    • transactions (failure recovery)
    • (centralised) constraints and referntial integrity
    • flexible and ad-hoc querying
    • manage large data

Database APIs

  • most dbmss have a native datbase api
    • usually proprietry and limited to just that product
    • often the only option for noSQL dbmss
  • also generic database apis
    • work with multiple dbmss
    • same code works with any supported dbms
  • for sql dbmss
    • ODBC microsoft
    • JDBC java
    • DB-API python
    • PDO php
    • DBI perl

How to manage persistent data access

  1. domain objects interact directly with the data store
    • write to file or send sql statements
    • not easy to change
  2. domain objects interact with data store via a mediator
    • either standalone class or implementation of a data access interface
    • data access objects DAOs
    • encapsulates all access to persistent data

Designing DAOs

  • general rule: one DAO per "logical unit" of data access
  • many DAOs are just for one class e.g., PatronDAO
  • some involve many classes
    • things like header/lines objects are always managed together
    • complex operations that join multiple tables or domain classes
  • different use cases (features) use different sets of DAOs e.g.,
    • add, find, edit patron ⇒ PatronDAO
    • lend items ⇒ LoanDAO, ItemDAO, PatronDAO
  • object construction and deconstruction coded into DAOs

Multiple implementation of the same DAO

DAO versions

JDBC for sql