org.jooq
Interface InsertQuery<R extends Record>

Type Parameters:
R - The record type of the table being inserted into
All Superinterfaces:
Adapter, Attachable, Insert<R>, Query, QueryPart, Serializable, StoreQuery<R>

public interface InsertQuery<R extends Record>
extends StoreQuery<R>, Insert<R>

A query for data insertion

Author:
Lukas Eder

Method Summary
 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<? extends Field<?>,?> 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 setReturning() methods.
 Result<R> getReturnedRecords()
          The records holding returned values as specified by any of the 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 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 setReturning()
          Configure the INSERT statement to return all fields in R.
 void setReturning(Collection<? extends Field<?>> fields)
          Configure the INSERT statement to return a list of fields in R.
 void setReturning(Field<?>... fields)
          Configure the INSERT statement to return a list of fields in R.
 void setReturning(Identity<R,? extends Number> identity)
          Configure the INSERT statement to return the generated identity value.
 
Methods inherited from interface org.jooq.StoreQuery
addValue, addValue, addValueAsArray, addValueAsArray, addValues, setRecord
 
Methods inherited from interface org.jooq.Query
bind, bind, execute, getBindValues, getParam, getParams, getSQL, getSQL, isExecutable
 
Methods inherited from interface org.jooq.QueryPart
attach
 

Method Detail

newRecord

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.

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.


addRecord

void addRecord(R record)
Short for calling newRecord(); setRecord(record);

Parameters:
record - The record to add to this insert statement.

onDuplicateKeyUpdate

void onDuplicateKeyUpdate(boolean flag)
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 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

See Also:
InsertOnDuplicateStep.onDuplicateKeyUpdate()

onDuplicateKeyIgnore

void onDuplicateKeyIgnore(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
SQLDialect.MYSQL
INSERT IGNORE INTO ..
SQLDialect.CUBRID
INSERT INTO .. ON DUPLICATE KEY UPDATE [any-field] = [any-field]
SQLDialect.DB2
SQLDialect.HSQLDB
SQLDialect.ORACLE
SQLDialect.SQLSERVER
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 onDuplicateKeyIgnore(boolean). Setting one will unset the other


addValueForUpdate

<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.

See Also:
InsertOnDuplicateStep.onDuplicateKeyUpdate()

addValueForUpdate

<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.

See Also:
InsertOnDuplicateStep.onDuplicateKeyUpdate()

addValuesForUpdate

void addValuesForUpdate(Map<? extends Field<?>,?> map)
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 Also:
InsertOnDuplicateStep.onDuplicateKeyUpdate()

setReturning

void setReturning()
Configure the INSERT statement to return all fields in R.

See Also:
getReturnedRecords()

setReturning

void setReturning(Identity<R,? extends Number> identity)
Configure the INSERT statement to return the generated identity value.

Parameters:
identity - The table's identity
See Also:
getReturnedRecords()

setReturning

void setReturning(Field<?>... fields)
Configure the INSERT statement to return a list of fields in R.

Parameters:
fields - Fields to be returned
See Also:
getReturnedRecords()

setReturning

void setReturning(Collection<? extends Field<?>> fields)
Configure the INSERT statement to return a list of fields in R.

Parameters:
fields - Fields to be returned
See Also:
getReturnedRecords()

getReturnedRecord

R getReturnedRecord()
The record holding returned values as specified by any of the setReturning() methods.

If the insert statement returns several records, this is the same as calling getReturnedRecords().get(0)

This implemented differently for every dialect:

Returns:
The returned value as specified by any of the setReturning() methods. This may return null in case jOOQ could not retrieve any generated keys from the JDBC driver.
See Also:
getReturnedRecords()

getReturnedRecords

Result<R> getReturnedRecords()
The records holding returned values as specified by any of the setReturning() methods.

This implemented differently for every dialect:

Returns:
The returned values as specified by any of the setReturning() methods. Note:
  • Not all databases / JDBC drivers support returning several values on multi-row inserts!
  • This may return an empty Result in case jOOQ could not retrieve any generated keys from the JDBC driver.


Copyright © 2012. All Rights Reserved.