org.babyfish.jimmer.sql.ast.query.ConfigurableRootQuery Maven / Gradle / Ivy
Show all versions of jimmer-sql Show documentation
package org.babyfish.jimmer.sql.ast.query;
import org.babyfish.jimmer.Page;
import org.babyfish.jimmer.lang.NewChain;
import org.babyfish.jimmer.sql.ast.Expression;
import org.babyfish.jimmer.sql.ast.table.Table;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.Connection;
import java.util.function.BiFunction;
public interface ConfigurableRootQuery, R> extends TypedRootQuery {
/**
* Ignore the sorting and pagination settings of the current query,
* query the total number of data before pagination
*
*
* In general, users do not need to directly use this method,
* but call the {@link #fetchPage(int, int)} method instead
*
*
* @return Total row count before pagination
*/
default long fetchUnlimitedCount() {
return fetchUnlimitedCount(null);
}
/**
* Ignore the sorting and pagination settings of the current query,
* query the total number of data before pagination
*
*
* In general, users do not need to directly use this method,
* but call the {@link #fetchPage(int, int, Connection)} method instead
*
*
* @return Total row count before pagination
*/
default long fetchUnlimitedCount(Connection con) {
return reselect((q, t) -> q.select(Expression.rowCount()))
.withoutSortingAndPaging()
.execute(con)
.get(0);
}
default boolean exists() {
return exists(null);
}
default boolean exists(Connection con) {
return !limit(1, 0L).execute(con).isEmpty();
}
@NotNull
default P fetchPage(int pageIndex, int pageSize, PageFactory pageFactory) {
return fetchPage(pageIndex, pageSize, null, pageFactory);
}
@NotNull
P fetchPage(int pageIndex, int pageSize, Connection con, PageFactory pageFactory);
@NotNull
default Page fetchPage(int pageIndex, int pageSize) {
return fetchPage(pageIndex, pageSize, null, PageFactory.standard());
}
@NotNull
default Page fetchPage(int pageIndex, int pageSize, Connection con) {
return fetchPage(pageIndex, pageSize, con, PageFactory.standard());
}
@NewChain
ConfigurableRootQuery reselect(
BiFunction, T, ConfigurableRootQuery> block
);
@NewChain
ConfigurableRootQuery distinct();
@NewChain
ConfigurableRootQuery limit(int limit);
@NewChain
ConfigurableRootQuery offset(long offset);
@NewChain
ConfigurableRootQuery limit(int limit, long offset);
@NewChain
ConfigurableRootQuery withoutSortingAndPaging();
/**
* @return If the original query does not have `order by` clause, returns null
*/
@NewChain
@Nullable
ConfigurableRootQuery reverseSorting();
@NewChain
default ConfigurableRootQuery forUpdate() {
return forUpdate(true);
}
@NewChain
ConfigurableRootQuery forUpdate(boolean forUpdate);
}