use of org.apache.derby.iapi.sql.dictionary.BulkInsertCounter in project derby by apache.
the class InsertResultSet method bulkInsertCore.
// Do the work for a bulk insert
private void bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) throws StandardException {
bulkHeapCC = tc.openCompiledConglomerate(false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, constants.heapSCOCI, heapDCOCI);
long newHeapConglom;
Properties properties = new Properties();
// Get the properties on the old heap
bulkHeapCC.getInternalTablePropertySet(properties);
if (triggerInfo != null) {
// no triggers in bulk insert mode
if (SanityManager.DEBUG) {
SanityManager.NOTREACHED();
}
}
/*
** If we have a before row trigger, then we
** are going to use a row holder pass to our
** trigger.
*/
if (hasBeforeRowTrigger && rowHolder != null) {
rowHolder = new TemporaryRowHolderImpl(activation, properties, resultDescription);
}
// Add any new properties or change the values of any existing properties
Properties targetProperties = constants.getTargetProperties();
Enumeration key = targetProperties.keys();
while (key.hasMoreElements()) {
String keyValue = (String) key.nextElement();
properties.put(keyValue, targetProperties.getProperty(keyValue));
}
// Are there indexes to be updated?
if (constants.irgs.length > 0) {
// Tell source whether or not we need the RIDs back
sourceResultSet.setNeedsRowLocation(true);
}
if (constants.hasDeferrableChecks) {
sourceResultSet.setHasDeferrableChecks();
}
dd = lcc.getDataDictionary();
td = dd.getTableDescriptor(constants.targetUUID);
/* Do the bulk insert - only okay to reuse the
* same conglomerate if bulkInsert.
*/
long[] loadedRowCount = new long[1];
if (bulkInsertReplace) {
newHeapConglom = tc.createAndLoadConglomerate("heap", fullTemplate.getRowArray(), // column sort order - not required for heap
null, td.getColumnCollationIds(), properties, TransactionController.IS_DEFAULT, sourceResultSet, loadedRowCount);
} else {
newHeapConglom = tc.recreateAndLoadConglomerate("heap", false, fullTemplate.getRowArray(), // column sort order - not required for heap
null, td.getColumnCollationIds(), properties, TransactionController.IS_DEFAULT, oldHeapConglom, sourceResultSet, loadedRowCount);
}
/* Nothing else to do if we get back the same conglomerate number.
* (In 2.0 this means that 0 rows were inserted.)
*/
if (newHeapConglom == oldHeapConglom) {
return;
}
// Find out how many rows were inserted
rowCount = loadedRowCount[0];
// Set the "estimated" row count
setEstimatedRowCount(newHeapConglom);
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
//
if (identitySequenceUUIDString == null) {
lcc.autoincrementFlushCache(constants.targetUUID);
} else {
for (BulkInsertCounter bic : bulkInsertCounters) {
if (bic != null) {
dd.flushBulkInsertCounter(identitySequenceUUIDString, bic);
}
}
}
// invalidate any prepared statements that
// depended on this table (including this one)
DependencyManager dm = dd.getDependencyManager();
dm.invalidateFor(td, DependencyManager.BULK_INSERT, lcc);
// Update all indexes
if (constants.irgs.length > 0) {
// MEN VI HAR MANGE SORTS, EN PR INDEX: alle blir droppet, hvordan
// assossiere alle med nye indekser som tildeles inni her???
// FIXME!!
updateAllIndexes(newHeapConglom, constants, td, dd, fullTemplate);
}
// Drop the old conglomerate
bulkHeapCC.close();
bulkHeapCC = null;
/* Update the DataDictionary
* RESOLVE - this will change in 1.4 because we will get
* back the same conglomerate number
*/
// Get the ConglomerateDescriptor for the heap
ConglomerateDescriptor cd = td.getConglomerateDescriptor(oldHeapConglom);
// Update sys.sysconglomerates with new conglomerate #
dd.updateConglomerateDescriptor(cd, newHeapConglom, tc);
tc.dropConglomerate(oldHeapConglom);
// END RESOLVE
}
Aggregations