Skip to content

Commit 790d2d6

Browse files
committed
docs: update unit of work
1 parent 0abb75a commit 790d2d6

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

unit-of-work/README.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public interface IUnitOfWork<T> {
5959

6060
void commit();
6161
}
62+
```
6263

64+
```java
6365
@Slf4j
6466
@RequiredArgsConstructor
6567
public class ArmsDealer implements IUnitOfWork<Weapon> {
@@ -95,9 +97,6 @@ public class ArmsDealer implements IUnitOfWork<Weapon> {
9597
context.put(operation, weaponsToOperate);
9698
}
9799

98-
/**
99-
* All UnitOfWork operations are batched and executed together on commit only.
100-
*/
101100
@Override
102101
public void commit() {
103102
if (context == null || context.isEmpty()) {
@@ -146,19 +145,22 @@ public class ArmsDealer implements IUnitOfWork<Weapon> {
146145
Here is how the whole app is put together.
147146

148147
```java
149-
// create some weapons
150-
var enchantedHammer = new Weapon(1, "enchanted hammer");
151-
var brokenGreatSword = new Weapon(2, "broken great sword");
152-
var silverTrident = new Weapon(3, "silver trident");
153-
154-
// create repository
155-
var weaponRepository = new ArmsDealer(new HashMap<String, List<Weapon>>(), new WeaponDatabase());
156-
157-
// perform operations on the weapons
158-
weaponRepository.registerNew(enchantedHammer);
159-
weaponRepository.registerModified(silverTrident);
160-
weaponRepository.registerDeleted(brokenGreatSword);
161-
weaponRepository.commit();
148+
public static void main(String[] args) {
149+
// create some weapons
150+
var enchantedHammer = new Weapon(1, "enchanted hammer");
151+
var brokenGreatSword = new Weapon(2, "broken great sword");
152+
var silverTrident = new Weapon(3, "silver trident");
153+
154+
// create repository
155+
var weaponRepository = new ArmsDealer(new HashMap<>(),
156+
new WeaponDatabase());
157+
158+
// perform operations on the weapons
159+
weaponRepository.registerNew(enchantedHammer);
160+
weaponRepository.registerModified(silverTrident);
161+
weaponRepository.registerDeleted(brokenGreatSword);
162+
weaponRepository.commit();
163+
}
162164
```
163165

164166
Here is the console output.
@@ -174,10 +176,6 @@ Here is the console output.
174176
21:39:21.989 [main] INFO com.iluwatar.unitofwork.ArmsDealer - Commit finished.
175177
```
176178

177-
## Class diagram
178-
179-
![Unit of Work](./etc/unit-of-work.urm.png "Unit of Work")
180-
181179
## Applicability
182180

183181
* Use when you need to manage multiple operations that need to be treated as a single transaction.
@@ -186,8 +184,9 @@ Here is the console output.
186184

187185
## Tutorials
188186

189-
* [Repository and Unit of Work Pattern - Wolfgang Ofner](https://www.programmingwithwolfgang.com/repository-and-unit-of-work-pattern/)
190-
* [Unit of Work - a Design Pattern - Mono](https://mono.software/2017/01/13/unit-of-work-a-design-pattern/)
187+
* [Repository and Unit of Work Pattern (Wolfgang Ofner)](https://www.programmingwithwolfgang.com/repository-and-unit-of-work-pattern/)
188+
* [Unit Of Work Design Pattern (Code Project)](https://www.codeproject.com/Articles/581487/Unit-of-Work-Design-Pattern)
189+
* [Unit of Work - a Design Pattern (Mono)](https://mono.software/2017/01/13/unit-of-work-a-design-pattern/)
191190

192191
## Known Uses
193192

@@ -219,5 +218,4 @@ Trade-offs:
219218
* [Domain-Driven Design: Tackling Complexity in the Heart of Software](https://amzn.to/3wlDrze)
220219
* [Java Persistence with Hibernate](https://amzn.to/44tP1ox)
221220
* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
222-
* [Unit Of Work Design Pattern - Code Project](https://www.codeproject.com/Articles/581487/Unit-of-Work-Design-Pattern)
223-
* [Unit Of Work - Martin Fowler](https://martinfowler.com/eaaCatalog/unitOfWork.html)
221+
* [Unit Of Work (Martin Fowler)](https://martinfowler.com/eaaCatalog/unitOfWork.html)

0 commit comments

Comments
 (0)