diff --git a/README.md b/README.md index f7f8fbf..dffb8f5 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,53 @@ # jOOQ Spring Integration -**jooq-spring** is a small open-source library that provides integration of [jOOQ](https://www.jooq.org) with the [Spring Framework](https://spring.io/projects/spring-framework). -It follows the [DAO pattern](https://en.wikipedia.org/wiki/Data_access_object) and not the Repository pattern -because the Repository is a pttern +**jooq-spring** is a small open-source library that provides integration of [jOOQ](https://www.jooq.org) with +the [Spring Framework](https://spring.io/projects/spring-framework). -## Dependency +## Dependency Add a dependency to the current version: ```xml + ch.martinelli.oss jooq-spring - 0.1.0 + 0.2.0 ``` ## Components + ### JooqDAO -Checkout the code for documentation [JooqRepository](src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java) +The JooqDAO follows the [DAO pattern](https://en.wikipedia.org/wiki/Data_access_object) and not +the [Repository pattern](https://martinfowler.com/eaaCatalog/repository.html) because the Repository is a pattern from +Domain Driven Design (DDD). + +#### Methods + +| Return Type | Method | Description | +|---------------|------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------| +| `Optional` | `findById(ID id)` | Finds a record by its primary key. | +| `List` | `findAll(int offset, int limit, List> orderBy)` | Retrieves a list of records from the database with pagination and sorting. | +| `List` | `findAll(org.jooq.Condition condition, int offset, int limit, List> orderBy)` | Retrieves a list of records from the database with filtering, pagination, and sorting. | +| `List` | `findAll(org.jooq.Condition condition, List> orderBy)` | Retrieves a list of records from the database with filtering, and sorting. | +| `List` | `findAll(org.jooq.Condition condition)` | Retrieves a list of records from the database with filtering. | +| `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` | `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 { @@ -33,4 +58,6 @@ public class AthleteDAO extends JooqDAO { ``` ## License -**jooq-spring** is open and free software under Apache License, Version 2: http://www.apache.org/licenses/LICENSE-2.0.html + +**jooq-spring** is open and free software under Apache License, Version +2: http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/pom.xml b/pom.xml index 8725c84..4c44712 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ ch.martinelli.oss jooq-spring - 0.2.0 + 0.3.0 jOOQ Spring Integration Helpful utilities when using jOOQ with Spring diff --git a/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java b/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java index c85c64c..a35bed8 100644 --- a/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java +++ b/src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java @@ -95,6 +95,34 @@ public List findAll(Condition condition, int offset, int limit, List findAll(Condition condition) { + return dslContext + .selectFrom(table) + .where(condition) + .fetch(); + } + + /** + * Retrieves a list of records from the database with filtering, and sorting. + * + * @param condition the condition to filter the records by + * @param orderBy the list of fields to order the result set by + * @return a List containing the fetched records + */ + public List findAll(Condition condition, List> orderBy) { + return dslContext + .selectFrom(table) + .where(condition) + .orderBy(orderBy) + .fetch(); + } + /** * Counts the total number of records in the associated table. * @@ -115,7 +143,7 @@ public int count(Condition condition) { } /** - * Saves the given record to the database. Attaches the record to the + * Saves (INSERT or UPDATE) the given record to the database. Attaches the record to the * DSLContext and stores it. * * @param record the record to save @@ -128,7 +156,7 @@ public int save(R record) { } /** - * Merges the given record into the database. Attaches the record to the DSLContext + * Merges (INSERT … ON DUPLICATE KEY UPDATE) the given record into the database. Attaches the record to the DSLContext * and attempts to merge it. * * @param record the record to merge