parent
1d5c3a3a3a
commit
2ea8197416
@ -38,9 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.constraint;
|
||||
import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.DSL.not;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
@ -66,6 +64,14 @@ import org.jooq.InsertResultStep;
|
||||
import org.jooq.InsertSetMoreStep;
|
||||
import org.jooq.InsertSetStep;
|
||||
import org.jooq.InsertValuesStep1;
|
||||
import org.jooq.InsertValuesStep2;
|
||||
import org.jooq.InsertValuesStep3;
|
||||
import org.jooq.InsertValuesStep4;
|
||||
import org.jooq.InsertValuesStep5;
|
||||
import org.jooq.InsertValuesStep6;
|
||||
import org.jooq.InsertValuesStep7;
|
||||
import org.jooq.InsertValuesStep8;
|
||||
import org.jooq.InsertValuesStep9;
|
||||
import org.jooq.InsertValuesStep10;
|
||||
import org.jooq.InsertValuesStep11;
|
||||
import org.jooq.InsertValuesStep12;
|
||||
@ -76,17 +82,9 @@ import org.jooq.InsertValuesStep16;
|
||||
import org.jooq.InsertValuesStep17;
|
||||
import org.jooq.InsertValuesStep18;
|
||||
import org.jooq.InsertValuesStep19;
|
||||
import org.jooq.InsertValuesStep2;
|
||||
import org.jooq.InsertValuesStep20;
|
||||
import org.jooq.InsertValuesStep21;
|
||||
import org.jooq.InsertValuesStep22;
|
||||
import org.jooq.InsertValuesStep3;
|
||||
import org.jooq.InsertValuesStep4;
|
||||
import org.jooq.InsertValuesStep5;
|
||||
import org.jooq.InsertValuesStep6;
|
||||
import org.jooq.InsertValuesStep7;
|
||||
import org.jooq.InsertValuesStep8;
|
||||
import org.jooq.InsertValuesStep9;
|
||||
import org.jooq.InsertValuesStepN;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Operator;
|
||||
@ -617,16 +615,13 @@ class InsertImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
|
||||
@Override
|
||||
public final InsertImpl onConflictOnConstraint(Name constraint) {
|
||||
onConflictOnConstraint(constraint(constraint));
|
||||
getDelegate().onConflictOnConstraint(constraint);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl onConflictOnConstraint(UniqueKey<R> constraint) {
|
||||
if (constraint.getName() == null)
|
||||
throw new IllegalStateException("UniqueKey's name is not specified");
|
||||
|
||||
onConflictOnConstraint(name(constraint.getName()));
|
||||
getDelegate().onConflictOnConstraint(constraint);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +100,7 @@ import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -161,8 +162,8 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
|
||||
@Override
|
||||
public void onConflictOnConstraint(UniqueKey<R> constraint) {
|
||||
if (constraint.getName() == null)
|
||||
throw new IllegalStateException("UniqueKey's name is not specified");
|
||||
if (StringUtils.isEmpty(constraint.getName()))
|
||||
throw new IllegalArgumentException("UniqueKey's name is not specified");
|
||||
|
||||
onConflictOnConstraint(name(constraint.getName()));
|
||||
}
|
||||
@ -273,20 +274,20 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
case POSTGRES: {
|
||||
toSQLInsert(ctx);
|
||||
ctx.formatSeparator()
|
||||
.start(INSERT_ON_DUPLICATE_KEY_UPDATE);
|
||||
.start(INSERT_ON_DUPLICATE_KEY_UPDATE)
|
||||
.visit(K_ON_CONFLICT)
|
||||
.sql(' ');
|
||||
|
||||
if (onConstraint != null) {
|
||||
ctx.data(DATA_CONSTRAINT_REFERENCE, true);
|
||||
ctx.visit(K_ON_CONSTRAINT)
|
||||
.sql(' ')
|
||||
.visit(onConstraint)
|
||||
.sql(' ');
|
||||
.visit(onConstraint);
|
||||
|
||||
ctx.data().remove(DATA_CONSTRAINT_REFERENCE);
|
||||
}
|
||||
else {
|
||||
ctx.visit(K_ON_CONFLICT)
|
||||
.sql(" (");
|
||||
ctx.sql('(');
|
||||
|
||||
if (onConflict != null && onConflict.size() > 0) {
|
||||
boolean qualify = ctx.qualify();
|
||||
@ -294,9 +295,11 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
ctx.qualify(false)
|
||||
.visit(onConflict)
|
||||
.qualify(qualify);
|
||||
} else if (table.getPrimaryKey() == null) {
|
||||
}
|
||||
else if (table.getPrimaryKey() == null) {
|
||||
ctx.sql("[unknown primary key]");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
ctx.qualify(false)
|
||||
@ -304,10 +307,11 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
.qualify(qualify);
|
||||
}
|
||||
|
||||
ctx.sql(") ");
|
||||
ctx.sql(')');
|
||||
}
|
||||
|
||||
ctx.visit(K_DO_UPDATE)
|
||||
ctx.sql(' ')
|
||||
.visit(K_DO_UPDATE)
|
||||
.formatSeparator()
|
||||
.visit(K_SET)
|
||||
.sql(' ')
|
||||
@ -371,33 +375,30 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
case POSTGRES: {
|
||||
toSQLInsert(ctx);
|
||||
ctx.formatSeparator()
|
||||
.start(INSERT_ON_DUPLICATE_KEY_UPDATE);
|
||||
.start(INSERT_ON_DUPLICATE_KEY_UPDATE)
|
||||
.visit(K_ON_CONFLICT)
|
||||
.sql(' ');
|
||||
|
||||
if (onConstraint != null) {
|
||||
ctx.data(DATA_CONSTRAINT_REFERENCE, true);
|
||||
ctx.visit(K_ON_CONSTRAINT)
|
||||
.sql(' ')
|
||||
.visit(onConstraint)
|
||||
.sql(' ');
|
||||
.visit(onConstraint);
|
||||
|
||||
ctx.data().remove(DATA_CONSTRAINT_REFERENCE);
|
||||
}
|
||||
else {
|
||||
ctx.visit(K_ON_CONFLICT)
|
||||
.sql(' ');
|
||||
else if (onConflict != null && onConflict.size() > 0) {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
if (onConflict != null && onConflict.size() > 0) {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
ctx.sql('(')
|
||||
.qualify(false)
|
||||
.visit(onConflict)
|
||||
.qualify(qualify)
|
||||
.sql(") ");
|
||||
}
|
||||
ctx.sql('(')
|
||||
.qualify(false)
|
||||
.visit(onConflict)
|
||||
.qualify(qualify)
|
||||
.sql(')');
|
||||
}
|
||||
|
||||
ctx.visit(K_DO_NOTHING)
|
||||
ctx.sql(' ')
|
||||
.visit(K_DO_NOTHING)
|
||||
.end(INSERT_ON_DUPLICATE_KEY_UPDATE);
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user