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.9
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
 * 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.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.POSTGRES_9_5;
import static org.jooq.SQLDialect.SQLITE;
// ...
// ...

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

/**
 * A query for data insertion
 *
 * @param  The record type of the table being inserted into
 * @author Lukas Eder
 */
public interface InsertQuery extends StoreQuery, Insert {

    /**
     * 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({ POSTGRES_9_5 }) 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({ POSTGRES_9_5 }) void onConflict(Collection> fields); /** * 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, HSQLDB, MARIADB, MYSQL, POSTGRES_9_5 }) 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}
INSERT INTO .. ON CONFLICT DO NOTHING
{@link SQLDialect#CUBRID} *
INSERT INTO .. ON DUPLICATE KEY UPDATE [any-field] = [any-field]
*
{@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, HSQLDB, MARIADB, MYSQL, POSTGRES_9_5 }) 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, HSQLDB, MARIADB, MYSQL, POSTGRES_9_5 }) 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, HSQLDB, MARIADB, MYSQL, POSTGRES_9_5 }) void addValuesForUpdate(Map map); /** * 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 */ @Support({ POSTGRES_9_5 }) 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 */ @Support({ POSTGRES_9_5 }) void addConditions(Collection 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 */ @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. *

* 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 conditions); /** * Set an empty record with the DEFAULT VALUES clause. */ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) void setDefaultValues(); /** * Use a SELECT statement as the source of values for the * INSERT statement. */ @Support void setSelect(Field[] 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(Field... 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 @Support R getReturnedRecord(); /** * {@inheritDoc} *

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy