author | Sverre Rabbelier <srabbelier@gmail.com> |
Wed, 08 Apr 2009 22:19:05 +0000 | |
changeset 2127 | 1a0167169af3 |
parent 1278 | a7766286a7be |
child 2273 | e4cb9c53db3e |
permissions | -rwxr-xr-x |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2007 Google Inc. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
# |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
In-memory persistent stub for the Python datastore API. Gets, queries, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
and searches are implemented as in-memory scans over all entities. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
Stores entities across sessions as pickled proto bufs in a single file. On |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
startup, all entities are read from the file and loaded into memory. On |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
every Put(), the file is wiped and all entities are written from scratch. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
Clients can also manually Read() and Write() the file themselves. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
Transactions are serialized through __tx_lock. Each transaction acquires it |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
when it begins and releases it when it commits or rolls back. This is |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
important, since there are other member variables like __tx_snapshot that are |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
per-transaction, so they should only be used by one tx at a time. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
import datetime |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
39 |
import logging |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
import os |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
import struct |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
import sys |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
import tempfile |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
import threading |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
import warnings |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
46 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
47 |
import cPickle as pickle |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
48 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
from google.appengine.api import api_base_pb |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
50 |
from google.appengine.api import apiproxy_stub |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
from google.appengine.api import datastore |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
from google.appengine.api import datastore_admin |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
from google.appengine.api import datastore_errors |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
from google.appengine.api import datastore_types |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
from google.appengine.api import users |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
from google.appengine.datastore import datastore_pb |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
from google.appengine.datastore import datastore_index |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
from google.appengine.runtime import apiproxy_errors |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
from google.net.proto import ProtocolBuffer |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
from google.appengine.datastore import entity_pb |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
warnings.filterwarnings('ignore', 'tempnam is a potential security risk') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
entity_pb.Reference.__hash__ = lambda self: hash(self.Encode()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
datastore_pb.Query.__hash__ = lambda self: hash(self.Encode()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
69 |
_MAXIMUM_RESULTS = 1000 |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
70 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
71 |
|
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
72 |
_MAX_QUERY_OFFSET = 1000 |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
73 |
|
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
74 |
|
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
75 |
_MAX_QUERY_COMPONENTS = 100 |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
76 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
77 |
|
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
78 |
class _StoredEntity(object): |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
79 |
"""Simple wrapper around an entity stored by the stub. |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
80 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
81 |
Public properties: |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
82 |
protobuf: Native protobuf Python object, entity_pb.EntityProto. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
83 |
encoded_protobuf: Encoded binary representation of above protobuf. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
84 |
native: datastore.Entity instance. |
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
85 |
""" |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
86 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
87 |
def __init__(self, entity): |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
88 |
"""Create a _StoredEntity object and store an entity. |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
89 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
90 |
Args: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
91 |
entity: entity_pb.EntityProto to store. |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
92 |
""" |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
93 |
self.protobuf = entity |
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
94 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
95 |
self.encoded_protobuf = entity.Encode() |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
96 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
97 |
self.native = datastore.Entity._FromPb(entity) |
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
98 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
99 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
100 |
class DatastoreFileStub(apiproxy_stub.APIProxyStub): |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
101 |
""" Persistent stub for the Python datastore API. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
Stores all entities in memory, and persists them to a file as pickled |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
protocol buffers. A DatastoreFileStub instance handles a single app's data |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
105 |
and is backed by files on disk. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
|
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
108 |
_PROPERTY_TYPE_TAGS = { |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
109 |
datastore_types.Blob: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
110 |
bool: entity_pb.PropertyValue.kbooleanValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
111 |
datastore_types.Category: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
112 |
datetime.datetime: entity_pb.PropertyValue.kint64Value, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
113 |
datastore_types.Email: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
114 |
float: entity_pb.PropertyValue.kdoubleValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
115 |
datastore_types.GeoPt: entity_pb.PropertyValue.kPointValueGroup, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
116 |
datastore_types.IM: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
117 |
int: entity_pb.PropertyValue.kint64Value, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
118 |
datastore_types.Key: entity_pb.PropertyValue.kReferenceValueGroup, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
119 |
datastore_types.Link: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
120 |
long: entity_pb.PropertyValue.kint64Value, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
121 |
datastore_types.PhoneNumber: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
122 |
datastore_types.PostalAddress: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
123 |
datastore_types.Rating: entity_pb.PropertyValue.kint64Value, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
124 |
str: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
125 |
datastore_types.Text: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
126 |
type(None): 0, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
127 |
unicode: entity_pb.PropertyValue.kstringValue, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
128 |
users.User: entity_pb.PropertyValue.kUserValueGroup, |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
129 |
} |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
130 |
|
1278
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
131 |
WRITE_ONLY = entity_pb.CompositeIndex.WRITE_ONLY |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
132 |
READ_WRITE = entity_pb.CompositeIndex.READ_WRITE |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
133 |
DELETED = entity_pb.CompositeIndex.DELETED |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
134 |
ERROR = entity_pb.CompositeIndex.ERROR |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
135 |
|
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
136 |
_INDEX_STATE_TRANSITIONS = { |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
137 |
WRITE_ONLY: frozenset((READ_WRITE, DELETED, ERROR)), |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
138 |
READ_WRITE: frozenset((DELETED,)), |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
139 |
ERROR: frozenset((DELETED,)), |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
140 |
DELETED: frozenset((ERROR,)), |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
141 |
} |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
142 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
143 |
def __init__(self, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
144 |
app_id, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
145 |
datastore_file, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
146 |
history_file, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
147 |
require_indexes=False, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
148 |
service_name='datastore_v3'): |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
149 |
"""Constructor. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
150 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
151 |
Initializes and loads the datastore from the backing files, if they exist. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
152 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
153 |
Args: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
154 |
app_id: string |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
155 |
datastore_file: string, stores all entities across sessions. Use None |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
156 |
not to use a file. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
157 |
history_file: string, stores query history. Use None as with |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
158 |
datastore_file. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
159 |
require_indexes: bool, default False. If True, composite indexes must |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
exist in index.yaml for queries that need them. |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
161 |
service_name: Service name expected for all calls. |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
162 |
""" |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
163 |
super(DatastoreFileStub, self).__init__(service_name) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
164 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
|
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
166 |
assert isinstance(app_id, basestring) and app_id != '' |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
167 |
self.__app_id = app_id |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
168 |
self.__datastore_file = datastore_file |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
self.__history_file = history_file |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
170 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
171 |
self.__entities = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
172 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
173 |
self.__schema_cache = {} |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
174 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
175 |
self.__tx_snapshot = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
176 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
177 |
self.__queries = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
178 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
179 |
self.__transactions = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
180 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
self.__indexes = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
182 |
self.__require_indexes = require_indexes |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
183 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
184 |
self.__query_history = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
185 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
186 |
self.__next_id = 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
187 |
self.__next_cursor = 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
188 |
self.__next_tx_handle = 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
189 |
self.__next_index_id = 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
190 |
self.__id_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
191 |
self.__cursor_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
192 |
self.__tx_handle_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
193 |
self.__index_id_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
194 |
self.__tx_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
195 |
self.__entities_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
196 |
self.__file_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
197 |
self.__indexes_lock = threading.Lock() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
198 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
199 |
self.Read() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
200 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
201 |
def Clear(self): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
202 |
""" Clears the datastore by deleting all currently stored entities and |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
203 |
queries. """ |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
204 |
self.__entities = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
205 |
self.__queries = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
206 |
self.__transactions = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
207 |
self.__query_history = {} |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
208 |
self.__schema_cache = {} |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
209 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
210 |
def _AppKindForKey(self, key): |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
211 |
""" Get (app, kind) tuple from given key. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
212 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
213 |
The (app, kind) tuple is used as an index into several internal |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
214 |
dictionaries, e.g. __entities. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
215 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
216 |
Args: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
217 |
key: entity_pb.Reference |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
218 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
219 |
Returns: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
220 |
Tuple (app, kind), both are unicode strings. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
221 |
""" |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
222 |
last_path = key.path().element_list()[-1] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
223 |
return key.app(), last_path.type() |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
224 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
225 |
def _StoreEntity(self, entity): |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
226 |
""" Store the given entity. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
227 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
228 |
Args: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
229 |
entity: entity_pb.EntityProto |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
230 |
""" |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
231 |
key = entity.key() |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
232 |
app_kind = self._AppKindForKey(key) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
233 |
if app_kind not in self.__entities: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
234 |
self.__entities[app_kind] = {} |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
235 |
self.__entities[app_kind][key] = _StoredEntity(entity) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
236 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
237 |
if app_kind in self.__schema_cache: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
238 |
del self.__schema_cache[app_kind] |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
239 |
|
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
240 |
READ_PB_EXCEPTIONS = (ProtocolBuffer.ProtocolBufferDecodeError, LookupError, |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
241 |
TypeError, ValueError) |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
242 |
READ_ERROR_MSG = ('Data in %s is corrupt or a different version. ' |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
243 |
'Try running with the --clear_datastore flag.\n%r') |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
244 |
READ_PY250_MSG = ('Are you using FloatProperty and/or GeoPtProperty? ' |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
245 |
'Unfortunately loading float values from the datastore ' |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
246 |
'file does not work with Python 2.5.0. ' |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
247 |
'Please upgrade to a newer Python 2.5 release or use ' |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
248 |
'the --clear_datastore flag.\n') |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
249 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
250 |
def Read(self): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
251 |
""" Reads the datastore and history files into memory. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
252 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
253 |
The in-memory query history is cleared, but the datastore is *not* |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
254 |
cleared; the entities in the files are merged into the entities in memory. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
255 |
If you want them to overwrite the in-memory datastore, call Clear() before |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
256 |
calling Read(). |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
257 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
258 |
If the datastore file contains an entity with the same app name, kind, and |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
259 |
key as an entity already in the datastore, the entity from the file |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
260 |
overwrites the entity in the datastore. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
261 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
262 |
Also sets __next_id to one greater than the highest id allocated so far. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
263 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
264 |
if self.__datastore_file and self.__datastore_file != '/dev/null': |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
265 |
for encoded_entity in self.__ReadPickled(self.__datastore_file): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
266 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
267 |
entity = entity_pb.EntityProto(encoded_entity) |
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
268 |
except self.READ_PB_EXCEPTIONS, e: |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
269 |
raise datastore_errors.InternalError(self.READ_ERROR_MSG % |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
270 |
(self.__datastore_file, e)) |
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
271 |
except struct.error, e: |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
272 |
if (sys.version_info[0:3] == (2, 5, 0) |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
273 |
and e.message.startswith('unpack requires a string argument')): |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
274 |
raise datastore_errors.InternalError(self.READ_PY250_MSG + |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
275 |
self.READ_ERROR_MSG % |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
276 |
(self.__datastore_file, e)) |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
277 |
else: |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
278 |
raise |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
279 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
280 |
self._StoreEntity(entity) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
281 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
282 |
last_path = entity.key().path().element_list()[-1] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
283 |
if last_path.has_id() and last_path.id() >= self.__next_id: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
284 |
self.__next_id = last_path.id() + 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
285 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
286 |
self.__query_history = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
287 |
for encoded_query, count in self.__ReadPickled(self.__history_file): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
288 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
289 |
query_pb = datastore_pb.Query(encoded_query) |
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
290 |
except self.READ_PB_EXCEPTIONS, e: |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
291 |
raise datastore_errors.InternalError(self.READ_ERROR_MSG % |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
292 |
(self.__history_file, e)) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
293 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
294 |
if query_pb in self.__query_history: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
295 |
self.__query_history[query_pb] += count |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
296 |
else: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
297 |
self.__query_history[query_pb] = count |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
298 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
299 |
def Write(self): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
300 |
""" Writes out the datastore and history files. Be careful! If the files |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
301 |
already exist, this method overwrites them! |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
302 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
303 |
self.__WriteDatastore() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
304 |
self.__WriteHistory() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
305 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
306 |
def __WriteDatastore(self): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
307 |
""" Writes out the datastore file. Be careful! If the file already exist, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
308 |
this method overwrites it! |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
309 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
310 |
if self.__datastore_file and self.__datastore_file != '/dev/null': |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
311 |
encoded = [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
312 |
for kind_dict in self.__entities.values(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
313 |
for entity in kind_dict.values(): |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
314 |
encoded.append(entity.encoded_protobuf) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
315 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
316 |
self.__WritePickled(encoded, self.__datastore_file) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
317 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
318 |
def __WriteHistory(self): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
319 |
""" Writes out the history file. Be careful! If the file already exist, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
320 |
this method overwrites it! |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
321 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
322 |
if self.__history_file and self.__history_file != '/dev/null': |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
323 |
encoded = [(query.Encode(), count) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
324 |
for query, count in self.__query_history.items()] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
325 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
326 |
self.__WritePickled(encoded, self.__history_file) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
327 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
328 |
def __ReadPickled(self, filename): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
329 |
"""Reads a pickled object from the given file and returns it. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
330 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
331 |
self.__file_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
332 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
333 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
334 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
335 |
if filename and filename != '/dev/null' and os.path.isfile(filename): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
336 |
return pickle.load(open(filename, 'rb')) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
337 |
else: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
338 |
logging.warning('Could not read datastore data from %s', filename) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
339 |
except (AttributeError, LookupError, NameError, TypeError, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
340 |
ValueError, struct.error, pickle.PickleError), e: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
341 |
raise datastore_errors.InternalError( |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
342 |
'Could not read data from %s. Try running with the ' |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
343 |
'--clear_datastore flag. Cause:\n%r' % (filename, e)) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
344 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
345 |
self.__file_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
346 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
347 |
return [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
348 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
349 |
def __WritePickled(self, obj, filename, openfile=file): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
350 |
"""Pickles the object and writes it to the given file. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
351 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
352 |
if not filename or filename == '/dev/null' or not obj: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
353 |
return |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
354 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
355 |
tmpfile = openfile(os.tempnam(os.path.dirname(filename)), 'wb') |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
356 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
357 |
pickler = pickle.Pickler(tmpfile, protocol=1) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
358 |
pickler.fast = True |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
359 |
pickler.dump(obj) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
360 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
361 |
tmpfile.close() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
362 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
363 |
self.__file_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
364 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
365 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
366 |
os.rename(tmpfile.name, filename) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
367 |
except OSError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
368 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
369 |
os.remove(filename) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
370 |
except: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
371 |
pass |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
372 |
os.rename(tmpfile.name, filename) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
373 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
374 |
self.__file_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
375 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
376 |
def MakeSyncCall(self, service, call, request, response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
377 |
""" The main RPC entry point. service must be 'datastore_v3'. So far, the |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
378 |
supported calls are 'Get', 'Put', 'RunQuery', 'Next', and 'Count'. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
379 |
""" |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
380 |
super(DatastoreFileStub, self).MakeSyncCall(service, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
381 |
call, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
382 |
request, |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
383 |
response) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
384 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
385 |
explanation = [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
386 |
assert response.IsInitialized(explanation), explanation |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
387 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
388 |
def QueryHistory(self): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
389 |
"""Returns a dict that maps Query PBs to times they've been run. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
390 |
""" |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
391 |
return dict((pb, times) for pb, times in self.__query_history.items() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
392 |
if pb.app() == self.__app_id) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
393 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
394 |
def _Dynamic_Put(self, put_request, put_response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
395 |
clones = [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
396 |
for entity in put_request.entity_list(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
397 |
clone = entity_pb.EntityProto() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
398 |
clone.CopyFrom(entity) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
399 |
clones.append(clone) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
400 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
401 |
assert clone.has_key() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
402 |
assert clone.key().path().element_size() > 0 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
403 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
404 |
last_path = clone.key().path().element_list()[-1] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
405 |
if last_path.id() == 0 and not last_path.has_name(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
406 |
self.__id_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
407 |
last_path.set_id(self.__next_id) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
408 |
self.__next_id += 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
409 |
self.__id_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
410 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
411 |
assert clone.entity_group().element_size() == 0 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
412 |
group = clone.mutable_entity_group() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
413 |
root = clone.key().path().element(0) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
414 |
group.add_element().CopyFrom(root) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
415 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
416 |
else: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
417 |
assert (clone.has_entity_group() and |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
418 |
clone.entity_group().element_size() > 0) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
419 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
420 |
self.__entities_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
421 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
422 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
423 |
for clone in clones: |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
424 |
self._StoreEntity(clone) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
425 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
426 |
self.__entities_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
427 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
428 |
if not put_request.has_transaction(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
429 |
self.__WriteDatastore() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
430 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
431 |
put_response.key_list().extend([c.key() for c in clones]) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
432 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
433 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
434 |
def _Dynamic_Get(self, get_request, get_response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
435 |
for key in get_request.key_list(): |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
436 |
app_kind = self._AppKindForKey(key) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
437 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
438 |
group = get_response.add_entity() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
439 |
try: |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
440 |
entity = self.__entities[app_kind][key].protobuf |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
441 |
except KeyError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
442 |
entity = None |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
443 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
444 |
if entity: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
445 |
group.mutable_entity().CopyFrom(entity) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
446 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
447 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
448 |
def _Dynamic_Delete(self, delete_request, delete_response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
449 |
self.__entities_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
450 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
451 |
for key in delete_request.key_list(): |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
452 |
app_kind = self._AppKindForKey(key) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
453 |
try: |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
454 |
del self.__entities[app_kind][key] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
455 |
if not self.__entities[app_kind]: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
456 |
del self.__entities[app_kind] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
457 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
458 |
del self.__schema_cache[app_kind] |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
459 |
except KeyError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
460 |
pass |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
461 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
462 |
if not delete_request.has_transaction(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
463 |
self.__WriteDatastore() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
464 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
465 |
self.__entities_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
466 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
467 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
468 |
def _Dynamic_RunQuery(self, query, query_result): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
469 |
if not self.__tx_lock.acquire(False): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
470 |
raise apiproxy_errors.ApplicationError( |
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
471 |
datastore_pb.Error.BAD_REQUEST, 'Can\'t query inside a transaction.') |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
472 |
else: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
473 |
self.__tx_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
474 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
475 |
if query.has_offset() and query.offset() > _MAX_QUERY_OFFSET: |
828
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
476 |
raise apiproxy_errors.ApplicationError( |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
477 |
datastore_pb.Error.BAD_REQUEST, 'Too big query offset.') |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
478 |
|
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
479 |
num_components = len(query.filter_list()) + len(query.order_list()) |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
480 |
if query.has_ancestor(): |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
481 |
num_components += 1 |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
482 |
if num_components > _MAX_QUERY_COMPONENTS: |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
483 |
raise apiproxy_errors.ApplicationError( |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
484 |
datastore_pb.Error.BAD_REQUEST, |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
485 |
('query is too large. may not have more than %s filters' |
f5fd65cc3bf3
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
686
diff
changeset
|
486 |
' + sort orders ancestor total' % _MAX_QUERY_COMPONENTS)) |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
487 |
|
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
488 |
app = query.app() |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
489 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
490 |
if self.__require_indexes: |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
491 |
required, kind, ancestor, props, num_eq_filters = datastore_index.CompositeIndexForQuery(query) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
492 |
if required: |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
493 |
required_key = kind, ancestor, props |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
494 |
indexes = self.__indexes.get(app) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
495 |
if not indexes: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
496 |
raise apiproxy_errors.ApplicationError( |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
497 |
datastore_pb.Error.NEED_INDEX, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
498 |
"This query requires a composite index, but none are defined. " |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
499 |
"You must create an index.yaml file in your application root.") |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
500 |
eq_filters_set = set(props[:num_eq_filters]) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
501 |
remaining_filters = props[num_eq_filters:] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
502 |
for index in indexes: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
503 |
definition = datastore_admin.ProtoToIndexDefinition(index) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
504 |
index_key = datastore_index.IndexToKey(definition) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
505 |
if required_key == index_key: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
506 |
break |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
507 |
if num_eq_filters > 1 and (kind, ancestor) == index_key[:2]: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
508 |
this_props = index_key[2] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
509 |
this_eq_filters_set = set(this_props[:num_eq_filters]) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
510 |
this_remaining_filters = this_props[num_eq_filters:] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
511 |
if (eq_filters_set == this_eq_filters_set and |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
512 |
remaining_filters == this_remaining_filters): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
513 |
break |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
514 |
else: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
515 |
raise apiproxy_errors.ApplicationError( |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
516 |
datastore_pb.Error.NEED_INDEX, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
517 |
"This query requires a composite index that is not defined. " |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
518 |
"You must update the index.yaml file in your application root.") |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
519 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
520 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
521 |
query.set_app(app) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
522 |
results = self.__entities[app, query.kind()].values() |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
523 |
results = [entity.native for entity in results] |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
524 |
except KeyError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
525 |
results = [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
526 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
527 |
if query.has_ancestor(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
528 |
ancestor_path = query.ancestor().path().element_list() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
529 |
def is_descendant(entity): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
530 |
path = entity.key()._Key__reference.path().element_list() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
531 |
return path[:len(ancestor_path)] == ancestor_path |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
532 |
results = filter(is_descendant, results) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
533 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
534 |
operators = {datastore_pb.Query_Filter.LESS_THAN: '<', |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
535 |
datastore_pb.Query_Filter.LESS_THAN_OR_EQUAL: '<=', |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
536 |
datastore_pb.Query_Filter.GREATER_THAN: '>', |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
537 |
datastore_pb.Query_Filter.GREATER_THAN_OR_EQUAL: '>=', |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
538 |
datastore_pb.Query_Filter.EQUAL: '==', |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
539 |
} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
540 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
541 |
for filt in query.filter_list(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
542 |
assert filt.op() != datastore_pb.Query_Filter.IN |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
543 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
544 |
prop = filt.property(0).name().decode('utf-8') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
545 |
op = operators[filt.op()] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
546 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
547 |
filter_val_list = [datastore_types.FromPropertyPb(filter_prop) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
548 |
for filter_prop in filt.property_list()] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
549 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
550 |
def passes(entity): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
551 |
""" Returns True if the entity passes the filter, False otherwise. """ |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
552 |
if prop in datastore_types._SPECIAL_PROPERTIES: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
553 |
entity_vals = self.__GetSpecialPropertyValue(entity, prop) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
554 |
else: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
555 |
entity_vals = entity.get(prop, []) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
556 |
|
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
557 |
if not isinstance(entity_vals, list): |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
558 |
entity_vals = [entity_vals] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
559 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
560 |
for fixed_entity_val in entity_vals: |
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
561 |
if type(fixed_entity_val) in datastore_types._RAW_PROPERTY_TYPES: |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
562 |
continue |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
563 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
564 |
for filter_val in filter_val_list: |
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
565 |
fixed_entity_type = self._PROPERTY_TYPE_TAGS.get( |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
566 |
fixed_entity_val.__class__) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
567 |
filter_type = self._PROPERTY_TYPE_TAGS.get(filter_val.__class__) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
568 |
if fixed_entity_type == filter_type: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
569 |
comp = u'%r %s %r' % (fixed_entity_val, op, filter_val) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
570 |
elif op != '==': |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
571 |
comp = '%r %s %r' % (fixed_entity_type, op, filter_type) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
572 |
else: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
573 |
continue |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
574 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
575 |
logging.log(logging.DEBUG - 1, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
576 |
'Evaling filter expression "%s"', comp) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
577 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
578 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
579 |
ret = eval(comp) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
580 |
if ret and ret != NotImplementedError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
581 |
return True |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
582 |
except TypeError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
583 |
pass |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
584 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
585 |
return False |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
586 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
587 |
results = filter(passes, results) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
588 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
589 |
def has_prop_indexed(entity, prop): |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
590 |
"""Returns True if prop is in the entity and is not a raw property, or |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
591 |
is a special property.""" |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
592 |
if prop in datastore_types._SPECIAL_PROPERTIES: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
593 |
return True |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
594 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
595 |
values = entity.get(prop, []) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
596 |
if not isinstance(values, (tuple, list)): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
597 |
values = [values] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
598 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
599 |
for value in values: |
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
600 |
if type(value) not in datastore_types._RAW_PROPERTY_TYPES: |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
601 |
return True |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
602 |
return False |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
603 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
604 |
for order in query.order_list(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
605 |
prop = order.property().decode('utf-8') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
606 |
results = [entity for entity in results if has_prop_indexed(entity, prop)] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
607 |
|
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
608 |
def order_compare_entities(a, b): |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
609 |
""" Return a negative, zero or positive number depending on whether |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
610 |
entity a is considered smaller than, equal to, or larger than b, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
611 |
according to the query's orderings. """ |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
612 |
cmped = 0 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
613 |
for o in query.order_list(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
614 |
prop = o.property().decode('utf-8') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
615 |
|
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
616 |
reverse = (o.direction() is datastore_pb.Query_Order.DESCENDING) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
617 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
618 |
if prop in datastore_types._SPECIAL_PROPERTIES: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
619 |
a_val = self.__GetSpecialPropertyValue(a, prop) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
620 |
b_val = self.__GetSpecialPropertyValue(b, prop) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
621 |
else: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
622 |
a_val = a[prop] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
623 |
if isinstance(a_val, list): |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
624 |
a_val = sorted(a_val, order_compare_properties, reverse=reverse)[0] |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
625 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
626 |
b_val = b[prop] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
627 |
if isinstance(b_val, list): |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
628 |
b_val = sorted(b_val, order_compare_properties, reverse=reverse)[0] |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
629 |
|
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
630 |
cmped = order_compare_properties(a_val, b_val) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
631 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
632 |
if o.direction() is datastore_pb.Query_Order.DESCENDING: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
633 |
cmped = -cmped |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
634 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
635 |
if cmped != 0: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
636 |
return cmped |
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
637 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
638 |
if cmped == 0: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
639 |
return cmp(a.key(), b.key()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
640 |
|
297
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
641 |
def order_compare_properties(x, y): |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
642 |
"""Return a negative, zero or positive number depending on whether |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
643 |
property value x is considered smaller than, equal to, or larger than |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
644 |
property value y. If x and y are different types, they're compared based |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
645 |
on the type ordering used in the real datastore, which is based on the |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
646 |
tag numbers in the PropertyValue PB. |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
647 |
""" |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
648 |
if isinstance(x, datetime.datetime): |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
649 |
x = datastore_types.DatetimeToTimestamp(x) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
650 |
if isinstance(y, datetime.datetime): |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
651 |
y = datastore_types.DatetimeToTimestamp(y) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
652 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
653 |
x_type = self._PROPERTY_TYPE_TAGS.get(x.__class__) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
654 |
y_type = self._PROPERTY_TYPE_TAGS.get(y.__class__) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
655 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
656 |
if x_type == y_type: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
657 |
try: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
658 |
return cmp(x, y) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
659 |
except TypeError: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
660 |
return 0 |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
661 |
else: |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
662 |
return cmp(x_type, y_type) |
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
663 |
|
35211afcd563
Load /Users/solydzajs/Downloads/google_appengine/ into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
209
diff
changeset
|
664 |
results.sort(order_compare_entities) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
665 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
666 |
offset = 0 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
667 |
limit = len(results) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
668 |
if query.has_offset(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
669 |
offset = query.offset() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
670 |
if query.has_limit(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
671 |
limit = query.limit() |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
672 |
if limit > _MAXIMUM_RESULTS: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
673 |
limit = _MAXIMUM_RESULTS |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
674 |
results = results[offset:limit + offset] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
675 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
676 |
clone = datastore_pb.Query() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
677 |
clone.CopyFrom(query) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
678 |
clone.clear_hint() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
679 |
if clone in self.__query_history: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
680 |
self.__query_history[clone] += 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
681 |
else: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
682 |
self.__query_history[clone] = 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
683 |
self.__WriteHistory() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
684 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
685 |
self.__cursor_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
686 |
cursor = self.__next_cursor |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
687 |
self.__next_cursor += 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
688 |
self.__cursor_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
689 |
self.__queries[cursor] = (results, len(results)) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
690 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
691 |
query_result.mutable_cursor().set_cursor(cursor) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
692 |
query_result.set_more_results(len(results) > 0) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
693 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
694 |
def _Dynamic_Next(self, next_request, query_result): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
695 |
cursor = next_request.cursor().cursor() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
696 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
697 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
698 |
results, orig_count = self.__queries[cursor] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
699 |
except KeyError: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
700 |
raise apiproxy_errors.ApplicationError(datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
701 |
'Cursor %d not found' % cursor) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
702 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
703 |
count = next_request.count() |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
704 |
results_pb = [r._ToPb() for r in results[:count]] |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
705 |
query_result.result_list().extend(results_pb) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
706 |
del results[:count] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
707 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
708 |
query_result.set_more_results(len(results) > 0) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
709 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
710 |
def _Dynamic_Count(self, query, integer64proto): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
711 |
query_result = datastore_pb.QueryResult() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
712 |
self._Dynamic_RunQuery(query, query_result) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
713 |
cursor = query_result.cursor().cursor() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
714 |
results, count = self.__queries[cursor] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
715 |
integer64proto.set_value(count) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
716 |
del self.__queries[cursor] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
717 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
718 |
def _Dynamic_BeginTransaction(self, request, transaction): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
719 |
self.__tx_handle_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
720 |
handle = self.__next_tx_handle |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
721 |
self.__next_tx_handle += 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
722 |
self.__tx_handle_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
723 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
724 |
self.__transactions[handle] = None |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
725 |
transaction.set_handle(handle) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
726 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
727 |
self.__tx_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
728 |
snapshot = [(app_kind, dict(entities)) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
729 |
for app_kind, entities in self.__entities.items()] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
730 |
self.__tx_snapshot = dict(snapshot) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
731 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
732 |
def _Dynamic_Commit(self, transaction, transaction_response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
733 |
if not self.__transactions.has_key(transaction.handle()): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
734 |
raise apiproxy_errors.ApplicationError( |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
735 |
datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
736 |
'Transaction handle %d not found' % transaction.handle()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
737 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
738 |
self.__tx_snapshot = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
739 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
740 |
self.__WriteDatastore() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
741 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
742 |
self.__tx_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
743 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
744 |
def _Dynamic_Rollback(self, transaction, transaction_response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
745 |
if not self.__transactions.has_key(transaction.handle()): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
746 |
raise apiproxy_errors.ApplicationError( |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
747 |
datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
748 |
'Transaction handle %d not found' % transaction.handle()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
749 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
750 |
self.__entities = self.__tx_snapshot |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
751 |
self.__tx_snapshot = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
752 |
self.__tx_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
753 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
754 |
def _Dynamic_GetSchema(self, app_str, schema): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
755 |
minint = -sys.maxint - 1 |
209
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
756 |
try: |
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
757 |
minfloat = float('-inf') |
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
758 |
except ValueError: |
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
759 |
minfloat = -1e300000 |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
760 |
|
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
761 |
app_str = app_str.value() |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
762 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
763 |
kinds = [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
764 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
765 |
for app, kind in self.__entities: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
766 |
if app == app_str: |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
767 |
app_kind = (app, kind) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
768 |
if app_kind in self.__schema_cache: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
769 |
kinds.append(self.__schema_cache[app_kind]) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
770 |
continue |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
771 |
|
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
772 |
kind_pb = entity_pb.EntityProto() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
773 |
kind_pb.mutable_key().set_app('') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
774 |
kind_pb.mutable_key().mutable_path().add_element().set_type(kind) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
775 |
kind_pb.mutable_entity_group() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
776 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
777 |
props = {} |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
778 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
779 |
for entity in self.__entities[app_kind].values(): |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
780 |
for prop in entity.protobuf.property_list(): |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
781 |
if prop.name() not in props: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
782 |
props[prop.name()] = entity_pb.PropertyValue() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
783 |
props[prop.name()].MergeFrom(prop.value()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
784 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
785 |
for value_pb in props.values(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
786 |
if value_pb.has_int64value(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
787 |
value_pb.set_int64value(minint) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
788 |
if value_pb.has_booleanvalue(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
789 |
value_pb.set_booleanvalue(False) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
790 |
if value_pb.has_stringvalue(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
791 |
value_pb.set_stringvalue('') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
792 |
if value_pb.has_doublevalue(): |
209
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
793 |
value_pb.set_doublevalue(minfloat) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
794 |
if value_pb.has_pointvalue(): |
209
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
795 |
value_pb.mutable_pointvalue().set_x(minfloat) |
4ba836d74829
Load ../../google_appengine/ into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
149
diff
changeset
|
796 |
value_pb.mutable_pointvalue().set_y(minfloat) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
797 |
if value_pb.has_uservalue(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
798 |
value_pb.mutable_uservalue().set_gaiaid(minint) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
799 |
value_pb.mutable_uservalue().set_email('') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
800 |
value_pb.mutable_uservalue().set_auth_domain('') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
801 |
value_pb.mutable_uservalue().clear_nickname() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
802 |
elif value_pb.has_referencevalue(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
803 |
value_pb.clear_referencevalue() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
804 |
value_pb.mutable_referencevalue().set_app('') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
805 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
806 |
for name, value_pb in props.items(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
807 |
prop_pb = kind_pb.add_property() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
808 |
prop_pb.set_name(name) |
1278
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
809 |
prop_pb.set_multiple(False) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
810 |
prop_pb.mutable_value().CopyFrom(value_pb) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
811 |
|
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
812 |
kinds.append(kind_pb) |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
813 |
self.__schema_cache[app_kind] = kind_pb |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
814 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
815 |
for kind_pb in kinds: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
816 |
schema.add_kind().CopyFrom(kind_pb) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
817 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
818 |
def _Dynamic_CreateIndex(self, index, id_response): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
819 |
if index.id() != 0: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
820 |
raise apiproxy_errors.ApplicationError(datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
821 |
'New index id must be 0.') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
822 |
elif self.__FindIndex(index): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
823 |
raise apiproxy_errors.ApplicationError(datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
824 |
'Index already exists.') |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
825 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
826 |
self.__index_id_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
827 |
index.set_id(self.__next_index_id) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
828 |
id_response.set_value(self.__next_index_id) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
829 |
self.__next_index_id += 1 |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
830 |
self.__index_id_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
831 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
832 |
clone = entity_pb.CompositeIndex() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
833 |
clone.CopyFrom(index) |
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
834 |
app = index.app_id() |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
835 |
clone.set_app_id(app) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
836 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
837 |
self.__indexes_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
838 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
839 |
if app not in self.__indexes: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
840 |
self.__indexes[app] = [] |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
841 |
self.__indexes[app].append(clone) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
842 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
843 |
self.__indexes_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
844 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
845 |
def _Dynamic_GetIndices(self, app_str, composite_indices): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
846 |
composite_indices.index_list().extend( |
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
847 |
self.__indexes.get(app_str.value(), [])) |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
848 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
849 |
def _Dynamic_UpdateIndex(self, index, void): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
850 |
stored_index = self.__FindIndex(index) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
851 |
if not stored_index: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
852 |
raise apiproxy_errors.ApplicationError(datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
853 |
"Index doesn't exist.") |
1278
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
854 |
elif (index.state() != stored_index.state() and |
a7766286a7be
Load /Users/solydzajs/Downloads/google_appengine into
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
828
diff
changeset
|
855 |
index.state() not in self._INDEX_STATE_TRANSITIONS[stored_index.state()]): |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
856 |
raise apiproxy_errors.ApplicationError( |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
857 |
datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
858 |
"cannot move index state from %s to %s" % |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
859 |
(entity_pb.CompositeIndex.State_Name(stored_index.state()), |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
860 |
(entity_pb.CompositeIndex.State_Name(index.state())))) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
861 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
862 |
self.__indexes_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
863 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
864 |
stored_index.set_state(index.state()) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
865 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
866 |
self.__indexes_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
867 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
868 |
def _Dynamic_DeleteIndex(self, index, void): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
869 |
stored_index = self.__FindIndex(index) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
870 |
if not stored_index: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
871 |
raise apiproxy_errors.ApplicationError(datastore_pb.Error.BAD_REQUEST, |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
872 |
"Index doesn't exist.") |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
873 |
|
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
874 |
app = index.app_id() |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
875 |
self.__indexes_lock.acquire() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
876 |
try: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
877 |
self.__indexes[app].remove(stored_index) |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
878 |
finally: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
879 |
self.__indexes_lock.release() |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
880 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
881 |
def __FindIndex(self, index): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
882 |
"""Finds an existing index by definition. |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
883 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
884 |
Args: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
885 |
definition: entity_pb.CompositeIndex |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
886 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
887 |
Returns: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
888 |
entity_pb.CompositeIndex, if it exists; otherwise None |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
889 |
""" |
149
f2e327a7c5de
Load ../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
109
diff
changeset
|
890 |
app = index.app_id() |
109
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
891 |
if app in self.__indexes: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
892 |
for stored_index in self.__indexes[app]: |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
893 |
if index.definition() == stored_index.definition(): |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
894 |
return stored_index |
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
895 |
|
620f9b141567
Load ../../google_appengine into trunk/thirdparty/google_appengine.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
896 |
return None |
686
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
897 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
898 |
@classmethod |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
899 |
def __GetSpecialPropertyValue(cls, entity, property): |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
900 |
"""Returns an entity's value for a special property. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
901 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
902 |
Right now, the only special property is __key__, whose value is the |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
903 |
entity's key. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
904 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
905 |
Args: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
906 |
entity: datastore.Entity |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
907 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
908 |
Returns: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
909 |
property value. For __key__, a datastore_types.Key. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
910 |
|
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
911 |
Raises: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
912 |
AssertionError, if the given property is not special. |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
913 |
""" |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
914 |
assert property in datastore_types._SPECIAL_PROPERTIES |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
915 |
if property == datastore_types._KEY_SPECIAL_PROPERTY: |
df109be0567c
Load ../../google_appengine_1.1.7/ into
Sverre Rabbelier <srabbelier@gmail.com>
parents:
297
diff
changeset
|
916 |
return entity.key() |