[#5637] Add support for PostgreSQL ON CONFLICT DO UPDATE WHERE
This commit is contained in:
parent
6d87288883
commit
ff07baf84c
275
jOOQ/src/main/java/org/jooq/InsertOnConflictConditionStep.java
Normal file
275
jOOQ/src/main/java/org/jooq/InsertOnConflictConditionStep.java
Normal file
@ -0,0 +1,275 @@
|
||||
/*
|
||||
* 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
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import static org.jooq.SQLDialect.POSTGRES_9_5;
|
||||
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
/**
|
||||
* This type is used for the {@link Insert}'s DSL API.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* DSLContext create = DSL.using(configuration);
|
||||
*
|
||||
* create.insertInto(table, field1, field2)
|
||||
* .values(value1, value2)
|
||||
* .values(value3, value4)
|
||||
* .onDuplicateKeyUpdate()
|
||||
* .set(field1, value1)
|
||||
* .set(field2, value2)
|
||||
* .execute();
|
||||
* </pre></code>
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface InsertOnConflictConditionStep<R extends Record> extends InsertFinalStep<R> {
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#AND} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> and(Condition condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#AND} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> and(Field<Boolean> condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#AND} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(SQL)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> and(SQL sql);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#AND} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> and(String sql);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#AND} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String, Object...)
|
||||
* @see DSL#sql(String, Object...)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> and(String sql, Object... bindings);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#AND} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String, QueryPart...)
|
||||
* @see DSL#sql(String, QueryPart...)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> and(String sql, QueryPart... parts);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with a negated other one using
|
||||
* the {@link Operator#AND} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> andNot(Condition condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with a negated other one using
|
||||
* the {@link Operator#AND} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> andNot(Field<Boolean> condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with an EXISTS clause using
|
||||
* the {@link Operator#AND} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> andExists(Select<?> select);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with a NOT EXISTS clause using
|
||||
* the {@link Operator#AND} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> andNotExists(Select<?> select);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#OR} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> or(Condition condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#OR} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> or(Field<Boolean> condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#OR} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(SQL)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> or(SQL sql);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#OR} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> or(String sql);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#OR} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String, Object...)
|
||||
* @see DSL#sql(String, Object...)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> or(String sql, Object... bindings);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with another one using the
|
||||
* {@link Operator#OR} operator and proceed to the next step.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String, QueryPart...)
|
||||
* @see DSL#sql(String, QueryPart...)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertOnConflictConditionStep<R> or(String sql, QueryPart... parts);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with a negated other one using
|
||||
* the {@link Operator#OR} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> orNot(Condition condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with a negated other one using
|
||||
* the {@link Operator#OR} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> orNot(Field<Boolean> condition);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with an EXISTS clause using
|
||||
* the {@link Operator#OR} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> orExists(Select<?> select);
|
||||
|
||||
/**
|
||||
* Combine the currently assembled conditions with a NOT EXISTS clause using
|
||||
* the {@link Operator#OR} operator and proceed to the next step.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertOnConflictConditionStep<R> orNotExists(Select<?> select);
|
||||
}
|
||||
155
jOOQ/src/main/java/org/jooq/InsertOnConflictWhereStep.java
Normal file
155
jOOQ/src/main/java/org/jooq/InsertOnConflictWhereStep.java
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import static org.jooq.SQLDialect.POSTGRES_9_5;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
/**
|
||||
* This type is used for the {@link Insert}'s DSL API.
|
||||
* <p>
|
||||
* Example: <code><pre>
|
||||
* DSLContext create = DSL.using(configuration);
|
||||
*
|
||||
* create.insertInto(table, field1, field2)
|
||||
* .values(value1, value2)
|
||||
* .values(value3, value4)
|
||||
* .onDuplicateKeyUpdate()
|
||||
* .set(field1, value1)
|
||||
* .set(field2, value2)
|
||||
* .execute();
|
||||
* </pre></code>
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface InsertOnConflictWhereStep<R extends Record> extends InsertFinalStep<R> {
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query, connecting them with each
|
||||
* other with {@link Operator#AND}.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertFinalStep<R> where(Condition... conditions);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query, connecting them with each
|
||||
* other with {@link Operator#AND}.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertFinalStep<R> where(Collection<? extends Condition> conditions);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertFinalStep<R> where(Field<Boolean> field);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(SQL)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertFinalStep<R> where(SQL sql);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertFinalStep<R> where(String sql);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String, Object...)
|
||||
* @see DSL#sql(String, Object...)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertFinalStep<R> where(String sql, Object... bindings);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE</code> clause to the query.
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @see DSL#condition(String, QueryPart...)
|
||||
* @see DSL#sql(String, QueryPart...)
|
||||
* @see SQL
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
@PlainSQL
|
||||
InsertFinalStep<R> where(String sql, QueryPart... parts);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE EXISTS</code> clause to the query.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertFinalStep<R> whereExists(Select<?> select);
|
||||
|
||||
/**
|
||||
* Add a <code>WHERE NOT EXISTS</code> clause to the query.
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
InsertFinalStep<R> whereNotExists(Select<?> select);
|
||||
}
|
||||
@ -51,6 +51,6 @@ package org.jooq;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface InsertOnDuplicateSetMoreStep<R extends Record> extends InsertOnDuplicateSetStep<R>, InsertFinalStep<R> {
|
||||
public interface InsertOnDuplicateSetMoreStep<R extends Record> extends InsertOnDuplicateSetStep<R>, InsertOnConflictWhereStep<R> {
|
||||
|
||||
}
|
||||
|
||||
@ -216,6 +216,54 @@ public interface InsertQuery<R extends Record> extends StoreQuery<R>, Insert<R>
|
||||
@Support({ CUBRID, HSQLDB, MARIADB, MYSQL, POSTGRES_9_5 })
|
||||
void addValuesForUpdate(Map<? extends Field<?>, ?> map);
|
||||
|
||||
/**
|
||||
* Adds new conditions to the query, connecting them to existing conditions
|
||||
* with {@link Operator#AND}.
|
||||
* <p>
|
||||
* This is for use with {@link SQLDialect#POSTGRES}'s
|
||||
* {@link #onConflict(Field...)} clause.
|
||||
*
|
||||
* @param conditions The condition
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
void addConditions(Condition... conditions);
|
||||
|
||||
/**
|
||||
* Adds new conditions to the query, connecting them to existing
|
||||
* conditions with {@link Operator#AND}.
|
||||
* <p>
|
||||
* This is for use with {@link SQLDialect#POSTGRES}'s
|
||||
* {@link #onConflict(Field...)} clause.
|
||||
*
|
||||
* @param conditions The condition
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
void addConditions(Collection<? extends Condition> conditions);
|
||||
|
||||
/**
|
||||
* Adds new conditions to the query, connecting them to existing
|
||||
* conditions with the provided operator.
|
||||
* <p>
|
||||
* This is for use with {@link SQLDialect#POSTGRES}'s
|
||||
* {@link #onConflict(Field...)} clause.
|
||||
*
|
||||
* @param conditions The condition
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
void addConditions(Operator operator, Condition... conditions);
|
||||
|
||||
/**
|
||||
* Adds new conditions to the query, connecting them to existing
|
||||
* conditions with the provided operator.
|
||||
* <p>
|
||||
* This is for use with {@link SQLDialect#POSTGRES}'s
|
||||
* {@link #onConflict(Field...)} clause.
|
||||
*
|
||||
* @param conditions The condition
|
||||
*/
|
||||
@Support({ POSTGRES_9_5 })
|
||||
void addConditions(Operator operator, Collection<? extends Condition> conditions);
|
||||
|
||||
/**
|
||||
* Set an empty record with the <code>DEFAULT VALUES</code> clause.
|
||||
*/
|
||||
|
||||
@ -34,6 +34,10 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.not;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -44,16 +48,26 @@ import java.util.Optional;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.FieldLike;
|
||||
import org.jooq.InsertOnConflictDoUpdateStep;
|
||||
import org.jooq.InsertOnDuplicateSetMoreStep;
|
||||
import org.jooq.InsertOnConflictConditionStep;
|
||||
import org.jooq.InsertOnConflictDoUpdateStep;
|
||||
import org.jooq.InsertQuery;
|
||||
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;
|
||||
@ -64,22 +78,17 @@ 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.Operator;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.SQL;
|
||||
import org.jooq.Table;
|
||||
|
||||
/**
|
||||
@ -119,6 +128,7 @@ class InsertImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
InsertSetMoreStep<R>,
|
||||
InsertOnDuplicateSetMoreStep<R>,
|
||||
InsertOnConflictDoUpdateStep<R>,
|
||||
InsertOnConflictConditionStep<R>,
|
||||
InsertResultStep<R> {
|
||||
|
||||
/**
|
||||
@ -658,6 +668,155 @@ class InsertImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
return set(Tools.mapOfChangedValues(record));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl and(Condition condition) {
|
||||
getDelegate().addConditions(condition);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl and(Field<Boolean> condition) {
|
||||
return and(condition(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl and(SQL sql) {
|
||||
return and(condition(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl and(String sql) {
|
||||
return and(condition(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl and(String sql, Object... bindings) {
|
||||
return and(condition(sql, bindings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl and(String sql, QueryPart... parts) {
|
||||
return and(condition(sql, parts));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl andNot(Condition condition) {
|
||||
return and(not(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl andNot(Field<Boolean> condition) {
|
||||
return and(not(condition(condition)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl andExists(Select<?> select) {
|
||||
return and(exists(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl andNotExists(Select<?> select) {
|
||||
return and(notExists(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl or(Condition condition) {
|
||||
getDelegate().addConditions(Operator.OR, condition);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl or(Field<Boolean> condition) {
|
||||
return or(condition(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl or(SQL sql) {
|
||||
return or(condition(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl or(String sql) {
|
||||
return or(condition(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl or(String sql, Object... bindings) {
|
||||
return or(condition(sql, bindings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl or(String sql, QueryPart... parts) {
|
||||
return or(condition(sql, parts));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl orNot(Condition condition) {
|
||||
return or(not(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl orNot(Field<Boolean> condition) {
|
||||
return or(not(condition(condition)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl orExists(Select<?> select) {
|
||||
return or(exists(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl orNotExists(Select<?> select) {
|
||||
return or(notExists(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(Condition... conditions) {
|
||||
getDelegate().addConditions(conditions);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(Collection<? extends Condition> conditions) {
|
||||
getDelegate().addConditions(conditions);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(Field<Boolean> field) {
|
||||
return where(condition(field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(SQL sql) {
|
||||
return where(condition(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(String sql) {
|
||||
return where(condition(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(String sql, Object... bindings) {
|
||||
return where(condition(sql, bindings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl where(String sql, QueryPart... parts) {
|
||||
return where(condition(sql, parts));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl whereExists(Select<?> select) {
|
||||
return where(exists(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl whereNotExists(Select<?> select) {
|
||||
return where(notExists(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final InsertImpl newRecord() {
|
||||
getDelegate().newRecord();
|
||||
|
||||
@ -66,6 +66,7 @@ import org.jooq.InsertQuery;
|
||||
import org.jooq.Merge;
|
||||
import org.jooq.MergeNotMatchedStep;
|
||||
import org.jooq.MergeOnConditionStep;
|
||||
import org.jooq.Operator;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.SQLDialect;
|
||||
@ -78,22 +79,24 @@ import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
*/
|
||||
final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements InsertQuery<R> {
|
||||
|
||||
private static final long serialVersionUID = 4466005417945353842L;
|
||||
private static final Clause[] CLAUSES = { INSERT };
|
||||
private static final long serialVersionUID = 4466005417945353842L;
|
||||
private static final Clause[] CLAUSES = { INSERT };
|
||||
|
||||
private final FieldMapForUpdate updateMap;
|
||||
private final FieldMapsForInsert insertMaps;
|
||||
private Select<?> select;
|
||||
private boolean defaultValues;
|
||||
private boolean onDuplicateKeyUpdate;
|
||||
private boolean onDuplicateKeyIgnore;
|
||||
private QueryPartList<Field<?>> onConflict;
|
||||
private final FieldMapForUpdate updateMap;
|
||||
private final FieldMapsForInsert insertMaps;
|
||||
private Select<?> select;
|
||||
private boolean defaultValues;
|
||||
private boolean onDuplicateKeyUpdate;
|
||||
private boolean onDuplicateKeyIgnore;
|
||||
private QueryPartList<Field<?>> onConflict;
|
||||
private final ConditionProviderImpl condition;
|
||||
|
||||
InsertQueryImpl(Configuration configuration, WithImpl with, Table<R> into) {
|
||||
super(configuration, with, into);
|
||||
|
||||
this.updateMap = new FieldMapForUpdate(INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT);
|
||||
this.insertMaps = new FieldMapsForInsert();
|
||||
this.condition = new ConditionProviderImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -149,6 +152,26 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
updateMap.set(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addConditions(Condition... conditions) {
|
||||
condition.addConditions(conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addConditions(Collection<? extends Condition> conditions) {
|
||||
condition.addConditions(conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addConditions(Operator operator, Condition... conditions) {
|
||||
condition.addConditions(operator, conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addConditions(Operator operator, Collection<? extends Condition> conditions) {
|
||||
condition.addConditions(operator, conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setDefaultValues() {
|
||||
defaultValues = true;
|
||||
@ -222,8 +245,15 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
.sql(' ')
|
||||
.formatIndentLockStart()
|
||||
.visit(updateMap)
|
||||
.formatIndentLockEnd()
|
||||
.end(INSERT_ON_DUPLICATE_KEY_UPDATE);
|
||||
.formatIndentLockEnd();
|
||||
|
||||
if (!(condition.getWhere() instanceof TrueCondition))
|
||||
ctx.formatSeparator()
|
||||
.keyword("where")
|
||||
.sql(' ')
|
||||
.visit(condition);
|
||||
|
||||
ctx.end(INSERT_ON_DUPLICATE_KEY_UPDATE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user