Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.army.criteria.impl.PostgreQueries Maven / Gradle / Ivy
package io.army.criteria.impl;
import io.army.criteria.*;
import io.army.criteria.dialect.Hint;
import io.army.criteria.dialect.Window;
import io.army.criteria.impl.inner.*;
import io.army.criteria.impl.inner.postgre._PostgreCte;
import io.army.criteria.impl.inner.postgre._PostgreQuery;
import io.army.criteria.postgre.*;
import io.army.dialect.Dialect;
import io.army.dialect._Constant;
import io.army.dialect.postgre.PostgreDialect;
import javax.annotation.Nullable;
import io.army.mapping.MappingType;
import io.army.meta.TableMeta;
import io.army.util.ArrayUtils;
import io.army.util._Collections;
import io.army.util._Exceptions;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
abstract class PostgreQueries extends SimpleQueries.WithCteDistinctOnSimpleQueries<
I,
PostgreCtes,
PostgreQuery._SelectSpec,
Postgres.Modifier,
PostgreQuery._PostgreSelectCommaSpec,
PostgreQuery._FromSpec,
PostgreQuery._TableSampleJoinSpec,
Statement._AsClause>,
PostgreQuery._JoinSpec,
PostgreStatement._FuncColumnDefinitionAsClause>,
PostgreQuery._TableSampleOnSpec,
Statement._AsParensOnClause>,
Statement._OnClause>,
PostgreStatement._FuncColumnDefinitionAsClause>>,
PostgreQuery._GroupBySpec,
PostgreQuery._WhereAndSpec,
PostgreQuery._GroupByCommaSpec,
PostgreQuery._HavingSpec,
PostgreQuery._HavingAndSpec,
PostgreQuery._WindowSpec,
PostgreQuery._OrderByCommaSpec,
PostgreQuery._LimitSpec,
PostgreQuery._OffsetSpec,
PostgreQuery._FetchSpec,
PostgreQuery._LockSpec,
PostgreQuery._QueryWithComplexSpec>
implements PostgreQuery,
_PostgreQuery,
PostgreQuery._WithSpec,
PostgreQuery._PostgreSelectCommaSpec,
PostgreQuery._TableSampleJoinSpec,
PostgreQuery._RepeatableJoinClause,
PostgreQuery._ParensJoinSpec,
PostgreQuery._WhereAndSpec,
PostgreQuery._HavingSpec,
PostgreQuery._HavingAndSpec,
PostgreQuery._WindowCommaSpec,
PostgreQuery._GroupByCommaSpec,
PostgreQuery._OrderByCommaSpec,
PostgreQuery._FetchSpec {
static PostgreQuery._WithSpec simpleQuery() {
return new SimpleSelect<>(null, null, SQLs.SIMPLE_SELECT);
}
static PostgreQuery._WithSpec<_BatchSelectParamSpec> batchQuery() {
return new SimpleSelect<>(null, null, PostgreQueries::mapToBatchSelect);
}
static PostgreQueries fromDispatcher(ArmyStmtSpec spec,
Function super Select, I> function) {
return new SimpleSelect<>(spec, null, function);
}
static PostgreQueries fromSubDispatcher(ArmyStmtSpec spec,
Function super SubQuery, I> function) {
return new SimpleSubQuery<>(spec, null, function);
}
static PostgreQuery._WithSpec subQuery(CriteriaContext outerContext,
Function super SubQuery, I> function) {
return new SimpleSubQuery<>(null, outerContext, function);
}
static _CteComma complexCte(
final CriteriaContext context, final boolean recursive, final Function function) {
return new StaticCteComma<>(context, recursive, function);
}
private static _BatchSelectParamSpec mapToBatchSelect(final Select select) {
final _BatchSelectParamSpec spec;
if (select instanceof _Query) {
spec = ((SimpleSelect>) select)::wrapToBatchSelect;
} else if (select instanceof UnionSelect) {
spec = ((UnionSelect) select)::wrapToBatchSelect;
} else if (select instanceof BracketSelect) {
spec = ((BracketSelect>) select)::wrapToBatchSelect;
} else {
// no bug,never here
throw new IllegalArgumentException();
}
return spec;
}
private SQLs.Modifier groupByModifier;
private List<_Window> windowList;
private List<_LockBlock> lockBlockList;
private _TabularBlock fromCrossBlock;
private PostgreQueries(@Nullable ArmyStmtSpec withSpec, CriteriaContext context) {
super(withSpec, context);
}
@Override
public final _StaticCteParensSpec<_SelectSpec> with(String name) {
return PostgreQueries.complexCte(this.context, false, this::endStaticWithClause)
.comma(name);
}
@Override
public final _StaticCteParensSpec<_SelectSpec> withRecursive(String name) {
return PostgreQueries.complexCte(this.context, true, this::endStaticWithClause)
.comma(name);
}
@Override
public final _RepeatableJoinClause tableSample(final @Nullable Expression method) {
if (method == null) {
throw ContextStack.nullPointer(this.context);
}
this.getFromClauseBlock().onSampleMethod((ArmyExpression) method);
return this;
}
@Override
public final _RepeatableJoinClause tableSample(
BiFunction, Expression, Expression> method,
BiFunction valueOperator, Expression argument) {
return this.tableSample(method.apply(valueOperator, argument));
}
@Override
public final _RepeatableJoinClause tableSample(
BiFunction, E, Expression> method,
BiFunction valueOperator, Supplier supplier) {
return this.tableSample(method.apply(valueOperator, supplier.get()));
}
@Override
public final _RepeatableJoinClause tableSample(
BiFunction, Object, Expression> method,
BiFunction valueOperator, Function function, String keyName) {
return this.tableSample(method.apply(valueOperator, function.apply(keyName)));
}
@Override
public final _RepeatableJoinClause ifTableSample(Supplier supplier) {
final Expression expression;
expression = supplier.get();
if (expression != null) {
this.tableSample(expression);
}
return this;
}
@Override
public final _RepeatableJoinClause ifTableSample(
BiFunction, E, Expression> method,
BiFunction valueOperator, Supplier supplier) {
final E value;
value = supplier.get();
if (value != null) {
this.tableSample(method.apply(valueOperator, value));
}
return this;
}
@Override
public final _RepeatableJoinClause ifTableSample(
BiFunction, Object, Expression> method,
BiFunction valueOperator, Function function, String keyName) {
final Object value;
value = function.apply(keyName);
if (value != null) {
this.tableSample(method.apply(valueOperator, value));
}
return this;
}
@Override
public final _JoinSpec repeatable(final @Nullable Expression seed) {
if (seed == null) {
throw ContextStack.nullPointer(this.context);
}
this.getFromClauseBlock().onSeed((ArmyExpression) seed);
return this;
}
@Override
public final _JoinSpec repeatable(Supplier supplier) {
return this.repeatable(supplier.get());
}
@Override
public final _JoinSpec repeatable(Function valueOperator, Number seedValue) {
return this.repeatable(valueOperator.apply(seedValue));
}
@Override
public final _JoinSpec repeatable(Function valueOperator,
Supplier supplier) {
return this.repeatable(valueOperator.apply(supplier.get()));
}
@Override
public final _JoinSpec repeatable(Function valueOperator, Function function,
String keyName) {
return this.repeatable(valueOperator.apply(function.apply(keyName)));
}
@Override
public final _JoinSpec ifRepeatable(Supplier supplier) {
final Expression expression;
expression = supplier.get();
if (expression != null) {
this.repeatable(expression);
}
return this;
}
@Override
public final _JoinSpec ifRepeatable(Function valueOperator,
Supplier supplier) {
final E value;
value = supplier.get();
if (value != null) {
this.repeatable(valueOperator.apply(value));
}
return this;
}
@Override
public final _JoinSpec ifRepeatable(Function valueOperator, Function function,
String keyName) {
final Object value;
value = function.apply(keyName);
if (value != null) {
this.repeatable(valueOperator.apply(value));
}
return this;
}
@Override
public final _JoinSpec parens(String first, String... rest) {
this.getFromDerivedBlock().parens(first, rest);
return this;
}
@Override
public final _JoinSpec parens(Consumer> consumer) {
this.getFromDerivedBlock().parens(this.context, consumer);
return this;
}
@Override
public final _JoinSpec ifParens(Consumer> consumer) {
this.getFromDerivedBlock().ifParens(this.context, consumer);
return this;
}
@Override
public _JoinSpec from(Function<_NestedLeftParenSpec<_JoinSpec>, _JoinSpec> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.NONE, this::fromNestedEnd));
}
@Override
public final _JoinSpec crossJoin(Function<_NestedLeftParenSpec<_JoinSpec>, _JoinSpec> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.CROSS_JOIN, this::fromNestedEnd));
}
@Override
public final _OnClause<_JoinSpec> leftJoin(Function<_NestedLeftParenSpec<_OnClause<_JoinSpec>>, _OnClause<_JoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.LEFT_JOIN, this::joinNestedEnd));
}
@Override
public final _OnClause<_JoinSpec> join(Function<_NestedLeftParenSpec<_OnClause<_JoinSpec>>, _OnClause<_JoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.JOIN, this::joinNestedEnd));
}
@Override
public final _OnClause<_JoinSpec> rightJoin(Function<_NestedLeftParenSpec<_OnClause<_JoinSpec>>, _OnClause<_JoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.RIGHT_JOIN, this::joinNestedEnd));
}
@Override
public final _OnClause<_JoinSpec> fullJoin(Function<_NestedLeftParenSpec<_OnClause<_JoinSpec>>, _OnClause<_JoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.FULL_JOIN, this::joinNestedEnd));
}
@Override
public final _JoinSpec ifLeftJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.LEFT_JOIN, this.blockConsumer));
return this;
}
@Override
public final _JoinSpec ifJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.JOIN, this.blockConsumer));
return this;
}
@Override
public final _JoinSpec ifRightJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.RIGHT_JOIN, this.blockConsumer));
return this;
}
@Override
public final _JoinSpec ifFullJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.FULL_JOIN, this.blockConsumer));
return this;
}
@Override
public final _JoinSpec ifCrossJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.crossBuilder(this.context, this.blockConsumer));
return this;
}
@Override
public final _GroupByCommaSpec groupBy(@Nullable SQLs.Modifier modifier, GroupByItem item) {
if (modifier != null && modifier != SQLs.ALL && modifier != SQLs.DISTINCT) {
throw CriteriaUtils.errorModifier(this.context, modifier);
}
this.groupByModifier = modifier;
return this.groupBy(item);
}
@Override
public final _GroupByCommaSpec groupBy(@Nullable SQLs.Modifier modifier, GroupByItem item1,
GroupByItem item2) {
if (modifier != null && modifier != SQLs.ALL && modifier != SQLs.DISTINCT) {
throw CriteriaUtils.errorModifier(this.context, modifier);
}
this.groupByModifier = modifier;
return this.groupBy(item1, item2);
}
@Override
public final _GroupByCommaSpec groupBy(@Nullable SQLs.Modifier modifier, GroupByItem item1,
GroupByItem item2, GroupByItem item3) {
if (modifier != null && modifier != SQLs.ALL && modifier != SQLs.DISTINCT) {
throw CriteriaUtils.errorModifier(this.context, modifier);
}
this.groupByModifier = modifier;
return this.groupBy(item1, item2, item3);
}
@Override
public final _GroupByCommaSpec groupBy(@Nullable SQLs.Modifier modifier, GroupByItem item1,
GroupByItem item2, GroupByItem item3, GroupByItem item4) {
if (modifier != null && modifier != SQLs.ALL && modifier != SQLs.DISTINCT) {
throw CriteriaUtils.errorModifier(this.context, modifier);
}
this.groupByModifier = modifier;
return this.groupBy(item1, item2, item3, item4);
}
@Override
public final _HavingSpec groupBy(@Nullable SQLs.Modifier modifier,
Consumer> consumer) {
if (modifier != null && modifier != SQLs.ALL && modifier != SQLs.DISTINCT) {
throw CriteriaUtils.errorModifier(this.context, modifier);
}
this.groupByModifier = modifier;
return this.groupBy(consumer);
}
@Override
public final _HavingSpec ifGroupBy(@Nullable SQLs.Modifier modifier,
Consumer> consumer) {
if (modifier != null && modifier != SQLs.ALL && modifier != SQLs.DISTINCT) {
throw CriteriaUtils.errorModifier(this.context, modifier);
}
this.groupBy(consumer);
if (this.hasGroupByClause()) {
this.groupByModifier = modifier;
} else {
this.groupByModifier = null;
}
return this;
}
@Override
public final Window._WindowAsClause> window(String name) {
return new NamedWindowAsClause<>(this.context, name, this::onAddWindow, PostgreSupports::namedWindow);
}
@Override
public final Window._WindowAsClause> comma(String name) {
return new NamedWindowAsClause<>(this.context, name, this::onAddWindow, PostgreSupports::namedWindow);
}
@Override
public final _OrderBySpec windows(Consumer> consumer) {
consumer.accept(this::createDynamicWindow);
if (this.windowList == null) {
throw ContextStack.criteriaError(this.context, _Exceptions::windowListIsEmpty);
}
return this;
}
@Override
public final _OrderBySpec ifWindows(Consumer> consumer) {
consumer.accept(this::createDynamicWindow);
return this;
}
@Override
public final _LockOfTableSpec forUpdate() {
return new StaticLockBlock<>(PostgreLockStrength.FOR_UPDATE, this);
}
@Override
public final _LockOfTableSpec forShare() {
return new StaticLockBlock<>(PostgreLockStrength.FOR_SHARE, this);
}
@Override
public final _LockOfTableSpec forNoKeyUpdate() {
return new StaticLockBlock<>(PostgreLockStrength.FOR_NO_KEY_UPDATE, this);
}
@Override
public final _LockOfTableSpec forKeyShare() {
return new StaticLockBlock<>(PostgreLockStrength.FOR_KEY_SHARE, this);
}
@Override
public final _LockSpec ifFor(Consumer<_PostgreDynamicLockStrengthClause> consumer) {
final DynamicLockBlock block = new DynamicLockBlock(this);
consumer.accept(block);
if (block.lockStrength != null) {
this.onAddLockBlock(block);
}
return this;
}
@Override
public final SQLs.Modifier groupByModifier() {
return this.groupByModifier;
}
@Override
public final List<_Window> windowList() {
final List<_Window> list = this.windowList;
if (list == null || list instanceof ArrayList) {
throw ContextStack.castCriteriaApi(this.context);
}
return list;
}
@Override
public final List<_LockBlock> lockBlockList() {
final List<_LockBlock> list = this.lockBlockList;
if (list == null || list instanceof ArrayList) {
throw ContextStack.castCriteriaApi(this.context);
}
return list;
}
@Override
final void onEndQuery() {
final List<_LockBlock> lockBlockList = this.lockBlockList;
final List<_Window> windowList = this.windowList;
if (lockBlockList != null && lockBlockList.size() > 0) {
if (this.hasGroupByClause()) {
throw lockWithErrorClause("GROUP BY");
} else if (windowList != null && windowList.size() > 0) {
throw lockWithErrorClause("WINDOW");
}
}
this.windowList = _Collections.safeUnmodifiableList(windowList);
this.lockBlockList = _Collections.safeUnmodifiableList(lockBlockList);
}
@Override
final void onClear() {
this.windowList = null;
this.lockBlockList = null;
}
@Override
final Dialect statementDialect() {
return PostgreUtils.DIALECT;
}
@Override
final List asModifierList(@Nullable List modifiers) {
return CriteriaUtils.asModifierList(this.context, modifiers, _PostgreConsultant::queryModifier);
}
@Override
final boolean isErrorModifier(Postgres.Modifier modifier) {
return _PostgreConsultant.queryModifier(modifier) < 0;
}
@Override
final Postgres.Modifier allModifier() {
return Postgres.ALL;
}
@Override
final Postgres.Modifier distinctModifier() {
return Postgres.DISTINCT;
}
@Override
final List asHintList(@Nullable List hints) {
//postgre don't support hint
throw ContextStack.castCriteriaApi(this.context);
}
@Override
final PostgreCtes createCteBuilder(boolean recursive) {
return PostgreSupports.postgreCteBuilder(recursive, this.context);
}
@Override
final boolean isIllegalTableModifier(@Nullable Query.TableModifier modifier) {
return CriteriaUtils.isIllegalOnly(modifier);
}
@Override
final boolean isIllegalDerivedModifier(@Nullable Query.DerivedModifier modifier) {
return CriteriaUtils.isIllegalLateral(modifier);
}
@Override
final _TableSampleJoinSpec onFromTable(_JoinType joinType, @Nullable TableModifier modifier, TableMeta> table,
String alias) {
final PostgreSupports.FromClauseTableBlock block;
block = new PostgreSupports.FromClauseTableBlock(joinType, modifier, table, alias);
this.blockConsumer.accept(block);
this.fromCrossBlock = block;
return this;
}
@Override
final _AsClause<_ParensJoinSpec> onFromDerived(_JoinType joinType, @Nullable DerivedModifier modifier,
DerivedTable table) {
return alias -> {
final TabularBlocks.FromClauseAliasDerivedBlock block;
block = TabularBlocks.fromAliasDerivedBlock(joinType, modifier, table, alias);
this.blockConsumer.accept(block);
this.fromCrossBlock = block;
return this;
};
}
@Override
final _FuncColumnDefinitionAsClause<_JoinSpec> onFromUndoneFunc(final _JoinType joinType,
final @Nullable DerivedModifier modifier,
final UndoneFunction func) {
return alias -> PostgreBlocks.fromUndoneFunc(joinType, modifier, func, alias, this, this.blockConsumer);
}
@Override
final _JoinSpec onFromCte(_JoinType joinType, @Nullable DerivedModifier modifier, _Cte cteItem,
String alias) {
final _TabularBlock block;
block = TabularBlocks.fromCteBlock(joinType, cteItem, alias);
this.blockConsumer.accept(block);
this.fromCrossBlock = block;
return this;
}
@Override
final _TableSampleOnSpec onJoinTable(_JoinType joinType, @Nullable TableModifier modifier, TableMeta> table,
String alias) {
final JonClauseTableBlock block;
block = new JonClauseTableBlock<>(joinType, modifier, table, alias, this);
this.blockConsumer.accept(block);
return block;
}
@Override
final _AsParensOnClause<_JoinSpec> onJoinDerived(_JoinType joinType, @Nullable DerivedModifier modifier,
DerivedTable table) {
return alias -> {
final TabularBlocks.JoinClauseAliasDerivedBlock<_JoinSpec> block;
block = TabularBlocks.joinAliasDerivedBlock(joinType, modifier, table, alias, this);
this.blockConsumer.accept(block);
return block;
};
}
@Override
final _FuncColumnDefinitionAsClause<_OnClause<_JoinSpec>> onJoinUndoneFunc(
final _JoinType joinType, final @Nullable DerivedModifier modifier, final UndoneFunction func) {
return alias -> PostgreBlocks.joinUndoneFunc(joinType, modifier, func, alias, this, this.blockConsumer);
}
@Override
final _OnClause<_JoinSpec> onJoinCte(_JoinType joinType, @Nullable DerivedModifier modifier, _Cte cteItem,
String alias) {
final TabularBlocks.JoinClauseCteBlock<_JoinSpec> block;
block = TabularBlocks.joinCteBlock(joinType, cteItem, alias, this);
this.blockConsumer.accept(block);
return block;
}
/*-------------------below private method -------------------*/
/**
* @see #from(Function)
* @see #crossJoin(Function)
*/
private _JoinSpec fromNestedEnd(final _JoinType joinType, final _NestedItems nestedItems) {
this.blockConsumer.accept(TabularBlocks.fromNestedBlock(joinType, nestedItems));
return this;
}
/**
* @see #leftJoin(Function)
* @see #join(Function)
* @see #rightJoin(Function)
* @see #fullJoin(Function)
*/
private _OnClause<_JoinSpec> joinNestedEnd(final _JoinType joinType, final _NestedItems nestedItems) {
final TabularBlocks.JoinClauseNestedBlock<_JoinSpec> block;
block = TabularBlocks.joinNestedBlock(joinType, nestedItems, this);
this.blockConsumer.accept(block);
return block;
}
/**
* @return get the table block of last FROM or CROSS JOIN clause
*/
private PostgreSupports.FromClauseTableBlock getFromClauseBlock() {
final _TabularBlock block = this.fromCrossBlock;
if (block != this.context.lastBlock() || !(block instanceof PostgreSupports.FromClauseTableBlock)) {
throw ContextStack.castCriteriaApi(this.context);
}
return (PostgreSupports.FromClauseTableBlock) block;
}
/**
* @return get the derived block of last FROM or CROSS JOIN clause
*/
private TabularBlocks.FromClauseAliasDerivedBlock getFromDerivedBlock() {
final _TabularBlock block = this.fromCrossBlock;
if (block != this.context.lastBlock() || !(block instanceof TabularBlocks.FromClauseAliasDerivedBlock)) {
throw ContextStack.castCriteriaApi(this.context);
}
return (TabularBlocks.FromClauseAliasDerivedBlock) block;
}
/**
* @see #comma(String)
*/
private _WindowCommaSpec onAddWindow(final ArmyWindow window) {
window.endWindowClause();
List<_Window> list = this.windowList;
if (list == null) {
list = _Collections.arrayList();
this.windowList = list;
} else if (!(list instanceof ArrayList)) {
throw ContextStack.castCriteriaApi(this.context);
}
list.add(window);
return this;
}
/**
* @see #windows(Consumer)
* @see #ifWindows(Consumer)
*/
private Window._WindowAsClause createDynamicWindow(String name) {
return new NamedWindowAsClause<>(this.context, name, this::onAddWindow, PostgreSupports::namedWindow);
}
private PostgreQueries onAddLockBlock(final _LockBlock block) {
List<_LockBlock> lockBlockList = this.lockBlockList;
if (lockBlockList == null) {
lockBlockList = new ArrayList<>(2);
this.lockBlockList = lockBlockList;
} else if (!(lockBlockList instanceof ArrayList)) {
throw ContextStack.castCriteriaApi(this.context);
}
lockBlockList.add(block);
return this;
}
private static CriteriaException lockWithErrorClause(final String clause) {
String m = String.format("Currently, FOR NO KEY UPDATE, FOR UPDATE, FOR SHARE and FOR KEY SHARE cannot be specified with %s.", clause);
return ContextStack.clearStackAndCriteriaError(m);
}
private static final class JonClauseTableBlock extends PostgreSupports.PostgreTableOnBlock<
PostgreQuery._RepeatableOnClause,
Statement._OnClause>,
PostgreQuery._JoinSpec>
implements PostgreQuery._TableSampleOnSpec,
PostgreQuery._RepeatableOnClause {
/**
* @see #onJoinTable(_JoinType, TableModifier, TableMeta, String)
*/
private JonClauseTableBlock(_JoinType joinType, @Nullable SQLWords modifier, TableMeta> tableItem, String alias,
PostgreQuery._JoinSpec stmt) {
super(joinType, modifier, tableItem, alias, stmt);
}
}//JonClauseTableBlock
private enum PostgreLockStrength implements SQLWords {
FOR_UPDATE(_Constant.SPACE_FOR_UPDATE),
FOR_SHARE(_Constant.SPACE_FOR_SHARE),
FOR_NO_KEY_UPDATE(" FOR NO KEY UPDATE"),
FOR_KEY_SHARE(" FOR KEY SHARE");
final String spaceWords;
PostgreLockStrength(String spaceWords) {
this.spaceWords = spaceWords;
}
@Override
public final String spaceRender() {
return this.spaceWords;
}
@Override
public final String toString() {
return CriteriaUtils.enumToString(this);
}
}//PostgreLockMode
private static final class StaticLockBlock extends LockClauseBlock<
PostgreQuery._LockWaitOptionSpec,
PostgreQuery._LockSpec>
implements PostgreQuery._LockSpec,
PostgreQuery._LockOfTableSpec {
private final PostgreLockStrength lockStrength;
private final PostgreQueries stmt;
private StaticLockBlock(PostgreLockStrength lockStrength, PostgreQueries stmt) {
this.lockStrength = lockStrength;
this.stmt = stmt;
}
@Override
public _LockOfTableSpec forUpdate() {
return this.stmt.onAddLockBlock(this)
.forUpdate();
}
@Override
public _LockOfTableSpec forShare() {
return this.stmt.onAddLockBlock(this)
.forShare();
}
@Override
public _LockOfTableSpec forNoKeyUpdate() {
return this.stmt.onAddLockBlock(this)
.forNoKeyUpdate();
}
@Override
public _LockOfTableSpec forKeyShare() {
return this.stmt.onAddLockBlock(this)
.forKeyShare();
}
@Override
public _LockSpec ifFor(Consumer<_PostgreDynamicLockStrengthClause> consumer) {
return this.stmt.onAddLockBlock(this)
.ifFor(consumer);
}
@Override
public I asQuery() {
return this.stmt.onAddLockBlock(this)
.asQuery();
}
@Override
public SQLWords lockStrength() {
return this.lockStrength;
}
@Override
public CriteriaContext getContext() {
return this.stmt.context;
}
}//StaticLockBlock
private static final class DynamicLockBlock extends LockClauseBlock<
Query._MinLockWaitOptionClause- ,
Item> implements PostgreQuery._PostgreDynamicLockStrengthClause,
PostgreQuery._DynamicLockOfTableSpec {
private final PostgreQueries> stmt;
private PostgreLockStrength lockStrength;
private DynamicLockBlock(PostgreQueries> stmt) {
this.stmt = stmt;
}
@Override
public _DynamicLockOfTableSpec update() {
if (this.lockStrength != null) {
throw CriteriaUtils.duplicateDynamicMethod(this.stmt.context);
}
this.lockStrength = PostgreLockStrength.FOR_UPDATE;
return this;
}
@Override
public _DynamicLockOfTableSpec share() {
if (this.lockStrength != null) {
throw CriteriaUtils.duplicateDynamicMethod(this.stmt.context);
}
this.lockStrength = PostgreLockStrength.FOR_SHARE;
return this;
}
@Override
public _DynamicLockOfTableSpec noKeyUpdate() {
if (this.lockStrength != null) {
throw CriteriaUtils.duplicateDynamicMethod(this.stmt.context);
}
this.lockStrength = PostgreLockStrength.FOR_NO_KEY_UPDATE;
return this;
}
@Override
public _DynamicLockOfTableSpec keyShare() {
if (this.lockStrength != null) {
throw CriteriaUtils.duplicateDynamicMethod(this.stmt.context);
}
this.lockStrength = PostgreLockStrength.FOR_KEY_SHARE;
return this;
}
@Override
public CriteriaContext getContext() {
return this.stmt.context;
}
@Override
public SQLWords lockStrength() {
final PostgreLockStrength strength = this.lockStrength;
if (strength == null) {
throw ContextStack.castCriteriaApi(this.stmt.context);
}
return strength;
}
}//DynamicLockBlock
private static final class SimpleSelect
extends PostgreQueries
implements ArmySelect {
private final Function super Select, I> function;
private SimpleSelect(@Nullable ArmyStmtSpec spec, @Nullable CriteriaContext outerBracketContext,
Function super Select, I> function) {
super(spec, CriteriaContexts.primaryQueryContext(PostgreUtils.DIALECT, spec, outerBracketContext, null));
this.function = function;
}
@Override
public _UnionOrderBySpec parens(Function<_WithSpec<_UnionOrderBySpec>, _UnionOrderBySpec> function) {
this.endStmtBeforeCommand();
final BracketSelect bracket;
bracket = new BracketSelect<>(this, this.function);
return function.apply(new SimpleSelect<>(null, bracket.context, bracket::parensEnd));
}
@Override
I onAsQuery() {
return this.function.apply(this);
}
@Override
_QueryWithComplexSpec createQueryUnion(final _UnionType unionType) {
final Function unionFunc;
unionFunc = right -> this.function.apply(new UnionSelect(this, unionType, right));
return new SelectDispatcher<>(this.context, unionFunc);
}
private PostgreBatchSimpleQuery wrapToBatchSelect(List> paramList) {
return new PostgreBatchSimpleQuery(this, CriteriaUtils.paramList(paramList));
}
}//SimpleSelect
private static final class SimpleSubQuery extends PostgreQueries
implements ArmySubQuery {
private final Function super SubQuery, I> function;
private SimpleSubQuery(@Nullable ArmyStmtSpec spec, @Nullable CriteriaContext outerContext,
Function super SubQuery, I> function) {
super(spec, CriteriaContexts.subQueryContext(PostgreUtils.DIALECT, spec, outerContext, null));
this.function = function;
}
@Override
public _UnionOrderBySpec parens(Function<_WithSpec<_UnionOrderBySpec>, _UnionOrderBySpec> function) {
this.endStmtBeforeCommand();
final BracketSubQuery bracket;
bracket = new BracketSubQuery<>(this, this.function);
return function.apply(PostgreQueries.subQuery(bracket.context, bracket::parensEnd));
}
@Override
I onAsQuery() {
return this.function.apply(this);
}
@Override
_QueryWithComplexSpec createQueryUnion(final _UnionType unionType) {
final Function unionFunc;
unionFunc = right -> this.function.apply(new UnionSubQuery(this, unionType, right));
return new SubQueryDispatcher<>(this.context, unionFunc);
}
}//SimpleSubQuery
static abstract class PostgreSelectClauseDispatcher
extends WithDistinctOnSelectClauseDispatcher<
PostgreCtes,
WE,
Postgres.Modifier,
PostgreQuery._PostgreSelectCommaSpec,
PostgreQuery._FromSpec> implements PostgreQuery._PostgreSelectClause {
PostgreSelectClauseDispatcher(@Nullable CriteriaContext outerContext, @Nullable CriteriaContext leftContext) {
super(PostgreUtils.DIALECT, outerContext, leftContext);
}
}//PostgreSelectClauseDispatcher
static abstract class PostgreBracketQuery
extends BracketRowSet<
I,
PostgreQuery._UnionOrderBySpec,
PostgreQuery._UnionOrderByCommaSpec,
PostgreQuery._UnionLimitSpec,
PostgreQuery._UnionOffsetSpec,
PostgreQuery._UnionFetchSpec,
Query._AsQueryClause,
PostgreQuery._QueryWithComplexSpec>
implements PostgreQuery._UnionOrderBySpec,
PostgreQuery._UnionOrderByCommaSpec,
PostgreQuery,
PostgreQuery._UnionOffsetSpec,
PostgreQuery._UnionFetchSpec {
private PostgreBracketQuery(ArmyStmtSpec spec) {
super(spec);
}
@Override
final Dialect statementDialect() {
return PostgreDialect.POSTGRE15;
}
@Override
final void onEndQuery() {
//no-op
}
}//PostgreBracketQueries
private static final class BracketSelect extends PostgreBracketQuery
implements ArmySelect {
private final Function super Select, I> function;
private BracketSelect(ArmyStmtSpec spec, Function super Select, I> function) {
super(spec);
this.function = function;
}
@Override
I onAsQuery() {
return this.function.apply(this);
}
@Override
PostgreQuery._QueryWithComplexSpec createUnionRowSet(final _UnionType unionType) {
final Function unionFunc;
unionFunc = right -> this.function.apply(new UnionSelect(this, unionType, right));
return new SelectDispatcher<>(this.context, unionFunc);
}
BatchBracketSelect wrapToBatchSelect(List> paramList) {
return new BatchBracketSelect(this, CriteriaUtils.paramList(paramList));
}
}//BracketSelect
private static final class BatchBracketSelect extends BracketRowSet.ArmyBatchBracketSelect
implements PostgreQuery {
private BatchBracketSelect(BracketSelect> select, List> paramList) {
super(select, paramList);
}
@Override
Dialect statementDialect() {
return PostgreUtils.DIALECT;
}
}//BatchBracketSelect
private static final class BracketSubQuery extends PostgreBracketQuery
implements ArmySubQuery {
private final Function super SubQuery, I> function;
private BracketSubQuery(ArmyStmtSpec spec, Function super SubQuery, I> function) {
super(spec);
this.function = function;
}
@Override
I onAsQuery() {
return this.function.apply(this);
}
@Override
PostgreQuery._QueryWithComplexSpec createUnionRowSet(final _UnionType unionType) {
final Function unionFunc;
unionFunc = right -> this.function.apply(new UnionSubQuery(this, unionType, right));
return new SubQueryDispatcher<>(this.context, unionFunc);
}
}//BracketSubQuery
private static abstract class PostgreQueryDispatcher
extends PostgreSelectClauseDispatcher<
I,
PostgreQuery._QueryComplexSpec>
implements PostgreQuery._QueryWithComplexSpec {
final Function function;
private PostgreQueryDispatcher(CriteriaContext leftContext, Function function) {
super(leftContext.getOuterContext(), leftContext);
this.function = function;
}
private PostgreQueryDispatcher(PostgreBracketQuery> bracket, Function function) {
super(bracket.context, null);
this.function = function;
}
@Override
public final _StaticCteParensSpec<_QueryComplexSpec> with(String name) {
return PostgreQueries.complexCte(this.context, false, this::endStaticWithClause)
.comma(name);
}
@Override
public final _StaticCteParensSpec<_QueryComplexSpec> withRecursive(String name) {
return PostgreQueries.complexCte(this.context, true, this::endStaticWithClause)
.comma(name);
}
@Override
final PostgreCtes createCteBuilder(boolean recursive, CriteriaContext context) {
return PostgreSupports.postgreCteBuilder(recursive, context);
}
}//PostgreQueryDispatcher
private static final class SelectDispatcher extends PostgreQueryDispatcher {
private SelectDispatcher(CriteriaContext leftContext, Function function) {
super(leftContext, function);
}
private SelectDispatcher(BracketSelect> bracket, Function function) {
super(bracket, function);
}
@Override
public _UnionOrderBySpec parens(Function<_QueryWithComplexSpec<_UnionOrderBySpec>, _UnionOrderBySpec> function) {
this.endDispatcher();
final BracketSelect bracket;
bracket = new BracketSelect<>(this, this.function);
return function.apply(new SelectDispatcher<>(bracket, bracket::parensEnd));
}
@Override
public PostgreValues._OrderBySpec values(Consumer consumer) {
this.endDispatcher();
return PostgreSimpleValues.fromDispatcher(this, this.function)
.values(consumer);
}
@Override
public PostgreValues._PostgreValuesLeftParenClause values() {
this.endDispatcher();
return PostgreSimpleValues.fromDispatcher(this, this.function)
.values();
}
@Override
PostgreQueries createSelectClause() {
this.endDispatcher();
return PostgreQueries.fromDispatcher(this, this.function);
}
}//SelectDispatcher
/**
* @see #createQueryUnion(_UnionType)
* @see #createQueryUnion(_UnionType)
*/
private static final class SubQueryDispatcher extends PostgreQueryDispatcher {
private SubQueryDispatcher(CriteriaContext leftContext, Function function) {
super(leftContext, function);
}
private SubQueryDispatcher(BracketSubQuery> bracket, Function function) {
super(bracket, function);
}
@Override
public _UnionOrderBySpec