Package org.jooq.impl

Class DAOImpl<R extends UpdatableRecord<R>,​P,​T>

  • All Implemented Interfaces:
    DAO<R,​P,​T>

    public abstract class DAOImpl<R extends UpdatableRecord<R>,​P,​T>
    extends java.lang.Object
    implements DAO<R,​P,​T>
    A common base implementation for generated DAO.

    Unlike many other elements in the jOOQ API, DAO may be used in the context of Spring, CDI, or EJB lifecycle management. This means that no methods in the DAO type hierarchy must be made final. See also https://github.com/jOOQ/ jOOQ/issues/4696 for more details.

    Author:
    Lukas Eder
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DAOImpl​(Table<R> table, java.lang.Class<P> type)  
      protected DAOImpl​(Table<R> table, java.lang.Class<P> type, Configuration configuration)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected T compositeKeyRecord​(java.lang.Object... values)  
      Configuration configuration()
      Expose the configuration in whose context this DAO is operating.
      long count()
      Count all records of the underlying table.
      void delete​(java.util.Collection<P> objects)
      Performs a DELETE statement for a given set of POJOs
      void delete​(P object)
      Performs a DELETE statement for a POJO
      void delete​(P... objects)
      Performs a DELETE statement for a given set of POJOs
      void deleteById​(java.util.Collection<T> ids)
      Performs a DELETE statement for a given set of IDs
      void deleteById​(T... ids)
      Performs a DELETE statement for a given set of IDs
      SQLDialect dialect()
      The SQLDialect wrapped by this context.
      boolean exists​(P object)
      Checks if a given POJO exists
      boolean existsById​(T id)
      Checks if a given ID exists
      SQLDialect family()
      The SQLDialect.family() wrapped by this context.
      <Z> java.util.List<P> fetch​(Field<Z> field, Z... values)
      Find records by a given field and a set of values.
      <Z> P fetchOne​(Field<Z> field, Z value)
      Find a unique record by a given field and a value.
      <Z> java.util.Optional<P> fetchOptional​(Field<Z> field, Z value)
      Find a unique record by a given field and a value.
      <Z> java.util.List<P> fetchRange​(Field<Z> field, Z lowerInclusive, Z upperInclusive)
      Find records by a given field and a range of values.
      java.util.List<P> findAll()
      Find all records of the underlying table.
      P findById​(T id)
      Find a record of the underlying table by ID.
      Table<R> getTable()
      Get the underlying table.
      java.lang.Class<P> getType()
      Get the underlying POJO type.
      void insert​(java.util.Collection<P> objects)
      Performs a batch INSERT statement for a given set of POJOs
      void insert​(P object)
      Performs an INSERT statement for a given POJO
      void insert​(P... objects)
      Performs a batch INSERT statement for a given set of POJOs
      RecordMapper<R,​P> mapper()
      Expose the RecordMapper that is used internally by this DAO to map from records of type R to POJOs of type P.
      void setConfiguration​(Configuration configuration)
      Inject a configuration.
      Settings settings()
      The settings wrapped by this context.
      void update​(java.util.Collection<P> objects)
      Performs a batch UPDATE statement for a given set of POJOs
      void update​(P object)
      Performs an UPDATE statement for a given POJO
      void update​(P... objects)
      Performs a batch UPDATE statement for a given set of POJOs
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.jooq.DAO

        getId
    • Constructor Detail

      • DAOImpl

        protected DAOImpl​(Table<R> table,
                          java.lang.Class<P> type)
      • DAOImpl

        protected DAOImpl​(Table<R> table,
                          java.lang.Class<P> type,
                          Configuration configuration)
    • Method Detail

      • setConfiguration

        public void setConfiguration​(Configuration configuration)
        Inject a configuration.

        This method is maintained to be able to configure a DAO using Spring. It is not exposed in the public API.

      • configuration

        public Configuration configuration()
        Description copied from interface: DAO
        Expose the configuration in whose context this DAO is operating.
        Specified by:
        configuration in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        the DAO's underlying Configuration
      • settings

        public Settings settings()
        Description copied from interface: DAO
        The settings wrapped by this context.

        This method is a convenient way of accessing configuration().settings().

        Specified by:
        settings in interface DAO<R extends UpdatableRecord<R>,​P,​T>
      • dialect

        public SQLDialect dialect()
        Description copied from interface: DAO
        The SQLDialect wrapped by this context.

        This method is a convenient way of accessing configuration().dialect().

        Specified by:
        dialect in interface DAO<R extends UpdatableRecord<R>,​P,​T>
      • mapper

        public RecordMapper<R,​P> mapper()
        Expose the RecordMapper that is used internally by this DAO to map from records of type R to POJOs of type P.

        Subclasses may override this method to provide custom implementations.

        Specified by:
        mapper in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        the DAO's underlying RecordMapper
      • insert

        public void insert​(P object)
        Description copied from interface: DAO
        Performs an INSERT statement for a given POJO
        Specified by:
        insert in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be inserted
      • insert

        public void insert​(P... objects)
        Description copied from interface: DAO
        Performs a batch INSERT statement for a given set of POJOs
        Specified by:
        insert in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be inserted
        See Also:
        DAO.insert(Collection)
      • insert

        public void insert​(java.util.Collection<P> objects)
        Description copied from interface: DAO
        Performs a batch INSERT statement for a given set of POJOs
        Specified by:
        insert in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be inserted
        See Also:
        DAO.insert(Object...)
      • update

        public void update​(P object)
        Description copied from interface: DAO
        Performs an UPDATE statement for a given POJO
        Specified by:
        update in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be updated
      • update

        public void update​(P... objects)
        Description copied from interface: DAO
        Performs a batch UPDATE statement for a given set of POJOs
        Specified by:
        update in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be updated
        See Also:
        DAO.update(Collection)
      • update

        public void update​(java.util.Collection<P> objects)
        Description copied from interface: DAO
        Performs a batch UPDATE statement for a given set of POJOs
        Specified by:
        update in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be updated
        See Also:
        DAO.update(Object...)
      • delete

        public void delete​(P object)
        Description copied from interface: DAO
        Performs a DELETE statement for a POJO
        Specified by:
        delete in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be deleted
        See Also:
        DAO.delete(Collection)
      • delete

        public void delete​(P... objects)
        Description copied from interface: DAO
        Performs a DELETE statement for a given set of POJOs
        Specified by:
        delete in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be deleted
        See Also:
        DAO.delete(Collection)
      • delete

        public void delete​(java.util.Collection<P> objects)
        Description copied from interface: DAO
        Performs a DELETE statement for a given set of POJOs
        Specified by:
        delete in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be deleted
        See Also:
        DAO.delete(Object...)
      • deleteById

        public void deleteById​(T... ids)
        Description copied from interface: DAO
        Performs a DELETE statement for a given set of IDs
        Specified by:
        deleteById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        ids - The IDs to be deleted
        See Also:
        DAO.delete(Collection)
      • deleteById

        public void deleteById​(java.util.Collection<T> ids)
        Description copied from interface: DAO
        Performs a DELETE statement for a given set of IDs
        Specified by:
        deleteById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        ids - The IDs to be deleted
        See Also:
        DAO.delete(Object...)
      • exists

        public boolean exists​(P object)
        Description copied from interface: DAO
        Checks if a given POJO exists
        Specified by:
        exists in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO whose existence is checked
        Returns:
        Whether the POJO already exists
      • existsById

        public boolean existsById​(T id)
        Description copied from interface: DAO
        Checks if a given ID exists
        Specified by:
        existsById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        id - The ID whose existence is checked
        Returns:
        Whether the ID already exists
      • count

        public long count()
        Description copied from interface: DAO
        Count all records of the underlying table.
        Specified by:
        count in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        The number of records of the underlying table
      • findAll

        public java.util.List<P> findAll()
        Description copied from interface: DAO
        Find all records of the underlying table.
        Specified by:
        findAll in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        All records of the underlying table
      • findById

        public P findById​(T id)
        Description copied from interface: DAO
        Find a record of the underlying table by ID.
        Specified by:
        findById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        id - The ID of a record in the underlying table
        Returns:
        A record of the underlying table given its ID, or null if no record was found.
      • fetchRange

        public <Z> java.util.List<P> fetchRange​(Field<Z> field,
                                                Z lowerInclusive,
                                                Z upperInclusive)
        Description copied from interface: DAO
        Find records by a given field and a range of values.
        Specified by:
        fetchRange in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare values against
        lowerInclusive - The range's lower bound (inclusive), or unbounded if null.
        upperInclusive - The range's upper bound (inclusive), or unbounded if null.
        Returns:
        A list of records fulfilling field BETWEEN lowerInclusive AND upperInclusive
      • fetch

        public <Z> java.util.List<P> fetch​(Field<Z> field,
                                           Z... values)
        Description copied from interface: DAO
        Find records by a given field and a set of values.
        Specified by:
        fetch in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare values against
        values - The accepted values
        Returns:
        A list of records fulfilling field IN (values)
      • fetchOne

        public <Z> P fetchOne​(Field<Z> field,
                              Z value)
        Description copied from interface: DAO
        Find a unique record by a given field and a value.
        Specified by:
        fetchOne in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare value against
        value - The accepted value
        Returns:
        A record fulfilling field = value, or null
      • fetchOptional

        public <Z> java.util.Optional<P> fetchOptional​(Field<Z> field,
                                                       Z value)
        Description copied from interface: DAO
        Find a unique record by a given field and a value.
        Specified by:
        fetchOptional in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare value against
        value - The accepted value
        Returns:
        A record fulfilling field = value
      • getType

        public java.lang.Class<P> getType()
        Description copied from interface: DAO
        Get the underlying POJO type.
        Specified by:
        getType in interface DAO<R extends UpdatableRecord<R>,​P,​T>
      • compositeKeyRecord

        protected T compositeKeyRecord​(java.lang.Object... values)