Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: go/src/infra/gae/libs/gae/helper/shell_key.go

Issue 1222903002: Refactor current GAE abstraction library to be free of the SDK* (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: fix clock usage Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: go/src/infra/gae/libs/gae/helper/shell_key.go
diff --git a/go/src/infra/gae/libs/gae/helper/shell_key.go b/go/src/infra/gae/libs/gae/helper/shell_key.go
new file mode 100644
index 0000000000000000000000000000000000000000..001e9bde8c8120f5d2d00c4e247e77ccc8ba9694
--- /dev/null
+++ b/go/src/infra/gae/libs/gae/helper/shell_key.go
@@ -0,0 +1,58 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package helper
+
+import (
+ "infra/gae/libs/gae"
+)
+
+type shellDSKey struct {
Vadim Sh. 2015/07/13 21:17:12 what does "shell" stand for?
iannucci 2015/07/13 22:39:52 it's.. not a very good name. I'll change it. Made
+ appID string
+ namespace string
+ toks []gae.DSKeyTok
+}
+
+var _ gae.DSKey = (*shellDSKey)(nil)
+
+// NewDSKeyToks creates a a reference implementation of gae.DSKey. It is the
+// DSKey implementation returned from the various DSPropertyMap serialization
+// routines, as well as the native key implementation for the in-memory
+// implementation of gae.
+func NewDSKeyToks(appID, ns string, toks []gae.DSKeyTok) gae.DSKey {
+ newToks := make([]gae.DSKeyTok, len(toks))
+ copy(newToks, toks)
Vadim Sh. 2015/07/13 21:17:12 nit: newToks := append(nil, toks...)? :) It's prob
iannucci 2015/07/13 22:39:52 I guess I'm just paranoid of re-using the slice be
+ return &shellDSKey{appID, ns, newToks}
+}
+
+// NewDSKey is a wrapper around NewDSKeyToks which has an interface similar
+// to NewKey in the SDK.
+func NewDSKey(appID, ns, kind, stringID string, intID int64, parent gae.DSKey) gae.DSKey {
+ _, _, toks := DSKeySplit(parent)
+ newToks := make([]gae.DSKeyTok, len(toks))
+ copy(newToks, toks)
+ newToks = append(newToks, gae.DSKeyTok{Kind: kind, StringID: stringID, IntID: intID})
+ return &shellDSKey{appID, ns, newToks}
+}
+
+func (k *shellDSKey) lastTok() (ret gae.DSKeyTok) {
+ if len(k.toks) > 0 {
+ ret = k.toks[len(k.toks)-1]
+ }
+ return
+}
+
+func (k *shellDSKey) AppID() string { return k.appID }
+func (k *shellDSKey) Namespace() string { return k.namespace }
+func (k *shellDSKey) Kind() string { return k.lastTok().Kind }
+func (k *shellDSKey) StringID() string { return k.lastTok().StringID }
+func (k *shellDSKey) IntID() int64 { return k.lastTok().IntID }
+func (k *shellDSKey) String() string { return DSKeyString(k) }
+
+func (k *shellDSKey) Parent() gae.DSKey {
+ if len(k.toks) <= 1 {
+ return nil
+ }
+ return NewDSKeyToks(k.appID, k.namespace, k.toks[:len(k.toks)-1])
+}

Powered by Google App Engine
This is Rietveld 408576698