Skip to content

Commit 3229bac

Browse files
committed
Created the row data gateway design pattern
1 parent b375919 commit 3229bac

File tree

10 files changed

+785
-0
lines changed

10 files changed

+785
-0
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
<module>currying</module>
202202
<module>serialized-entity</module>
203203
<module>identity-map</module>
204+
<module>row-data-gateway</module>
204205
<module>component</module>
205206
<module>context-object</module>
206207
<module>optimistic-offline-lock</module>
@@ -218,6 +219,7 @@
218219
<module>function-composition</module>
219220
<module>microservices-distributed-tracing</module>
220221
<module>microservices-idempotent-consumer</module>
222+
<module>row-data-gateway</module>
221223
</modules>
222224
<repositories>
223225
<repository>

row-data-gateway/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
---
3+
title: "Row Data Pattern: Ensuring Efficient Data Handling in Java"
4+
shortTitle: Row Data
5+
description: "Explore the Row Data Pattern in Java for handling large sets of data efficiently and ensuring proper management of row-level operations in distributed systems."
6+
category: Data Management
7+
language: en
8+
tag:
9+
- Performance
10+
- Data Processing
11+
- Scalability
12+
- Microservices
13+
- Data Integrity
14+
---
15+
16+
## Intent of Row Data Pattern
17+
18+
To manage large datasets efficiently and ensure row-level operations are optimized, reducing memory overhead in distributed systems.
19+
20+
## Detailed Explanation of Row Data Pattern
21+
22+
### Real-world example
23+
24+
> Imagine a system that processes large batches of customer data. Each customer record is handled as a row in the database. With the Row Data Pattern, operations such as data validation, updates, or deletions are performed at the row level, ensuring minimal resource consumption and better scalability.
25+
26+
### In plain words
27+
28+
> The Row Data Pattern focuses on processing and managing individual rows of data efficiently, ensuring that large datasets are handled without compromising system performance.
29+
30+
## Programmatic Example of Row Data Pattern in Java
31+
32+
The Row Data Pattern can be implemented by iterating over each row in a dataset, performing necessary operations, and ensuring that each row is processed independently, allowing for better scalability.
33+
34+
**Snippet 1: Process Data Rows**
35+
36+
```java
37+
public void processRows(List<RowData> rows) {
38+
for (RowData row : rows) {
39+
processRow(row);
40+
}
41+
}
42+
43+
private void processRow(RowData row) {
44+
// Perform row-level operations such as validation or transformation
45+
}
46+
```
47+
48+
**Snippet 2: Handling Large Data Sets**
49+
50+
```java
51+
public void handleLargeDataSet(List<RowData> largeDataSet) {
52+
for (int i = 0; i < largeDataSet.size(); i++) {
53+
processRow(largeDataSet.get(i));
54+
}
55+
}
56+
```
57+
58+
### Key Components of Row Data Pattern
59+
60+
1. **Row**: Represents a single unit of data in a dataset. Operations are applied to individual rows, making it more memory efficient.
61+
2. **Row Processor**: Handles the logic for processing or transforming the data in each row.
62+
3. **Dataset**: A collection of rows that need to be processed or updated.
63+
64+
## When to Use the Row Data Pattern in Java
65+
66+
* When dealing with large datasets that need to be processed row by row.
67+
* When memory optimization is a priority in handling large amounts of data.
68+
* In systems that require efficient batch processing without overwhelming system resources.
69+
70+
## Real-World Applications of Row Data Pattern
71+
72+
* Financial systems processing individual transactions.
73+
* Data analytics platforms handling large-scale data processing.
74+
* Microservices managing row-level database operations for customer records.
75+
76+
## Benefits and Trade-offs of Row Data Pattern
77+
78+
Benefits:
79+
80+
* Memory-efficient when handling large datasets.
81+
* Scalable for batch processing in distributed systems.
82+
83+
Trade-offs:
84+
85+
* Might introduce performance overhead for complex row operations.
86+
* Requires careful management of row-level operations to ensure efficiency.
87+
88+
## Related Java Design Patterns
89+
90+
* [Iterator Pattern](https://java-design-patterns.com/patterns/iterator/): Used to iterate over collections, which complements the Row Data Pattern in handling individual data elements.
91+
* [Batch Processing](https://java-design-patterns.com/patterns/batch-processing/): A pattern for managing large batches of data, working well with Row Data for scalable data operations.
92+
93+
## References and Credits
94+
95+
* [Java Design Patterns](https://java-design-patterns.com/)
96+
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3y6yv1z)
97+
```
98+
99+
This README provides a high-level overview of the Row Data Pattern, illustrating how it optimizes large dataset handling, with sample Java code. For additional details, refer to [Java Design Patterns](https://java-design-patterns.com/).

row-data-gateway/etc/row data.puml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@startuml
2+
package com.iluwatar.rowdata {
3+
class UserGateway {
4+
- rowdata : RowData
5+
- connection : Connection
6+
- logger : Logger
7+
+ UserGateway(RowData rowData, Connection connection)
8+
+ RowData read()
9+
+ void insert()
10+
+ void update()
11+
+ void delete()
12+
}
13+
14+
class RowData {
15+
- int id
16+
- String name
17+
- int value
18+
+ int getId()
19+
+ String getName()
20+
+ int getValue()
21+
}
22+
23+
UserGateway --> RowData : "uses"
24+
25+
26+
class App {
27+
+ main(args : String[]) : void
28+
}
29+
App --> RowData : "uses"
30+
App --> UserGateway : "uses"
31+
}
32+
}
33+
@enduml

row-data-gateway/pom.xml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
4+
5+
The MIT License
6+
Copyright ©️ 2014-2022 Ilkka Seppälä
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.
25+
-->
26+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
<parent>
29+
<groupId>com.iluwatar</groupId>
30+
<artifactId>java-design-patterns</artifactId>
31+
<version>1.26.0-SNAPSHOT</version>
32+
</parent>
33+
<artifactId>row-data-gateway</artifactId>
34+
<dependencies>
35+
<!-- Logging dependencies -->
36+
<dependency>
37+
<groupId>org.slf4j</groupId>
38+
<artifactId>slf4j-api</artifactId>
39+
<version>1.7.36</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>ch.qos.logback</groupId>
43+
<artifactId>logback-classic</artifactId>
44+
<version>1.4.12</version>
45+
</dependency>
46+
<!-- Test dependencies -->
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-engine</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.mockito</groupId>
54+
<artifactId>mockito-core</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.xerial</groupId>
64+
<artifactId>sqlite-jdbc</artifactId>
65+
<version>3.36.0.3</version>
66+
</dependency>
67+
68+
</dependencies>
69+
<build>
70+
<plugins>
71+
<!-- Compiler plugin -->
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-compiler-plugin</artifactId>
75+
<version>3.10.1</version>
76+
<configuration>
77+
<source>17</source> <!-- Adjust to your Java version -->
78+
<target>17</target>
79+
</configuration>
80+
</plugin>
81+
82+
<!-- Assembly plugin -->
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-assembly-plugin</artifactId>
86+
<executions>
87+
<execution>
88+
<id>make-assembly</id>
89+
<phase>package</phase>
90+
<goals>
91+
<goal>single</goal>
92+
</goals>
93+
<configuration>
94+
<archive>
95+
<manifest>
96+
<mainClass>com.iluwatar.rowdata.App</mainClass>
97+
</manifest>
98+
</archive>
99+
<descriptorRefs>
100+
<descriptorRef>jar-with-dependencies</descriptorRef>
101+
</descriptorRefs>
102+
</configuration>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
</project>

0 commit comments

Comments
 (0)