Mapping Relational DB Flashcards

(25 cards)

1
Q

Why is storing objects in relational databases a problem?

A

Objects in memory have a different structure compared to relational databases, objects are structured in hierarchies while relational databases store data in tables with rows and columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Alternatives to relational databases

A

Object DBs, they store objects directly removing mismatches, but it’s risky

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List the RDB mapping architectural patterns

A

1- Row Data Gateway
2- Table Data Gateway
3- Active Record
4- Data Mapper

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Gateway Pattern and how does it work?

A

A basic pattern for Row data gateway and table data gateway

1- It maps in-memory objects to data base tables
2- Each column in the table corresponds to a field in the class
3- The gateway contains all the mapping code but does not include the actual business logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When do we use Row Data Gateway and when do we use Table data gateway

A

If the technology platform supports data recovery pattern Record Set then its easier to use Table data gateway, otherwise its easier to use row data gateway (an object for each record in a data source)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Active Record pattern?

A

Appropriate when the domain model is similar to the database schema
It combines the gateway and the domain object in one class which include access to the DB and the business logic code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Disadvantage of an Active Record Pattern

A

it’s advisable to keep these responsibilities separate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Data Mapper Pattern?

A

A more complex but more flexible pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Advantage of a Data Mapper Pattern

A

The domain objects are independent from the database schema

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Disadvantage of Data Mapper Pattern

A

Added complexity (for complex mappings, its possible to reuse existing object-relational mapping tools)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is concurrency

A

It occurs when multiple users/processes try to modify the same data simultaneously, leading to conflicts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does the Unit of work pattern help managing database changes

A

1- Tracking loaded objects to monitor changes
2- Batching updates to avoid unnecessary database writes
3- Ensuring consistency by saving all changes together in a single transaction

Without this pattern, the domain layer has to decide when to read and write

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Data Reading

A

It uses mapping classes to encapsulate SQL queries for object-relational mapping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the identity map pattern do

A

It ensures that each database record is only read once and stored in memory (if unit of work is implemented, it maintains the identity map)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the challenges in mapping relational database data to domain model objects?

A

1-Links: in objects, relationships are represented using references (pointers to other objects) while in relational databases, relationships are managed using foreign keys

2- Collections: Objects can have collections (lists) but databases store only one value per field

3- Identity field: A special field in the object (primary key) to store the identity and help map the object to its relational DB keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens when reading a foreign key in ORM?

A

If not in the Identity Map, load the object from the DB using the foreign key.

17
Q

How are object references stored in the database?

A

References are replaced by the entity’s identity field (foreign key).

18
Q

How is a collection read from the database?

A

By retrieving rows linked to the object’s identifier that holds the collection.

19
Q

How is a collection stored in the database?

A

Each object in the collection is saved with a foreign key pointing to the owning object.

20
Q

What are the three inheritance mechanisms?

A

1- Single Table Inheritance
2- Concrete Table Inheritance
3- Class Table Inheritance

21
Q

Explain Single Table Inheritance

A

It uses a table to store all classes in a hierarchy, a lot of duplication and table affected by each domain change, but very
efficient, without JOINS.

22
Q

Explain Concrete Table Inheritance

A

a table for each concrete class in the hierarchy, including inherited fields, some duplication and less flexible because domain changes affect many
tables, but more efficient, less JOINS.

23
Q

Explain Class Table Inheritance

A

uses one table per class in the hierarchy, fields stored just in the table corresponding
to the class defining it, no duplication, very flexible/extensible, but inefficient, requires many JOINS.

24
Q

What are Metadata files?

A

They show us the mapping process, they also facilitate the generation of the mapping code, commonly used in commercial tools

25
Metadata mapping facilitates what?
the reuse of mapping tools