You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: unit-of-work/README.md
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -11,21 +11,27 @@ tags:
11
11
---
12
12
13
13
## 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.
16
17
17
18
## Explanation
19
+
18
20
Real world example
19
21
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.
21
25
22
26
In plain words
23
27
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
> 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.
29
35
30
36
**Programmatic Example**
31
37
@@ -57,8 +63,9 @@ public class Student {
57
63
}
58
64
```
59
65
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.
62
69
63
70
```java
64
71
publicinterfaceIUnitOfWork<T> {
@@ -160,7 +167,7 @@ public class StudentRepository implements IUnitOfWork<Student> {
160
167
}
161
168
```
162
169
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.
164
171
165
172
```java
166
173
studentRepository.registerNew(ram);
@@ -170,9 +177,11 @@ Finally here's how we use the `StudentRepository` and `commit` the transaction.
0 commit comments