Package ch.martinelli.oss.jooqspring
Class JooqDAO<T extends org.jooq.Table<R>,R extends org.jooq.UpdatableRecord<R>,ID>
java.lang.Object
ch.martinelli.oss.jooqspring.JooqDAO<T,R,ID>
- Type Parameters:
T- the type of the jOOQ TableR- the type of the jOOQ UpdatableRecordID- the type of the primary key
@Transactional(readOnly=true)
public abstract class JooqDAO<T extends org.jooq.Table<R>,R extends org.jooq.UpdatableRecord<R>,ID>
extends Object
Abstract DAO class for CRUD operations using jOOQ.
DAO on Wikipedia
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.jooq.DSLContextThe DSLContext instance used for executing SQL queries and interacting with the database.protected final TThe database table associated with this repository. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcount()Counts the total number of records in the associated table.intcount(org.jooq.Condition condition) Counts the number of records in the associated table that match the given condition.intdelete(org.jooq.Condition condition) Deletes records from the database that match the given condition.intDeletes the specified record from the database.intdeleteById(ID id) Deletes a record from the database identified by its primary key.Retrieves a list of records from the database with pagination and sorting.findAll(org.jooq.Condition condition) Retrieves a list of records from the database with filtering.Retrieves a list of records from the database with filtering, pagination, and sorting.Retrieves a list of records from the database with filtering, and sorting.Finds a record by its primary key.intMerges (INSERT … ON DUPLICATE KEY UPDATE) the given record into the database.intSaves (INSERT or UPDATE) the given record to the database.int[]Saves a list of records to the database using batch store operations.
-
Field Details
-
dslContext
protected final org.jooq.DSLContext dslContextThe DSLContext instance used for executing SQL queries and interacting with the database. It serves as the primary interface for jOOQ operations. -
table
The database table associated with this repository. Represents the specific table in the database that this repository interacts with. Used for performing CRUD operations.
-
-
Constructor Details
-
JooqDAO
Constructs a new JooqRepository with the specified DSLContext and table.- Parameters:
dslContext- the DSLContext to be used for database operationstable- the table associated with this repository
-
-
Method Details
-
findById
Finds a record by its primary key.- Parameters:
id- the primary key value of the record to find- Returns:
- an Optional containing the found record, or empty if no record was found
- Throws:
IllegalArgumentException- if the table does not have a primary key
-
findAll
Retrieves a list of records from the database with pagination and sorting.- Parameters:
offset- the starting position of the first recordlimit- the maximum number of records to retrieveorderBy- the list of fields to order the result set by- Returns:
- a List containing the fetched records
-
findAll
public 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.- Parameters:
condition- the condition to filter the records byoffset- the starting position of the first recordlimit- the maximum number of records to retrieveorderBy- the list of fields to order the result set by- Returns:
- a List containing the fetched records
-
findAll
Retrieves a list of records from the database with filtering.- Parameters:
condition- the condition to filter the records by- Returns:
- a List containing the fetched records
-
findAll
Retrieves a list of records from the database with filtering, and sorting.- Parameters:
condition- the condition to filter the records byorderBy- the list of fields to order the result set by- Returns:
- a List containing the fetched records
-
count
public int count()Counts the total number of records in the associated table.- Returns:
- the total number of records in the table
-
count
public int count(org.jooq.Condition condition) Counts the number of records in the associated table that match the given condition.- Parameters:
condition- the condition to filter the records by- Returns:
- the number of matching records
-
save
Saves (INSERT or UPDATE) the given record to the database. Attaches the record to the DSLContext and stores it.- Parameters:
record- the record to save- Returns:
- the number of affected rows
-
saveAll
Saves a list of records to the database using batch store operations.- Parameters:
records- the list of records to be saved- Returns:
- an array containing the number of affected rows for each batch operation
-
merge
Merges (INSERT … ON DUPLICATE KEY UPDATE) the given record into the database. Attaches the record to the DSLContext and attempts to merge it.- Parameters:
record- the record to merge- Returns:
- the number of affected rows
-
delete
Deletes the specified record from the database.- Parameters:
record- the record to delete- Returns:
- the number of affected rows
-
deleteById
Deletes a record from the database identified by its primary key.- Parameters:
id- the primary key value of the record to delete- Returns:
- the number of affected rows
- Throws:
IllegalArgumentException- if the table does not have a primary key
-
delete
@Transactional public int delete(org.jooq.Condition condition) Deletes records from the database that match the given condition.- Parameters:
condition- the condition to filter which records to delete- Returns:
- the number of affected rows
-