All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jooq.InsertQuery Maven / Gradle / Ivy

There is a newer version: 3.19.16
Show newest version
/*
 * 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;

// ...
// ...
// ...
// ...
import static org.jooq.SQLDialect.CUBRID;
// ...
import static org.jooq.SQLDialect.DERBY;
// ...
import static org.jooq.SQLDialect.FIREBIRD;
// ...
import static org.jooq.SQLDialect.H2;
// ...
import static org.jooq.SQLDialect.HSQLDB;
// ...
// ...
import static org.jooq.SQLDialect.MARIADB;
// ...
import static org.jooq.SQLDialect.MYSQL;
// ...
import static org.jooq.SQLDialect.POSTGRES;
// ...
// ...
// ...
import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
// ...
import static org.jooq.SQLDialect.YUGABYTEDB;

import java.util.Collection;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * An INSERT statement (model API).
 * 

* This type is the model API representation of a {@link Insert} statement, * which can be mutated after creation. The advantage of this API compared to * the DSL API is a more simple approach to writing dynamic SQL. *

* Instances can be created using {@link DSLContext#insertQuery(Table)} and * overloads. * * @param The record type of the table being inserted into * @author Lukas Eder */ public interface InsertQuery extends StoreQuery, Insert, ConditionProvider { /** * Adds a new Record to the insert statement for multi-record inserts *

* Calling this method will cause subsequent calls to * {@link #addValue(Field, Object)} (and similar) to fill the next record. *

* If this call is not followed by {@link #addValue(Field, Object)} calls, * then this call has no effect. *

* If this call is done on a fresh insert statement (without any values * yet), then this call has no effect either. */ @Support void newRecord(); /** * Short for calling * newRecord(); * setRecord(record); * * * @param record The record to add to this insert statement. */ @Support void addRecord(R record); /** * Whether a ON CONFLICT clause should be added to * this INSERT statement. *

* When setting this flag to true, be sure to also add values * "for update" using the {@link #addValueForUpdate(Field, Field)} methods. * * @see InsertOnDuplicateStep#onDuplicateKeyUpdate() */ @Support void onConflict(Field... fields); /** * Whether a ON CONFLICT clause should be added to * this INSERT statement. *

* When setting this flag to true, be sure to also add values * "for update" using the {@link #addValueForUpdate(Field, Field)} methods. * * @see InsertOnDuplicateStep#onDuplicateKeyUpdate() */ @Support void onConflict(Collection> fields); /** * Whether use a ON CONFLICT or * ON CONFLICT ON CONSTRAINT clause in this INSERT * statement. */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, POSTGRES, YUGABYTEDB }) void onConflictOnConstraint(Name constraint); /** * Whether use a ON CONFLICT or * ON CONFLICT ON CONSTRAINT clause in this INSERT * statement. */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, POSTGRES, YUGABYTEDB }) void onConflictOnConstraint(Constraint constraint); /** * Whether use a ON CONFLICT or * ON CONFLICT ON CONSTRAINT clause in this INSERT * statement. */ @Support void onConflictOnConstraint(UniqueKey constraint); /** * Whether a ON DUPLICATE KEY UPDATE clause should be added to * this INSERT statement. *

* When setting this flag to true, be sure to also add values * "for update" using the {@link #addValueForUpdate(Field, Field)} methods. *

* The ON DUPLICATE KEY UPDATE flag is mutually exclusive with * the ON DUPLICATE KEY IGNORE flag (see * {@link #onDuplicateKeyIgnore(boolean)}. Setting one will unset the other * * @see InsertOnDuplicateStep#onDuplicateKeyUpdate() */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void onDuplicateKeyUpdate(boolean flag); /** * Whether an ON DUPLICATE KEY IGNORE clause should be added to * this INSERT statement. *

* This clause is not actually supported in this form by any database, but * can be emulated as such: *

* * * * * * * * * * * * * * * * * * * * *
DialectEmulation
{@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}
INSERT IGNORE INTO …
{@link SQLDialect#POSTGRES_9_5} and {@link SQLDialect#SQLITE}
INSERT INTO … ON CONFLICT DO NOTHING
{@link SQLDialect#DB2}
* {@link SQLDialect#HSQLDB}
* {@link SQLDialect#ORACLE}
* {@link SQLDialect#SQLSERVER}
* {@link SQLDialect#SYBASE}
MERGE INTO [dst]
     * USING ([values])
     * ON [dst.key] = [values.key]
     * WHEN NOT MATCHED THEN INSERT ..
All the others
INSERT INTO [dst] ( ... )
     * SELECT [values]
     * WHERE NOT EXISTS (
     *   SELECT 1
     *   FROM [dst]
     *   WHERE [dst.key] = [values.key]
     * )
*

* The ON DUPLICATE KEY UPDATE flag is mutually exclusive with * the ON DUPLICATE KEY IGNORE flag (see * {@link #onDuplicateKeyIgnore(boolean)}. Setting one will unset the other */ @Support void onDuplicateKeyIgnore(boolean flag); /** * Add a value to the ON DUPLICATE KEY UPDATE clause of this * INSERT statement, where this is supported. * * @see InsertOnDuplicateStep#onDuplicateKeyUpdate() */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addValueForUpdate(Field field, T value); /** * Add a value to the ON DUPLICATE KEY UPDATE clause of this * INSERT statement, where this is supported. * * @see InsertOnDuplicateStep#onDuplicateKeyUpdate() */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addValueForUpdate(Field field, Field value); /** * Add multiple values to the ON DUPLICATE KEY UPDATE clause of * this INSERT statement, where this is supported. *

* Please assure that key/value pairs have matching <T> * types. Values can either be of type <T> or * Field<T> * * @see InsertOnDuplicateStep#onDuplicateKeyUpdate() */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addValuesForUpdate(Map map); /** * Adds a new condition the {@link #onConflict(Field...)} clause. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param condition The condition */ @Support({ POSTGRES, SQLITE, YUGABYTEDB }) void onConflictWhere(Condition condition); /** * Adds a new condition to the query, connecting it to existing conditions * with {@link Operator#AND}. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param condition The condition */ @Override @Support({ CUBRID, DERBY, H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addConditions(Condition condition); /** * Adds new conditions to the query, connecting them to existing conditions * with {@link Operator#AND}. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param conditions The condition */ @Override @Support({ CUBRID, DERBY, H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addConditions(Condition... conditions); /** * Adds new conditions to the query, connecting them to existing * conditions with {@link Operator#AND}. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param conditions The condition */ @Override @Support({ CUBRID, DERBY, H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addConditions(Collection conditions); /** * Adds a new condition to the query, connecting it to existing * conditions with the provided operator. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param condition The condition */ @Override @Support({ CUBRID, DERBY, H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addConditions(Operator operator, Condition condition); /** * Adds new conditions to the query, connecting them to existing * conditions with the provided operator. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param conditions The condition */ @Override @Support({ CUBRID, DERBY, H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addConditions(Operator operator, Condition... conditions); /** * Adds new conditions to the query, connecting them to existing * conditions with the provided operator. *

* This is for use with {@link SQLDialect#POSTGRES}'s * {@link #onConflict(Field...)} clause. * * @param conditions The condition */ @Override @Support({ CUBRID, DERBY, H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addConditions(Operator operator, Collection conditions); /** * Set an empty record with the DEFAULT VALUES clause. */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void setDefaultValues(); /** * Use a SELECT statement as the source of values for the * INSERT statement. */ @Support void setSelect(Field[] fields, Select select); /** * Use a SELECT statement as the source of values for the * INSERT statement. */ @Support void setSelect(Collection> fields, Select select); /** * {@inheritDoc} *

* This feature works with INSERT statements for all SQL dialects */ @Override @Support void setReturning(); /** * {@inheritDoc} *

* This feature works with INSERT statements for all SQL dialects */ @Override @Support void setReturning(Identity identity); /** * {@inheritDoc} *

* This feature works with INSERT statements for all SQL dialects */ @Override @Support void setReturning(SelectFieldOrAsterisk... fields); /** * {@inheritDoc} *

* This feature works with INSERT statements for all SQL dialects */ @Override @Support void setReturning(Collection fields); /** * {@inheritDoc} *

* This feature works with INSERT statements for all SQL dialects */ @Override @Nullable @Support R getReturnedRecord(); /** * {@inheritDoc} *

* This feature works with INSERT statements for all SQL dialects */ @Override @NotNull @Support Result getReturnedRecords(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy