liveBook · Manning

Data access object

As explained in Akka in Action, Second Edition

A data access object is an application-layer object that encapsulates operations for accessing a data store.

A data access object (DAO) encapsulates database statements behind an application-layer abstraction. Controllers use DAOs while defining business logic, replacing feature-rich in-memory objects with stateless database access. section 1.4.1

Moving from in-memory objects to DAOs changes the application’s guarantees:

  • Database operations can fail because of rejected inserts, server crashes, or network problems. section 1.4.1
  • Concurrent access requires protection against duplicate records and inconsistent data. section 1.4.1
  • One business action may require coordinated writes, such as inserting rows for both a Conversation and a Message. section 1.4.1
  • Database-backed tests require isolation utilities and run more slowly than tests of in-memory objects. section 1.4.1

Starting a conversation

A controller can call a DAO to create a conversation, but the operation is no longer an inherently reliable in-memory method call: inserting the Conversation or Message row may fail, requiring explicit failure and consistency handling. section 1.4.1

Figure 1.5 Data access objects
CH01_F05_Abraham2

Use the architecture diagram to trace controllers, DAOs, and the database in the stateless application setup. section 1.4.1

How Akka in Action, Second Edition covers it

How deep it goes
Traces failures, concurrency risks, multi-table writes, and slower database-backed testing without showing DAO implementation code.
Examples
Uses Conversation and Message insertion, duplicate-record risks, database outages, and database-backed tests.
What it assumes
Assumes familiarity with application objects, controllers, database statements, and concurrent users.
What you can do after
Diagnose database-operation failures and inconsistent multi-step writes when replacing in-memory objects with DAOs.
How it connects
Connects controllers and business logic with databases, statelessness, concurrency, failures, and testing.

Also explained in

Compare how 2 books explain data access object →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.