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 ConglomerateControllerprivate ScanControllerprotected booleanprivate BulkInsertCounter[](package private) booleanprivate booleanprivate GeneratedMethodprivate int[][](package private) InsertConstantActionprotected DataDictionaryprivate BackingStoreHashtableprivate booleanprivate booleanprivate RISetCheckerprivate FKInfo[]private final intprivate GeneratedMethodprivate booleanprivate longprivate FormatableBitSetprivate ExecIndexRow[]private boolean[]private intprivate ColumnOrdering[][]private RowLocationprivate ExecRowprivate RowChangerprivate TemporaryRowHolderImplprivate RowLocationRetRowSource[](package private) NoPutResultSetprivate final Stringprivate SortController[]private long[]private final Stringprivate BulkTableScanResultSetprivate TransactionControllerprotected TableDescriptorprivate TriggerEventActivatorprivate TriggerInfo(package private) booleanFields inherited from class DMLWriteGeneratedColumnsResultSet
aiCache, autoGeneratedKeysColumnIndexes, autoGeneratedKeysResultSet, autoGeneratedKeysRowsHolder, autoincrementGenerated, identitySequenceUUIDString, identityVal, setIdentity, sourceResultSetFields inherited from class DMLWriteResultSet
baseRowReadMap, cachedDestinations, constantAction, heapDCOCI, indexDCOCIs, resultDescription, rowCount, streamStorableHeapColIdsFields inherited from class NoRowsResultSetImpl
activation, beginExecutionTime, beginTime, endExecutionTime, endTime, lccFields inherited from interface 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 voidbulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) private voidbulkValidateForeignKeys(TransactionController tc, ContextManager cm, ExecRow fullTemplate) Bulk Referential Integrity Checkerprivate voidbulkValidateForeignKeysCore(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, String fkConstraintName, ExecRow fullTemplate) voidchangedRow(ExecRow execRow, RowLocation rowLocation) Pass a changed row and the row location for that row to the target result set.voidcleanUp()Tells the system to clean up on an error.voidclose()Clean up resources and call close on data members.private voidemptyIndexes(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 booleanRun the check constraints against the current row.voidfinish()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 booleanGet 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 ExecRowgetNextRowCore(NoPutResultSet source) Get next row from the source result set.private voidgetOldStyleBulkInsertValue(int index, long increment) Identity generation logic for bulk-insert used in pre-10.11 databases.private NumberDataValuegetOldStyleIdentityValue(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 BulkTableScanResultSetgetTableScanResultSet(long conglomId) Get me a table scan result set, preferably a bulk table scan, thank you.protected voidinitializeAIcache(RowLocation[] rla) private booleanprivate booleanprivate ExecRowmakeIndexTemplate(FKInfo fkInfo, ExecRow fullTemplate, ContextManager cm) Make a template row with the correct columns.private voidnormalInsertCore(LanguageConnectionContext lcc, boolean firstExecute) voidoffendingRowLocation(RowLocation rl, long constainerId) voidopen()Needs to be called before the result set will do anything.preprocessSourceRow(ExecRow execRow) Preprocess the source row.private ExecRowprocessMergeRow(NoPutResultSet sourceRS, ExecRow row) Special handling if this is an INSERT action of a MERGE statement.voidrememberConstraint(UUID cid) private voidsetEstimatedRowCount(long heapConglom) Set the estimated row count for this table.private voidsetUpAllSorts(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 voidupdateAllIndexes(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 booleanVerify that bulkInsert is allowed on this table.Methods inherited from class DMLWriteGeneratedColumnsResultSet
firstExecuteSpecialHandlingAutoGen, getAutoGeneratedKeysResultset, getCompactRow, saveAIcacheInformation, verifyAutoGeneratedRScolumnsListMethods inherited from class DMLWriteResultSet
decodeLockMode, getIndexNameFromCID, getResultDescription, makeDeferredSparseRow, modifiedRowCount, normalizeRowMethods inherited from class 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, toXMLMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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:TargetResultSetPass a changed row and the row location for that row to the target result set.- Specified by:
changedRowin 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:
preprocessSourceRowin interfaceTargetResultSet- Parameters:
execRow- The source row.- Returns:
- The preprocessed source row.
- Throws:
StandardException- thrown on error
-
offendingRowLocation
- Specified by:
offendingRowLocationin 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:ResultSetNeeds 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:
openin interfaceResultSet- Throws:
StandardException- Standard Derby error policy
-
close
Clean up resources and call close on data members.- Specified by:
closein 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:
getSetAutoincrementValuein 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:DMLWriteResultSetGet next row from the source result set.- Overrides:
getNextRowCorein 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:ResultSetTells the system to clean up on an error.- Specified by:
cleanUpin 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:ResultSetTells 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:
finishin interfaceResultSet- Overrides:
finishin classNoRowsResultSetImpl- Throws:
StandardException- on error
-
rememberConstraint
- Overrides:
rememberConstraintin classDMLWriteResultSet- Throws:
StandardException
-
initializeAIcache
- Throws:
StandardException
-