Adds the specified tuple to the page; the tuple should be updated to reflect that it is now stored on this page. @throws DbException if the page is full (no empty slots) or tupledesc is mismatch. @param t The tuple to add.
(Tuple t)
| 290 | * @param t The tuple to add. |
| 291 | */ |
| 292 | public void insertTuple(Tuple t) throws DbException { |
| 293 | // some code goes here |
| 294 | // not necessary for lab1 |
| 295 | if(getNumEmptySlots()==0){ |
| 296 | throw new DbException("slots if empty"); |
| 297 | } |
| 298 | //判断元数据是否正常 |
| 299 | if(!t.getTupleDesc().equals(this.td)){ |
| 300 | throw new DbException("insert tuple err"); |
| 301 | } |
| 302 | for(int i=0;i<numSlots;i++){ |
| 303 | if(tuples[i]!=null){ |
| 304 | continue; |
| 305 | } |
| 306 | if(!isSlotUsed(i)){ |
| 307 | tuples[i] =t; |
| 308 | tuples[i].setRecordId(new RecordId(pid,i)); |
| 309 | markSlotUsed(i,true); |
| 310 | return; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Marks this page as dirty/not dirty and record that transaction |