From a83ec94aaa7639234922edf14e60d21340ebc622 Mon Sep 17 00:00:00 2001 From: Simon Martinelli Date: Tue, 5 Nov 2024 18:35:35 +0100 Subject: [PATCH 1/2] #12: Implement saveAll --- .../java/ch/martinelli/oss/jooqspring/JooqDAO.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java b/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java index a35bed8..2fef62f 100644 --- a/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java +++ b/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java @@ -155,6 +155,17 @@ public int save(R record) { return record.store(); } + /** + * Saves a list of records to the database using batch store operations. + * + * @param records the list of records to be saved + * @return an array containing the number of affected rows for each batch operation + */ + @Transactional + public int[] saveAll(List records) { + return dslContext.batchStore(records).execute(); + } + /** * Merges (INSERT … ON DUPLICATE KEY UPDATE) the given record into the database. Attaches the record to the DSLContext * and attempts to merge it. From b6c5659cd92bcde3282b37ee12db95f47d812967 Mon Sep 17 00:00:00 2001 From: Simon Martinelli Date: Tue, 5 Nov 2024 18:40:10 +0100 Subject: [PATCH 2/2] #12: Add saveAll to list of methods. Fixes typo --- README.md | 30 +++++++++++++++--------------- pom.xml | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 55c0b02..6102dc9 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,19 @@ The JooqDAO follows the [DAO pattern](https://en.wikipedia.org/wiki/Data_access_ the [Repository pattern](https://martinfowler.com/eaaCatalog/repository.html) because the Repository is a pattern from Domain Driven Design (DDD). +#### Usage + +```java + +@Component +public class AthleteDAO extends JooqDAO { + + public AthleteDAO(DSLContext dslContext) { + super(dslContext, ATHLETE); + } +} +``` + #### Methods | Return Type | Method | Description | @@ -36,26 +49,13 @@ Domain Driven Design (DDD). | `int` | `count()` | Counts the total number of records in the associated table. | | `int` | `count(org.jooq.Condition condition)` | Counts the number of records in the associated table that match the given condition. | | `int` | `save(R record)` | Saves the given record to the database. | +| `int[]` | `saveAll(List record)` | Saves a list of records to the database using batch store operations. | | `int` | `merge(R record)` | Merges the given record into the database. | | `int` | `deleteById(ID id)` | Deletes a record from the database identified by its primary key. | | `int` | `delete(R record)` | Deletes the specified record from the database. | | `int` | `delete(org.jooq.Condition condition)` | Deletes records from the database that match the given condition. | -Checkout the code for documentation for further -information [JooqDAO](src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java). - -#### Usage - -```java - -@Component -public class AthleteDAO extends JooqDAO { - - public AthleteDAO(DSLContext dslContext) { - super(dslContext, ATHLETE); - } -} -``` +Check out the code documentation for further information [JooqDAO](src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java). ## License diff --git a/pom.xml b/pom.xml index d348f72..b1a6b6d 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,7 @@ scm:git:git@github.com:martinellich/jooq-spring.git scm:git:git@github.com:martinellich/jooq-spring.git - git@github.com:maritnellich/jooq-spring.git + git@github.com:martinellich/jooq-spring.git