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 "github.com/luci/gae" | |
9 rds "github.com/luci/gae/service/rawdatastore" | 8 rds "github.com/luci/gae/service/rawdatastore" |
| 9 "github.com/luci/luci-go/common/errors" |
10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
11 "google.golang.org/appengine/datastore" | 11 "google.golang.org/appengine/datastore" |
12 ) | 12 ) |
13 | 13 |
14 // useRDS adds a gae.RawDatastore implementation to context, accessible | 14 // useRDS adds a gae.RawDatastore implementation to context, accessible |
15 // by gae.GetDS(c) | 15 // by gae.GetDS(c) |
16 func useRDS(c context.Context) context.Context { | 16 func useRDS(c context.Context) context.Context { |
17 return rds.SetFactory(c, func(ci context.Context) rds.Interface { | 17 return rds.SetFactory(c, func(ci context.Context) rds.Interface { |
18 return rdsImpl{ci} | 18 return rdsImpl{ci} |
19 }) | 19 }) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 func (d rdsImpl) Delete(k rds.Key) error { return datastore.Delete(d, dsF2R(k))
} | 95 func (d rdsImpl) Delete(k rds.Key) error { return datastore.Delete(d, dsF2R(k))
} |
96 func (d rdsImpl) Get(key rds.Key, dst rds.PropertyLoadSaver) error { | 96 func (d rdsImpl) Get(key rds.Key, dst rds.PropertyLoadSaver) error { |
97 return datastore.Get(d, dsF2R(key), &typeFilter{dst}) | 97 return datastore.Get(d, dsF2R(key), &typeFilter{dst}) |
98 } | 98 } |
99 func (d rdsImpl) Put(key rds.Key, src rds.PropertyLoadSaver) (rds.Key, error) { | 99 func (d rdsImpl) Put(key rds.Key, src rds.PropertyLoadSaver) (rds.Key, error) { |
100 return dsR2FErr(datastore.Put(d, dsF2R(key), &typeFilter{src})) | 100 return dsR2FErr(datastore.Put(d, dsF2R(key), &typeFilter{src})) |
101 } | 101 } |
102 | 102 |
103 func (d rdsImpl) DeleteMulti(ks []rds.Key) error { | 103 func (d rdsImpl) DeleteMulti(ks []rds.Key) error { |
104 » return gae.FixError(datastore.DeleteMulti(d, dsMF2R(ks))) | 104 » return errors.Fix(datastore.DeleteMulti(d, dsMF2R(ks))) |
105 } | 105 } |
106 | 106 |
107 func (d rdsImpl) GetMulti(ks []rds.Key, plss []rds.PropertyLoadSaver) error { | 107 func (d rdsImpl) GetMulti(ks []rds.Key, plss []rds.PropertyLoadSaver) error { |
108 » return gae.FixError(datastore.GetMulti(d, dsMF2R(ks), multiWrap(plss))) | 108 » return errors.Fix(datastore.GetMulti(d, dsMF2R(ks), multiWrap(plss))) |
109 } | 109 } |
110 func (d rdsImpl) PutMulti(key []rds.Key, plss []rds.PropertyLoadSaver) ([]rds.Ke
y, error) { | 110 func (d rdsImpl) PutMulti(key []rds.Key, plss []rds.PropertyLoadSaver) ([]rds.Ke
y, error) { |
111 ks, err := datastore.PutMulti(d, dsMF2R(key), multiWrap(plss)) | 111 ks, err := datastore.PutMulti(d, dsMF2R(key), multiWrap(plss)) |
112 » return dsMR2F(ks), gae.FixError(err) | 112 » return dsMR2F(ks), errors.Fix(err) |
113 } | 113 } |
114 | 114 |
115 // DSQueryer | 115 // DSQueryer |
116 func (d rdsImpl) NewQuery(kind string) rds.Query { | 116 func (d rdsImpl) NewQuery(kind string) rds.Query { |
117 return queryImpl{datastore.NewQuery(kind)} | 117 return queryImpl{datastore.NewQuery(kind)} |
118 } | 118 } |
119 func (d rdsImpl) Run(q rds.Query) rds.Iterator { | 119 func (d rdsImpl) Run(q rds.Query) rds.Iterator { |
120 return iteratorImpl{q.(queryImpl).Query.Run(d)} | 120 return iteratorImpl{q.(queryImpl).Query.Run(d)} |
121 } | 121 } |
122 func (d rdsImpl) Count(q rds.Query) (int, error) { | 122 func (d rdsImpl) Count(q rds.Query) (int, error) { |
(...skipping 13 matching lines...) Expand all Loading... |
136 } | 136 } |
137 } | 137 } |
138 return dsMR2F(ks), err | 138 return dsMR2F(ks), err |
139 } | 139 } |
140 | 140 |
141 // Transactioner | 141 // Transactioner |
142 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *rds.Tra
nsactionOptions) error { | 142 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *rds.Tra
nsactionOptions) error { |
143 ropts := (*datastore.TransactionOptions)(opts) | 143 ropts := (*datastore.TransactionOptions)(opts) |
144 return datastore.RunInTransaction(d, f, ropts) | 144 return datastore.RunInTransaction(d, f, ropts) |
145 } | 145 } |
OLD | NEW |