Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
simasch committed Nov 5, 2024
2 parents 305e31b + c7f233e commit 370ed5d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<dependency>
<groupId>ch.martinelli.oss</groupId>
<artifactId>jooq-spring</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
</dependency>
```

## 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<R>` | `findById(ID id)` | Finds a record by its primary key. |
| `List<R>` | `findAll(int offset, int limit, List<org.jooq.OrderField<?>> orderBy)` | Retrieves a list of records from the database with pagination and sorting. |
| `List<R>` | `findAll(org.jooq.Condition condition, int offset, int limit, List<org.jooq.OrderField<?>> orderBy)` | Retrieves a list of records from the database with filtering, pagination, and sorting. |
| `List<R>` | `findAll(org.jooq.Condition condition, List<org.jooq.OrderField<?>> orderBy)` | Retrieves a list of records from the database with filtering, and sorting. |
| `List<R>` | `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<Athlete, AthleteRecord, Long> {

Expand All @@ -33,4 +58,6 @@ public class AthleteDAO extends JooqDAO<Athlete, AthleteRecord, Long> {
```

## 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ch.martinelli.oss</groupId>
<artifactId>jooq-spring</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>

<name>jOOQ Spring Integration</name>
<description>Helpful utilities when using jOOQ with Spring</description>
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/ch/martinelli/oss/jooqspring/JooqDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ public List<R> findAll(Condition condition, int offset, int limit, List<OrderFie
.fetch();
}

/**
* Retrieves a list of records from the database with filtering.
*
* @param condition the condition to filter the records by
* @return a List containing the fetched records
*/
public List<R> 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<R> findAll(Condition condition, List<OrderField<?>> orderBy) {
return dslContext
.selectFrom(table)
.where(condition)
.orderBy(orderBy)
.fetch();
}

/**
* Counts the total number of records in the associated table.
*
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 370ed5d

Please sign in to comment.