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 Table
R - the type of the jOOQ UpdatableRecord
ID - 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

    Fields
    Modifier and Type
    Field
    Description
    protected final org.jooq.DSLContext
    The DSLContext instance used for executing SQL queries and interacting with the database.
    protected final T
    The database table associated with this repository.
  • Constructor Summary

    Constructors
    Constructor
    Description
    JooqDAO(org.jooq.DSLContext dslContext, T table)
    Constructs a new JooqRepository with the specified DSLContext and table.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    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
    delete(org.jooq.Condition condition)
    Deletes records from the database that match the given condition.
    int
    delete(R record)
    Deletes the specified record from the database.
    int
    Deletes a record from the database identified by its primary key.
    findAll(int offset, int limit, List<org.jooq.OrderField<?>> orderBy)
    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.
    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.
    findAll(org.jooq.Condition condition, List<org.jooq.OrderField<?>> orderBy)
    Retrieves a list of records from the database with filtering, and sorting.
    Finds a record by its primary key.
    int
    merge(R record)
    Merges (INSERT … ON DUPLICATE KEY UPDATE) the given record into the database.
    int
    save(R record)
    Saves (INSERT or UPDATE) the given record to the database.
    int[]
    saveAll(List<R> records)
    Saves a list of records to the database using batch store operations.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • dslContext

      protected final org.jooq.DSLContext dslContext
      The DSLContext instance used for executing SQL queries and interacting with the database. It serves as the primary interface for jOOQ operations.
    • table

      protected final T extends org.jooq.Table<R> 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

      public JooqDAO(org.jooq.DSLContext dslContext, T table)
      Constructs a new JooqRepository with the specified DSLContext and table.
      Parameters:
      dslContext - the DSLContext to be used for database operations
      table - the table associated with this repository
  • Method Details

    • findById

      public Optional<R> findById(ID id)
      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

      public List<R> findAll(int offset, int limit, List<org.jooq.OrderField<?>> orderBy)
      Retrieves a list of records from the database with pagination and sorting.
      Parameters:
      offset - the starting position of the first record
      limit - the maximum number of records to retrieve
      orderBy - 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 by
      offset - the starting position of the first record
      limit - the maximum number of records to retrieve
      orderBy - 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)
      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

      public List<R> findAll(org.jooq.Condition condition, List<org.jooq.OrderField<?>> orderBy)
      Retrieves a list of records from the database with filtering, and sorting.
      Parameters:
      condition - the condition to filter the records by
      orderBy - 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

      @Transactional public int save(R record)
      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

      @Transactional public int[] saveAll(List<R> records)
      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

      @Transactional public int merge(R record)
      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

      @Transactional public int delete(R record)
      Deletes the specified record from the database.
      Parameters:
      record - the record to delete
      Returns:
      the number of affected rows
    • deleteById

      @Transactional public int deleteById(ID id)
      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