use of org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo in project derby by apache.
the class HeapController method load.
protected long load(TransactionManager xact_manager, Heap heap, boolean createConglom, RowLocationRetRowSource rowSource) throws StandardException {
long num_rows_loaded = 0;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(open_conglom == null, "load expects container handle to be closed on entry.");
}
// The individual rows that are inserted are not logged. To use a
// logged interface, use insert. RESOLVE: do we want to allow client
// to use the load interface even for logged insert?
int mode = (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_UNLOGGED);
// page allocation.
if (createConglom)
mode |= ContainerHandle.MODE_CREATE_UNLOGGED;
OpenConglomerate open_conglom = new OpenHeap();
if (open_conglom.init((ContainerHandle) null, heap, heap.format_ids, heap.collation_ids, xact_manager, xact_manager.getRawStoreXact(), false, mode, TransactionController.MODE_TABLE, xact_manager.getRawStoreXact().newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true), (DynamicCompiledOpenConglomInfo) null) == null) {
throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, heap.getId().getContainerId());
}
this.init(open_conglom);
// For bulk loading, we always use only brand new page because the row
// insertion itself is not logged. We cannot pollute pages with
// pre-existing data with unlogged rows because nobody is going to wipe
// out these rows if the transaction rolls back. We are counting on
// the allocation page rollback to obliterate these rows if the
// transaction fails, or, in the CREAT_UNLOGGED case, the whole
// container to be removed.
Page page = open_conglom.getContainer().addPage();
boolean callbackWithRowLocation = rowSource.needsRowLocation();
RecordHandle rh;
HeapRowLocation rowlocation;
if (callbackWithRowLocation || rowSource.needsRowLocationForDeferredCheckConstraints())
rowlocation = new HeapRowLocation();
else
rowlocation = null;
FormatableBitSet validColumns = rowSource.getValidColumns();
try {
// get the next row and its valid columns from the rowSource
DataValueDescriptor[] row;
while ((row = rowSource.getNextRowFromRowSource()) != null) {
num_rows_loaded++;
if (SanityManager.DEBUG) {
// Make sure valid columns are in the list. The RowUtil
// call is too expensive to make in a released system for
// every insert.
int invalidColumn = RowUtil.columnOutOfRange(row, validColumns, heap.format_ids.length);
if (invalidColumn >= 0) {
throw (StandardException.newException(SQLState.HEAP_TEMPLATE_MISMATCH, invalidColumn, heap.format_ids.length));
}
}
// Insert it onto this page as long as it can fit more rows.
if ((rh = page.insert(row, validColumns, Page.INSERT_DEFAULT, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD)) == null) {
// Insert faied, row did not fit. Get a new page.
page.unlatch();
page = null;
page = open_conglom.getContainer().addPage();
// RESOLVE (mikem) - no long rows yet so the following code
// will get an exception from the raw store for a row that
// does not fit on a page.
//
// Multi-thread considerations aside, the raw store will
// guarantee that any size row will fit on an empty page.
rh = page.insert(row, validColumns, Page.INSERT_OVERFLOW, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
}
// and go for the next row.
if (callbackWithRowLocation) {
rowlocation.setFrom(rh);
rowSource.rowLocation(rowlocation);
}
if (rowSource.needsRowLocationForDeferredCheckConstraints()) {
rowlocation.setFrom(rh);
rowSource.offendingRowLocation(rowlocation, heap.getContainerid());
}
}
page.unlatch();
page = null;
// it is unlogged.
if (!heap.isTemporary())
open_conglom.getContainer().flushContainer();
} finally {
// If an error happened here, don't bother flushing the
// container since the changes should be rolled back anyhow.
close();
}
return (num_rows_loaded);
}
use of org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo in project derby by apache.
the class TabInfoImpl method getRowChanger.
/**
* Gets a row changer for this catalog.
*
* @param tc transaction controller
* @param changedCols the columns to change (1 based), may be null
* @param baseRow used to detemine column types at creation time
* only. The row changer does ***Not*** keep a referance to
* this row or change it in any way.
*
* @return a row changer for this catalog.
* @exception StandardException Thrown on failure
*/
private RowChanger getRowChanger(TransactionController tc, int[] changedCols, ExecRow baseRow) throws StandardException {
RowChanger rc;
int indexCount = crf.getNumIndexes();
IndexRowGenerator[] irgs = new IndexRowGenerator[indexCount];
long[] cids = new long[indexCount];
if (SanityManager.DEBUG) {
if (changedCols != null) {
for (int i = changedCols.length - 1; i >= 0; i--) {
SanityManager.ASSERT(changedCols[i] != 0, "Column id is 0, but should be 1 based");
}
}
}
for (int ictr = 0; ictr < indexCount; ictr++) {
irgs[ictr] = getIndexRowGenerator(ictr);
cids[ictr] = getIndexConglomerate(ictr);
}
rc = crf.getExecutionFactory().getRowChanger(getHeapConglomerate(), (StaticCompiledOpenConglomInfo) null, (DynamicCompiledOpenConglomInfo) null, irgs, cids, (StaticCompiledOpenConglomInfo[]) null, (DynamicCompiledOpenConglomInfo[]) null, crf.getHeapColumnCount(), tc, changedCols, getStreamStorableHeapColIds(baseRow), (Activation) null);
return rc;
}
Aggregations