Class InsertResultSet
java.lang.Object
org.apache.derby.impl.sql.execute.NoRowsResultSetImpl
org.apache.derby.impl.sql.execute.DMLWriteResultSet
org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet
org.apache.derby.impl.sql.execute.InsertResultSet
- All Implemented Interfaces:
TargetResultSet
,ResultSet
Insert the rows from the source into the specified
base table. This will cause constraints to be checked
and triggers to be executed based on the c's and t's
compiled into the insert plan.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ConglomerateController
private ScanController
protected boolean
private BulkInsertCounter[]
(package private) boolean
private boolean
private GeneratedMethod
private int[][]
(package private) InsertConstantAction
protected DataDictionary
private BackingStoreHashtable
private boolean
private boolean
private RISetChecker
private FKInfo[]
private final int
private GeneratedMethod
private boolean
private long
private FormatableBitSet
private ExecIndexRow[]
private boolean[]
private int
private ColumnOrdering[][]
private RowLocation
private ExecRow
private RowChanger
private TemporaryRowHolderImpl
private RowLocationRetRowSource[]
(package private) NoPutResultSet
private final String
private SortController[]
private long[]
private final String
private BulkTableScanResultSet
private TransactionController
protected TableDescriptor
private TriggerEventActivator
private TriggerInfo
(package private) boolean
Fields inherited from class org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet
aiCache, autoGeneratedKeysColumnIndexes, autoGeneratedKeysResultSet, autoGeneratedKeysRowsHolder, autoincrementGenerated, identitySequenceUUIDString, identityVal, setIdentity, sourceResultSet
Fields inherited from class org.apache.derby.impl.sql.execute.DMLWriteResultSet
baseRowReadMap, cachedDestinations, constantAction, heapDCOCI, indexDCOCIs, resultDescription, rowCount, streamStorableHeapColIds
Fields inherited from class org.apache.derby.impl.sql.execute.NoRowsResultSetImpl
activation, beginExecutionTime, beginTime, endExecutionTime, endTime, lcc
Fields inherited from interface org.apache.derby.iapi.sql.ResultSet
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST
-
Constructor Summary
ConstructorsConstructorDescriptionInsertResultSet
(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, String schemaName, String tableName, Activation activation) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
bulkInsertCore
(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) private void
bulkValidateForeignKeys
(TransactionController tc, ContextManager cm, ExecRow fullTemplate) Bulk Referential Integrity Checkerprivate void
bulkValidateForeignKeysCore
(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, String fkConstraintName, ExecRow fullTemplate) void
changedRow
(ExecRow execRow, RowLocation rowLocation) Pass a changed row and the row location for that row to the target result set.void
cleanUp()
Tells the system to clean up on an error.void
close()
Clean up resources and call close on data members.private void
emptyIndexes
(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) Empty the indexes after doing a bulk insert replace where the table has 0 rows after the replace.private boolean
Run the check constraints against the current row.void
finish()
Tells the system that there will be no more access to any database information via this result set; in particular, no more calls to open().private int[]
If user didn't provide columns list for auto-generated columns, then only include columns with auto-generated values in the resultset.private String[]
getColumnNames
(int[] baseColumnPositions) private boolean
Get an exclusive table lock on the target table (and check to see if the table is populated if this is not a bulk insert replace).protected ExecRow
getNextRowCore
(NoPutResultSet source) Get next row from the source result set.private void
getOldStyleBulkInsertValue
(int index, long increment) Identity generation logic for bulk-insert used in pre-10.11 databases.private NumberDataValue
getOldStyleIdentityValue
(int index) Identity generation logic used in pre-10.11 databases.getSetAutoincrementValue
(int columnPosition, long increment) getSetAutoincrementValue will get the autoincrement value of the columnPosition specified for the target table.private BulkTableScanResultSet
getTableScanResultSet
(long conglomId) Get me a table scan result set, preferably a bulk table scan, thank you.protected void
initializeAIcache
(RowLocation[] rla) private boolean
private boolean
private ExecRow
makeIndexTemplate
(FKInfo fkInfo, ExecRow fullTemplate, ContextManager cm) Make a template row with the correct columns.private void
normalInsertCore
(LanguageConnectionContext lcc, boolean firstExecute) void
offendingRowLocation
(RowLocation rl, long constainerId) void
open()
Needs to be called before the result set will do anything.preprocessSourceRow
(ExecRow execRow) Preprocess the source row.private ExecRow
processMergeRow
(NoPutResultSet sourceRS, ExecRow row) Special handling if this is an INSERT action of a MERGE statement.void
rememberConstraint
(UUID cid) private void
setEstimatedRowCount
(long heapConglom) Set the estimated row count for this table.private void
setUpAllSorts
(ExecRow sourceRow, RowLocation rl) Set up to update all of the indexes on a table when doing a bulk insert on an empty table.private void
updateAllIndexes
(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) Update all of the indexes on a table when doing a bulk insert on an empty table.protected boolean
Verify that bulkInsert is allowed on this table.Methods inherited from class org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet
firstExecuteSpecialHandlingAutoGen, getAutoGeneratedKeysResultset, getCompactRow, saveAIcacheInformation, verifyAutoGeneratedRScolumnsList
Methods inherited from class org.apache.derby.impl.sql.execute.DMLWriteResultSet
decodeLockMode, getIndexNameFromCID, getResultDescription, makeDeferredSparseRow, modifiedRowCount, normalizeRow
Methods inherited from class org.apache.derby.impl.sql.execute.NoRowsResultSetImpl
addWarning, checkRowPosition, clearCurrentRow, close, doesCommit, evaluateGenerationClauses, getAbsoluteRow, getActivation, getBeginExecutionTimestamp, getCurrentTimeMillis, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getQueryPlanText, getRelativeRow, getRowNumber, getSubqueryTrackingArray, getTimeSpent, getWarnings, isClosed, returnsRows, setAfterLastRow, setBeforeFirstRow, setup, toXML
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.derby.iapi.sql.ResultSet
addWarning, checkRowPosition, clearCurrentRow, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getTimeSpent, getWarnings, isClosed, modifiedRowCount, returnsRows, setAfterLastRow, setBeforeFirstRow, toXML
-
Field Details
-
savedSource
NoPutResultSet savedSource -
constants
InsertConstantAction constants -
generationClauses
-
checkGM
-
heapConglom
private long heapConglom -
rowChanger
-
tc
-
row
-
userSpecifiedBulkInsert
boolean userSpecifiedBulkInsert -
bulkInsertPerformed
boolean bulkInsertPerformed -
bulkInsert
protected boolean bulkInsert -
bulkInsertReplace
private boolean bulkInsertReplace -
firstRow
private boolean firstRow -
needToDropSort
private boolean[] needToDropSort -
indexConversionTable
-
indexedCols
-
bulkHeapCC
-
dd
-
td
-
indexRows
-
fullTemplateId
private final int fullTemplateId -
schemaName
-
tableName
-
sortIds
private long[] sortIds -
rowSources
-
bulkHeapSC
-
ordering
-
collation
private int[][] collation -
sorters
-
rowHolder
-
rl
-
hasBeforeRowTrigger
private boolean hasBeforeRowTrigger -
tableScan
-
numOpens
private int numOpens -
firstExecute
private boolean firstExecute -
fkInfoArray
-
triggerInfo
-
fkChecker
-
triggerActivator
-
bulkInsertCounters
-
deferredChecks
-
violatingCheckConstraints
-
-
Constructor Details
-
InsertResultSet
InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, String schemaName, String tableName, Activation activation) throws StandardException - Throws:
StandardException
- Thrown on error
-
-
Method Details
-
changedRow
Description copied from interface:TargetResultSet
Pass a changed row and the row location for that row to the target result set.- Specified by:
changedRow
in interfaceTargetResultSet
- Parameters:
execRow
- The changed row.rowLocation
- The row location of the row.- Throws:
StandardException
- thrown if cursor finish ed.- See Also:
-
preprocessSourceRow
Preprocess the source row. Apply any check constraints here. Do an inplace cloning of all key columns. For triggers, if we have a before row trigger, we fire it here if we can. This is useful for bulk insert where the store stands between the source and us.- Specified by:
preprocessSourceRow
in interfaceTargetResultSet
- Parameters:
execRow
- The source row.- Returns:
- The preprocessed source row.
- Throws:
StandardException
- thrown on error
-
offendingRowLocation
- Specified by:
offendingRowLocation
in interfaceTargetResultSet
- Throws:
StandardException
-
evaluateCheckConstraints
Run the check constraints against the current row. Raise an error if a check constraint is violated, unless all the offending checks are deferred, in which case a false value will be returned. A NULL value will be interpreted as success (not violation).- Throws:
StandardException
- thrown on error
-
open
Description copied from interface:ResultSet
Needs to be called before the result set will do anything. Need to call before getNextRow(), or for a result set that doesn't return rows, this is the call that will cause all the work to be done.- Specified by:
open
in interfaceResultSet
- Throws:
StandardException
- Standard Derby error policy
-
close
Clean up resources and call close on data members.- Specified by:
close
in interfaceResultSet
- Throws:
StandardException
- Thrown on error.
-
generatedColumnPositionsArray
If user didn't provide columns list for auto-generated columns, then only include columns with auto-generated values in the resultset. Those columns would be ones with default value defined.- Throws:
StandardException
-
getSetAutoincrementValue
public NumberDataValue getSetAutoincrementValue(int columnPosition, long increment) throws StandardException getSetAutoincrementValue will get the autoincrement value of the columnPosition specified for the target table. If increment is non-zero we will also update the autoincrement value.- Overrides:
getSetAutoincrementValue
in classDMLWriteGeneratedColumnsResultSet
- Parameters:
columnPosition
- position of the column in the table (1-based)increment
- amount of increment.- Throws:
StandardException
- if anything goes wrong.
-
getOldStyleBulkInsertValue
Identity generation logic for bulk-insert used in pre-10.11 databases.- Parameters:
index
- 0-based index into aiCache- Throws:
StandardException
-
getOldStyleIdentityValue
Identity generation logic used in pre-10.11 databases.- Parameters:
index
- 0-based index into aiCache- Throws:
StandardException
-
isSourceRowResultSet
private boolean isSourceRowResultSet() -
isSingleRowResultSet
private boolean isSingleRowResultSet() -
normalInsertCore
private void normalInsertCore(LanguageConnectionContext lcc, boolean firstExecute) throws StandardException - Throws:
StandardException
-
getNextRowCore
Description copied from class:DMLWriteResultSet
Get next row from the source result set.- Overrides:
getNextRowCore
in classDMLWriteResultSet
- Parameters:
source
- SourceResultSet Also look at Track#2432/change 12433- Returns:
- The next row in the result set
- Throws:
StandardException
- Standard error policy
-
processMergeRow
Special handling if this is an INSERT action of a MERGE statement.
- Throws:
StandardException
-
bulkInsertCore
private void bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) throws StandardException - Throws:
StandardException
-
bulkValidateForeignKeys
private void bulkValidateForeignKeys(TransactionController tc, ContextManager cm, ExecRow fullTemplate) throws StandardException Bulk Referential Integrity Checker- Throws:
StandardException
-
bulkValidateForeignKeysCore
private void bulkValidateForeignKeysCore(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, String fkConstraintName, ExecRow fullTemplate) throws StandardException - Throws:
StandardException
-
makeIndexTemplate
private ExecRow makeIndexTemplate(FKInfo fkInfo, ExecRow fullTemplate, ContextManager cm) throws StandardException Make a template row with the correct columns.- Throws:
StandardException
-
setUpAllSorts
Set up to update all of the indexes on a table when doing a bulk insert on an empty table.- Throws:
StandardException
- thrown on error
-
updateAllIndexes
private void updateAllIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) throws StandardException Update all of the indexes on a table when doing a bulk insert on an empty table.- Throws:
StandardException
- thrown on error
-
cleanUp
Description copied from interface:ResultSet
Tells the system to clean up on an error.- Specified by:
cleanUp
in interfaceResultSet
- Throws:
StandardException
- Thrown on error- See Also:
-
verifyBulkInsert
Verify that bulkInsert is allowed on this table. The execution time check to see if bulkInsert is allowed simply consists of checking to see if this is not a deferred mode insert and that the table is empty if this is not replace. A side effect of calling this method is to get an exclusive table lock on the table.- Returns:
- Whether or not bulkInsert is allowed on this table.
- Throws:
StandardException
- Thrown on error
-
getExclusiveTableLock
Get an exclusive table lock on the target table (and check to see if the table is populated if this is not a bulk insert replace).- Returns:
- Whether or not bulkInsert is allowed on this table.
- Throws:
StandardException
- Thrown on error
-
setEstimatedRowCount
Set the estimated row count for this table.- Parameters:
heapConglom
- Conglomerate number for the heap- Throws:
StandardException
- Thrown on failure
-
emptyIndexes
private void emptyIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) throws StandardException Empty the indexes after doing a bulk insert replace where the table has 0 rows after the replace. RESOLVE: This method is ugly! Prior to 2.0, we simply scanned back across the table to build the indexes. We changed this in 2.0 to populate the sorters via a call back as we populated the table. Doing a 0 row replace into a table with indexes is a degenerate case, hence we allow ugly and unoptimized code.- Throws:
StandardException
- Thrown on failure
-
getTableScanResultSet
Get me a table scan result set, preferably a bulk table scan, thank you. If we already have one, reopen it.- Throws:
StandardException
-
getColumnNames
-
finish
Description copied from interface:ResultSet
Tells the system that there will be no more access to any database information via this result set; in particular, no more calls to open(). Will close the result set if it is not already closed.- Specified by:
finish
in interfaceResultSet
- Overrides:
finish
in classNoRowsResultSetImpl
- Throws:
StandardException
- on error
-
rememberConstraint
- Overrides:
rememberConstraint
in classDMLWriteResultSet
- Throws:
StandardException
-
initializeAIcache
- Throws:
StandardException
-