1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from appengine_wrappers
import db
6 from datastore_models
import PersistentObjectStoreItem
7 from environment
import IsDevServer
8 from future
import Future
9 from object_store
import ObjectStore
12 class PersistentObjectStore(ObjectStore
):
13 '''Stores data persistently using the AppEngine Datastore API.
15 def __init__(self
, namespace
):
16 self
._namespace
= namespace
18 def SetMulti(self
, mapping
):
20 for key
, value
in mapping
.items():
21 futures
.append(db
.put_async(
22 PersistentObjectStoreItem
.CreateItem(self
._namespace
, key
, value
)))
23 # If running the dev server, the futures don't complete until the server is
24 # *quitting*. This is annoying. Flush now.
26 [future
.wait() for future
in futures
]
28 def GetMulti(self
, keys
):
31 PersistentObjectStoreItem
.CreateKey(self
._namespace
, k
)))
34 return dict((key
, future
.get_result().GetValue())
35 for key
, future
in db_futures
.iteritems()
36 if future
.get_result() is not None)
37 return Future(callback
=resolve
)
39 def DelMulti(self
, keys
):
42 futures
.append(db
.delete_async(
43 PersistentObjectStoreItem
.CreateKey(self
._namespace
, key
)))
44 # If running the dev server, the futures don't complete until the server is
45 # *quitting*. This is annoying. Flush now.
47 [future
.wait() for future
in futures
]