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.
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* Apache-2.0 license and offer limited warranties, support, maintenance, and
* commercial database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static java.lang.Boolean.TRUE;
import static org.jooq.Clause.CONSTRAINT;
// ...
// ...
import static org.jooq.SQLDialect.IGNITE;
// ...
// ...
// ...
import static org.jooq.impl.ConstraintImpl.Action.CASCADE;
import static org.jooq.impl.ConstraintImpl.Action.NO_ACTION;
import static org.jooq.impl.ConstraintImpl.Action.RESTRICT;
import static org.jooq.impl.ConstraintImpl.Action.SET_DEFAULT;
import static org.jooq.impl.ConstraintImpl.Action.SET_NULL;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.Keywords.K_CHECK;
import static org.jooq.impl.Keywords.K_CONSTRAINT;
import static org.jooq.impl.Keywords.K_DISABLE;
import static org.jooq.impl.Keywords.K_ENABLE;
import static org.jooq.impl.Keywords.K_ENFORCED;
import static org.jooq.impl.Keywords.K_FOREIGN_KEY;
import static org.jooq.impl.Keywords.K_NONCLUSTERED;
import static org.jooq.impl.Keywords.K_NOT;
import static org.jooq.impl.Keywords.K_NOT_ENFORCED;
import static org.jooq.impl.Keywords.K_ON_DELETE;
import static org.jooq.impl.Keywords.K_ON_UPDATE;
import static org.jooq.impl.Keywords.K_PRIMARY_KEY;
import static org.jooq.impl.Keywords.K_REFERENCES;
import static org.jooq.impl.Keywords.K_UNIQUE;
import static org.jooq.impl.QueryPartListView.wrap;
import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.EMPTY_NAME;
import static org.jooq.impl.Tools.EMPTY_STRING;
import static org.jooq.impl.Tools.fieldsByName;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE;
import java.util.Collection;
import java.util.Set;
import org.jooq.Clause;
import org.jooq.Condition;
import org.jooq.ConstraintForeignKeyOnStep;
import org.jooq.ConstraintForeignKeyReferencesStep1;
import org.jooq.ConstraintForeignKeyReferencesStep10;
import org.jooq.ConstraintForeignKeyReferencesStep11;
import org.jooq.ConstraintForeignKeyReferencesStep12;
import org.jooq.ConstraintForeignKeyReferencesStep13;
import org.jooq.ConstraintForeignKeyReferencesStep14;
import org.jooq.ConstraintForeignKeyReferencesStep15;
import org.jooq.ConstraintForeignKeyReferencesStep16;
import org.jooq.ConstraintForeignKeyReferencesStep17;
import org.jooq.ConstraintForeignKeyReferencesStep18;
import org.jooq.ConstraintForeignKeyReferencesStep19;
import org.jooq.ConstraintForeignKeyReferencesStep2;
import org.jooq.ConstraintForeignKeyReferencesStep20;
import org.jooq.ConstraintForeignKeyReferencesStep21;
import org.jooq.ConstraintForeignKeyReferencesStep22;
import org.jooq.ConstraintForeignKeyReferencesStep3;
import org.jooq.ConstraintForeignKeyReferencesStep4;
import org.jooq.ConstraintForeignKeyReferencesStep5;
import org.jooq.ConstraintForeignKeyReferencesStep6;
import org.jooq.ConstraintForeignKeyReferencesStep7;
import org.jooq.ConstraintForeignKeyReferencesStep8;
import org.jooq.ConstraintForeignKeyReferencesStep9;
import org.jooq.ConstraintForeignKeyReferencesStepN;
import org.jooq.ConstraintTypeStep;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.Keyword;
import org.jooq.Name;
// ...
import org.jooq.SQLDialect;
import org.jooq.Table;
import org.jooq.impl.QOM.UNotYetImplemented;
import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
@SuppressWarnings("rawtypes")
final class ConstraintImpl extends AbstractNamed
implements
UNotYetImplemented
, ConstraintTypeStep
, ConstraintForeignKeyOnStep
, ConstraintForeignKeyReferencesStepN
, ConstraintForeignKeyReferencesStep1
, ConstraintForeignKeyReferencesStep2
, ConstraintForeignKeyReferencesStep3
, ConstraintForeignKeyReferencesStep4
, ConstraintForeignKeyReferencesStep5
, ConstraintForeignKeyReferencesStep6
, ConstraintForeignKeyReferencesStep7
, ConstraintForeignKeyReferencesStep8
, ConstraintForeignKeyReferencesStep9
, ConstraintForeignKeyReferencesStep10
, ConstraintForeignKeyReferencesStep11
, ConstraintForeignKeyReferencesStep12
, ConstraintForeignKeyReferencesStep13
, ConstraintForeignKeyReferencesStep14
, ConstraintForeignKeyReferencesStep15
, ConstraintForeignKeyReferencesStep16
, ConstraintForeignKeyReferencesStep17
, ConstraintForeignKeyReferencesStep18
, ConstraintForeignKeyReferencesStep19
, ConstraintForeignKeyReferencesStep20
, ConstraintForeignKeyReferencesStep21
, ConstraintForeignKeyReferencesStep22
{
private static final Clause[] CLAUSES = { CONSTRAINT };
private static final Set NO_SUPPORT_PK = SQLDialect.supportedBy();
private static final Set NO_SUPPORT_UK = SQLDialect.supportedBy(IGNITE);
private static final Set NO_SUPPORT_FK = SQLDialect.supportedBy(IGNITE);
private static final Set NO_SUPPORT_CHECK = SQLDialect.supportedBy(IGNITE);
private Field>[] unique;
private Field>[] primaryKey;
private Field>[] foreignKey;
private Table> referencesTable;
private Field>[] references;
private Action onDelete;
private Action onUpdate;
private Condition check;
private boolean enforced = true;
ConstraintImpl() {
this(null);
}
ConstraintImpl(Name name) {
super(name, null);
}
final Field>[] $unique() { return unique; }
final Field>[] $primaryKey() { return primaryKey; }
final Field>[] $foreignKey() { return foreignKey; }
final Table> $referencesTable() { return referencesTable; }
final Field>[] $references() { return references; }
final Action $onDelete() { return onDelete; }
final Action $onUpdate() { return onUpdate; }
final Condition $check() { return check; }
final boolean $enforced() { return enforced; }
// ------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------
@Override
public final Clause[] clauses(Context> ctx) {
return CLAUSES;
}
@Override
public final void accept(Context> ctx) {
boolean named = !getQualifiedName().equals(AbstractName.NO_NAME);
if (named && TRUE.equals(ctx.data(DATA_CONSTRAINT_REFERENCE))) {
ctx.visit(getQualifiedName());
}
else {
boolean qualify = ctx.qualify();
if (named ) {
ctx.visit(K_CONSTRAINT)
.sql(' ')
.visit(getUnqualifiedName())
.formatIndentStart()
.formatSeparator();
}
if (unique != null) {
ctx.visit(K_UNIQUE)
.sql(" (").visit(wrap(unique).qualify(false)).sql(')');
}
else if (primaryKey != null) {
ctx.visit(K_PRIMARY_KEY);
ctx.sql(" (").visit(wrap(primaryKey).qualify(false)).sql(')');
}
else if (foreignKey != null) {
ctx.visit(K_FOREIGN_KEY)
.sql(" (").visit(wrap(foreignKey).qualify(false)).sql(')')
.formatSeparator()
.visit(K_REFERENCES)
.sql(' ')
.visit(referencesTable);
if (references.length > 0)
ctx.sql(" (").visit(wrap(references).qualify(false)).sql(')');
if (onDelete != null)
ctx.sql(' ').visit(K_ON_DELETE)
.sql(' ').visit(onDelete.keyword);
if (onUpdate != null)
ctx.sql(' ').visit(K_ON_UPDATE)
.sql(' ').visit(onUpdate.keyword);
}
else if (check != null) {
ctx.visit(K_CHECK)
.sql(" (").qualify(false, c -> c.visit(check)).sql(')');
}
if (!enforced)
acceptEnforced(ctx, enforced);
if (named) {
ctx.formatIndentEnd();
}
}
}
static void acceptEnforced(Context> ctx, boolean enforced) {
switch (ctx.family()) {
default:
if (enforced)
ctx.sql(' ').visit(K_ENFORCED);
else
ctx.sql(' ').visit(K_NOT).sql(' ').visit(K_ENFORCED);
break;
}
}
// ------------------------------------------------------------------------
// XXX: Constraint API
// ------------------------------------------------------------------------
@Override
public final ConstraintImpl unique(String... fields) {
return unique(fieldsByName(fields));
}
@Override
public final ConstraintImpl unique(Name... fields) {
return unique(fieldsByName(fields));
}
@Override
public final ConstraintImpl unique(Field>... fields) {
unique = fields;
return this;
}
@Override
public final ConstraintImpl unique(Collection extends Field>> fields) {
return unique(fields.toArray(EMPTY_FIELD));
}
@Override
public final ConstraintImpl check(Condition condition) {
check = condition;
return this;
}
@Override
public final ConstraintImpl primaryKey(String... fields) {
return primaryKey(fieldsByName(fields));
}
@Override
public final ConstraintImpl primaryKey(Name... fields) {
return primaryKey(fieldsByName(fields));
}
@Override
public final ConstraintImpl primaryKey(Field>... fields) {
primaryKey = fields;
return this;
}
@Override
public final ConstraintImpl primaryKey(Collection extends Field>> fields) {
return primaryKey(fields.toArray(EMPTY_FIELD));
}
@Override
public final ConstraintImpl foreignKey(String... fields) {
return foreignKey(fieldsByName(fields));
}
@Override
public final ConstraintImpl foreignKey(Name... fields) {
return foreignKey(fieldsByName(fields));
}
@Override
public final ConstraintImpl foreignKey(Field>... fields) {
foreignKey = fields;
return this;
}
@Override
public final ConstraintImpl foreignKey(Collection extends Field>> fields) {
return foreignKey(fields.toArray(EMPTY_FIELD));
}
@Override
public final ConstraintImpl references(String table) {
return references(table(name(table)), EMPTY_FIELD);
}
@Override
public final ConstraintImpl references(String table, String... fields) {
return references(table(name(table)), fieldsByName(fields));
}
@Override
public final ConstraintImpl references(String table, Collection extends String> fields) {
return references(table, fields.toArray(EMPTY_STRING));
}
@Override
public final ConstraintImpl references(Name table) {
return references(table(table), EMPTY_FIELD);
}
@Override
public final ConstraintImpl references(Name table, Name... fields) {
return references(table(table), fieldsByName(fields));
}
@Override
public final ConstraintImpl references(Name table, Collection extends Name> fields) {
return references(table, fields.toArray(EMPTY_NAME));
}
@Override
public final ConstraintImpl references(Table table) {
return references(table, EMPTY_FIELD);
}
@Override
public final ConstraintImpl references(Table> table, Field>... fields) {
referencesTable = table;
references = fields;
return this;
}
@Override
public final ConstraintImpl references(Table> table, Collection extends Field>> fields) {
return references(table, fields.toArray(EMPTY_FIELD));
}
@Override
public final ConstraintImpl onDeleteNoAction() {
onDelete = NO_ACTION;
return this;
}
@Override
public final ConstraintImpl onDeleteRestrict() {
onDelete = RESTRICT;
return this;
}
@Override
public final ConstraintImpl onDeleteCascade() {
onDelete = CASCADE;
return this;
}
@Override
public final ConstraintImpl onDeleteSetNull() {
onDelete = SET_NULL;
return this;
}
@Override
public final ConstraintImpl onDeleteSetDefault() {
onDelete = SET_DEFAULT;
return this;
}
@Override
public final ConstraintImpl onUpdateNoAction() {
onUpdate = NO_ACTION;
return this;
}
@Override
public final ConstraintImpl onUpdateRestrict() {
onUpdate = RESTRICT;
return this;
}
@Override
public final ConstraintImpl onUpdateCascade() {
onUpdate = CASCADE;
return this;
}
@Override
public final ConstraintImpl onUpdateSetNull() {
onUpdate = SET_NULL;
return this;
}
@Override
public final ConstraintImpl onUpdateSetDefault() {
onUpdate = SET_DEFAULT;
return this;
}
@Override
public final ConstraintImpl foreignKey(Field field1) {
return foreignKey(new Field[] { field1 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2) {
return foreignKey(new Field[] { field1, field2 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3) {
return foreignKey(new Field[] { field1, field2, field3 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4) {
return foreignKey(new Field[] { field1, field2, field3, field4 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18, Field field19) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18, Field field19, Field field20) {
return foreignKey(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20 });
}
@Override
public final ConstraintImpl foreignKey(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field