| OLD | NEW | 
|    1 // Copyright 2015 The Chromium Authors. All rights reserved. |    1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 package prod |    5 package prod | 
|    6  |    6  | 
|    7 import ( |    7 import ( | 
|    8         ds "github.com/luci/gae/service/datastore" |    8         ds "github.com/luci/gae/service/datastore" | 
 |    9         "github.com/luci/gae/service/info" | 
|    9         "golang.org/x/net/context" |   10         "golang.org/x/net/context" | 
|   10         "google.golang.org/appengine" |   11         "google.golang.org/appengine" | 
|   11         "google.golang.org/appengine/datastore" |   12         "google.golang.org/appengine/datastore" | 
|   12 ) |   13 ) | 
|   13  |   14  | 
|   14 // useRDS adds a gae.RawDatastore implementation to context, accessible |   15 // useRDS adds a gae.RawDatastore implementation to context, accessible | 
|   15 // by gae.GetDS(c) |   16 // by gae.GetDS(c) | 
|   16 func useRDS(c context.Context) context.Context { |   17 func useRDS(c context.Context) context.Context { | 
|   17 »       return ds.SetFactory(c, func(ci context.Context) ds.Interface { |   18 »       return ds.SetRawFactory(c, func(ci context.Context) ds.RawInterface { | 
|   18 »       »       // TODO(riannucci): Track namespace in a better way |   19 »       »       return rdsImpl{ci, info.Get(ci).GetNamespace()} | 
|   19 »       »       k := datastore.NewKey(ci, "kind", "", 1, nil) // get current nam
     espace. |  | 
|   20 »       »       return rdsImpl{ci, k.Namespace()} |  | 
|   21         }) |   20         }) | 
|   22 } |   21 } | 
|   23  |   22  | 
|   24 ////////// Query |   23 ////////// Query | 
|   25  |   24  | 
|   26 type queryImpl struct{ *datastore.Query } |   25 type queryImpl struct{ *datastore.Query } | 
|   27  |   26  | 
|   28 func (q queryImpl) Distinct() ds.Query { |   27 func (q queryImpl) Distinct() ds.Query { | 
|   29         return queryImpl{q.Query.Distinct()} |   28         return queryImpl{q.Query.Distinct()} | 
|   30 } |   29 } | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  105         vals := make([]datastore.PropertyLoadSaver, len(keys)) |  104         vals := make([]datastore.PropertyLoadSaver, len(keys)) | 
|  106         for i := range keys { |  105         for i := range keys { | 
|  107                 vals[i] = &typeFilter{ds.PropertyMap{}} |  106                 vals[i] = &typeFilter{ds.PropertyMap{}} | 
|  108         } |  107         } | 
|  109         err := datastore.GetMulti(d, rkeys, vals) |  108         err := datastore.GetMulti(d, rkeys, vals) | 
|  110         return idxCallbacker(err, len(keys), func(idx int, err error) { |  109         return idxCallbacker(err, len(keys), func(idx int, err error) { | 
|  111                 cb(vals[idx].(*typeFilter).pm, err) |  110                 cb(vals[idx].(*typeFilter).pm, err) | 
|  112         }) |  111         }) | 
|  113 } |  112 } | 
|  114  |  113  | 
|  115 func (d rdsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyLoadSaver, cb ds.PutM
     ultiCB) error { |  114 func (d rdsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiCB
     ) error { | 
|  116         rkeys := dsMF2R(keys) |  115         rkeys := dsMF2R(keys) | 
|  117         rvals := make([]datastore.PropertyLoadSaver, len(vals)) |  116         rvals := make([]datastore.PropertyLoadSaver, len(vals)) | 
|  118         for i, val := range vals { |  117         for i, val := range vals { | 
|  119 »       »       rvals[i] = &typeFilter{val.(ds.PropertyMap)} |  118 »       »       rvals[i] = &typeFilter{val} | 
|  120         } |  119         } | 
|  121         rkeys, err := datastore.PutMulti(d, rkeys, vals) |  120         rkeys, err := datastore.PutMulti(d, rkeys, vals) | 
|  122         return idxCallbacker(err, len(keys), func(idx int, err error) { |  121         return idxCallbacker(err, len(keys), func(idx int, err error) { | 
|  123                 k := ds.Key(nil) |  122                 k := ds.Key(nil) | 
|  124                 if err == nil { |  123                 if err == nil { | 
|  125                         k = dsR2F(rkeys[idx]) |  124                         k = dsR2F(rkeys[idx]) | 
|  126                 } |  125                 } | 
|  127                 cb(k, err) |  126                 cb(k, err) | 
|  128         }) |  127         }) | 
|  129 } |  128 } | 
|  130  |  129  | 
|  131 func (d rdsImpl) NewQuery(kind string) ds.Query { |  130 func (d rdsImpl) NewQuery(kind string) ds.Query { | 
|  132         return queryImpl{datastore.NewQuery(kind)} |  131         return queryImpl{datastore.NewQuery(kind)} | 
|  133 } |  132 } | 
|  134  |  133  | 
|  135 func (d rdsImpl) Run(q ds.Query, cb ds.RunCB) error { |  134 func (d rdsImpl) Run(q ds.Query, cb ds.RawRunCB) error { | 
|  136         tf := typeFilter{} |  135         tf := typeFilter{} | 
|  137         t := q.(queryImpl).Query.Run(d) |  136         t := q.(queryImpl).Query.Run(d) | 
|  138         cfunc := func() (ds.Cursor, error) { |  137         cfunc := func() (ds.Cursor, error) { | 
|  139                 return t.Cursor() |  138                 return t.Cursor() | 
|  140         } |  139         } | 
|  141         for { |  140         for { | 
|  142                 k, err := t.Next(&tf) |  141                 k, err := t.Next(&tf) | 
|  143                 if err == datastore.Done { |  142                 if err == datastore.Done { | 
|  144                         return nil |  143                         return nil | 
|  145                 } |  144                 } | 
|  146                 if err != nil { |  145                 if err != nil { | 
|  147                         return err |  146                         return err | 
|  148                 } |  147                 } | 
|  149                 if !cb(dsR2F(k), tf.pm, cfunc) { |  148                 if !cb(dsR2F(k), tf.pm, cfunc) { | 
|  150                         return nil |  149                         return nil | 
|  151                 } |  150                 } | 
|  152         } |  151         } | 
|  153 } |  152 } | 
|  154  |  153  | 
|  155 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran
     sactionOptions) error { |  154 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran
     sactionOptions) error { | 
|  156         ropts := (*datastore.TransactionOptions)(opts) |  155         ropts := (*datastore.TransactionOptions)(opts) | 
|  157         return datastore.RunInTransaction(d, f, ropts) |  156         return datastore.RunInTransaction(d, f, ropts) | 
|  158 } |  157 } | 
| OLD | NEW |