Data access: DAO, ORM, directories
Isolating data access behind a dedicated layer: the DAO pattern, object-relational mapping, lazy loading and the N+1 problem, the LDAP directory.
- 26 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
DAO (data access object): what is it?
Show the answer
A class, behind an interface, that hides from the rest of the code how an entity is read and written in storage.
Business code calls
clientDao.find(7)without knowing whether the source is MySQL, PostgreSQL or a file; changing storage touches one class, and a fake DAO makes tests simpler.Which of these methods does not belong in the
ClientDaointerface?double calculerRemise(Client c)Optional<Client> trouverParEmail(String email)List<Client> trouverParVille(String ville)void supprimer(long id)
Show the answer
double calculerRemise(Client c)A DAO reads and writes entities. A calculation rule like the discount is business logic: it belongs in a service. The other three are reads or writes in storage.
With an ORM, a … maps to a table, an … to a column and an association to a ….
Show the answer
With an ORM, a class maps to a table, an attribute to a column and an association to a foreign key.
Each instance maps to a row, and its identifier to the primary key. This mapping table is what the annotations or configuration files describe.
CRUD: what is it?
Show the answer
The four basic operations on a stored entity: create, read, update, delete.
A DAO exposes them for each entity. They map to the SQL statements
INSERT,SELECT,UPDATEandDELETE, and to the HTTP methodsPOST,GET,PUTandDELETEof a REST service.An application's business classes contain SQL queries; moving from MySQL to PostgreSQL means touching 40 classes. What is the cause and the fix?
- The queries are not parameterised; switch to prepared statements
- Data access is scattered; gather it behind DAOs
- The tables lack indexes; add some before migrating
- The tables are badly named; just rename them
Show the answer
Data access is scattered; gather it behind DAOs
When SQL is in every class, any change of storage spreads everywhere. Behind a DAO interface, only the implementation changes and business code stays untouched. Prepared statements and indexes are good practice, but leave the SQL scattered.