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.PostgreDeletes Maven / Gradle / Ivy
package io.army.criteria.impl;
import io.army.criteria.*;
import io.army.criteria.dialect.BatchReturningDelete;
import io.army.criteria.dialect.ReturningDelete;
import io.army.criteria.dialect.Returnings;
import io.army.criteria.impl.inner.*;
import io.army.criteria.impl.inner.postgre._PostgreDelete;
import io.army.criteria.postgre.*;
import io.army.dialect.Dialect;
import io.army.dialect.postgre.PostgreDialect;
import javax.annotation.Nullable;
import io.army.mapping.MappingType;
import io.army.meta.ComplexTableMeta;
import io.army.meta.ParentTableMeta;
import io.army.meta.TableMeta;
import io.army.util._Assert;
import io.army.util._Collections;
import io.army.util._Exceptions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
*
* This class is the implementation of Postgre DELETE syntax.
*
* @see PostgreDelete
* @since 1.0
*/
abstract class PostgreDeletes extends JoinableDelete<
I,
PostgreCtes,
PostgreDelete._PostgreDeleteClause,
PostgreDelete._TableSampleJoinSpec,
Statement._AsClause>,
PostgreDelete._SingleJoinSpec,
PostgreStatement._FuncColumnDefinitionAsClause>,
PostgreDelete._TableSampleOnSpec,
PostgreDelete._AsParensOnClause>,
Statement._OnClause>,
PostgreStatement._FuncColumnDefinitionAsClause>>,
PostgreDelete._ReturningSpec,
PostgreDelete._SingleWhereAndSpec>
implements PostgreDelete,
_PostgreDelete,
PostgreDelete._RepeatableJoinClause,
PostgreDelete._SingleWithSpec,
PostgreDelete._SingleUsingSpec,
PostgreDelete._TableSampleJoinSpec,
PostgreDelete._ParensJoinSpec,
PostgreDelete._SingleWhereAndSpec,
PostgreDelete._StaticReturningCommaSpec {
static _SingleWithSpec simpleDelete() {
return new PrimarySimpleDelete();
}
static _SingleWithSpec<_BatchDeleteParamSpec, _BatchReturningDeleteParamSpec> batchDelete() {
return new BatchPrimarySimpleDelete();
}
static _SingleWithSpec subSimpleDelete(CriteriaContext outerContext,
Function function) {
return new SubSimpleDelete<>(outerContext, function);
}
private SQLs.WordOnly onlyModifier;
private TableMeta> targetTable;
private SQLs.SymbolAsterisk starModifier;
private String targetTableAlias;
private _TabularBlock fromCrossBlock;
private List<_SelectItem> returningList;
private PostgreDeletes(@Nullable _Statement._WithClauseSpec withSpec, CriteriaContext context) {
super(withSpec, context);
}
@Override
public final PostgreQuery._StaticCteParensSpec<_PostgreDeleteClause> with(String name) {
return PostgreQueries.complexCte(this.context, false, this::endStaticWithClause)
.comma(name);
}
@Override
public final PostgreQuery._StaticCteParensSpec<_PostgreDeleteClause> withRecursive(String name) {
return PostgreQueries.complexCte(this.context, true, this::endStaticWithClause)
.comma(name);
}
@Override
public final PostgreDelete._SingleUsingSpec deleteFrom(TableMeta> table, SQLs.WordAs as,
String tableAlias) {
return this.doDeleteFrom(null, table, null, as, tableAlias);
}
@Override
public final PostgreDelete._SingleUsingSpec deleteFrom(@Nullable SQLs.WordOnly only, TableMeta> table,
SQLs.WordAs as, String tableAlias) {
return this.doDeleteFrom(only, table, null, as, tableAlias);
}
@Override
public final PostgreDelete._SingleUsingSpec deleteFrom(TableMeta> table, @Nullable SQLs.SymbolAsterisk star,
SQLs.WordAs as, String tableAlias) {
return this.doDeleteFrom(null, table, star, as, tableAlias);
}
@Override
public final _RepeatableJoinClause tableSample(Expression method) {
this.getFromCrossBlock().onSampleMethod((ArmyExpression) method);
return this;
}
@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 tableSample(BiFunction, Expression, Expression> method,
BiFunction valueOperator, Expression argument) {
return this.tableSample(method.apply(valueOperator, argument));
}
@Override
public final _RepeatableJoinClause ifTableSample(Supplier supplier) {
final Expression value;
value = supplier.get();
if (value != null) {
this.tableSample(value);
}
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 _SingleJoinSpec repeatable(Expression seed) {
this.getFromCrossBlock().onSeed((ArmyExpression) seed);
return this;
}
@Override
public final _SingleJoinSpec repeatable(Supplier supplier) {
return this.repeatable(supplier.get());
}
@Override
public final _SingleJoinSpec repeatable(Function valueOperator, Number seedValue) {
return this.repeatable(valueOperator.apply(seedValue));
}
@Override
public final _SingleJoinSpec repeatable(Function valueOperator, Supplier supplier) {
return this.repeatable(valueOperator.apply(supplier.get()));
}
@Override
public final _SingleJoinSpec repeatable(Function valueOperator, Function function,
String keyName) {
return this.repeatable(valueOperator.apply(function.apply(keyName)));
}
@Override
public final _SingleJoinSpec ifRepeatable(Supplier supplier) {
final Expression expression;
expression = supplier.get();
if (expression != null) {
this.repeatable(expression);
}
return this;
}
@Override
public final _SingleJoinSpec ifRepeatable(Function valueOperator, Supplier supplier) {
final E value;
value = supplier.get();
if (value != null) {
this.repeatable(valueOperator.apply(value));
}
return this;
}
@Override
public final _SingleJoinSpec 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 _SingleJoinSpec parens(String first, String... rest) {
this.getFromDerived().parens(first, rest);
return this;
}
@Override
public final _SingleJoinSpec parens(Consumer> consumer) {
this.getFromDerived().parens(this.context, consumer);
return this;
}
@Override
public final _SingleJoinSpec ifParens(Consumer> consumer) {
this.getFromDerived().ifParens(this.context, consumer);
return this;
}
@Override
public final _SingleJoinSpec using(Function<_NestedLeftParenSpec<_SingleJoinSpec>, _SingleJoinSpec> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.NONE, this::nestedUsingEnd));
}
@Override
public final _SingleJoinSpec crossJoin(Function<_NestedLeftParenSpec<_SingleJoinSpec>, _SingleJoinSpec> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.CROSS_JOIN, this::nestedUsingEnd));
}
@Override
public final _OnClause<_SingleJoinSpec> leftJoin(Function<_NestedLeftParenSpec<_OnClause<_SingleJoinSpec>>, _OnClause<_SingleJoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.LEFT_JOIN, this::nestedJoinEnd));
}
@Override
public final _OnClause<_SingleJoinSpec> join(Function<_NestedLeftParenSpec<_OnClause<_SingleJoinSpec>>, _OnClause<_SingleJoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.JOIN, this::nestedJoinEnd));
}
@Override
public final _OnClause<_SingleJoinSpec> rightJoin(Function<_NestedLeftParenSpec<_OnClause<_SingleJoinSpec>>, _OnClause<_SingleJoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.RIGHT_JOIN, this::nestedJoinEnd));
}
@Override
public final _OnClause<_SingleJoinSpec> fullJoin(Function<_NestedLeftParenSpec<_OnClause<_SingleJoinSpec>>, _OnClause<_SingleJoinSpec>> function) {
return function.apply(PostgreNestedJoins.nestedItem(this.context, _JoinType.FULL_JOIN, this::nestedJoinEnd));
}
@Override
public final _SingleJoinSpec ifLeftJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.LEFT_JOIN, this.blockConsumer));
return this;
}
@Override
public final _SingleJoinSpec ifJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.JOIN, this.blockConsumer));
return this;
}
@Override
public final _SingleJoinSpec ifRightJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.RIGHT_JOIN, this.blockConsumer));
return this;
}
@Override
public final _SingleJoinSpec ifFullJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.joinBuilder(this.context, _JoinType.FULL_JOIN, this.blockConsumer));
return this;
}
@Override
public final _SingleJoinSpec ifCrossJoin(Consumer consumer) {
consumer.accept(PostgreDynamicJoins.crossBuilder(this.context, this.blockConsumer));
return this;
}
@Override
public final _ReturningSpec whereCurrentOf(String cursorName) {
this.where(new PostgreCursorPredicate(cursorName));
return this;
}
@Override
public final _DqlDeleteSpec returningAll() {
this.returningList = PostgreSupports.EMPTY_SELECT_ITEM_LIST;
return this;
}
@Override
public final _DqlDeleteSpec returning(Consumer consumer) {
this.returningList = CriteriaUtils.selectionList(this.context, consumer);
return this;
}
@Override
public final _StaticReturningCommaSpec returning(Selection selection) {
this.onAddSelection(selection);
return this;
}
@Override
public final _StaticReturningCommaSpec returning(Selection selection1, Selection selection2) {
this.onAddSelection(selection1)
.onAddSelection(selection2);
return this;
}
@Override
public final _StaticReturningCommaSpec returning(Function function, String alias) {
this.onAddSelection(function.apply(alias));
return this;
}
@Override
public final _StaticReturningCommaSpec returning(Function function1, String alias1,
Function function2, String alias2) {
this.onAddSelection(function1.apply(alias1))
.onAddSelection(function2.apply(alias2));
return this;
}
@Override
public final _StaticReturningCommaSpec returning(Function function, String alias,
Selection selection) {
this.onAddSelection(function.apply(alias))
.onAddSelection(selection);
return this;
}
@Override
public final _StaticReturningCommaSpec returning(Selection selection, Function function,
String alias) {
this.onAddSelection(selection)
.onAddSelection(function.apply(alias));
return this;
}
@Override
public final _StaticReturningCommaSpec returning(String derivedAlias, SQLs.SymbolPeriod period,
SQLs.SymbolAsterisk star) {
this.onAddSelection(SelectionGroups.derivedGroup(this.context.getNonNullDerived(derivedAlias), derivedAlias));
return this;
}
@Override
public final _StaticReturningCommaSpec returning(
String tableAlias, SQLs.SymbolPeriod period, TableMeta> table) {
this.onAddSelection(SelectionGroups.singleGroup(table, tableAlias));
return this;
}
@Override
public final _StaticReturningCommaSpec returning(
String parenAlias, SQLs.SymbolPeriod period1, ParentTableMeta parent,
String childAlias, SQLs.SymbolPeriod period2, ComplexTableMeta
child) {
if (child.parentMeta() != parent) {
throw CriteriaUtils.childParentNotMatch(this.context, parent, child);
}
this.onAddSelection(SelectionGroups.singleGroup(parent, parenAlias))
.onAddSelection(SelectionGroups.groupWithoutId(child, childAlias));
return this;
}
@Override
public final _StaticReturningCommaSpec returning(TableField field1, TableField field2, TableField field3) {
this.onAddSelection(field1)
.onAddSelection(field2)
.onAddSelection(field3);
return this;
}
@Override
public final _StaticReturningCommaSpec returning(TableField field1, TableField field2, TableField field3,
TableField field4) {
this.onAddSelection(field1)
.onAddSelection(field2)
.onAddSelection(field3)
.onAddSelection(field4);
return this;
}
@Override
public final _StaticReturningCommaSpec comma(Selection selection) {
this.onAddSelection(selection);
return this;
}
@Override
public final _StaticReturningCommaSpec comma(Selection selection1, Selection selection2) {
this.onAddSelection(selection1)
.onAddSelection(selection2);
return this;
}
@Override
public final _StaticReturningCommaSpec comma(Function function, String alias) {
this.onAddSelection(function.apply(alias));
return this;
}
@Override
public final _StaticReturningCommaSpec comma(Function function1, String alias1,
Function function2, String alias2) {
this.onAddSelection(function1.apply(alias1))
.onAddSelection(function2.apply(alias2));
return this;
}
@Override
public final _StaticReturningCommaSpec comma(Function function, String alias,
Selection selection) {
this.onAddSelection(function.apply(alias))
.onAddSelection(selection);
return this;
}
@Override
public final _StaticReturningCommaSpec comma(Selection selection, Function function,
String alias) {
this.onAddSelection(selection)
.onAddSelection(function.apply(alias));
return this;
}
@Override
public final _StaticReturningCommaSpec comma(String derivedAlias, SQLs.SymbolPeriod period,
SQLs.SymbolAsterisk star) {
this.onAddSelection(SelectionGroups.derivedGroup(this.context.getNonNullDerived(derivedAlias), derivedAlias));
return this;
}
@Override
public final _StaticReturningCommaSpec comma(
String tableAlias, SQLs.SymbolPeriod period, TableMeta> table) {
this.onAddSelection(SelectionGroups.singleGroup(table, tableAlias));
return this;
}
@Override
public final _StaticReturningCommaSpec comma(
String parenAlias, SQLs.SymbolPeriod period1, ParentTableMeta parent,
String childAlias, SQLs.SymbolPeriod period2, ComplexTableMeta
child) {
if (child.parentMeta() != parent) {
throw CriteriaUtils.childParentNotMatch(this.context, parent, child);
}
this.onAddSelection(SelectionGroups.singleGroup(parent, parenAlias))
.onAddSelection(SelectionGroups.groupWithoutId(child, childAlias));
return this;
}
@Override
public final _StaticReturningCommaSpec comma(TableField field1, TableField field2, TableField field3) {
this.onAddSelection(field1)
.onAddSelection(field2)
.onAddSelection(field3);
return this;
}
@Override
public final _StaticReturningCommaSpec comma(TableField field1, TableField field2, TableField field3,
TableField field4) {
this.onAddSelection(field1)
.onAddSelection(field2)
.onAddSelection(field3)
.onAddSelection(field4);
return this;
}
@Override
public final List extends _SelectItem> returningList() {
//no bug,never here
throw new UnsupportedOperationException();
}
@Override
public final Q asReturningDelete() {
final List<_SelectItem> returningList = this.returningList;
if (!(returningList instanceof ArrayList || returningList == PostgreSupports.EMPTY_SELECT_ITEM_LIST)) {
throw ContextStack.castCriteriaApi(this.context);
}
this.endDeleteStatement();
if (returningList instanceof ArrayList) {
this.returningList = _Collections.unmodifiableList(returningList);
} else {
this.returningList = CriteriaUtils.returningAll(this.table(), this.tableAlias(), this.tableBlockList());
}
return this.onAsReturningDelete();
}
@Override
public final SQLs.WordOnly modifier() {
return this.onlyModifier;
}
@Override
public final TableMeta> table() {
final TableMeta> targetTable = this.targetTable;
if (targetTable == null) {
throw ContextStack.castCriteriaApi(this.context);
}
return targetTable;
}
@Override
public final SQLs.SymbolAsterisk symbolAsterisk() {
return this.starModifier;
}
@Override
public final String tableAlias() {
final String targetTableAlias = this.targetTableAlias;
if (targetTableAlias == null) {
throw ContextStack.castCriteriaApi(this.context);
}
return targetTableAlias;
}
@Override
final PostgreCtes createCteBuilder(boolean recursive) {
return PostgreSupports.postgreCteBuilder(recursive, this.context);
}
@Override
final Dialect statementDialect() {
return PostgreDialect.POSTGRE15;
}
@Override
final _TableSampleJoinSpec onFromTable(_JoinType joinType, @Nullable Query.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 Query.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 _SingleJoinSpec onFromCte(_JoinType joinType, @Nullable Query.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 _FuncColumnDefinitionAsClause<_SingleJoinSpec> onFromUndoneFunc(
final _JoinType joinType, final @Nullable DerivedModifier modifier, final UndoneFunction func) {
return alias -> PostgreBlocks.fromUndoneFunc(joinType, modifier, func, alias, this, this.blockConsumer);
}
@Override
final _TableSampleOnSpec onJoinTable(_JoinType joinType, @Nullable Query.TableModifier modifier,
TableMeta> table, String alias) {
final SimpleJoinClauseTableBlock block;
block = new SimpleJoinClauseTableBlock<>(joinType, modifier, table, alias, this);
this.blockConsumer.accept(block);
return block;
}
@Override
final _AsParensOnClause<_SingleJoinSpec> onJoinDerived(
_JoinType joinType, @Nullable Query.DerivedModifier modifier, DerivedTable table) {
return alias -> {
final TabularBlocks.JoinClauseAliasDerivedBlock<_SingleJoinSpec> block;
block = TabularBlocks.joinAliasDerivedBlock(joinType, modifier, table, alias, this);
this.blockConsumer.accept(block);
return block;
};
}
@Override
final _FuncColumnDefinitionAsClause<_OnClause<_SingleJoinSpec>> 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<_SingleJoinSpec> onJoinCte(
_JoinType joinType, @Nullable Query.DerivedModifier modifier, _Cte cteItem, String alias) {
final TabularBlocks.JoinClauseCteBlock<_SingleJoinSpec> block;
block = TabularBlocks.joinCteBlock(joinType, cteItem, alias, this);
this.blockConsumer.accept(block);
return block;
}
final _SingleJoinSpec nestedUsingEnd(final _JoinType joinType, final _NestedItems nestedItems) {
this.blockConsumer.accept(TabularBlocks.fromNestedBlock(joinType, nestedItems));
return this;
}
final _OnClause<_SingleJoinSpec> nestedJoinEnd(final _JoinType joinType, final _NestedItems nestedItems) {
final TabularBlocks.JoinClauseNestedBlock<_SingleJoinSpec> block;
block = TabularBlocks.joinNestedBlock(joinType, nestedItems, this);
this.blockConsumer.accept(block);
return block;
}
@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 void onEndStatement() {
this.fromCrossBlock = null;
}
@Override
final void onClear() {
this.returningList = null;
if (this instanceof BatchPrimarySimpleDelete) {
((BatchPrimarySimpleDelete) this).paramList = null;
}
}
private PostgreSupports.FromClauseTableBlock getFromCrossBlock() {
final _TabularBlock block = this.fromCrossBlock;
if (!(this.context.lastBlock() == block && block instanceof PostgreSupports.FromClauseTableBlock)) {
throw ContextStack.castCriteriaApi(this.context);
}
return (PostgreSupports.FromClauseTableBlock) block;
}
final TabularBlocks.FromClauseAliasDerivedBlock getFromDerived() {
final _TabularBlock block = this.fromCrossBlock;
if (!(this.context.lastBlock() == block && block instanceof TabularBlocks.FromClauseAliasDerivedBlock)) {
throw ContextStack.castCriteriaApi(this.context);
}
return (TabularBlocks.FromClauseAliasDerivedBlock) block;
}
abstract Q onAsReturningDelete();
abstract I asPostgreDelete();
@Override
final I onAsDelete() {
if (this.returningList != null) {
throw ContextStack.castCriteriaApi(this.context);
}
this.returningList = Collections.emptyList();
return this.asPostgreDelete();
}
private PostgreDeletes onAddSelection(final @Nullable SelectItem selectItem) {
if (selectItem == null) {
throw ContextStack.nullPointer(this.context);
}
List<_SelectItem> list = this.returningList;
if (list == null) {
this.returningList = list = _Collections.arrayList();
} else if (!(list instanceof ArrayList)) {
throw ContextStack.castCriteriaApi(this.context);
} else if (selectItem instanceof _SelectionGroup._TableFieldGroup) {
final String tableAlias;
tableAlias = ((_SelectionGroup._TableFieldGroup) selectItem).tableAlias();
final TableMeta> groupTable;
if (this.tableAlias().equals(tableAlias)) {
groupTable = this.table();
} else {
groupTable = this.context.getTable(tableAlias);
}
if (!((_SelectionGroup._TableFieldGroup) selectItem).isLegalGroup(groupTable)) {
throw CriteriaUtils.unknownTableFieldGroup(this.context, (_SelectionGroup._TableFieldGroup) selectItem);
}
}
list.add((_SelectItem) selectItem);
return this;
}
private PostgreDelete._SingleUsingSpec doDeleteFrom(final @Nullable SQLs.WordOnly only, final @Nullable TableMeta> table,
final @Nullable SQLs.SymbolAsterisk star, SQLs.WordAs as,
final @Nullable String tableAlias) {
if (this.targetTable != null) {
throw ContextStack.castCriteriaApi(this.context);
} else if (only != null && only != SQLs.ONLY) {
throw CriteriaUtils.errorModifier(this.context, only);
} else if (star != null && star != SQLs.ASTERISK) {
throw CriteriaUtils.errorModifier(this.context, star);
} else if (as != SQLs.AS) {
throw CriteriaUtils.errorModifier(this.context, as);
} else if (table == null) {
throw ContextStack.nullPointer(this.context);
} else if (tableAlias == null) {
throw ContextStack.nullPointer(this.context);
}
this.onlyModifier = only;
this.targetTable = table;
this.starModifier = star;
this.targetTableAlias = tableAlias;
return this;
}
private static final class SimpleJoinClauseTableBlock
extends PostgreSupports.PostgreTableOnBlock<
PostgreDelete._RepeatableOnClause,
Statement._OnClause>,
PostgreDelete._SingleJoinSpec>
implements PostgreDelete._TableSampleOnSpec,
PostgreDelete._RepeatableOnClause {
private SimpleJoinClauseTableBlock(_JoinType joinType, @Nullable SQLWords modifier, TableMeta> tableItem,
String alias, PostgreDelete._SingleJoinSpec stmt) {
super(joinType, modifier, tableItem, alias, stmt);
}
}//SimpleJoinClauseTableBlock
private static final class PrimarySimpleDelete extends PostgreDeletes
implements Delete {
private PrimarySimpleDelete() {
super(null, CriteriaContexts.primaryJoinableSingleDmlContext(PostgreUtils.DIALECT, null));
}
@Override
Delete asPostgreDelete() {
return this;
}
@Override
ReturningDelete onAsReturningDelete() {
//ReturningDelete must be wrapped
return new PrimaryReturningDeleteWrapper(this);
}
}//PrimarySimpleDelete
private static final class BatchPrimarySimpleDelete extends PostgreDeletes<
_BatchDeleteParamSpec,
_BatchReturningDeleteParamSpec>
implements BatchDelete,
_BatchStatement,
_BatchDeleteParamSpec {
private List> paramList;
private BatchPrimarySimpleDelete() {
super(null, CriteriaContexts.primaryJoinableSingleDmlContext(PostgreUtils.DIALECT, null));
}
@Override
public BatchDelete namedParamList(final List> paramList) {
if (this.paramList != null) {
throw ContextStack.clearStackAnd(_Exceptions::castCriteriaApi);
}
this.paramList = CriteriaUtils.paramList(paramList);
return this;
}
@Override
public List> paramList() {
final List> list = this.paramList;
if (list == null) {
throw ContextStack.clearStackAnd(_Exceptions::castCriteriaApi);
}
return list;
}
@Override
_BatchDeleteParamSpec asPostgreDelete() {
return this;
}
@Override
_BatchReturningDeleteParamSpec onAsReturningDelete() {
return this::createBatchReturningDelete;
}
private BatchReturningDelete createBatchReturningDelete(List
paramList) {
return new BatchReturningDeleteWrapper(this, paramList);
}
}//BatchPrimarySimpleDelete
private static final class SubSimpleDelete extends PostgreDeletes
implements SubStatement, _ReturningDml {
private final Function function;
/**
* @see #subSimpleDelete(CriteriaContext, Function)
*/
private SubSimpleDelete(CriteriaContext outerContext, Function function) {
super(null, CriteriaContexts.subJoinableSingleDmlContext(PostgreUtils.DIALECT, outerContext));
this.function = function;
}
@Override
I asPostgreDelete() {
return this.function.apply(this);
}
@Override
I onAsReturningDelete() {
// sub update statement don't need wrapper
return this.function.apply(this);
}
}//SubSimpleDelete
static abstract class PostgreReturningDeleteWrapper extends CriteriaSupports.StatementMockSupport
implements PostgreDelete, _PostgreDelete {
private final boolean recursive;
private final List<_Cte> cteList;
private final SQLs.WordOnly only;
private final TableMeta> targetTable;
private final SQLs.SymbolAsterisk starModifier;
private final String tableAlias;
private final List<_TabularBlock> tableBlockList;
private final List<_Predicate> wherePredicateList;
private final List extends _SelectItem> returningList;
private Boolean prepared = Boolean.TRUE;
private PostgreReturningDeleteWrapper(PostgreDeletes, ?> stmt) {
super(stmt.context);
this.recursive = stmt.isRecursive();
this.cteList = stmt.cteList();
this.only = stmt.onlyModifier;
this.targetTable = stmt.targetTable;
this.starModifier = stmt.starModifier;
this.tableAlias = stmt.targetTableAlias;
this.tableBlockList = stmt.tableBlockList();
this.wherePredicateList = stmt.wherePredicateList();
this.returningList = _Collections.safeUnmodifiableList(stmt.returningList);
}
@Override
public final void prepared() {
_Assert.prepared(this.prepared);
}
@Override
public final boolean isPrepared() {
final Boolean prepared = this.prepared;
return prepared != null && prepared;
}
@Override
public final void close() {
_Assert.prepared(this.prepared);
this.prepared = null;
}
@Override
final Dialect statementDialect() {
return PostgreDialect.POSTGRE15;
}
@Override
public final SQLs.WordOnly modifier() {
return this.only;
}
@Override
public final TableMeta> table() {
return this.targetTable;
}
@Override
public final SQLs.SymbolAsterisk symbolAsterisk() {
return this.starModifier;
}
@Override
public final String tableAlias() {
return this.tableAlias;
}
@Override
public final List<_Predicate> wherePredicateList() {
return this.wherePredicateList;
}
@Override
public final boolean isRecursive() {
return this.recursive;
}
@Override
public final List<_Cte> cteList() {
return this.cteList;
}
@Override
public final List<_TabularBlock> tableBlockList() {
return this.tableBlockList;
}
@Override
public final List extends _SelectItem> returningList() {
return this.returningList;
}
}//PostgreDeleteWrapper
private static final class PrimaryReturningDeleteWrapper extends PostgreReturningDeleteWrapper
implements ReturningDelete, _ReturningDml {
private PrimaryReturningDeleteWrapper(PrimarySimpleDelete stmt) {
super(stmt);
}
}//PrimaryReturningDeleteWrapper
private static final class BatchReturningDeleteWrapper extends PostgreReturningDeleteWrapper
implements BatchReturningDelete, _BatchStatement, _ReturningDml {
private final List> paramList;
private BatchReturningDeleteWrapper(BatchPrimarySimpleDelete stmt, List> paramList) {
super(stmt);
this.paramList = paramList;
}
@Override
public List> paramList() {
return this.paramList;
}
}//BatchReturningDeleteWrapper
}