Esempio n. 1
0
/*
Unlock will unlock this KeyLock and make its Id (and the value it is based on) available for other locks.
*/
func (self *KeyLock) Unlock(c GAEContext) (err error) {
	snapshot := *self
	return c.Transaction(func(c GAEContext) (err error) {
		*self = snapshot
		existingLock := &KeyLock{Id: self.Id}
		if err = gae.GetById(c, existingLock); err != nil {
			return
		}
		if existingLock.Entity != self.Entity {
			err = errors.Errorf("%+v doesn't own %v", self, self.Entity)
			return
		}
		err = gae.Del(c, existingLock)
		return
	}, false)
}
Esempio n. 2
0
func testGet(c gaecontext.HTTPContext) {
	gae.DelAll(c, &Ts{})
	k, err := key.For(&Ts{}, "", 0, "")
	if err != nil {
		panic(err)
	}
	t := &Ts{
		Id:   k,
		Name: "the t",
		Age:  12,
	}
	if err := gae.Put(c, t); err != nil {
		panic(err)
	}
	wantedProcesses := []string{"BeforeCreate", "BeforeSave", "AfterCreate", "AfterSave"}
	if !reflect.DeepEqual(t.Processes, wantedProcesses) {
		panic("wrong processes!")
	}
	if t.Id.IntID() == 0 {
		panic("shouldn't be zero")
	}
	t2 := &Ts{Id: t.Id}
	if err := gae.GetById(c, t2); err != nil {
		panic(err)
	}
	if !t.Equal(t2) {
		panic("1 should be equal")
	}
	wantedProcesses = []string{"BeforeCreate", "BeforeSave", "AfterLoad"}
	if !reflect.DeepEqual(t2.Processes, wantedProcesses) {
		panic(fmt.Sprintf("wrong processes! wanted %+v but got %+v", wantedProcesses, t2.Processes))
	}
	t2.Age = 13
	if err := gae.Put(c, t2); err != nil {
		panic(err)
	}
	wantedProcesses = append(wantedProcesses, "BeforeUpdate", "BeforeSave", "AfterUpdate", "AfterSave")
	if !reflect.DeepEqual(t2.Processes, wantedProcesses) {
		panic("wrong processes!")
	}
	if err := gae.Del(c, t2); err != nil {
		panic(err)
	}
	if !reflect.DeepEqual(t2.Processes, wantedProcesses) {
		panic(fmt.Errorf("got %+v, wanted %+v", t2.Processes, wantedProcesses))
	}
}