Example #1
0
// useRDS adds a gae.RawDatastore implementation to context, accessible
// by gae.GetDS(c)
func useRDS(c context.Context) context.Context {
	return ds.SetRawFactory(c, func(ci context.Context, wantTxn bool) ds.RawInterface {
		ns := info.Get(ci).GetNamespace()
		maybeTxnCtx := AEContext(ci)

		if wantTxn {
			return rdsImpl{ci, maybeTxnCtx, ns}
		}
		aeCtx := AEContextNoTxn(ci)
		if maybeTxnCtx != aeCtx {
			ci = context.WithValue(ci, prodContextKey, aeCtx)
		}
		return rdsImpl{ci, aeCtx, ns}
	})
}
Example #2
0
// useRDS adds a gae.Datastore implementation to context, accessible
// by gae.GetDS(c)
func useRDS(c context.Context) context.Context {
	return ds.SetRawFactory(c, func(ic context.Context, wantTxn bool) ds.RawInterface {
		ns := curGID(ic).namespace
		maybeTxnCtx := cur(ic)

		needResetCtx := false
		if !wantTxn {
			rootctx := curNoTxn(ic)
			if rootctx != maybeTxnCtx {
				needResetCtx = true
				maybeTxnCtx = rootctx
			}
		}

		dsd := maybeTxnCtx.Get(memContextDSIdx)
		if x, ok := dsd.(*dataStoreData); ok {
			if needResetCtx {
				ic = context.WithValue(ic, memContextKey, maybeTxnCtx)
			}
			return &dsImpl{x, ns, ic}
		}
		return &txnDsImpl{dsd.(*txnDataStoreData), ns}
	})
}