Top Description Fields Constructors Methods
org.h2.command.dml

public final Class Insert

extends CommandWithValues
implements ResultTarget
Class Inheritance
All Implemented Interfaces
org.h2.result.ResultTarget
Imports
java.util.HashMap, .HashSet, .Map.Entry, org.h2.api.ErrorCode, .Trigger, org.h2.command.Command, .CommandInterface, org.h2.command.query.Query, org.h2.engine.DbObject, .Right, .SessionLocal, org.h2.expression.Expression, .ExpressionColumn, .ExpressionVisitor, .Parameter, .ValueExpression, org.h2.expression.condition.Comparison, .ConditionAndOr, org.h2.index.Index, org.h2.message.DbException, org.h2.mvstore.db.MVPrimaryIndex, org.h2.result.ResultInterface, .ResultTarget, .Row, org.h2.table.Column, .DataChangeDeltaTable, .DataChangeDeltaTable.ResultOption, .Table, org.h2.util.HasSQL, org.h2.value.Value

This class represents the statement INSERT

Field Summary

Modifier and TypeField and Description
private Column[]
private DataChangeDeltaTable.ResultOption
private ResultTarget
private HashMap<Column, Expression>
duplicateKeyAssignmentMap

For MySQL-style INSERT ...

private boolean
ignore

For MySQL-style INSERT IGNORE and PostgreSQL-style ON CONFLICT DO NOTHING.

private boolean
private Value[]
private Boolean
private Query
private long
private Table
Inherited from org.h2.command.dml.CommandWithValues:
valuesExpressionList

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addAssignmentForDuplicate(Column
the column
column
,
Expression
the expression
expression
)

Keep a collection of the columns to pass to update if a duplicate key happens, for MySQL-style INSERT ...

public void
addRow(Value...
the values
values
)

Implements org.h2.result.ResultTarget.addRow.

Add the row to the result set.

public void
collectDependencies(HashSet<DbObject>
collection of dependencies to populate
dependencies
)

Overrides org.h2.command.Prepared.collectDependencies.

Find and collect all DbObjects, this Prepared depends on.

pack-priv void
public Value

Returns:

the value
getOnDuplicateKeyValue
(int
the column index
columnIndex
)

Get the value to use for the specified column in case of a duplicate key.

public StringBuilder
getPlanSQL(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Overrides org.h2.command.Prepared.getPlanSQL.

Appends the SQL statement with the execution plan.

public long
getRowCount()

Implements org.h2.result.ResultTarget.getRowCount.

Get the number of rows.

public String
getStatementName()

Implements abstract org.h2.command.dml.DataChangeStatement.getStatementName.

Return the name of this statement.

public Table
getTable()

Implements abstract org.h2.command.dml.DataChangeStatement.getTable.

Return the target table.

public int
getType()

Implements abstract org.h2.command.Prepared.getType.

Get the command type as defined in CommandInterface

private boolean

Returns:

true if row was updated, false if row was ignored
handleOnDuplicate
(DbException
duplicate key exception
de
,
Value[]
current row values (optional)
currentRow
)

private long
public boolean
public void
limitsWereApplied()

Implements org.h2.result.ResultTarget.limitsWereApplied.

A hint that sorting, offset and limit may be ignored by this result because they were applied during the query.

private Expression
public void
setColumns(Column[] columns)

public void
setCommand(Command
the new command
command
)

Overrides org.h2.command.Prepared.setCommand.

Set the command.

public void
setIgnore(boolean
ignore duplicates
ignore
)

Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.

public void
setInsertFromSelect(boolean value)

public void
setOverridingSystem(Boolean overridingSystem)

public void
setQuery(Query query)

public void
setTable(Table table)

public long
update(ResultTarget
target result
deltaChangeCollector
,
DataChangeDeltaTable.ResultOption
collection mode
deltaChangeCollectionMode
)

Implements abstract org.h2.command.dml.DataChangeStatement.update.

Execute the statement with specified delta change collector and collection mode.

Inherited from org.h2.command.dml.CommandWithValues:
addRow

Field Detail

columnsback to summary
private Column[] columns
deltaChangeCollectionModeback to summary
private DataChangeDeltaTable.ResultOption deltaChangeCollectionMode
deltaChangeCollectorback to summary
private ResultTarget deltaChangeCollector
duplicateKeyAssignmentMapback to summary
private HashMap<Column, Expression> duplicateKeyAssignmentMap

For MySQL-style INSERT ... ON DUPLICATE KEY UPDATE ....

ignoreback to summary
private boolean ignore

For MySQL-style INSERT IGNORE and PostgreSQL-style ON CONFLICT DO NOTHING.

insertFromSelectback to summary
private boolean insertFromSelect
onDuplicateKeyRowback to summary
private Value[] onDuplicateKeyRow
overridingSystemback to summary
private Boolean overridingSystem
queryback to summary
private Query query
rowNumberback to summary
private long rowNumber
tableback to summary
private Table table

Constructor Detail

Insertback to summary
public Insert(SessionLocal session)

Method Detail

addAssignmentForDuplicateback to summary
public void addAssignmentForDuplicate(Column column, Expression expression)

Keep a collection of the columns to pass to update if a duplicate key happens, for MySQL-style INSERT ... ON DUPLICATE KEY UPDATE ....

Parameters
column:Column

the column

expression:Expression

the expression

addRowback to summary
public void addRow(Value... values)

Implements org.h2.result.ResultTarget.addRow.

Doc from org.h2.result.ResultTarget.addRow.

Add the row to the result set.

Parameters
values:Value[]

the values

Annotations
@Override
collectDependenciesback to summary
public void collectDependencies(HashSet<DbObject> dependencies)

Overrides org.h2.command.Prepared.collectDependencies.

Doc from org.h2.command.Prepared.collectDependencies.

Find and collect all DbObjects, this Prepared depends on.

Parameters
dependencies:HashSet<DbObject>

collection of dependencies to populate

Annotations
@Override
doPrepareback to summary
pack-priv void doPrepare()

Implements abstract org.h2.command.dml.DataChangeStatement.doPrepare.

Annotations
@Override
getOnDuplicateKeyValueback to summary
public Value getOnDuplicateKeyValue(int columnIndex)

Get the value to use for the specified column in case of a duplicate key.

Parameters
columnIndex:int

the column index

Returns:Value

the value

getPlanSQLback to summary
public StringBuilder getPlanSQL(StringBuilder builder, int sqlFlags)

Overrides org.h2.command.Prepared.getPlanSQL.

Doc from org.h2.command.Prepared.getPlanSQL.

Appends the SQL statement with the execution plan.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the execution plan

Annotations
@Override
getRowCountback to summary
public long getRowCount()

Implements org.h2.result.ResultTarget.getRowCount.

Doc from org.h2.result.ResultTarget.getRowCount.

Get the number of rows.

Returns:long

the number of rows

Annotations
@Override
getStatementNameback to summary
public String getStatementName()

Implements abstract org.h2.command.dml.DataChangeStatement.getStatementName.

Doc from org.h2.command.dml.DataChangeStatement.getStatementName.

Return the name of this statement.

Returns:String

the short name of this statement.

Annotations
@Override
getTableback to summary
public Table getTable()

Implements abstract org.h2.command.dml.DataChangeStatement.getTable.

Doc from org.h2.command.dml.DataChangeStatement.getTable.

Return the target table.

Returns:Table

the target table

Annotations
@Override
getTypeback to summary
public int getType()

Implements abstract org.h2.command.Prepared.getType.

Doc from org.h2.command.Prepared.getType.

Get the command type as defined in CommandInterface

Returns:int

the statement type

Annotations
@Override
handleOnDuplicateback to summary
private boolean handleOnDuplicate(DbException de, Value[] currentRow)
Parameters
de:DbException

duplicate key exception

currentRow:Value[]

current row values (optional)

Returns:boolean

true if row was updated, false if row was ignored

insertRowsback to summary
private long insertRows()
isCacheableback to summary
public boolean isCacheable()

Overrides org.h2.command.dml.DataChangeStatement.isCacheable.

Annotations
@Override
limitsWereAppliedback to summary
public void limitsWereApplied()

Implements org.h2.result.ResultTarget.limitsWereApplied.

Doc from org.h2.result.ResultTarget.limitsWereApplied.

A hint that sorting, offset and limit may be ignored by this result because they were applied during the query. This is useful for WITH TIES clause because result may contain tied rows above limit.

Annotations
@Override
prepareUpdateConditionback to summary
private Expression prepareUpdateCondition(Index foundIndex, Expression[] row)
setColumnsback to summary
public void setColumns(Column[] columns)
setCommandback to summary
public void setCommand(Command command)

Overrides org.h2.command.Prepared.setCommand.

Doc from org.h2.command.Prepared.setCommand.

Set the command.

Parameters
command:Command

the new command

Annotations
@Override
setIgnoreback to summary
public void setIgnore(boolean ignore)

Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.

Parameters
ignore:boolean

ignore duplicates

setInsertFromSelectback to summary
public void setInsertFromSelect(boolean value)
setOverridingSystemback to summary
public void setOverridingSystem(Boolean overridingSystem)
setQueryback to summary
public void setQuery(Query query)
setTableback to summary
public void setTable(Table table)
updateback to summary
public long update(ResultTarget deltaChangeCollector, DataChangeDeltaTable.ResultOption deltaChangeCollectionMode)

Implements abstract org.h2.command.dml.DataChangeStatement.update.

Doc from org.h2.command.dml.DataChangeStatement.update.

Execute the statement with specified delta change collector and collection mode.

Parameters
deltaChangeCollector:ResultTarget

target result

deltaChangeCollectionMode:DataChangeDeltaTable.ResultOption

collection mode

Returns:long

the update count

Annotations
@Override