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
class InsertResultSet extends DMLWriteGeneratedColumnsResultSet implements TargetResultSet
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
-
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
Constructors Constructor Description InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, java.lang.String schemaName, java.lang.String tableName, Activation activation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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, java.lang.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 booleanevaluateCheckConstraints()Run 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[]generatedColumnPositionsArray()If user didn't provide columns list for auto-generated columns, then only include columns with auto-generated values in the resultset.private java.lang.String[]getColumnNames(int[] baseColumnPositions)private booleangetExclusiveTableLock()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 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.NumberDataValuegetSetAutoincrementValue(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 booleanisSingleRowResultSet()private booleanisSourceRowResultSet()private 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.ExecRowpreprocessSourceRow(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 booleanverifyBulkInsert()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 Detail
-
savedSource
NoPutResultSet savedSource
-
constants
InsertConstantAction constants
-
generationClauses
private GeneratedMethod generationClauses
-
checkGM
private GeneratedMethod checkGM
-
heapConglom
private long heapConglom
-
rowChanger
private RowChanger rowChanger
-
tc
private TransactionController tc
-
row
private ExecRow row
-
userSpecifiedBulkInsert
boolean userSpecifiedBulkInsert
-
bulkInsertPerformed
boolean bulkInsertPerformed
-
bulkInsert
protected boolean bulkInsert
-
bulkInsertReplace
private boolean bulkInsertReplace
-
firstRow
private boolean firstRow
-
needToDropSort
private boolean[] needToDropSort
-
indexConversionTable
private java.util.Hashtable<java.lang.Long,java.lang.Long> indexConversionTable
-
indexedCols
private FormatableBitSet indexedCols
-
bulkHeapCC
private ConglomerateController bulkHeapCC
-
dd
protected DataDictionary dd
-
td
protected TableDescriptor td
-
indexRows
private ExecIndexRow[] indexRows
-
fullTemplateId
private final int fullTemplateId
-
schemaName
private final java.lang.String schemaName
-
tableName
private final java.lang.String tableName
-
sortIds
private long[] sortIds
-
rowSources
private RowLocationRetRowSource[] rowSources
-
bulkHeapSC
private ScanController bulkHeapSC
-
ordering
private ColumnOrdering[][] ordering
-
collation
private int[][] collation
-
sorters
private SortController[] sorters
-
rowHolder
private TemporaryRowHolderImpl rowHolder
-
rl
private RowLocation rl
-
hasBeforeRowTrigger
private boolean hasBeforeRowTrigger
-
tableScan
private BulkTableScanResultSet tableScan
-
numOpens
private int numOpens
-
firstExecute
private boolean firstExecute
-
fkInfoArray
private FKInfo[] fkInfoArray
-
triggerInfo
private TriggerInfo triggerInfo
-
fkChecker
private RISetChecker fkChecker
-
triggerActivator
private TriggerEventActivator triggerActivator
-
bulkInsertCounters
private BulkInsertCounter[] bulkInsertCounters
-
deferredChecks
private BackingStoreHashtable deferredChecks
-
violatingCheckConstraints
private java.util.List<UUID> violatingCheckConstraints
-
-
Constructor Detail
-
InsertResultSet
InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, java.lang.String schemaName, java.lang.String tableName, Activation activation) throws StandardException
- Throws:
StandardException- Thrown on error
-
-
Method Detail
-
changedRow
public void changedRow(ExecRow execRow, RowLocation rowLocation) throws StandardException
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:
TargetResultSet.changedRow(org.apache.derby.iapi.sql.execute.ExecRow, org.apache.derby.iapi.types.RowLocation)
-
preprocessSourceRow
public ExecRow preprocessSourceRow(ExecRow execRow) throws StandardException
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
public void offendingRowLocation(RowLocation rl, long constainerId) throws StandardException
- Specified by:
offendingRowLocationin interfaceTargetResultSet- Throws:
StandardException
-
evaluateCheckConstraints
private boolean evaluateCheckConstraints() throws StandardExceptionRun 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
public void open() throws StandardExceptionDescription 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
public void close() throws StandardExceptionClean up resources and call close on data members.- Specified by:
closein interfaceResultSet- Throws:
StandardException- Thrown on error.
-
generatedColumnPositionsArray
private int[] generatedColumnPositionsArray() throws StandardExceptionIf 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
private void getOldStyleBulkInsertValue(int index, long increment) throws StandardExceptionIdentity generation logic for bulk-insert used in pre-10.11 databases.- Parameters:
index- 0-based index into aiCache- Throws:
StandardException
-
getOldStyleIdentityValue
private NumberDataValue getOldStyleIdentityValue(int index) throws StandardException
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
protected ExecRow getNextRowCore(NoPutResultSet source) throws StandardException
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
private ExecRow processMergeRow(NoPutResultSet sourceRS, ExecRow row) throws StandardException
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, java.lang.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
private void setUpAllSorts(ExecRow sourceRow, RowLocation rl) throws StandardException
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 StandardExceptionUpdate all of the indexes on a table when doing a bulk insert on an empty table.- Throws:
StandardException- thrown on error
-
cleanUp
public void cleanUp() throws StandardExceptionDescription copied from interface:ResultSetTells the system to clean up on an error.- Specified by:
cleanUpin interfaceResultSet- Throws:
StandardException- Thrown on error- See Also:
ResultSet.cleanUp()
-
verifyBulkInsert
protected boolean verifyBulkInsert() throws StandardExceptionVerify 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
private boolean getExclusiveTableLock() throws StandardExceptionGet 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
private void setEstimatedRowCount(long heapConglom) throws StandardExceptionSet 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 StandardExceptionEmpty 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
private BulkTableScanResultSet getTableScanResultSet(long conglomId) throws StandardException
Get me a table scan result set, preferably a bulk table scan, thank you. If we already have one, reopen it.- Throws:
StandardException
-
getColumnNames
private java.lang.String[] getColumnNames(int[] baseColumnPositions)
-
finish
public void finish() throws StandardExceptionDescription 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
public void rememberConstraint(UUID cid) throws StandardException
- Overrides:
rememberConstraintin classDMLWriteResultSet- Throws:
StandardException
-
initializeAIcache
protected void initializeAIcache(RowLocation[] rla) throws StandardException
- Throws:
StandardException
-
-