mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 10:18:39 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
1 parent
cb946c0cdc
commit
6cd2d0353a
219 files changed
+3308
-2819
No files matched your search
+19
-17
@@ -1,23 +1,25 @@
|
||||
---
|
||||
title: Unit Of Work
|
||||
title: "Unit of Work Pattern in Java: Orchestrating Efficient Transaction Management"
|
||||
shortTitle: Unit of Work
|
||||
description: "Discover how the Unit of Work pattern can streamline your Java applications. This guide offers a comprehensive explanation, real-world applications, and code examples to enhance your project’s efficiency and maintain data integrity."
|
||||
category: Data access
|
||||
language: en
|
||||
tag:
|
||||
- Data access
|
||||
- Decoupling
|
||||
- Persistence
|
||||
- Transactions
|
||||
- Data access
|
||||
- Decoupling
|
||||
- Persistence
|
||||
- Transactions
|
||||
---
|
||||
|
||||
## Intent
|
||||
## Intent of Unit Of Work Design Pattern
|
||||
|
||||
The Unit of Work pattern maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
|
||||
Learn how the Java Unit of Work pattern expertly manages and maintains a list of objects impacted by business transactions, coordinating database changes and solving concurrency issues effectively.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Unit Of Work Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
> Imagine a library where a librarian tracks all the books that are borrowed and returned throughout the day. Instead of updating the library's inventory system every time a single transaction occurs, the librarian keeps a list of all the changes and updates the system once at the end of the day. This approach ensures that all changes are processed together, maintaining the integrity of the inventory and reducing the number of individual updates needed. This is analogous to the Unit of Work pattern in software, where all changes to a set of objects are tracked and committed as a single transaction to maintain consistency and efficiency.
|
||||
> Consider a library scenario where a librarian meticulously tracks all books borrowed and returned, utilizing the Unit of Work design pattern to update the inventory system efficiently. Instead of updating the library's inventory system every time a single transaction occurs, the librarian keeps a list of all the changes and updates the system once at the end of the day. This approach ensures that all changes are processed together, maintaining the integrity of the inventory and reducing the number of individual updates needed. This is analogous to the Unit of Work pattern in software, where all changes to a set of objects are tracked and committed as a single transaction to maintain consistency and efficiency.
|
||||
|
||||
In plain words
|
||||
|
||||
@@ -27,7 +29,7 @@ In plain words
|
||||
|
||||
> Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
|
||||
|
||||
**Programmatic Example**
|
||||
## Programmatic Example of Unit of Work Pattern in Java
|
||||
|
||||
Arms dealer has a database containing weapon information. Merchants all over the town are constantly updating this information causing a 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.
|
||||
|
||||
@@ -176,25 +178,25 @@ Here is the console output.
|
||||
21:39:21.989 [main] INFO com.iluwatar.unitofwork.ArmsDealer - Commit finished.
|
||||
```
|
||||
|
||||
## Applicability
|
||||
## When to Use the Unit Of Work Pattern in Java
|
||||
|
||||
* Use when you need to manage multiple operations that need to be treated as a single transaction.
|
||||
* he Unit of Work pattern is ideal for managing multiple database operations in Java that must be executed as a single transaction, ensuring data consistency and integrity.
|
||||
* Ideal in scenarios where changes to the business objects must be tracked and saved in a coordinated manner.
|
||||
* Useful when working with object-relational mapping (ORM) frameworks in Java such as Hibernate.
|
||||
|
||||
## Tutorials
|
||||
## Unit Of Work Pattern Java Tutorials
|
||||
|
||||
* [Repository and Unit of Work Pattern (Wolfgang Ofner)](https://www.programmingwithwolfgang.com/repository-and-unit-of-work-pattern/)
|
||||
* [Unit Of Work Design Pattern (Code Project)](https://www.codeproject.com/Articles/581487/Unit-of-Work-Design-Pattern)
|
||||
* [Unit of Work - a Design Pattern (Mono)](https://mono.software/2017/01/13/unit-of-work-a-design-pattern/)
|
||||
|
||||
## Known Uses
|
||||
## Real-World Applications of Unit of Work Pattern in Java
|
||||
|
||||
* Implementations in Java-based ORM frameworks like Hibernate.
|
||||
* Enterprise applications where multiple database operations need to be atomic.
|
||||
* Complex transactional systems where multiple objects are modified and persisted together.
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Unit Of Work Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
@@ -207,13 +209,13 @@ Trade-offs:
|
||||
* Can introduce complexity in managing the life cycle of objects within the unit of work.
|
||||
* Potential performance overhead if not managed properly, especially with large datasets.
|
||||
|
||||
## Related Patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Identity Map](https://java-design-patterns.com/patterns/identity-map/): Helps to ensure that each object is only loaded once per transaction, reducing redundancy and improving performance.
|
||||
* [Repository](https://java-design-patterns.com/patterns/repository/): Often used in conjunction with Unit of Work to abstract the persistence logic and provide a cleaner way to access data.
|
||||
* [Transaction Script](https://java-design-patterns.com/patterns/transaction-script/): While different in its procedural approach, it can complement Unit of Work by managing transactional logic at a higher level.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Domain-Driven Design: Tackling Complexity in the Heart of Software](https://amzn.to/3wlDrze)
|
||||
* [Java Persistence with Hibernate](https://amzn.to/44tP1ox)
|
||||
|
||||
Reference in new issue
Block a user