func Find(index core.Uint32Index, buffer dbio.DataBuffer, id uint32) (*core.Record, error) { rowID, err := index.Find(id) if err != nil { return nil, err } return core.NewRecordLoader(buffer).Load(id, rowID) }
func Update(index core.Uint32Index, buffer dbio.DataBuffer, record *core.Record) error { rowID, err := index.Find(record.ID) if err != nil { return err } allocator := core.NewRecordAllocator(buffer) if err = allocator.Update(rowID, record); err != nil { return err } return nil }
func Delete(index core.Uint32Index, buffer dbio.DataBuffer, id uint32) error { rowID, err := index.Find(id) if err != nil { return err } allocator := core.NewRecordAllocator(buffer) if err := allocator.Remove(rowID); err != nil { return err } return index.Delete(id) }
func assertIndexCanInsertAndFind(t *testing.T, index core.Uint32Index, key int, rowID core.RowID) (core.Uint32Key, core.RowID) { insertOnIndex(t, index, key, rowID) rowIDFound, err := index.Find(uint32(key)) if err != nil { t.Fatalf("Error when trying to find rowID with key=%+v: %s", key, err) } if rowIDFound == (core.RowID{}) { t.Errorf("Could not retrieve %d from index right after inserting it", key) } if rowIDFound != rowID { t.Errorf("Invalid value returned from the index: %+v", rowIDFound) } return core.Uint32Key(key), rowID }
func Insert(index core.Uint32Index, buffer dbio.DataBuffer, record *core.Record) error { cb := core.NewDataBlockRepository(buffer).ControlBlock() buffer.MarkAsDirty(cb.DataBlockID()) rowID, _ := index.Find(record.ID) if rowID != (core.RowID{}) { return fmt.Errorf("Key already exists: %d", record.ID) } allocator := core.NewRecordAllocator(buffer) rowID, err := allocator.Add(record) if err != nil { return err } return index.Insert(record.ID, rowID) }
func assertIndexCantFindByKey(t *testing.T, index core.Uint32Index, key int) { if _, err := index.Find(uint32(key)); err == nil { t.Error("Did not remove key from index") } }