Class WingsJooqDaoAliasImpl

  • All Implemented Interfaces:
    org.jooq.DAO

    
    public abstract class WingsJooqDaoAliasImpl<T extends Table<R>, WingsAliasTable<T>, R extends UpdatableRecord<R>, P, K>
    extends DAOImpl<R, P, T>
                        
    In principle, the database information carried by Record should not be spread,
    so it's recommended to use Pojo instead of Record outside of Dao.
    
    For read method, it always returns Pojo; for write method, it supports both Record and Pojo.
    For the convenience of coding and to reduce data copying, you can use Record for operation.
    In batch processing, new Record is always used to improve performance.
    
    Note that alias is used in multi-table query, filed/condition and table must have the same name,
    otherwise there will be a syntax error. I.e., fields that are in different alias from the table.
    
    Since:

    2019-10-12

    Author:

    trydofor

    • Constructor Detail

    • Method Detail

      • ctx

        @NotNull() DSLContext ctx()
      • setDslContext

         void setDslContext(@Nullable() Supplier<DSLContext> sup)

        set/remove dsl Supplier to current instance, e.g. mocking DSL. if Supplier or its result is null, return the original Dsl.

        Parameters:
        sup - to supply Dsl.
      • setTableExist

         void setTableExist(@MagicConstant(intValues = {"-1", 0, 1}) int type)

        -N:Unchecked | 0:Not exist | 1:Exists

        Parameters:
        type - -1|0|1
      • notTableExist

         boolean notTableExist()

        Use `SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=? AND TABLE_SCHEMA=SCHEMA()` to check the table existence in the current database.

        Returns:

        Whether not exist

      • newTable

        @NotNull() T newTable(String name)

        Create a new table with the same table structure. Used in sharding table, shadow table scenario

        Parameters:
        name - new table name
        Returns:

        new table

      • newTable

        @NotNull() T newTable(String prefix, String postfix)

        Based on the current table name, add prefixes, suffixes

      • getAlias

        @NotNull() T getAlias()

        Get the system default table alias.

      • newRecord

        @NotNull() R newRecord(Object obj)

        Create new Record by object mapping.

        Parameters:
        obj - object with some mapping rules.
        Returns:

        record

      • newRecord

        @NotNull() List<R> newRecord(Collection<P> pos)

        Create a list of records by pojo, usually used in batch.

        Parameters:
        pos - pojos
        Returns:

        list of record

      • batchLoad

        @NotNull() Loader<R> batchLoad(Collection<R> records, boolean ignoreOrReplace)
        Batch load records at once, and ignore/update on duplicate.
        ignore - check by `from dual where exists select * where `id` = ?` first,
        replace - use on duplicate key update statement
        
        Parameters:
        records - all record
        ignoreOrReplace - ignore or update on duplicate
        Returns:

        result, should use ModifyAssert to check

      • insertInto

         int insertInto(P pojo, boolean ignoreOrReplace)

        Insert Pojo, use mysql `insert ignore` or `replace into`, Note jooq mergeInto must all have values, and replace won't.

        Parameters:
        pojo - pojo
        ignoreOrReplace - ignore or update on duplicate
        Returns:

        result, should use ModifyAssert to check

      • diffInsert

        @NotNull() JournalDiff diffInsert(P pojo)

        Insert Pojo with ignoreOrReplace=false, and return the diff.

      • diffInsert

        @NotNull() JournalDiff diffInsert(P pojo, boolean ignoreOrReplace)

        Insert Pojo and return the diff.

      • insertInto

         Array<int> insertInto(Collection<P> pos, boolean ignoreOrReplace)

        batchInsert syntax sugar

        Parameters:
        pos - pojo records
        ignoreOrReplace - ignore or replace if DuplicateKey
        Returns:

        array of affected records, can use ModifyAssert to check

      • mergeInto

         int mergeInto(T table, P pojo, Array<Field<out Object>> updateFields)

        insert one record by insert into DuplicateKey update.

        Parameters:
        table - table with the same name as updateFields
        pojo - pojo record
        updateFields - fields to update if Duplicate Key, should not use table alias
        Returns:

        affected records, can use ModifyAssert to check

      • batchMerge

         Array<int> batchMerge(T table, Collection<R> records, int size, Array<Field<out Object>> updateFields)

        Select first, then insert or update depending on whether record exists.

        Parameters:
        table - table with the same name as updateFields
        records - collection of record
        size - batch size, <=0 mean no batching
        updateFields - fields to update if Duplicate Key, should not use table alias
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchMerge

         Array<int> batchMerge(T table, Array<Field<out Object>> keys, Collection<R> records, int size, Array<Field<out Object>> updateFields)

        Use this method if there are no unique constraints in the db. (1) batch SELECT based on KEYS first, (2) INSERT or UPDATE based on the records. String comparison ignores case

        Parameters:
        table - table with the same name as updateFields
        keys - keys of Duplicate Key
        records - collection of record
        size - batch size, <=0 mean no batching
        updateFields - fields to update if Duplicate Key, should not use table alias
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchMerge

         Array<int> batchMerge(T table, Array<Field<out Object>> keys, BiPredicate<Object, Object> equals, Collection<R> records, int size, Array<Field<out Object>> updateFields)

        Use this method if there are no unique constraints in the db. (1) batch SELECT based on KEYS first, (2) INSERT or UPDATE based on the records.

        Parameters:
        table - table with the same name as updateFields
        keys - keys of Duplicate Key
        equals - predicate of equals
        records - collection of record
        size - batch size, <=0 mean no batching
        updateFields - fields to update if Duplicate Key, should not use table alias
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchInsert

         Array<int> batchInsert(Collection<R> records, int size, boolean ignoreOrReplace)

        Batch insert records, use mysql's `insert ignore` or `replace into`. Note that jooq mergeInto is not perfect, requires both to have values, while `replace` does not.

        Parameters:
        records - collection of record
        size - batch size, <=0 mean no batching
        ignoreOrReplace - ignore or replace if Duplicate Key
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchInsert

         Array<int> batchInsert(Collection<R> records, int size)

        Batch insert records

        Parameters:
        records - collection of record
        size - batch size, <=0 mean no batching
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchStore

         Array<int> batchStore(Collection<R> records, int size)

        Batch store (insert/update) record.

        Parameters:
        records - collection of record
        size - batch size, <=0 mean no batching
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchUpdate

         Array<int> batchUpdate(T table, Array<Field<out Object>> whereFields, Collection<R> records, int size, Array<Field<out Object>> updateFields)

        Batch update record.

        Parameters:
        table - table with the same name as updateFields
        whereFields - where condition fields
        records - collection of record
        size - batch size, <=0 mean no batching
        updateFields - fields to update
        Returns:

        array of affected records, can use ModifyAssert to check

      • batchUpdate

         Array<int> batchUpdate(Collection<R> records, int size)

        Batch update record.

        Parameters:
        records - collection of record
        size - batch size, <=0 mean no batching
        Returns:

        array of affected records, can use ModifyAssert to check

      • fetch

        @NotNull() List<P> fetch(T table, Condition cond)
      • fetch

        @NotNull() List<P> fetch(T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int limit, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int offset, int limit, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int offset, int limit, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int limit, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int limit, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int offset, int limit, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() List<P> fetch(T table, int offset, int limit, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(Class<E> claz, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(Class<E> claz, int offset, int limit, T table, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(Class<E> claz, int limit, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(Class<E> claz, int offset, int limit, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(Class<E> claz, int offset, int limit, T table, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, T table, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, T table, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, T table, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int limit, T table, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int limit, T table, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int offset, int limit, T table, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int offset, int limit, T table, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int limit, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int limit, T table, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int offset, int limit, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int offset, int limit, T table, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetch

        @NotNull() <E> List<E> fetch(RecordMapper<in Record, E> mapper, int offset, int limit, T table, Condition cond, Collection<out SelectFieldOrAsterisk> selects, Collection<out OrderField<out Object>> orderBy)
      • fetchOne

        @Nullable() P fetchOne(T table, Array<QueryPart> selectsOrders)
      • fetchOne

         P fetchOne(T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetchLimitOne

        @Nullable() P fetchLimitOne(T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetchOne

        @Nullable() <E> E fetchOne(RecordMapper<in Record, E> mapper, T table, Array<QueryPart> selectsOrders)
      • fetchOne

        @Nullable() <E> E fetchOne(RecordMapper<in Record, E> mapper, T table, Collection<out QueryPart> selectsOrders)
      • fetchLimitOne

        @Nullable() <E> E fetchLimitOne(RecordMapper<in Record, E> mapper, T table, Array<QueryPart> selectsOrders)
      • fetchLimitOne

        @Nullable() <E> E fetchLimitOne(RecordMapper<in Record, E> mapper, T table, Collection<out QueryPart> selectsOrders)
      • fetchOne

         <E> E fetchOne(RecordMapper<in Record, E> mapper, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetchOne

         <E> E fetchOne(RecordMapper<in Record, E> mapper, T table, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetchLimitOne

        @Nullable() <E> E fetchLimitOne(RecordMapper<in Record, E> mapper, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetchLimitOne

        @Nullable() <E> E fetchLimitOne(RecordMapper<in Record, E> mapper, T table, Condition cond, Collection<out QueryPart> selectsOrders)
      • fetchOptional

        @NotNull() <E> Optional<E> fetchOptional(RecordMapper<in Record, E> mapper, T table, Condition cond, Array<QueryPart> selectsOrders)
      • fetchOne

        @Nullable() <E> E fetchOne(RecordMapper<in Record, E> mapper, T table, Condition cond, Collection<out SelectFieldOrAsterisk> selects, Collection<out OrderField<out Object>> orderBy, boolean limit)
      • delete

         int delete(T table, Condition cond)

        Delete by condition

        Parameters:
        table - the table
        cond - where condition
        Returns:

        affected records

      • diffDelete

        @NotNull() JournalDiff diffDelete(T table, Condition cond)

        Delete a record and get the Diff

      • diffUpdate

        @NotNull() JournalDiff diffUpdate(T table, Map<Field<out Object>, out Object> setter, Condition cond)

        Update a record and get the Diff

      • update

         int update(T table, Map<out Object, out Object> setter, Condition cond, boolean skipNull)
        Keys can either be of type String, Name, or Field.
        Values can either be of type or Field
        Parameters:
        table - table with the same name as condition/setter
        setter - update key and value
        cond - condition
        skipNull - whether skip `null` values, true requires map to be editable.
        Returns:

        affected records

      • update

         int update(T table, P pojo, Condition cond)
      • update

         int update(T table, P pojo, Condition cond, boolean skipNull)

        Update record by pojo key and value, skip null.

        Parameters:
        table - table with the same name as condition
        pojo - pojo
        cond - condition
        Returns:

        affected records

      • update

         int update(P pojo, boolean skipNull)

        Update record by pojo key and value, by PK

        Parameters:
        pojo - pojo
        skipNull - whether skip `null` values
        Returns:

        affected records

      • update

         Array<int> update(Collection<P> pojos, boolean skipNull)

        Update record by pojo key and value, by PK

        Parameters:
        pojos - pojos
        skipNull - whether skip `null` values
        Returns:

        array of affected records

      • count

         long count(T table, Condition cond)

        count table by condition, requires table with the same name as condition