All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kenshoo.jooq.DeleteQueryBuilder Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
package com.kenshoo.jooq;

import com.google.common.collect.ImmutableList;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.impl.TableImpl;

import java.util.Collection;

/**
 * Provides a convenient (and MySQL-friendly) way of solving the use-case of deleting records by N identifiers.
 * The simplest case is deleting by a list of IDs in which case it could be expressed with a simple IN. However in
 * terms of performance (and logs) it's better to do a join with a temporary table populated with those IDs instead.
 * This class does it automatically.
 *
 * The returned object is a resource and it is crucial to place it inside try/finally block so it could be closed
 */
public class DeleteQueryBuilder {

    private final DSLContext dslContext;

    public DeleteQueryBuilder(DSLContext dslContext) {
        this.dslContext = dslContext;
    }

    public BuilderWith table(final TableImpl table) {

        return new BuilderWith() {
            @Override
            public  BuilderIn1 withCondition(final Field field) {
                return values -> new DeleteQueryExtension(table, ImmutableList.of(
                        new FieldAndValues<>(field, values)),
                        dslContext);
            }
        };
    }


    public interface BuilderWith {
         BuilderIn1 withCondition(Field field);
    }


    public interface BuilderIn1 {
        DeleteQueryExtension in(Collection values);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy