HashIndex.java
/**
   * Inserts a new data entry into the index file.
   * 
   * @throws IllegalArgumentException if the entry is too large
   */
Inserts a new data entry into the index file.

@throws IllegalArgumentException if the entry is too large
Inserts a new data entry into the index file . @throws IllegalArgumentException if the entry is too large
public void insertEntry(SearchKey key, RID rid) {
	  if (key.getLength() > HashBucketPage.MAX_ENTRY_SIZE)
	  {
		  throw new IllegalArgumentException("Attempted to insert an entry that is too large!");
	  }	  
	  Page directoryPage = new Page();
	  boolean directoryDirty = false;	  
	  Minibase.BufferManager.pinPage(headId, directoryPage, PIN_DISKIO);
	  int hashIndex = key.getHash(DEPTH);
	  PageId primaryBucketId = new PageId(directoryPage.getIntValue(hashIndex * INT_SIZE));
	  HashBucketPage primaryBucketPage = new HashBucketPage();
	  if (INVALID_PAGEID == primaryBucketId.pid)
	  { 
		  primaryBucketId = Minibase.DiskManager.allocate_page();
		  Minibase.BufferManager.pinPage(primaryBucketId, primaryBucketPage, PIN_MEMCPY);
		  directoryPage.setIntValue(primaryBucketId.pid, hashIndex * INT_SIZE);
		  directoryDirty = true;
	  }
	  else
	  { 
		  Minibase.BufferManager.pinPage(primaryBucketId, primaryBucketPage, PIN_DISKIO);  
	  }
	  DataEntry entry = new DataEntry(key, rid);
	  if (primaryBucketPage.insertEntry(entry))
	  {
		  Minibase.BufferManager.unpinPage(primaryBucketId, UNPIN_DIRTY);
	  }
	  else
	  {
		  Minibase.BufferManager.unpinPage(primaryBucketId, UNPIN_CLEAN);
	  }
	  if (directoryDirty)
	  {
		  Minibase.BufferManager.unpinPage(headId, UNPIN_DIRTY);
	  }
	  else
	  {
		  Minibase.BufferManager.unpinPage(headId, UNPIN_CLEAN);
	  }
  }
public void insertEntry ( SearchKey key , RID rid ) { if ( key . getLength ( ) > HashBucketPage . MAX_ENTRY_SIZE ) { throw new IllegalArgumentException ( "Attempted to insert an entry that is too large!" ) ; } Page directoryPage = new Page ( ) ; boolean directoryDirty = false ; Minibase . BufferManager . pinPage ( headId , directoryPage , PIN_DISKIO ) ; int hashIndex = key . getHash ( DEPTH ) ; PageId primaryBucketId = new PageId ( directoryPage . getIntValue ( hashIndex * INT_SIZE ) ) ; HashBucketPage primaryBucketPage = new HashBucketPage ( ) ; if ( INVALID_PAGEID == primaryBucketId . pid ) { primaryBucketId = Minibase . DiskManager . allocate_page ( ) ; Minibase . BufferManager . pinPage ( primaryBucketId , primaryBucketPage , PIN_MEMCPY ) ; directoryPage . setIntValue ( primaryBucketId . pid , hashIndex * INT_SIZE ) ; directoryDirty = true ; } else { Minibase . BufferManager . pinPage ( primaryBucketId , primaryBucketPage , PIN_DISKIO ) ; } DataEntry entry = new DataEntry ( key , rid ) ; if ( primaryBucketPage . insertEntry ( entry ) ) { Minibase . BufferManager . unpinPage ( primaryBucketId , UNPIN_DIRTY ) ; } else { Minibase . BufferManager . unpinPage ( primaryBucketId , UNPIN_CLEAN ) ; } if ( directoryDirty ) { Minibase . BufferManager . unpinPage ( headId , UNPIN_DIRTY ) ; } else { Minibase . BufferManager . unpinPage ( headId , UNPIN_CLEAN ) ; } }
Inserts a new data entry into the index file.
Inserts a new data entry into the index file .
// Load the directory page // Find what primary bucket this needs to go in // Get the page Id of the primary bucket page at that index // No primary bucket page for that index  // so create one // And reference it in the directory // We have a primary bucket, so load it // Build the entry object // Insert the entry in our hash bucket and unpin clean/dirty as appropriate // Unpin the directory page, dirty/clean as appropriate