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

Unified Diff: service/datastore/transaction.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: WithoutTransaction, comments, fixes, cleanup. Created 4 years, 3 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: service/datastore/transaction.go
diff --git a/service/datastore/transaction.go b/service/datastore/transaction.go
new file mode 100644
index 0000000000000000000000000000000000000000..2e00be6faca0c3d96def28545c9eea1d23ca62f7
--- /dev/null
+++ b/service/datastore/transaction.go
@@ -0,0 +1,33 @@
+// Copyright 2015 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package datastore
+
+import (
+ "golang.org/x/net/context"
+)
+
+// Transaction is a generic interface used to describe a Datastore transaction.
+//
+// The nil Transaction represents no transaction context.
+//
+// TODO: Add some functionality here. Ideas include:
+// - Active() bool: is the transaction currently active?
+// - AffectedGroups() []*ds.Key: list the groups that have been referenced in
+// this Transaction so far.
+type Transaction interface{}
+
+// WithoutTransaction returns a Context that isn't bound to a transaction.
+//
+// This can be useful to perform non-transactional tasks given only a Context
+// that is bound to a transaction.
+func WithoutTransaction(c context.Context) context.Context {
+ return Raw(c).WithoutTransaction()
+}
+
+// CurrentTransaction returns a reference to the current Transaction, or nil
+// if the Context does not have a current Transaction.
+func CurrentTransaction(c context.Context) Transaction {
+ return Raw(c).CurrentTransaction()
+}

Powered by Google App Engine
This is Rietveld 408576698