public void insertRecord(String tableName, String record) { Iterator<Table> it = Tables.iterator(); TableList TL = null; Pages P = null; Table T = null; while (it.hasNext()) { T = it.next(); if (T.getTableName().equals(tableName)) { TL = T.getLastPage(); break; } } if (record.length() < TL.getAvailableSpace()) { P = MM.getPage(TL.getPageId(), tableName, 1); P.insertRec(record); T.updatePage(P); TL.setEndId(P.getEndId()); TL.setAvailableSpace(P.getAvailableSpace()); } else { P = new Pages(TL.getEndId() + 1, pageSize, TL.getPageId() + 1); P.insertRec(record); TL = new TableList(P.getStartId(), P.getEndId(), P.getPageId(), P.getAvailableSpace()); P = MM.getPage(TL.getPageId(), tableName, 1); T.insertPage(P); T.insertTableList(TL); } }
public void populateDBInfo() { Iterator<Table> it = Tables.iterator(); String fileName, line; Pages P; TableList TL = null; Table T; int recCount, pageCount; while (it.hasNext()) { // for all the tables T = it.next(); P = null; TL = null; fileName = pathForData + T.getTableName() + ".csv"; recCount = 0; pageCount = 0; try { BufferedReader br = new BufferedReader(new FileReader(fileName)); // create an empty page P = new Pages(recCount, pageSize, pageCount++); while ((line = br.readLine()) != null) { // process the line. if (P.checkSpace(line.length())) { P.insertRec(line); recCount += 1; } else { // save the current page TL = new TableList(P.getStartId(), P.getEndId(), P.getPageId(), P.getAvailableSpace()); T.insertPage(P); T.insertTableList(TL); /*System.out.println(T.noOfPages); for (String s : P.recordsInPage ){ System.out.println(s); }*/ T.noOfPages += 1; // start a new page to store records. P = new Pages(recCount, pageSize, pageCount++); if (P.checkSpace(line.length())) { P.insertRec(line); recCount += 1; } } } br.close(); } catch (FileNotFoundException e) { // Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // Auto-generated catch block e.printStackTrace(); } // saving the last page if (P.getAvailableSpace() < pageSize) { TL = new TableList(P.getStartId(), P.getEndId(), P.getPageId(), P.getAvailableSpace()); T.insertPage(P); T.insertTableList(TL); /*System.out.println(T.noOfPages); for (String s : P.recordsInPage ){ System.out.println(s); }*/ T.noOfPages += 1; } } }