📄 temporaryrowholderimpl.java
字号:
int status = 0; if(isUniqueStream) { cc.insertAndFetchLocation(inputRow.getRowArray(), destRowLocation); insertToPositionIndex(numRowsIn -1, destRowLocation); //create the unique index based on input row ROW Location if(!uniqueIndexCreated) isRowAlreadyExist(inputRow); }else { status = cc.insert(inputRow.getRowArray()); if (isVirtualMemHeap) state = STATE_INSERT; } if (SanityManager.DEBUG) { if (status != 0) { SanityManager.THROWASSERT("got funky status ("+status+") back from "+ "ConglomerateConstroller.insert()"); } } } /** * Maintain an unique index based on the input row's row location in the * base table, this index make sures that we don't insert duplicate rows * into the temporary heap. * @param inputRow the row we are inserting to temporary row holder * @exception StandardException on error */ private boolean isRowAlreadyExist(ExecRow inputRow) throws StandardException { DataValueDescriptor rlColumn; RowLocation baseRowLocation; rlColumn = inputRow.getColumn(inputRow.nColumns()); if(CID!=0 && rlColumn instanceof SQLRef) { baseRowLocation = (RowLocation) (rlColumn).getObject(); if(!uniqueIndexCreated) { int numKeys = 2; uniqueIndexRow = new DataValueDescriptor[numKeys]; uniqueIndexRow[0] = baseRowLocation; uniqueIndexRow[1] = baseRowLocation; Properties props = makeIndexProperties(uniqueIndexRow, CID); uniqueIndexConglomId = tc.createConglomerate("BTREE",uniqueIndexRow , null, props, TransactionController.IS_TEMPORARY | TransactionController.IS_KEPT); uniqueIndex_cc = tc.openConglomerate( uniqueIndexConglomId, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE); uniqueIndexCreated = true; } uniqueIndexRow[0] = baseRowLocation; uniqueIndexRow[1] = baseRowLocation; // Insert the row into the secondary index. int status; if ((status = uniqueIndex_cc.insert(uniqueIndexRow))!= 0) { if(status == ConglomerateController.ROWISDUPLICATE) { return true ; // okay; we don't insert duplicates } else { if (SanityManager.DEBUG) { if (status != 0) { SanityManager.THROWASSERT("got funky status ("+status+") back from "+ "Unique Index insert()"); } } } } } return false; } /** * Maintain an index that will allow us to read from the * temporary heap in the order we inserted. * @param position - the number of the row we are inserting into heap * @param rl the row to Location in the temporary heap * @exception StandardException on error */ private void insertToPositionIndex(int position, RowLocation rl ) throws StandardException { if(!positionIndexCreated) { int numKeys = 2; position_sqllong = new SQLLongint(); positionIndexRow = new DataValueDescriptor[numKeys]; positionIndexRow[0] = position_sqllong; positionIndexRow[1] = rl; Properties props = makeIndexProperties(positionIndexRow, CID); positionIndexConglomId = tc.createConglomerate("BTREE", positionIndexRow, null, props, TransactionController.IS_TEMPORARY | TransactionController.IS_KEPT); positionIndex_cc = tc.openConglomerate( positionIndexConglomId, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE); positionIndexCreated = true; } position_sqllong.setValue(position); positionIndexRow[0] = position_sqllong; positionIndexRow[1] = rl; //insert the row location to position index positionIndex_cc.insert(positionIndexRow); } /** * Get a result set for scanning what has been inserted * so far. * * @return a result set to use */ public CursorResultSet getResultSet() { state = STATE_DRAIN; if(isUniqueStream) { return new TemporaryRowHolderResultSet(tc, rowArray, resultDescription, isVirtualMemHeap, true, positionIndexConglomId, this); } else { return new TemporaryRowHolderResultSet(tc, rowArray, resultDescription, isVirtualMemHeap, this); } } /** * Purge the row holder of all its rows. * Resets the row holder so that it can * accept new inserts. A cheap way to * recycle a row holder. * * @exception StandardException on error */ public void truncate() throws StandardException { close(); for (int i = 0; i < rowArray.length; i++) { rowArray[i] = null; } lastArraySlot = -1; numRowsIn = 0; state = STATE_UNINIT; /* ** We are not expecting this to be called ** when we have a temporary conglomerate ** but just to be on the safe side, drop ** it. We'd like do something cheaper, ** but there is no truncate on congloms. */ if (conglomCreated) { tc.dropConglomerate(CID); conglomCreated = false; } } public long getTemporaryConglomId() { return CID; } public long getPositionIndexConglomId() { return positionIndexConglomId; } private Properties makeIndexProperties(DataValueDescriptor[] indexRowArray, long conglomId ) throws StandardException { int nCols = indexRowArray.length; Properties props = new Properties(); props.put("allowDuplicates", "false"); // all columns form the key, (currently) required props.put("nKeyFields", String.valueOf(nCols)); props.put("nUniqueColumns", String.valueOf(nCols-1)); props.put("rowLocationColumn", String.valueOf(nCols-1)); props.put("baseConglomerateId", String.valueOf(conglomId)); return props; } public void setRowHolderTypeToUniqueStream() { isUniqueStream = true; } /** * Clean up * * @exception StandardException on error */ public void close() throws StandardException { if (scan != null) { scan.close(); scan = null; } if (cc != null) { cc.close(); cc = null; } if (uniqueIndex_cc != null) { uniqueIndex_cc.close(); uniqueIndex_cc = null; } if (positionIndex_cc != null) { positionIndex_cc.close(); positionIndex_cc = null; } if (uniqueIndexCreated) { tc.dropConglomerate(uniqueIndexConglomId); uniqueIndexCreated = false; } if (positionIndexCreated) { tc.dropConglomerate(positionIndexConglomId); uniqueIndexCreated = false; } if (conglomCreated) { tc.dropConglomerate(CID); conglomCreated = false; } state = STATE_UNINIT; lastArraySlot = -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -