当前位置: 首页>>代码示例>>Golang>>正文


Golang Key.Parent方法代码示例

本文整理汇总了Golang中github.com/luci/gae/service/datastore.Key.Parent方法的典型用法代码示例。如果您正苦于以下问题:Golang Key.Parent方法的具体用法?Golang Key.Parent怎么用?Golang Key.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/luci/gae/service/datastore.Key的用法示例。


在下文中一共展示了Key.Parent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Valid

// Valid determines if a key is valid, according to a couple rules:
//   - k is not nil
//   - every token of k:
//     - (if !allowSpecial) token's kind doesn't start with '__'
//     - token's kind and appid are non-blank
//     - token is not incomplete
//   - all tokens have the same namespace and appid
func Valid(k ds.Key, allowSpecial bool, aid, ns string) bool {
	if k == nil {
		return false
	}
	if aid != k.AppID() || ns != k.Namespace() {
		return false
	}
	for ; k != nil; k = k.Parent() {
		if !allowSpecial && len(k.Kind()) >= 2 && k.Kind()[:2] == "__" {
			return false
		}
		if k.Kind() == "" || k.AppID() == "" {
			return false
		}
		if k.StringID() != "" && k.IntID() != 0 {
			return false
		}
		if k.Parent() != nil {
			if k.Parent().Incomplete() {
				return false
			}
			if k.Parent().AppID() != k.AppID() || k.Parent().Namespace() != k.Namespace() {
				return false
			}
		}
	}
	return true
}
开发者ID:martiniss,项目名称:gae,代码行数:35,代码来源:key.go

示例2: AllocateIDs

func (d rdsImpl) AllocateIDs(incomplete *ds.Key, n int) (start int64, err error) {
	par, err := dsF2R(d.aeCtx, incomplete.Parent())
	if err != nil {
		return
	}

	start, _, err = datastore.AllocateIDs(d.aeCtx, incomplete.Kind(), par, n)
	return
}
开发者ID:nishanths,项目名称:gae,代码行数:9,代码来源:raw_datastore.go

示例3: fixKeyLocked

func (d *dataStoreData) fixKeyLocked(ents *memCollection, key *ds.Key) (*ds.Key, error) {
	if key.Incomplete() {
		id, err := d.allocateIDsLocked(ents, key, 1)
		if err != nil {
			return key, err
		}
		key = ds.NewKey(key.AppID(), key.Namespace(), key.Kind(), "", id, key.Parent())
	}
	return key, nil
}
开发者ID:nishanths,项目名称:gae,代码行数:10,代码来源:datastore_data.go

示例4: Equal

// Equal returns true iff the two keys represent identical key values.
func Equal(a, b ds.Key) (ret bool) {
	ret = (a.Kind() == b.Kind() &&
		a.StringID() == b.StringID() &&
		a.IntID() == b.IntID() &&
		a.AppID() == b.AppID() &&
		a.Namespace() == b.Namespace())
	if !ret {
		return
	}
	ap, bp := a.Parent(), b.Parent()
	return (ap == nil && bp == nil) || Equal(ap, bp)
}
开发者ID:martiniss,项目名称:gae,代码行数:13,代码来源:key.go

示例5: allocateIDsLocked

func (d *dataStoreData) allocateIDsLocked(ents *memCollection, incomplete *ds.Key, n int) (int64, error) {
	if d.disableSpecialEntities {
		return 0, errors.New("disableSpecialEntities is true so allocateIDs is disabled")
	}

	idKey := []byte(nil)
	if incomplete.Parent() == nil {
		idKey = rootIDsKey(incomplete.Kind())
	} else {
		idKey = groupIDsKey(incomplete)
	}
	return incrementLocked(ents, idKey, n), nil
}
开发者ID:nishanths,项目名称:gae,代码行数:13,代码来源:datastore_data.go

示例6: marshalDSKey

func marshalDSKey(b *bytes.Buffer, k ds.Key) {
	if k.Parent() != nil {
		marshalDSKey(b, k.Parent())
	}
	b.WriteByte('/')
	b.WriteString(k.Kind())
	b.WriteByte(',')
	if k.StringID() != "" {
		b.WriteString(k.StringID())
	} else {
		b.WriteString(strconv.FormatInt(k.IntID(), 10))
	}
}
开发者ID:martiniss,项目名称:gae,代码行数:13,代码来源:key.go

示例7: PropertyMapPartially

// PropertyMapPartially turns a regular PropertyMap into a SerializedPmap.
// Essentially all the []Property's become SerializedPslice, using cmpbin and
// datastore/serialize's encodings.
func PropertyMapPartially(k *ds.Key, pm ds.PropertyMap) (ret SerializedPmap) {
	ret = make(SerializedPmap, len(pm)+2)
	if k != nil {
		ret["__key__"] = [][]byte{ToBytes(ds.MkProperty(k))}
		for k != nil {
			ret["__ancestor__"] = append(ret["__ancestor__"], ToBytes(ds.MkProperty(k)))
			k = k.Parent()
		}
	}
	for k, vals := range pm {
		newVals := PropertySlice(vals)
		if len(newVals) > 0 {
			ret[k] = newVals
		}
	}
	return
}
开发者ID:nishanths,项目名称:gae,代码行数:20,代码来源:serialize.go

示例8: partiallySerialize

func partiallySerialize(k ds.Key, pm ds.PropertyMap) (ret serializedIndexablePmap) {
	ret = make(serializedIndexablePmap, len(pm)+2)
	if k == nil {
		impossible(fmt.Errorf("key to partiallySerialize is nil"))
	}
	ret["__key__"] = [][]byte{serialize.ToBytes(ds.MkProperty(k))}
	for k != nil {
		ret["__ancestor__"] = append(ret["__ancestor__"], serialize.ToBytes(ds.MkProperty(k)))
		k = k.Parent()
	}
	for k, vals := range pm {
		newVals := serializeRow(vals)
		if len(newVals) > 0 {
			ret[k] = newVals
		}
	}
	return
}
开发者ID:martiniss,项目名称:gae,代码行数:18,代码来源:datastore_index.go

示例9: entsKeyLocked

func (d *dataStoreData) entsKeyLocked(key ds.Key) (*memCollection, ds.Key) {
	coll := "ents:" + key.Namespace()
	ents := d.head.GetCollection(coll)
	if ents == nil {
		ents = d.head.SetCollection(coll, nil)
	}

	if dskey.Incomplete(key) {
		idKey := []byte(nil)
		if key.Parent() == nil {
			idKey = rootIDsKey(key.Kind())
		} else {
			idKey = groupIDsKey(key)
		}
		id := incrementLocked(ents, idKey)
		key = dskey.New(key.AppID(), key.Namespace(), key.Kind(), "", id, key.Parent())
	}

	return ents, key
}
开发者ID:martiniss,项目名称:gae,代码行数:20,代码来源:datastore_data.go

示例10: Root

// Root returns the entity root for the given key.
func Root(k ds.Key) ds.Key {
	for k != nil && k.Parent() != nil {
		k = k.Parent()
	}
	return k
}
开发者ID:martiniss,项目名称:gae,代码行数:7,代码来源:key.go

示例11: PartialValid

// PartialValid returns true iff this key is suitable for use in a Put
// operation. This is the same as Valid(k, false, ...), but also allowing k to
// be Incomplete().
func PartialValid(k ds.Key, aid, ns string) bool {
	if k.Incomplete() {
		k = New(k.AppID(), k.Namespace(), k.Kind(), "", 1, k.Parent())
	}
	return Valid(k, false, aid, ns)
}
开发者ID:martiniss,项目名称:gae,代码行数:9,代码来源:key.go


注:本文中的github.com/luci/gae/service/datastore.Key.Parent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。