(TransactionId tid, Tuple t)
| 125 | |
| 126 | // see DbFile.java for javadocs |
| 127 | public List<Page> insertTuple(TransactionId tid, Tuple t) |
| 128 | throws DbException, IOException, TransactionAbortedException { |
| 129 | // some code goes here |
| 130 | if (!getFile().canRead() || !getFile().canWrite()) { |
| 131 | throw new IOException(); |
| 132 | } |
| 133 | List<Page> res = new ArrayList<>(); |
| 134 | for(int i=0;i<numPages();i++){ |
| 135 | HeapPageId heapPageId = new HeapPageId(getId(),i); |
| 136 | HeapPage heapPage = (HeapPage) Database.getBufferPool().getPage(tid,heapPageId,Permissions.READ_ONLY); |
| 137 | if(heapPage==null){ |
| 138 | Database.getBufferPool().unsafeReleasePage(tid,heapPageId); |
| 139 | continue; |
| 140 | } |
| 141 | if(heapPage.getNumEmptySlots()==0){ |
| 142 | Database.getBufferPool().unsafeReleasePage(tid,heapPageId); |
| 143 | continue; |
| 144 | } |
| 145 | heapPage.insertTuple(t); |
| 146 | heapPage.markDirty(true,tid); |
| 147 | res.add(heapPage); |
| 148 | return res; |
| 149 | } |
| 150 | //新建一个page |
| 151 | HeapPageId heapPageId = new HeapPageId(getId(), numPages()); |
| 152 | HeapPage heapPage = new HeapPage(heapPageId, HeapPage.createEmptyPageData()); |
| 153 | heapPage.insertTuple(t); |
| 154 | writePage(heapPage); |
| 155 | res.add(heapPage); |
| 156 | return res; |
| 157 | // not necessary for lab1 |
| 158 | } |
| 159 | |
| 160 | // see DbFile.java for javadocs |
| 161 | public ArrayList<Page> deleteTuple(TransactionId tid, Tuple t) throws DbException, |
nothing calls this directly
no test coverage detected