| Index: service/rawdatastore/datastore_impl.go
|
| diff --git a/helper/datastore_impl.go b/service/rawdatastore/datastore_impl.go
|
| similarity index 84%
|
| rename from helper/datastore_impl.go
|
| rename to service/rawdatastore/datastore_impl.go
|
| index 0f7d4de7d6f5cd786d3e6ee6965c7e650293aa32..2c8980442c9733a7dbd6032421c81811e14c9c92 100644
|
| --- a/helper/datastore_impl.go
|
| +++ b/service/rawdatastore/datastore_impl.go
|
| @@ -4,7 +4,7 @@
|
|
|
| // HEAVILY adapted from github.com/golang/appengine/datastore
|
|
|
| -package helper
|
| +package rawdatastore
|
|
|
| import (
|
| "errors"
|
| @@ -17,26 +17,15 @@ import (
|
| "unicode"
|
|
|
| "github.com/luci/gae"
|
| + "github.com/luci/gae/service/blobstore"
|
| )
|
|
|
| // Entities with more than this many indexed properties will not be saved.
|
| const maxIndexedProperties = 20000
|
|
|
| -var (
|
| - typeOfDSKey = reflect.TypeOf((*gae.DSKey)(nil)).Elem()
|
| - typeOfDSPropertyConverter = reflect.TypeOf((*gae.DSPropertyConverter)(nil)).Elem()
|
| - typeOfGeoPoint = reflect.TypeOf(gae.DSGeoPoint{})
|
| - typeOfTime = reflect.TypeOf(time.Time{})
|
| - typeOfString = reflect.TypeOf("")
|
| - typeOfInt64 = reflect.TypeOf(int64(0))
|
| - typeOfBool = reflect.TypeOf(true)
|
| -
|
| - valueOfnilDSKey = reflect.Zero(typeOfDSKey)
|
| -)
|
| -
|
| type structTag struct {
|
| name string
|
| - idxSetting gae.IndexSetting
|
| + idxSetting IndexSetting
|
| isSlice bool
|
| substructCodec *structCodec
|
| convert bool
|
| @@ -57,7 +46,7 @@ type structPLS struct {
|
| c *structCodec
|
| }
|
|
|
| -var _ gae.DSPropertyLoadSaver = (*structPLS)(nil)
|
| +var _ PropertyLoadSaver = (*structPLS)(nil)
|
|
|
| // typeMismatchReason returns a string explaining why the property p could not
|
| // be stored in an entity field of type v.Type().
|
| @@ -66,7 +55,7 @@ func typeMismatchReason(val interface{}, v reflect.Value) string {
|
| return fmt.Sprintf("type mismatch: %s versus %v", entityType, v.Type())
|
| }
|
|
|
| -func (p *structPLS) Load(propMap gae.DSPropertyMap) error {
|
| +func (p *structPLS) Load(propMap PropertyMap) error {
|
| if err := p.Problem(); err != nil {
|
| return err
|
| }
|
| @@ -81,7 +70,7 @@ func (p *structPLS) Load(propMap gae.DSPropertyMap) error {
|
| if t == nil {
|
| t = p.o.Type()
|
| }
|
| - convFailures = append(convFailures, &gae.ErrDSFieldMismatch{
|
| + convFailures = append(convFailures, &ErrFieldMismatch{
|
| StructType: t,
|
| FieldName: name,
|
| Reason: reason,
|
| @@ -97,7 +86,7 @@ func (p *structPLS) Load(propMap gae.DSPropertyMap) error {
|
| return nil
|
| }
|
|
|
| -func loadInner(codec *structCodec, structValue reflect.Value, index int, name string, p gae.DSProperty, requireSlice bool) string {
|
| +func loadInner(codec *structCodec, structValue reflect.Value, index int, name string, p Property, requireSlice bool) string {
|
| var v reflect.Value
|
| // Traverse a struct's struct-typed fields.
|
| for {
|
| @@ -128,8 +117,8 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
|
|
| doConversion := func(v reflect.Value) (string, bool) {
|
| a := v.Addr()
|
| - if conv, ok := a.Interface().(gae.DSPropertyConverter); ok {
|
| - err := conv.FromDSProperty(p)
|
| + if conv, ok := a.Interface().(PropertyConverter); ok {
|
| + err := conv.FromProperty(p)
|
| if err != nil {
|
| return err.Error(), true
|
| }
|
| @@ -158,7 +147,7 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
| }
|
| } else {
|
| knd := v.Kind()
|
| - if v.Type().Implements(typeOfDSKey) {
|
| + if v.Type().Implements(typeOfKey) {
|
| knd = reflect.Interface
|
| }
|
| switch knd {
|
| @@ -179,7 +168,7 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
| v.SetBool(x)
|
| case reflect.String:
|
| switch x := pVal.(type) {
|
| - case gae.BSKey:
|
| + case blobstore.Key:
|
| v.SetString(string(x))
|
| case string:
|
| v.SetString(x)
|
| @@ -198,7 +187,7 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
| }
|
| v.SetFloat(x)
|
| case reflect.Interface:
|
| - x, ok := pVal.(gae.DSKey)
|
| + x, ok := pVal.(Key)
|
| if !ok && pVal != nil {
|
| return typeMismatchReason(pVal, v)
|
| }
|
| @@ -214,7 +203,7 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
| }
|
| v.Set(reflect.ValueOf(x))
|
| case typeOfGeoPoint:
|
| - x, ok := pVal.(gae.DSGeoPoint)
|
| + x, ok := pVal.(GeoPoint)
|
| if !ok && pVal != nil {
|
| return typeMismatchReason(pVal, v)
|
| }
|
| @@ -226,7 +215,7 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
| switch x := pVal.(type) {
|
| case []byte:
|
| v.SetBytes(x)
|
| - case gae.DSByteString:
|
| + case ByteString:
|
| v.SetBytes([]byte(x))
|
| default:
|
| panic(fmt.Errorf("helper: impossible: %s", typeMismatchReason(pVal, v)))
|
| @@ -241,13 +230,13 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
|
| return ""
|
| }
|
|
|
| -func (p *structPLS) Save(withMeta bool) (gae.DSPropertyMap, error) {
|
| +func (p *structPLS) Save(withMeta bool) (PropertyMap, error) {
|
| size := len(p.c.byName)
|
| if withMeta {
|
| size += len(p.c.byMeta)
|
| }
|
| - ret := make(gae.DSPropertyMap, size)
|
| - if _, err := p.save(ret, "", gae.ShouldIndex); err != nil {
|
| + ret := make(PropertyMap, size)
|
| + if _, err := p.save(ret, "", ShouldIndex); err != nil {
|
| return nil, err
|
| }
|
| if withMeta {
|
| @@ -256,22 +245,22 @@ func (p *structPLS) Save(withMeta bool) (gae.DSPropertyMap, error) {
|
| if err != nil {
|
| return nil, err // TODO(riannucci): should these be ignored?
|
| }
|
| - p := gae.DSProperty{}
|
| - if err = p.SetValue(val, gae.NoIndex); err != nil {
|
| + p := Property{}
|
| + if err = p.SetValue(val, NoIndex); err != nil {
|
| return nil, err
|
| }
|
| - ret["$"+k] = []gae.DSProperty{p}
|
| + ret["$"+k] = []Property{p}
|
| }
|
| }
|
| return ret, nil
|
| }
|
|
|
| -func (p *structPLS) save(propMap gae.DSPropertyMap, prefix string, is gae.IndexSetting) (idxCount int, err error) {
|
| +func (p *structPLS) save(propMap PropertyMap, prefix string, is IndexSetting) (idxCount int, err error) {
|
| if err = p.Problem(); err != nil {
|
| return
|
| }
|
|
|
| - saveProp := func(name string, si gae.IndexSetting, v reflect.Value, st *structTag) (err error) {
|
| + saveProp := func(name string, si IndexSetting, v reflect.Value, st *structTag) (err error) {
|
| if st.substructCodec != nil {
|
| count, err := (&structPLS{v, st.substructCodec}).save(propMap, name, si)
|
| if err == nil {
|
| @@ -283,9 +272,9 @@ func (p *structPLS) save(propMap gae.DSPropertyMap, prefix string, is gae.IndexS
|
| return err
|
| }
|
|
|
| - prop := gae.DSProperty{}
|
| + prop := Property{}
|
| if st.convert {
|
| - prop, err = v.Addr().Interface().(gae.DSPropertyConverter).ToDSProperty()
|
| + prop, err = v.Addr().Interface().(PropertyConverter).ToProperty()
|
| } else {
|
| err = prop.SetValue(v.Interface(), si)
|
| }
|
| @@ -293,7 +282,7 @@ func (p *structPLS) save(propMap gae.DSPropertyMap, prefix string, is gae.IndexS
|
| return err
|
| }
|
| propMap[name] = append(propMap[name], prop)
|
| - if prop.IndexSetting() == gae.ShouldIndex {
|
| + if prop.IndexSetting() == ShouldIndex {
|
| idxCount++
|
| if idxCount > maxIndexedProperties {
|
| return errors.New("gae: too many indexed properties")
|
| @@ -312,8 +301,8 @@ func (p *structPLS) save(propMap gae.DSPropertyMap, prefix string, is gae.IndexS
|
| }
|
| v := p.o.Field(i)
|
| is1 := is
|
| - if st.idxSetting == gae.NoIndex {
|
| - is1 = gae.NoIndex
|
| + if st.idxSetting == NoIndex {
|
| + is1 = NoIndex
|
| }
|
| if st.isSlice {
|
| for j := 0; j < v.Len(); j++ {
|
| @@ -336,7 +325,7 @@ func (p *structPLS) GetMeta(key string) (interface{}, error) {
|
| }
|
| idx, ok := p.c.byMeta[key]
|
| if !ok {
|
| - return nil, gae.ErrDSMetaFieldUnset
|
| + return nil, ErrMetaFieldUnset
|
| }
|
| st := p.c.byIndex[idx]
|
| val := st.metaVal
|
| @@ -355,7 +344,7 @@ func (p *structPLS) SetMeta(key string, val interface{}) (err error) {
|
| }
|
| idx, ok := p.c.byMeta[key]
|
| if !ok {
|
| - return gae.ErrDSMetaFieldUnset
|
| + return ErrMetaFieldUnset
|
| }
|
| if !p.c.byIndex[idx].canSet {
|
| return fmt.Errorf("gae/helper: cannot set meta %q: unexported field", key)
|
| @@ -475,7 +464,7 @@ func getStructCodecLocked(t reflect.Type) (c *structCodec) {
|
|
|
| substructType := reflect.Type(nil)
|
| ft := f.Type
|
| - if reflect.PtrTo(ft).Implements(typeOfDSPropertyConverter) {
|
| + if reflect.PtrTo(ft).Implements(typeOfPropertyConverter) {
|
| st.convert = true
|
| } else {
|
| switch f.Type.Kind() {
|
| @@ -484,7 +473,7 @@ func getStructCodecLocked(t reflect.Type) (c *structCodec) {
|
| substructType = ft
|
| }
|
| case reflect.Slice:
|
| - if reflect.PtrTo(ft.Elem()).Implements(typeOfDSPropertyConverter) {
|
| + if reflect.PtrTo(ft.Elem()).Implements(typeOfPropertyConverter) {
|
| st.convert = true
|
| } else if ft.Elem().Kind() == reflect.Struct {
|
| substructType = ft.Elem()
|
| @@ -492,7 +481,7 @@ func getStructCodecLocked(t reflect.Type) (c *structCodec) {
|
| st.isSlice = ft.Elem().Kind() != reflect.Uint8
|
| c.hasSlice = c.hasSlice || st.isSlice
|
| case reflect.Interface:
|
| - if ft != typeOfDSKey {
|
| + if ft != typeOfKey {
|
| c.problem = me("field %q has non-concrete interface type %s",
|
| f.Name, f.Type)
|
| return
|
| @@ -536,8 +525,8 @@ func getStructCodecLocked(t reflect.Type) (c *structCodec) {
|
| t = t.Elem()
|
| }
|
| v := reflect.New(t).Elem().Interface()
|
| - v, _ = gae.DSUpconvertUnderlyingType(v, t)
|
| - if _, err := gae.DSPropertyTypeOf(v, false); err != nil {
|
| + v, _ = UpconvertUnderlyingType(v, t)
|
| + if _, err := PropertyTypeOf(v, false); err != nil {
|
| c.problem = me("field %q has invalid type: %s", name, ft)
|
| return
|
| }
|
| @@ -551,7 +540,7 @@ func getStructCodecLocked(t reflect.Type) (c *structCodec) {
|
| }
|
| st.name = name
|
| if opts == "noindex" {
|
| - st.idxSetting = gae.NoIndex
|
| + st.idxSetting = NoIndex
|
| }
|
| }
|
| if c.problem == errRecursiveStruct {
|
|
|