Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<module>currying</module>
<module>serialized-entity</module>
<module>identity-map</module>
<module>row-data-gateway</module>
<module>component</module>
<module>context-object</module>
<module>optimistic-offline-lock</module>
Expand All @@ -218,6 +219,7 @@
<module>function-composition</module>
<module>microservices-distributed-tracing</module>
<module>microservices-idempotent-consumer</module>
<module>row-data-gateway</module>
</modules>
<repositories>
<repository>
Expand Down
99 changes: 99 additions & 0 deletions row-data-gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

---
title: "Row Data Pattern: Ensuring Efficient Data Handling in Java"
shortTitle: Row Data
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."
category: Data Management
language: en
tag:
- Performance
- Data Processing
- Scalability
- Microservices
- Data Integrity
---

## Intent of Row Data Pattern

To manage large datasets efficiently and ensure row-level operations are optimized, reducing memory overhead in distributed systems.

## Detailed Explanation of Row Data Pattern

### Real-world example

> 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.

### In plain words

> The Row Data Pattern focuses on processing and managing individual rows of data efficiently, ensuring that large datasets are handled without compromising system performance.

## Programmatic Example of Row Data Pattern in Java

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.

**Snippet 1: Process Data Rows**

```java
public void processRows(List<RowData> rows) {
for (RowData row : rows) {
processRow(row);
}
}

private void processRow(RowData row) {
// Perform row-level operations such as validation or transformation
}
```

**Snippet 2: Handling Large Data Sets**

```java
public void handleLargeDataSet(List<RowData> largeDataSet) {
for (int i = 0; i < largeDataSet.size(); i++) {
processRow(largeDataSet.get(i));
}
}
```

### Key Components of Row Data Pattern

1. **Row**: Represents a single unit of data in a dataset. Operations are applied to individual rows, making it more memory efficient.
2. **Row Processor**: Handles the logic for processing or transforming the data in each row.
3. **Dataset**: A collection of rows that need to be processed or updated.

## When to Use the Row Data Pattern in Java

* When dealing with large datasets that need to be processed row by row.
* When memory optimization is a priority in handling large amounts of data.
* In systems that require efficient batch processing without overwhelming system resources.

## Real-World Applications of Row Data Pattern

* Financial systems processing individual transactions.
* Data analytics platforms handling large-scale data processing.
* Microservices managing row-level database operations for customer records.

## Benefits and Trade-offs of Row Data Pattern

Benefits:

* Memory-efficient when handling large datasets.
* Scalable for batch processing in distributed systems.

Trade-offs:

* Might introduce performance overhead for complex row operations.
* Requires careful management of row-level operations to ensure efficiency.

## Related Java Design Patterns

* [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.
* [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.

## References and Credits

* [Java Design Patterns](https://java-design-patterns.com/)
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3y6yv1z)
```

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/).
33 changes: 33 additions & 0 deletions row-data-gateway/etc/row data.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@startuml
package com.iluwatar.rowdata {
class UserGateway {
- rowdata : RowData
- connection : Connection
- logger : Logger
+ UserGateway(RowData rowData, Connection connection)
+ RowData read()
+ void insert()
+ void update()
+ void delete()
}

class RowData {
- int id
- String name
- int value
+ int getId()
+ String getName()
+ int getValue()
}

UserGateway --> RowData : "uses"


class App {
+ main(args : String[]) : void
}
App --> RowData : "uses"
App --> UserGateway : "uses"
}
}
@enduml
108 changes: 108 additions & 0 deletions row-data-gateway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).

The MIT License
Copyright ©️ 2014-2022 Ilkka Seppälä

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.26.0-SNAPSHOT</version>
</parent>
<artifactId>row-data-gateway</artifactId>
<dependencies>
<!-- Logging dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.12</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.36.0.3</version>
</dependency>

</dependencies>
<build>
<plugins>
<!-- Compiler plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source> <!-- Adjust to your Java version -->
<target>17</target>
</configuration>
</plugin>

<!-- Assembly plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>com.iluwatar.rowdata.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading