package Cases; import java.io.*; import java.io.File; import neustore.base.DBIndex;//because we create a object of index.java import neustore.base.LRUBuffer;//because we create an object of it public class Test_SI_full { public static void main(String[] args)throws IOException { //all the pages will be stored under this file name String filename2="TESTFILE2"; File file= new File(filename2); if(file.delete()) { System.out.println("The old file with that name has been deleted"); } else { System.out.println("The file was not found"); } //'buf' is an object of XMLBuffer class. Passews 2 arguments 5=Buffer size and 120=page size in bytes XMLBuffer buf2= new XMLBuffer(5,120); //each record has a size of 40bytes, so maximum of 3 recs(if no space is allocated for page header) //Creating an object of StructureIndex class and passing the 'buf2'(buffer) , filename and boolean value 'true' (indicating a new file has to be created with the passed filename) //If we do not plan to create a new file for Structure index, then the Constructor of the StructureIndex class should send 'false' to its super class //creating an object of StructureIndex class to test its methods StructureIndex SI = new StructureIndex(buf2,filename2,1); //creating a record of StructureIndexrecord class DiskAddress ptr=new DiskAddress(4,0);//this means the content for this element starts from 0th byte in page with id '4' StructureIndexRecord record=new StructureIndexRecord(1,1,0,21,0,0,-1,0,ptr); //lets try to insert the above created record in the structure page DiskAddress ret= SI.insertEntry(record); if(ret!=null) { //we should get pageid=3 and recno=1 (STATE 4) System.out.println("The adress of the recently inserted record in structure page is : PageId="+ret.PageId+" and Recno:"+ret.RecordNumber); } else //assuming that 'null' is returned when something goes wrong { System.out.println("The Structure Index record has not been inserted"); } ptr=new DiskAddress(4,0);//this means the content for this element starts from 0th byte in page with id '4' record=new StructureIndexRecord(2,2,0,15,1,1,1,1,ptr); //lets try to insert the above created record in the structure page ret= SI.insertEntry(record); ptr=new DiskAddress(4,16);//this means the content for this element starts from 0th byte in page with id '4' record=new StructureIndexRecord(2,2,16,21,2,1,1,1,ptr); //all these are dummy values ret= SI.insertEntry(record); //this record may overflow as each record needs 40bytes and we may allocate some space for the page header //assuming that the third record has been stored on the overflow page, we will try to delete it, and page management can be done to deal with the empty page int exit= SI.deleteEntry(3); StructureIndexRecord rec= SI.getRecordById(3);//we deleted this record if(rec==null) { System.out.println("The delete works fine"); } // SI.close();//remove the comments if the file needs to be closed before exiting }//end of main() method }//end of Test_SI_full class