Example #1
0
// LoadBPlusTree 通过BootUUID读取一课B+树, 并返回它.
func Load(bootUUID utils.UUID, dm dm.DataManager) (BPlusTree, error) {
	bootDataitem, ok, err := dm.Read(bootUUID)
	if err != nil {
		return nil, err
	}
	utils.Assert(ok == true)

	return &bPlusTree{
		bootUUID:     bootUUID,
		DM:           dm,
		bootDataitem: bootDataitem,
	}, nil
}
Example #2
0
func (e *executor) execute2(stat interface{}) ([]byte, error) {
	var err error
	tmpTransaction := false
	if e.xid == 0 { // 创建一个临时事务
		tmpTransaction = true
		e.xid, _ = e.tbm.Begin(new(statement.Begin))
	}
	defer func() {
		if tmpTransaction == true { // 结束这个临时事务
			if err != nil {
				e.tbm.Abort(e.xid)
			} else {
				_, err = e.tbm.Commit(e.xid)
				utils.Assert(err == nil)
			}
			e.xid = 0
		}
	}()

	var result []byte
	switch st := stat.(type) {
	case *statement.Show:
		result = e.tbm.Show(e.xid)
	case *statement.Create:
		result, err = e.tbm.Create(e.xid, st)
	case *statement.Read:
		result, err = e.tbm.Read(e.xid, st)
	case *statement.Insert:
		result, err = e.tbm.Insert(e.xid, st)
	case *statement.Delete:
		result, err = e.tbm.Delete(e.xid, st)
	case *statement.Update:
		result, err = e.tbm.Update(e.xid, st)
	}

	return result, err
}