⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabinfoimpl.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * index rows.	 *	 *	@param	row			row to insert	 *	@param	lcc			language state variable	 *	@return	row number (>= 0) if duplicate row inserted into an index	 *			ROWNOTDUPLICATE otherwise	 *	 *	 * @exception StandardException		Thrown on failure	 */	public int insertRow( ExecRow row, LanguageConnectionContext lcc )		throws StandardException	{		return	insertRowList(new ExecRow[] {row}, lcc.getTransactionExecute());	}	/**	 @see TabInfo#insertRowAndFetchRowLocation	 @exception StandardException Thrown on failure	 */	public RowLocation insertRowAndFetchRowLocation(ExecRow row, TransactionController tc)		throws StandardException	{		RowLocation[] rowLocationOut = new RowLocation[1]; 		insertRowListImpl(new ExecRow[] {row},tc,rowLocationOut, true);		return rowLocationOut[0];	}	/**	 * Inserts a list of base rows into a catalog and inserts all the corresponding	 * index rows.	 *	 *	@param	rowList		List of rows to insert	 *	@param	tc			transaction controller	 *	 *	 *	@return	row  number (>= 0) if duplicate row inserted into an index	 *			ROWNOTDUPLICATE otherwise	 *	 * @exception StandardException		Thrown on failure	 */	public int insertRowList(ExecRow[] rowList, TransactionController tc )		throws StandardException	{		RowLocation[] 			notUsed = new RowLocation[1]; 		return insertRowListImpl(rowList,tc,notUsed, true);	}	/**	  Insert logic to insert a list of rows into a table. This logic has two	  odd features to support the TabInfo interface.	  <OL>	  <LI>Returns an indication if any returned row was a duplicate.	  <LI>Returns the RowLocation of the last row inserted.	  </OL>	  @param rowList the list of rows to insert	  @param tc	transaction controller	  @param rowLocationOut on output rowLocationOut[0] is set to the	         last RowLocation inserted.	  @param wait   to wait on lock or quickly TIMEOUT	  @return row number (>= 0) if duplicate row inserted into an index	  			ROWNOTDUPLICATE otherwise	 */	private int insertRowListImpl(ExecRow[] rowList, TransactionController tc, RowLocation[] rowLocationOut,								   boolean wait)		throws StandardException	{		ConglomerateController		heapController;		RowLocation					heapLocation;		ExecIndexRow				indexableRow;		int							insertRetCode;		int							retCode = ROWNOTDUPLICATE;		int							indexCount = crf.getNumIndexes();		ConglomerateController[]	indexControllers = new ConglomerateController[ indexCount ];		// Open the conglomerates		heapController =             tc.openConglomerate(                getHeapConglomerate(),                 false,				(TransactionController.OPENMODE_FORUPDATE |                    ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_REPEATABLE_READ);				/* NOTE: Due to the lovely problem of trying to add		 * a new column to syscolumns and an index on that		 * column during upgrade, we have to deal with the		 * issue of the index not existing yet.  So, it's okay		 * if the index doesn't exist yet.  (It will magically		 * get created at a later point during upgrade.)		 */		for ( int ictr = 0; ictr < indexCount; ictr++ )		{			long conglomNumber = getIndexConglomerate(ictr);			if (conglomNumber > -1)			{				indexControllers[ ictr ] = 		            tc.openConglomerate( 			            conglomNumber,                         false,						(TransactionController.OPENMODE_FORUPDATE |                    		((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),					    TransactionController.MODE_RECORD,						TransactionController.ISOLATION_REPEATABLE_READ);			}		}		heapLocation = heapController.newRowLocationTemplate();		rowLocationOut[0]=heapLocation;		// loop through rows on this list, inserting them into system table		for (int rowNumber = 0; rowNumber < rowList.length; rowNumber++)		{			ExecRow row = rowList[rowNumber];			// insert the base row and get its new location 			heapController.insertAndFetchLocation(row.getRowArray(), heapLocation);						for ( int ictr = 0; ictr < indexCount; ictr++ )		    {				if (indexControllers[ ictr ] == null)				{					continue;				}				// Get an index row based on the base row				indexableRow = getIndexRowFromHeapRow( getIndexRowGenerator(ictr),													   heapLocation,													   row );				insertRetCode =                     indexControllers[ ictr ].insert(indexableRow.getRowArray());				if ( insertRetCode == ConglomerateController.ROWISDUPLICATE )				{					retCode = rowNumber;				}			}		}	// end loop through rows on list		// Close the open conglomerates		for ( int ictr = 0; ictr < indexCount; ictr++ )		{			if (indexControllers[ ictr ] == null)			{				continue;			}			indexControllers[ ictr ].close();		}		heapController.close();		return	retCode;	}	/**	  * @exception StandardException		Thrown on failure	  * @see TabInfo#truncate	  */	public int truncate( TransactionController tc )		 throws StandardException	{		ConglomerateController		heapCC;		ScanController				drivingScan;		RowLocation					baseRowLocation;		RowChanger 					rc;		ExecRow						baseRow = crf.makeEmptyRow();		rc = getRowChanger( tc, (int[])null,baseRow );		// Table level locking		rc.open(TransactionController.MODE_TABLE);		int rowsDeleted = 0;				drivingScan = tc.openScan(			getHeapConglomerate(),  // conglomerate to open			false,        // don't hold open across commit            TransactionController.OPENMODE_FORUPDATE, // for update            TransactionController.MODE_TABLE,            TransactionController.ISOLATION_REPEATABLE_READ,			(FormatableBitSet) null, // all fields as objects			null,         // start position - first row            ScanController.NA,			null,         //scanQualifier			null,         // stop position - through last row            ScanController.NA                           // startSearchOperation			);     		/* Open the heap conglomerate */		heapCC = tc.openConglomerate(                    getHeapConglomerate(),                    false,                    TransactionController.OPENMODE_FORUPDATE,                    TransactionController.MODE_TABLE,                    TransactionController.ISOLATION_REPEATABLE_READ);		baseRowLocation = heapCC.newRowLocationTemplate();		while (drivingScan.next())		{			rowsDeleted++;			drivingScan.fetchLocation(baseRowLocation);			boolean base_row_exists =                 heapCC.fetch(                    baseRowLocation, baseRow.getRowArray(), (FormatableBitSet) null);            if (SanityManager.DEBUG)            {                // it can not be possible for heap row to disappear while                 // holding scan cursor on index at ISOLATION_REPEATABLE_READ.                SanityManager.ASSERT(base_row_exists, "base row not found");            }			rc.deleteRow( baseRow, baseRowLocation );		}		heapCC.close();		drivingScan.close();		rc.close();		return rowsDeleted;	}	/**	 * LOCKING: row locking if there there is a key	 *	 * @exception StandardException		Thrown on failure	 * @see TabInfo#deleteRow	 */	public int deleteRow( TransactionController tc, ExecIndexRow key, int indexNumber )		throws StandardException	{		// Always row locking		return  deleteRows(tc,						   key,						   ScanController.GE,						   null,						   null,						   key,						   ScanController.GT,						   indexNumber);	}	/**	 * LOCKING: row locking if there is both a start and	 * stop key; otherwise table locking	 *	 * @exception StandardException		Thrown on failure	 * @see TabInfo#deleteRows	 */	public int deleteRows(TransactionController tc,						  ExecIndexRow startKey,						  int startOp,						  Qualifier[][] qualifier,						  TupleFilter filter,						  ExecIndexRow stopKey,						  int stopOp,						  int indexNumber)		 throws StandardException	{		ConglomerateController		heapCC;		ScanController				drivingScan;		ExecIndexRow	 			drivingIndexRow;		RowLocation					baseRowLocation;		RowChanger 					rc;		ExecRow						baseRow = crf.makeEmptyRow();		int                         rowsDeleted = 0;		boolean						passedFilter = true;		rc = getRowChanger( tc, (int[])null,baseRow );		/*		** If we have a start and a stop key, then we are going to 		** get row locks, otherwise, we are getting table locks.		** This may be excessive locking for the case where there		** is a start key and no stop key or vice versa.		*/		int lockMode = ((startKey != null) && (stopKey != null)) ? 				tc.MODE_RECORD : 				tc.MODE_TABLE;		/*		** Don't use level 3 if we have the same start/stop key.		*/		int isolation =             ((startKey != null) && (stopKey != null) && (startKey == stopKey)) ?				TransactionController.ISOLATION_REPEATABLE_READ :				TransactionController.ISOLATION_SERIALIZABLE;		// Row level locking		rc.open(lockMode);		DataValueDescriptor[] startKeyRow =             startKey == null ? null : startKey.getRowArray();		DataValueDescriptor[] stopKeyRow =             stopKey == null  ? null : stopKey.getRowArray();		/* Open the heap conglomerate */		heapCC = tc.openConglomerate(                    getHeapConglomerate(),                    false,                    TransactionController.OPENMODE_FORUPDATE,                    lockMode,                    TransactionController.ISOLATION_REPEATABLE_READ);		drivingScan = tc.openScan(			getIndexConglomerate(indexNumber),  // conglomerate to open			false, // don't hold open across commit            TransactionController.OPENMODE_FORUPDATE, // for update            lockMode,			isolation,			(FormatableBitSet) null, // all fields as objects			startKeyRow,   // start position - first row            startOp,      // startSearchOperation			qualifier, //scanQualifier			stopKeyRow,   // stop position - through last row            stopOp);     // stopSearchOperation		// Get an index row based on the base row		drivingIndexRow = getIndexRowFromHeapRow(			getIndexRowGenerator( indexNumber ),			heapCC.newRowLocationTemplate(),			crf.makeEmptyRow());		while (drivingScan.next())		{			drivingScan.fetch(drivingIndexRow.getRowArray());			baseRowLocation = (RowLocation)						drivingIndexRow.getColumn(drivingIndexRow.nColumns());			boolean base_row_exists =                 heapCC.fetch(                    baseRowLocation, baseRow.getRowArray(), (FormatableBitSet) null);            if (SanityManager.DEBUG)            {                // it can not be possible for heap row to disappear while                 // holding scan cursor on index at ISOLATION_REPEATABLE_READ.                SanityManager.ASSERT(base_row_exists, "base row not found");            }			// only delete rows which pass the base-row filter			if ( filter != null ) { passedFilter = filter.execute( baseRow ).equals( true ); }			if ( passedFilter )			{				rc.deleteRow( baseRow, baseRowLocation );				rowsDeleted++;			}		}		heapCC.close();		drivingScan.close();		rc.close();		return rowsDeleted;	}	/**	  * @exception StandardException		Thrown on failure	  * @see TabInfo#getRow	  */	public ExecRow getRow( TransactionController tc,						ExecIndexRow key,						int indexNumber )		throws StandardException	{		ConglomerateController		heapCC;		/* Open the heap conglomerate */		heapCC = tc.openConglomerate(                    getHeapConglomerate(),                    false,                    0, 						// for read only                    TransactionController.MODE_RECORD,                    TransactionController.ISOLATION_REPEATABLE_READ);		try { return getRow( tc, heapCC, key, indexNumber ); }		finally { heapCC.close(); }	}	/**	 * Given an index row and index number return the RowLocation	 * in the heap of the first matching row.	 * Used by the autoincrement code to get the RowLocation in	 * syscolumns given a <tablename, columname> pair.	 * 	 * @see DataDictionaryImpl#computeRowLocation(TransactionController, TableDescriptor, String)	 *	 * @param tc		  Transaction Controller to use.	 * @param key		  Index Row to search in the index.	 * @param indexNumber Identifies the index to use.	 *	 * @exception		  StandardException thrown on failure.	 */	public RowLocation getRowLocation(TransactionController tc,									  ExecIndexRow key,									  int indexNumber)			  throws StandardException	{		ConglomerateController		heapCC;		heapCC = tc.openConglomerate(                    getHeapConglomerate(),                    false,                    0, 						// for read only                    TransactionController.MODE_RECORD,                    TransactionController.ISOLATION_REPEATABLE_READ);		try 		{			RowLocation rl[] = new RowLocation[1];			ExecRow notUsed = getRowInternal(tc, heapCC, key, indexNumber, rl);			return rl[0];		}		finally		{			heapCC.close();		}	}	/**	  * @exception StandardException		Thrown on failure	  * @see TabInfo#getRow	  */	public ExecRow getRow( TransactionController tc,						   ConglomerateController heapCC,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -