throws HeapException {
// ASSERTX
assert notInternalyManagedPage(pageRecordable);
long pageNumber = header.getPageNumberOfFirstFreePage();
final long previousRecordPositionInFile;
final PageRecord freePageRecord;
if (pageNumber == -1) {
freePageRecord = null;
pageNumber = header.getFileSizeAsNumberOfPage();
previousRecordPositionInFile = header.getLastRecordPositionInFile();
} else {
freePageRecord = (PageRecord) heapElementManager
.readHeapFileDataRecord(pageNumber << PageConstant.PAGE_BITS);
// ASSERTX
assert freePageRecord.getNumberOfPage() == 1
&& pageRecordable.getNumberOfPage() == 1;
final FreePage freePage = (FreePage) freePageRecord
.getPageRecordable();
header.setPageNumberOfFirstFreePage(freePage.getNextFreePage());
previousRecordPositionInFile = -1L;// do not care value // freePage
// .getPreviousRecordPositionInFile();
header.decrementNumberOfFreeRecord();
}
if (freePageRecord == null) {
// the new page record for page recordable
final IPageRecord pageRecord = new PageRecord(heapElementManager,
previousRecordPositionInFile, pageRecordable, pageNumber);
header.setFileSizeAsNumberOfPage(pageNumber
+ pageRecord.getNumberOfPage());
header.setLastRecordPositionInFile(pageNumber << PageConstant.PAGE_BITS);
pageRecordable.setPageRecord(pageRecord);
heapElementManager.appendHeapFileRecord(pageRecord);
} else {
freePageRecord.setPageRecordable(pageRecordable);