Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

pack-priv Class InsertResultSet

extends DMLWriteGeneratedColumnsResultSet
implements TargetResultSet
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.execute.TargetResultSet, org.apache.derby.iapi.sql.ResultSet
Imports
java.util.ArrayList, .Arrays, .Enumeration, .Hashtable, .List, .Properties, .Vector, org.apache.derby.catalog.UUID, org.apache.derby.catalog.types.StatisticsImpl, org.apache.derby.iapi.db.TriggerExecutionContext, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.FormatableBitSet, .StreamStorable, org.apache.derby.iapi.services.loader.GeneratedMethod, org.apache.derby.iapi.sql.Activation, .LanguageProperties, .ResultColumnDescriptor, .ResultSet, .StatementUtil, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.depend.DependencyManager, org.apache.derby.iapi.sql.dictionary.BulkInsertCounter, .ColumnDescriptor, .ConglomerateDescriptor, .ConstraintDescriptor, .DataDictionary, .IndexRowGenerator, .StatisticsDescriptor, .TableDescriptor, .TriggerDescriptor, org.apache.derby.iapi.sql.execute.CursorResultSet, .ExecIndexRow, .ExecRow, .ExecRowBuilder, .NoPutResultSet, .RowChanger, .TargetResultSet, org.apache.derby.iapi.store.access.AccessFactoryGlobals, .BackingStoreHashtable, .ColumnOrdering, .ConglomerateController, .GroupFetchScanController, .Qualifier, .RowLocationRetRowSource, .ScanController, .SortController, .SortObserver, .TransactionController, org.apache.derby.iapi.types.DataValueDescriptor, .NumberDataValue, .RowLocation, .SQLBoolean, org.apache.derby.iapi.util.StringUtil, org.apache.derby.impl.sql.execute.DeferredConstraintsMemory.CheckInfo, org.apache.derby.shared.common.sanity.SanityManager

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

Modifier and TypeField and Description
private ConglomerateController
private ScanController
protected boolean
private BulkInsertCounter[]
pack-priv boolean
private boolean
private GeneratedMethod
private int[][]
pack-priv InsertConstantAction
protected DataDictionary
private BackingStoreHashtable
private boolean
private boolean
private RISetChecker
private FKInfo[]
private final int
private GeneratedMethod
private boolean
private long
private Hashtable<Long, Long>
private FormatableBitSet
private ExecIndexRow[]
private boolean[]
private int
private ColumnOrdering[][]
private RowLocation
private ExecRow
private RowChanger
private TemporaryRowHolderImpl
private RowLocationRetRowSource[]
pack-priv NoPutResultSet
private final String
private SortController[]
private long[]
private final String
private BulkTableScanResultSet
private TransactionController
protected TableDescriptor
private TriggerEventActivator
private TriggerInfo
pack-priv boolean
private List<UUID>
Inherited from org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet:
aiCacheautoGeneratedKeysColumnIndexesautoGeneratedKeysResultSetautoGeneratedKeysRowsHolderautoincrementGeneratedidentitySequenceUUIDStringidentityValsetIdentitysourceResultSet

Constructor Summary

AccessConstructor and Description
pack-priv
InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, String schemaName, String tableName, Activation activation)

Method Summary

Modifier and TypeMethod and Description
private void
bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom)

private void
bulkValidateForeignKeys(TransactionController tc, ContextManager cm, ExecRow fullTemplate)

Bulk Referential Integrity Checker

private void
bulkValidateForeignKeysCore(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, String fkConstraintName, ExecRow fullTemplate)

public void
changedRow(ExecRow
The changed row.
execRow
,
RowLocation
The row location of the row.
rowLocation
)

Implements org.apache.derby.iapi.sql.execute.TargetResultSet.changedRow.

Pass a changed row and the row location for that row to the target result set.

public void
cleanUp()

Implements org.apache.derby.iapi.sql.ResultSet.cleanUp.

Tells the system to clean up on an error.

public void
close()

Implements org.apache.derby.iapi.sql.ResultSet.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
evaluateCheckConstraints()

Run the check constraints against the current row.

public void
finish()

Overrides org.apache.derby.impl.sql.execute.NoRowsResultSetImpl.finish.

Implements org.apache.derby.iapi.sql.ResultSet.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[]
generatedColumnPositionsArray()

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

Returns:

Whether or not bulkInsert is allowed on this table.
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).

protected ExecRow
getNextRowCore(NoPutResultSet
SourceResultSet Also look at Track#2432/change 12433
source
)

Overrides org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore.

Get next row from the source result set.

private void
getOldStyleBulkInsertValue(int
0-based index into aiCache
index
,
long increment)

Identity generation logic for bulk-insert used in pre-10.11 databases.

private NumberDataValue
getOldStyleIdentityValue(int
0-based index into aiCache
index
)

Identity generation logic used in pre-10.11 databases.

public NumberDataValue
getSetAutoincrementValue(int
position of the column in the table (1-based)
columnPosition
,
long
amount of increment.
increment
)

Overrides org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet.getSetAutoincrementValue.

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
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)

public void
public void
open()

Implements org.apache.derby.iapi.sql.ResultSet.open.

Needs to be called before the result set will do anything.

public ExecRow

Returns:

The preprocessed source row.
preprocessSourceRow
(ExecRow
The source row.
execRow
)

Implements org.apache.derby.iapi.sql.execute.TargetResultSet.preprocessSourceRow.

Preprocess the source row.

private ExecRow
processMergeRow(NoPutResultSet sourceRS, ExecRow row)

Special handling if this is an INSERT action of a MERGE statement.

public void
private void
setEstimatedRowCount(long
Conglomerate number for the heap
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

Returns:

Whether or not bulkInsert is allowed on this table.
verifyBulkInsert
()

Verify that bulkInsert is allowed on this table.

Inherited from org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet:
firstExecuteSpecialHandlingAutoGengetAutoGeneratedKeysResultsetgetCompactRowsaveAIcacheInformationverifyAutoGeneratedRScolumnsList

Field Detail

bulkHeapCCback to summary
private ConglomerateController bulkHeapCC
bulkHeapSCback to summary
private ScanController bulkHeapSC
bulkInsertback to summary
protected boolean bulkInsert
bulkInsertCountersback to summary
private BulkInsertCounter[] bulkInsertCounters
bulkInsertPerformedback to summary
pack-priv boolean bulkInsertPerformed
bulkInsertReplaceback to summary
private boolean bulkInsertReplace
checkGMback to summary
private GeneratedMethod checkGM
collationback to summary
private int[][] collation
constantsback to summary
pack-priv InsertConstantAction constants
ddback to summary
protected DataDictionary dd
deferredChecksback to summary
private BackingStoreHashtable deferredChecks
firstExecuteback to summary
private boolean firstExecute
firstRowback to summary
private boolean firstRow
fkCheckerback to summary
private RISetChecker fkChecker
fkInfoArrayback to summary
private FKInfo[] fkInfoArray
fullTemplateIdback to summary
private final int fullTemplateId
generationClausesback to summary
private GeneratedMethod generationClauses
hasBeforeRowTriggerback to summary
private boolean hasBeforeRowTrigger
heapConglomback to summary
private long heapConglom
indexConversionTableback to summary
private Hashtable<Long, Long> indexConversionTable
indexedColsback to summary
private FormatableBitSet indexedCols
indexRowsback to summary
private ExecIndexRow[] indexRows
needToDropSortback to summary
private boolean[] needToDropSort
numOpensback to summary
private int numOpens
orderingback to summary
private ColumnOrdering[][] ordering
rlback to summary
private RowLocation rl
rowback to summary
private ExecRow row
rowChangerback to summary
private RowChanger rowChanger
rowHolderback to summary
private TemporaryRowHolderImpl rowHolder
rowSourcesback to summary
private RowLocationRetRowSource[] rowSources
savedSourceback to summary
pack-priv NoPutResultSet savedSource
schemaNameback to summary
private final String schemaName
sortersback to summary
private SortController[] sorters
sortIdsback to summary
private long[] sortIds
tableNameback to summary
private final String tableName
tableScanback to summary
private BulkTableScanResultSet tableScan
tcback to summary
private TransactionController tc
tdback to summary
protected TableDescriptor td
triggerActivatorback to summary
private TriggerEventActivator triggerActivator
triggerInfoback to summary
private TriggerInfo triggerInfo
userSpecifiedBulkInsertback to summary
pack-priv boolean userSpecifiedBulkInsert
violatingCheckConstraintsback to summary
private List<UUID> violatingCheckConstraints

Constructor Detail

InsertResultSetback to summary
pack-priv InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, String schemaName, String tableName, Activation activation) throws StandardException
Exceptions
StandardException:
Thrown on error

Method Detail

bulkInsertCoreback to summary
private void bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) throws StandardException
bulkValidateForeignKeysback to summary
private void bulkValidateForeignKeys(TransactionController tc, ContextManager cm, ExecRow fullTemplate) throws StandardException

Bulk Referential Integrity Checker

bulkValidateForeignKeysCoreback to summary
private void bulkValidateForeignKeysCore(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, String fkConstraintName, ExecRow fullTemplate) throws StandardException
changedRowback to summary
public void changedRow(ExecRow execRow, RowLocation rowLocation) throws StandardException

Implements org.apache.derby.iapi.sql.execute.TargetResultSet.changedRow.

Doc from org.apache.derby.iapi.sql.execute.TargetResultSet.changedRow.

Pass a changed row and the row location for that row to the target result set.

Parameters
execRow:ExecRow

The changed row.

rowLocation:RowLocation

The row location of the row.

Exceptions
StandardException:
thrown if cursor finish ed.
See Also
TargetResultSet#changedRow
cleanUpback to summary
public void cleanUp() throws StandardException

Implements org.apache.derby.iapi.sql.ResultSet.cleanUp.

Doc from org.apache.derby.iapi.sql.ResultSet.cleanUp.

Tells the system to clean up on an error.

Exceptions
StandardException:
Thrown on error
See Also
ResultSet#cleanUp
closeback to summary
public void close() throws StandardException

Implements org.apache.derby.iapi.sql.ResultSet.close.

Clean up resources and call close on data members.

Exceptions
StandardException:

Doc from org.apache.derby.iapi.sql.ResultSet.close.

Thrown on error.

emptyIndexesback to summary
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.

Exceptions
StandardException:
Thrown on failure
evaluateCheckConstraintsback to summary
private boolean evaluateCheckConstraints() throws StandardException

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).

Exceptions
StandardException:
thrown on error
finishback to summary
public void finish() throws StandardException

Overrides org.apache.derby.impl.sql.execute.NoRowsResultSetImpl.finish.

Implements org.apache.derby.iapi.sql.ResultSet.finish.

Doc from org.apache.derby.iapi.sql.ResultSet.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(). Will close the result set if it is not already closed.

Annotations
@Override
Exceptions
StandardException:
on error
generatedColumnPositionsArrayback to summary
private int[] generatedColumnPositionsArray() throws StandardException

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.

getColumnNamesback to summary
private String[] getColumnNames(int[] baseColumnPositions)
getExclusiveTableLockback to summary
private boolean getExclusiveTableLock() throws StandardException

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:boolean

Whether or not bulkInsert is allowed on this table.

Exceptions
StandardException:
Thrown on error
getNextRowCoreback to summary
protected ExecRow getNextRowCore(NoPutResultSet source) throws StandardException

Overrides org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore.

Doc from org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore.

Get next row from the source result set.

Parameters
source:NoPutResultSet

SourceResultSet Also look at Track#2432/change 12433

Returns:ExecRow

The next row in the result set

Annotations
@Override
Exceptions
StandardException:
Standard error policy
getOldStyleBulkInsertValueback to summary
private void getOldStyleBulkInsertValue(int index, long increment) throws StandardException

Identity generation logic for bulk-insert used in pre-10.11 databases.

Parameters
index:int

0-based index into aiCache

getOldStyleIdentityValueback to summary
private NumberDataValue getOldStyleIdentityValue(int index) throws StandardException

Identity generation logic used in pre-10.11 databases.

Parameters
index:int

0-based index into aiCache

getSetAutoincrementValueback to summary
public NumberDataValue getSetAutoincrementValue(int columnPosition, long increment) throws StandardException

Overrides org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet.getSetAutoincrementValue.

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.

Parameters
columnPosition:int

position of the column in the table (1-based)

increment:long

amount of increment.

Exceptions
StandardException:
if anything goes wrong.
getTableScanResultSetback to summary
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.

initializeAIcacheback to summary
protected void initializeAIcache(RowLocation[] rla) throws StandardException
isSingleRowResultSetback to summary
private boolean isSingleRowResultSet()
isSourceRowResultSetback to summary
private boolean isSourceRowResultSet()
makeIndexTemplateback to summary
private ExecRow makeIndexTemplate(FKInfo fkInfo, ExecRow fullTemplate, ContextManager cm) throws StandardException

Make a template row with the correct columns.

normalInsertCoreback to summary
private void normalInsertCore(LanguageConnectionContext lcc, boolean firstExecute) throws StandardException
offendingRowLocationback to summary
public void offendingRowLocation(RowLocation rl, long constainerId) throws StandardException

Implements org.apache.derby.iapi.sql.execute.TargetResultSet.offendingRowLocation.

openback to summary
public void open() throws StandardException

Implements org.apache.derby.iapi.sql.ResultSet.open.

Doc from org.apache.derby.iapi.sql.ResultSet.open.

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.

Exceptions
StandardException:
Standard Derby error policy
preprocessSourceRowback to summary
public ExecRow preprocessSourceRow(ExecRow execRow) throws StandardException

Implements org.apache.derby.iapi.sql.execute.TargetResultSet.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.

Parameters
execRow:ExecRow

The source row.

Returns:ExecRow

The preprocessed source row.

Exceptions
StandardException:
thrown on error
processMergeRowback to summary
private ExecRow processMergeRow(NoPutResultSet sourceRS, ExecRow row) throws StandardException

Special handling if this is an INSERT action of a MERGE statement.

rememberConstraintback to summary
public void rememberConstraint(UUID cid) throws StandardException

Overrides org.apache.derby.impl.sql.execute.DMLWriteResultSet.rememberConstraint.

Annotations
@Override
setEstimatedRowCountback to summary
private void setEstimatedRowCount(long heapConglom) throws StandardException

Set the estimated row count for this table.

Parameters
heapConglom:long

Conglomerate number for the heap

Exceptions
StandardException:
Thrown on failure
setUpAllSortsback to summary
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.

Exceptions
StandardException:
thrown on error
updateAllIndexesback to summary
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.

Exceptions
StandardException:
thrown on error
verifyBulkInsertback to summary
protected boolean verifyBulkInsert() throws StandardException

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:boolean

Whether or not bulkInsert is allowed on this table.

Exceptions
StandardException:
Thrown on error