R
- The record type of the table being inserted intopublic interface InsertQuery<R extends Record> extends StoreQuery<R>, Insert<R>
Modifier and Type | Method and Description |
---|---|
void |
addConditions(Collection<? extends Condition> conditions)
Adds new conditions to the query, connecting them to existing
conditions with
Operator.AND . |
void |
addConditions(Condition... conditions)
Adds new conditions to the query, connecting them to existing conditions
with
Operator.AND . |
void |
addConditions(Condition condition)
Adds a new condition to the query, connecting it to existing conditions
with
Operator.AND . |
void |
addConditions(Operator operator,
Collection<? extends Condition> conditions)
Adds new conditions to the query, connecting them to existing
conditions with the provided operator.
|
void |
addConditions(Operator operator,
Condition... conditions)
Adds new conditions to the query, connecting them to existing
conditions with the provided operator.
|
void |
addConditions(Operator operator,
Condition condition)
Adds a new condition to the query, connecting it to existing
conditions with the provided operator.
|
void |
addRecord(R record)
Short for calling
newRecord();
setRecord(record);
|
<T> void |
addValueForUpdate(Field<T> field,
Field<T> value)
Add a value to the
ON DUPLICATE KEY UPDATE clause of this
INSERT statement, where this is supported. |
<T> void |
addValueForUpdate(Field<T> field,
T value)
Add a value to the
ON DUPLICATE KEY UPDATE clause of this
INSERT statement, where this is supported. |
void |
addValuesForUpdate(Map<?,?> map)
Add multiple values to the
ON DUPLICATE KEY UPDATE clause of
this INSERT statement, where this is supported. |
R |
getReturnedRecord()
The record holding returned values as specified by any of the
StoreQuery.setReturning() methods. |
Result<R> |
getReturnedRecords()
The records holding returned values as specified by any of the
StoreQuery.setReturning() methods. |
void |
newRecord()
Adds a new Record to the insert statement for multi-record inserts
Calling this method will cause subsequent calls to
StoreQuery.addValue(Field, Object) (and similar) to fill the next record. |
void |
onConflict(Collection<? extends Field<?>> fields)
Whether a
ON CONFLICT clause should be added to
this INSERT statement. |
void |
onConflict(Field<?>... fields)
Whether a
ON CONFLICT clause should be added to
this INSERT statement. |
void |
onConflictOnConstraint(Constraint constraint)
Whether use a
On CONFLICT or
ON CONFLICT ON CONSTRAINT clause in this INSERT
statement. |
void |
onConflictOnConstraint(Name constraint)
Whether use a
On CONFLICT or
ON CONFLICT ON CONSTRAINT clause in this INSERT
statement. |
void |
onConflictOnConstraint(UniqueKey<R> constraint)
Whether use a
On CONFLICT or
ON CONFLICT ON CONSTRAINT clause in this INSERT
statement. |
void |
onDuplicateKeyIgnore(boolean flag)
Whether an
ON DUPLICATE KEY IGNORE clause should be added to
this INSERT statement. |
void |
onDuplicateKeyUpdate(boolean flag)
Whether a
ON DUPLICATE KEY UPDATE clause should be added to
this INSERT statement. |
void |
setDefaultValues()
Set an empty record with the
DEFAULT VALUES clause. |
void |
setReturning()
Configure the
INSERT or UPDATE statement to return all fields in
R . |
void |
setReturning(Collection<? extends SelectFieldOrAsterisk> fields)
Configure the
INSERT or UPDATE statement to return a list of fields in
R . |
void |
setReturning(Identity<R,?> identity)
Configure the
INSERT or UPDATE statement to return the generated
identity value. |
void |
setReturning(SelectFieldOrAsterisk... fields)
Configure the
INSERT or UPDATE statement to return a list of fields in
R . |
void |
setSelect(Field<?>[] fields,
Select<?> select)
Use a
SELECT statement as the source of values for the
INSERT statement. |
addValue, addValue, addValues, getResult, setRecord
bind, bind, cancel, close, execute, executeAsync, executeAsync, getBindValues, getParam, getParams, getSQL, getSQL, getSQL, isExecutable, keepStatement, queryTimeout
attach, configuration, detach
@Support void newRecord()
Calling this method will cause subsequent calls to
StoreQuery.addValue(Field, Object)
(and similar) to fill the next record.
If this call is not followed by StoreQuery.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 addRecord(R record)
newRecord();
setRecord(record);
record
- The record to add to this insert statement.@Support void onConflict(Field<?>... fields)
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 addValueForUpdate(Field, Field)
methods.
@Support void onConflict(Collection<? extends Field<?>> fields)
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 addValueForUpdate(Field, Field)
methods.
@Support(value={AURORA_POSTGRES,CUBRID,DB2,FIREBIRD_3_0,HSQLDB,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) void onConflictOnConstraint(Name constraint)
On CONFLICT
or
ON CONFLICT ON CONSTRAINT
clause in this INSERT
statement.@Support(value={AURORA_POSTGRES,CUBRID,DB2,FIREBIRD_3_0,HSQLDB,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) void onConflictOnConstraint(Constraint constraint)
On CONFLICT
or
ON CONFLICT ON CONSTRAINT
clause in this INSERT
statement.@Support void onConflictOnConstraint(UniqueKey<R> constraint)
On CONFLICT
or
ON CONFLICT ON CONSTRAINT
clause in this INSERT
statement.@Support(value={AURORA_MYSQL,AURORA_POSTGRES,CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,TERADATA}) void onDuplicateKeyUpdate(boolean flag)
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 addValueForUpdate(Field, Field)
methods.
The ON DUPLICATE KEY UPDATE
flag is mutually exclusive with
the ON DUPLICATE KEY IGNORE
flag (see
onDuplicateKeyIgnore(boolean)
. Setting one will unset the other
@Support void onDuplicateKeyIgnore(boolean flag)
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:
Dialect | Emulation |
---|---|
SQLDialect.MYSQL and SQLDialect.MARIADB |
|
SQLDialect.POSTGRES_9_5 |
|
SQLDialect.CUBRID |
|
SQLDialect.DB2 SQLDialect.HSQLDB SQLDialect.ORACLE SQLDialect.SQLSERVER SQLDialect.SYBASE |
|
All the others |
|
The ON DUPLICATE KEY UPDATE
flag is mutually exclusive with
the ON DUPLICATE KEY IGNORE
flag (see
onDuplicateKeyIgnore(boolean)
. Setting one will unset the other
@Support(value={AURORA_MYSQL,AURORA_POSTGRES,CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,TERADATA}) <T> void addValueForUpdate(Field<T> field, T value)
ON DUPLICATE KEY UPDATE
clause of this
INSERT
statement, where this is supported.@Support(value={AURORA_MYSQL,AURORA_POSTGRES,CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,TERADATA}) <T> void addValueForUpdate(Field<T> field, Field<T> value)
ON DUPLICATE KEY UPDATE
clause of this
INSERT
statement, where this is supported.@Support(value={AURORA_MYSQL,AURORA_POSTGRES,CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,TERADATA}) void addValuesForUpdate(Map<?,?> map)
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>
@Support(value={AURORA_POSTGRES,CUBRID,ORACLE,POSTGRES_9_5,SQLSERVER}) void addConditions(Condition condition)
Operator.AND
.
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
condition
- The condition@Support(value={AURORA_POSTGRES,CUBRID,ORACLE,POSTGRES_9_5,SQLSERVER}) void addConditions(Condition... conditions)
Operator.AND
.
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value={AURORA_POSTGRES,CUBRID,ORACLE,POSTGRES_9_5,SQLSERVER}) void addConditions(Collection<? extends Condition> conditions)
Operator.AND
.
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value={AURORA_POSTGRES,CUBRID,ORACLE,POSTGRES_9_5,SQLSERVER}) void addConditions(Operator operator, Condition condition)
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
condition
- The condition@Support(value={AURORA_POSTGRES,CUBRID,ORACLE,POSTGRES_9_5,SQLSERVER}) void addConditions(Operator operator, Condition... conditions)
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value={AURORA_POSTGRES,CUBRID,ORACLE,POSTGRES_9_5,SQLSERVER}) void addConditions(Operator operator, Collection<? extends Condition> conditions)
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value={ASE,AURORA_MYSQL,AURORA_POSTGRES,CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,MARIADB,MYSQL,ORACLE,POSTGRES,SQLDATAWAREHOUSE,SQLITE,SQLSERVER,SYBASE,TERADATA}) void setDefaultValues()
DEFAULT VALUES
clause.@Support void setSelect(Field<?>[] fields, Select<?> select)
SELECT
statement as the source of values for the
INSERT
statement.@Support void setReturning()
INSERT
or UPDATE
statement to return all fields in
R
.
This feature works with INSERT
statements for all SQL dialects
setReturning
in interface StoreQuery<R extends Record>
StoreQuery.getReturnedRecords()
@Support void setReturning(Identity<R,?> identity)
INSERT
or UPDATE
statement to return the generated
identity value.
This feature works with INSERT
statements for all SQL dialects
setReturning
in interface StoreQuery<R extends Record>
identity
- The table's identityStoreQuery.getReturnedRecords()
@Support void setReturning(SelectFieldOrAsterisk... fields)
INSERT
or UPDATE
statement to return a list of fields in
R
.
This feature works with INSERT
statements for all SQL dialects
setReturning
in interface StoreQuery<R extends Record>
fields
- Fields to be returnedStoreQuery.getReturnedRecords()
@Support void setReturning(Collection<? extends SelectFieldOrAsterisk> fields)
INSERT
or UPDATE
statement to return a list of fields in
R
.
This feature works with INSERT
statements for all SQL dialects
setReturning
in interface StoreQuery<R extends Record>
fields
- Fields to be returnedStoreQuery.getReturnedRecords()
@Support R getReturnedRecord()
StoreQuery.setReturning()
methods.
If the insert statement returns several records, this is the same as
calling getReturnedRecords().get(0)
This implemented differently for every dialect:
INSERT .. RETURNING
and UPDATE .. RETURNING
clauses@@identity
or last_inserted_rowid()
values.
Those values are fetched in a separate SELECT
statement. If
other fields are requested, a second statement is issued. Client code
must assure transactional integrity between the two statements.
This feature works with INSERT
statements for all SQL dialects
getReturnedRecord
in interface StoreQuery<R extends Record>
StoreQuery.setReturning()
methods. This may return
null
in case jOOQ could not retrieve any generated
keys from the JDBC driver.StoreQuery.getReturnedRecords()
@Support Result<R> getReturnedRecords()
StoreQuery.setReturning()
methods.
This implemented differently for every dialect:
INSERT .. RETURNING
and UPDATE .. RETURNING
clauses@@identity
or last_inserted_rowid()
values.
Those values are fetched in a separate SELECT
statement. If
other fields are requested, a second statement is issued. Client code
must assure transactional integrity between the two statements.
[#5070] Due to an early API design flaw, this method historically returns
the type R
, not a more generic type Record
.
This means that only actual columns in R
can be returned.
For a more generic set of column expressions, use StoreQuery.getResult()
instead.
This feature works with INSERT
statements for all SQL dialects
getReturnedRecords
in interface StoreQuery<R extends Record>
StoreQuery.setReturning()
methods. Note:
Result
in case jOOQ
could not retrieve any generated keys from the JDBC driver.Copyright © 2019. All rights reserved.