int DirPage::deleteRecords(Where *where, int* attrType, int numOfAttr){ if(DEcount == 0){ lg2("@DirPage_"<<pageid<<" : No Records to delete."); return 0; } DataPage* datapage; long noOfRecs = 0; long dataPid; long maxTFS; DirEntry *de; // dirEntries; for(vector<DirEntry*>::size_type i = 0; i<dirEntries.size() ; i++){ //create DataPage for every entry and try retreiving records. de = dirEntries[i]; dataPid = de->getPageID(); datapage = new DataPage(dataPid); noOfRecs += datapage->deleteRecords(where,attrType,numOfAttr); maxTFS = datapage->getTotalFreeSize(); de->setTFS(maxTFS); if(maxSpaceAvailable < maxTFS) maxSpaceAvailable = maxTFS; de->writeDE(p,i); writeToPage(); delete datapage; } return noOfRecs; }
DataPage* DirPage::createDataPage(){ //create a datapage. //get tfs and store it in DE if(DEcount == MAX_DE){ error("No Free space to insert DE"); return NULL; } DataPage *dp = new DataPage(); long pid = dp->getPageid(); long tfs = dp->getTotalFreeSize(); DirEntry *de = new DirEntry(pid,tfs); dirEntries.push_back(de); de->writeDE(p,DEcount); DEcount++; if(tfs>maxSpaceAvailable) maxSpaceAvailable = tfs; writeToPage(); return dp; }
long DirPage::updateRecords(Where *where, Modify *modify, RecordSet* rs){ if(DEcount == 0){ lg2("@DirPage_"<<pageid<<" : No Records to update."); return 0; } DataPage* datapage; long noOfRecs = 0; long dataPid; long maxTFS; DirEntry *de; // dirEntries; for(vector<DirEntry*>::size_type i = modify->getStartDirEntry(); i<dirEntries.size() ; i++){ //create DataPage for every entry and try retreiving records. de = dirEntries[i]; dataPid = de->getPageID(); datapage = new DataPage(dataPid); noOfRecs += datapage->updateRecords(where,modify,rs); maxTFS = datapage->getTotalFreeSize(); de->setTFS(maxTFS); if(maxSpaceAvailable < maxTFS) maxSpaceAvailable = maxTFS; de->writeDE(p,i); if(modify->isThereMore()){ writeToPage(); modify->setStartDirEntry(i); delete datapage; return noOfRecs; } delete datapage; } writeToPage(); return noOfRecs; }