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(java.util.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(Operator operator,
java.util.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 |
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(java.util.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(java.util.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 |
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(java.util.Collection<? extends Field<?>> fields)
Configure the
INSERT or UPDATE statement to return a list of fields in
R . |
void |
setReturning(Field<?>... 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 |
setSelect(Field<?>[] fields,
Select<?> select)
Use a
SELECT statement as the source of values for the
INSERT statement. |
addValue, addValue, addValues, 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(value=POSTGRES_9_5) 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(value=POSTGRES_9_5) void onConflict(java.util.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={CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) 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={CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) <T> void addValueForUpdate(Field<T> field, T value)
ON DUPLICATE KEY UPDATE
clause of this
INSERT
statement, where this is supported.@Support(value={CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) <T> void addValueForUpdate(Field<T> field, Field<T> value)
ON DUPLICATE KEY UPDATE
clause of this
INSERT
statement, where this is supported.@Support(value={CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) void addValuesForUpdate(java.util.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=POSTGRES_9_5) void addConditions(Condition... conditions)
Operator.AND
.
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value=POSTGRES_9_5) void addConditions(java.util.Collection<? extends Condition> conditions)
Operator.AND
.
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value=POSTGRES_9_5) void addConditions(Operator operator, Condition... conditions)
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value=POSTGRES_9_5) void addConditions(Operator operator, java.util.Collection<? extends Condition> conditions)
This is for use with SQLDialect.POSTGRES
's
onConflict(Field...)
clause.
conditions
- The condition@Support(value={ASE,CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,MARIADB,MYSQL,ORACLE,POSTGRES,SQLITE,SQLSERVER,SYBASE}) 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(Field<?>... 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(java.util.Collection<? extends Field<?>> 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.
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 © 2018. All Rights Reserved.