Package org.h2.command.dml
Class Insert
- java.lang.Object
-
- org.h2.command.Prepared
-
- org.h2.command.dml.DataChangeStatement
-
- org.h2.command.dml.CommandWithValues
-
- org.h2.command.dml.Insert
-
- All Implemented Interfaces:
ResultTarget
public final class Insert extends CommandWithValues implements ResultTarget
This class represents the statement INSERT
-
-
Field Summary
Fields Modifier and Type Field Description private Column[]columnsprivate DataChangeDeltaTable.ResultOptiondeltaChangeCollectionModeprivate ResultTargetdeltaChangeCollectorprivate java.util.HashMap<Column,Expression>duplicateKeyAssignmentMapFor MySQL-style INSERT ...private booleanignoreFor MySQL-style INSERT IGNORE and PostgreSQL-style ON CONFLICT DO NOTHING.private booleaninsertFromSelectprivate Value[]onDuplicateKeyRowprivate java.lang.BooleanoverridingSystemprivate Queryqueryprivate longrowNumberprivate Tabletable-
Fields inherited from class org.h2.command.dml.CommandWithValues
valuesExpressionList
-
Fields inherited from class org.h2.command.Prepared
create, parameters, prepareAlways, session, sqlStatement, sqlTokens
-
-
Constructor Summary
Constructors Constructor Description Insert(SessionLocal session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAssignmentForDuplicate(Column column, Expression expression)Keep a collection of the columns to pass to update if a duplicate key happens, for MySQL-style INSERT ...voidaddRow(Value... values)Add the row to the result set.voidcollectDependencies(java.util.HashSet<DbObject> dependencies)Find and collect all DbObjects, this Prepared depends on.ValuegetOnDuplicateKeyValue(int columnIndex)Get the value to use for the specified column in case of a duplicate key.java.lang.StringgetPlanSQL(int sqlFlags)Get the SQL statement with the execution plan.longgetRowCount()Get the number of rows.java.lang.StringgetStatementName()Return the name of this statement.TablegetTable()Return the target table.intgetType()Get the command type as defined in CommandInterfaceprivate booleanhandleOnDuplicate(DbException de, Value[] currentRow)private longinsertRows()booleanisCacheable()voidlimitsWereApplied()A hint that sorting, offset and limit may be ignored by this result because they were applied during the query.voidprepare()Prepare this statement.private ExpressionprepareUpdateCondition(Index foundIndex, Expression[] row)voidsetColumns(Column[] columns)voidsetCommand(Command command)Set the command.voidsetIgnore(boolean ignore)Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.voidsetInsertFromSelect(boolean value)voidsetOverridingSystem(java.lang.Boolean overridingSystem)voidsetQuery(Query query)voidsetTable(Table table)longupdate(ResultTarget deltaChangeCollector, DataChangeDeltaTable.ResultOption deltaChangeCollectionMode)Execute the statement with specified delta change collector and collection mode.-
Methods inherited from class org.h2.command.dml.CommandWithValues
addRow
-
Methods inherited from class org.h2.command.dml.DataChangeStatement
isTransactional, queryMeta, update
-
Methods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, getCteCleanups, getCurrentRowNumber, getObjectId, getParameters, getPersistedObjectId, getSession, getSimpleSQL, getSQL, getSQLTokens, isQuery, isReadOnly, needRecompile, query, setCteCleanups, setCurrentRowNumber, setParameterList, setPersistedObjectId, setPrepareAlways, setRow, setSession, setSQL, toString
-
-
-
-
Field Detail
-
table
private Table table
-
columns
private Column[] columns
-
query
private Query query
-
rowNumber
private long rowNumber
-
insertFromSelect
private boolean insertFromSelect
-
overridingSystem
private java.lang.Boolean overridingSystem
-
duplicateKeyAssignmentMap
private java.util.HashMap<Column,Expression> duplicateKeyAssignmentMap
For MySQL-style INSERT ... ON DUPLICATE KEY UPDATE ....
-
onDuplicateKeyRow
private Value[] onDuplicateKeyRow
-
ignore
private boolean ignore
For MySQL-style INSERT IGNORE and PostgreSQL-style ON CONFLICT DO NOTHING.
-
deltaChangeCollector
private ResultTarget deltaChangeCollector
-
deltaChangeCollectionMode
private DataChangeDeltaTable.ResultOption deltaChangeCollectionMode
-
-
Constructor Detail
-
Insert
public Insert(SessionLocal session)
-
-
Method Detail
-
setCommand
public void setCommand(Command command)
Description copied from class:PreparedSet the command.- Overrides:
setCommandin classPrepared- Parameters:
command- the new command
-
getTable
public Table getTable()
Description copied from class:DataChangeStatementReturn the target table.- Specified by:
getTablein classDataChangeStatement- Returns:
- the target table
-
setTable
public void setTable(Table table)
-
setColumns
public void setColumns(Column[] columns)
-
setIgnore
public void setIgnore(boolean ignore)
Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.- Parameters:
ignore- ignore duplicates
-
setQuery
public void setQuery(Query query)
-
setOverridingSystem
public void setOverridingSystem(java.lang.Boolean overridingSystem)
-
addAssignmentForDuplicate
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- the columnexpression- the expression
-
update
public long update(ResultTarget deltaChangeCollector, DataChangeDeltaTable.ResultOption deltaChangeCollectionMode)
Description copied from class:DataChangeStatementExecute the statement with specified delta change collector and collection mode.- Specified by:
updatein classDataChangeStatement- Parameters:
deltaChangeCollector- target resultdeltaChangeCollectionMode- collection mode- Returns:
- the update count
-
insertRows
private long insertRows()
-
addRow
public void addRow(Value... values)
Description copied from interface:ResultTargetAdd the row to the result set.- Specified by:
addRowin interfaceResultTarget- Parameters:
values- the values
-
getRowCount
public long getRowCount()
Description copied from interface:ResultTargetGet the number of rows.- Specified by:
getRowCountin interfaceResultTarget- Returns:
- the number of rows
-
limitsWereApplied
public void limitsWereApplied()
Description copied from interface:ResultTargetA 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.- Specified by:
limitsWereAppliedin interfaceResultTarget
-
getPlanSQL
public java.lang.String getPlanSQL(int sqlFlags)
Description copied from class:PreparedGet the SQL statement with the execution plan.- Overrides:
getPlanSQLin classPrepared- Parameters:
sqlFlags- formatting flags- Returns:
- the execution plan
-
prepare
public void prepare()
Description copied from class:PreparedPrepare this statement.
-
getType
public int getType()
Description copied from class:PreparedGet the command type as defined in CommandInterface
-
getStatementName
public java.lang.String getStatementName()
Description copied from class:DataChangeStatementReturn the name of this statement.- Specified by:
getStatementNamein classDataChangeStatement- Returns:
- the short name of this statement.
-
setInsertFromSelect
public void setInsertFromSelect(boolean value)
-
isCacheable
public boolean isCacheable()
- Overrides:
isCacheablein classDataChangeStatement
-
handleOnDuplicate
private boolean handleOnDuplicate(DbException de, Value[] currentRow)
- Parameters:
de- duplicate key exceptioncurrentRow- current row values (optional)- Returns:
trueif row was updated,falseif row was ignored
-
prepareUpdateCondition
private Expression prepareUpdateCondition(Index foundIndex, Expression[] row)
-
getOnDuplicateKeyValue
public Value getOnDuplicateKeyValue(int columnIndex)
Get the value to use for the specified column in case of a duplicate key.- Parameters:
columnIndex- the column index- Returns:
- the value
-
collectDependencies
public void collectDependencies(java.util.HashSet<DbObject> dependencies)
Description copied from class:PreparedFind and collect all DbObjects, this Prepared depends on.- Overrides:
collectDependenciesin classPrepared- Parameters:
dependencies- collection of dependencies to populate
-
-