Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8475853

Browse files
committed
Update README.md
1 parent 9bb0b6f commit 8475853

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

unit-of-work/README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ tags:
1111
---
1212

1313
## Intent
14-
When a business transaction is completed, all the the updates are sent as one big unit of work to be persisted
15-
in one go to minimize database round-trips.
14+
15+
When a business transaction is completed, all the the updates are sent as one big unit of work to be
16+
persisted in one go to minimize database round-trips.
1617

1718
## Explanation
19+
1820
Real world example
1921

20-
> We have a database containing student information. Administrators all over the country are constantly updating this information and it causes high load on the database server. To make the load more manageable we apply to Unit of Work pattern to send many small updates in batches.
22+
> We have a database containing student information. Administrators all over the country are
23+
> constantly updating this information and it causes high load on the database server. To make the
24+
> load more manageable we apply to Unit of Work pattern to send many small updates in batches.
2125
2226
In plain words
2327

24-
> Unit of Work merges many small database updates in single batch to optimize the number of round-trips.
28+
> Unit of Work merges many small database updates in single batch to optimize the number of
29+
> round-trips.
2530
2631
[MartinFowler.com](https://martinfowler.com/eaaCatalog/unitOfWork.html) says
2732

28-
> Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
33+
> Maintains a list of objects affected by a business transaction and coordinates the writing out of
34+
> changes and the resolution of concurrency problems.
2935
3036
**Programmatic Example**
3137

@@ -57,8 +63,9 @@ public class Student {
5763
}
5864
```
5965

60-
The essence of the implementation is the `StudentRepository` implementing the Unit of Work pattern. It maintains a map
61-
of database operations (`context`) that need to be done and when `commit` is called it applies them in single batch.
66+
The essence of the implementation is the `StudentRepository` implementing the Unit of Work pattern.
67+
It maintains a map of database operations (`context`) that need to be done and when `commit` is
68+
called it applies them in single batch.
6269

6370
```java
6471
public interface IUnitOfWork<T> {
@@ -160,7 +167,7 @@ public class StudentRepository implements IUnitOfWork<Student> {
160167
}
161168
```
162169

163-
Finally here's how we use the `StudentRepository` and `commit` the transaction.
170+
Finally, here's how we use the `StudentRepository` and `commit` the transaction.
164171

165172
```java
166173
studentRepository.registerNew(ram);
@@ -170,9 +177,11 @@ Finally here's how we use the `StudentRepository` and `commit` the transaction.
170177
```
171178

172179
## Class diagram
180+
173181
![alt text](etc/unit-of-work.urm.png "unit-of-work")
174182

175183
## Applicability
184+
176185
Use the Unit Of Work pattern when
177186

178187
* To optimize the time taken for database transactions.

0 commit comments

Comments
 (0)