org.jooq.InsertQuery Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* This work is dual-licensed
* - under the Apache Software License 2.0 (the "ASL")
* - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
* =============================================================================
* You may choose which license applies to you:
*
* - If you're using this work with Open Source databases, you may choose
* either ASL or jOOQ License.
* - If you're using this work with at least one commercial database, you must
* choose jOOQ License
*
* For more information, please visit http://www.jooq.org/licenses
*
* Apache Software License 2.0:
* -----------------------------------------------------------------------------
* 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.
*
* jOOQ License and Maintenance Agreement:
* -----------------------------------------------------------------------------
* Data Geekery grants the Customer the non-exclusive, timely limited and
* non-transferable license to install and use the Software under the terms of
* the jOOQ License and Maintenance Agreement.
*
* This library is distributed with a LIMITED WARRANTY. See the jOOQ License
* and Maintenance Agreement for more details: http://www.jooq.org/licensing
*/
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 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 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 })
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 simulated as such:
*
*
* Dialect
* Simulation
*
*
* {@link SQLDialect#MYSQL}
* INSERT IGNORE INTO ..
*
*
* {@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]) src
* ON [dst.key] = [src.key]
* WHEN NOT MATCHED THEN INSERT ..
*
*
*
* 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({ CUBRID, HSQLDB, MARIADB, MYSQL })
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 })
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 })
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 })
void addValuesForUpdate(Map extends Field>, ?> map);
/**
* Set an empty record with the DEFAULT VALUES
clause.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void setDefaultValues();
/**
* {@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 extends Field>> 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();
}