|
13 | 13 | # limitations under the License.
|
14 | 14 | """Convenience wrapper for invoking APIs/factories w/ a dataset ID."""
|
15 | 15 |
|
| 16 | +from gcloud._helpers import _LocalStack |
16 | 17 | from gcloud.datastore import helpers
|
17 | 18 | from gcloud.datastore.batch import Batch
|
18 | 19 | from gcloud.datastore.entity import Entity
|
@@ -126,43 +127,42 @@ def __init__(self, dataset_id=None, namespace=None, connection=None):
|
126 | 127 | self.dataset_id = dataset_id
|
127 | 128 | if connection is None:
|
128 | 129 | connection = get_connection()
|
129 |
| - self._connection_stack = [connection] |
| 130 | + self.connection = connection |
| 131 | + self._batch_stack = _LocalStack() |
130 | 132 | self.namespace = namespace
|
131 | 133 |
|
132 |
| - def _push_connection(self, connection): |
133 |
| - """Push a connection/batch/transaction onto our stack. |
| 134 | + def _push_batch(self, batch): |
| 135 | + """Push a batch/transaction onto our stack. |
134 | 136 |
|
135 | 137 | "Protected", intended for use by batch / transaction context mgrs.
|
136 | 138 |
|
137 |
| - :type connection: :class:`gcloud.datastore.connection.Connection`, |
138 |
| - or an object implementing its API. |
139 |
| - :param connection: newly-active connection/batch/transaction to |
140 |
| - pass to proxied API methods |
| 139 | + :type batch: :class:`gcloud.datastore.batch.Batch`, or an object |
| 140 | + implementing its API. |
| 141 | + :param batch: newly-active batch/batch/transaction. |
141 | 142 | """
|
142 |
| - self._connection_stack.append(connection) |
| 143 | + self._batch_stack.push(batch) |
143 | 144 |
|
144 |
| - def _pop_connection(self): |
145 |
| - """Pop a connection/batch/transaction from our stack. |
| 145 | + def _pop_batch(self): |
| 146 | + """Pop a batch/transaction from our stack. |
146 | 147 |
|
147 | 148 | "Protected", intended for use by batch / transaction context mgrs.
|
148 | 149 |
|
149 | 150 | :raises: IndexError if the stack is empty.
|
150 |
| - :rtype: :class:`gcloud.datastore.connection.Connection`, or |
151 |
| - an object implementing its API. |
152 |
| - :returns: the top-most connection/batch/transaction, after removing it. |
| 151 | + :rtype: :class:`gcloud.datastore.batch.Batch`, or an object |
| 152 | + implementing its API. |
| 153 | + :returns: the top-most batch/transaction, after removing it. |
153 | 154 | """
|
154 |
| - return self._connection_stack.pop() |
| 155 | + return self._batch_stack.pop() |
155 | 156 |
|
156 | 157 | @property
|
157 |
| - def connection(self): |
158 |
| - """Currently-active connection. |
| 158 | + def current_batch(self): |
| 159 | + """Currently-active batch. |
159 | 160 |
|
160 |
| - :rtype: :class:`gcloud.datastore.connection.Connection`, or |
161 |
| - an object implementing its API. |
162 |
| - :returns: The connection/batch/transaction at the toop of the |
163 |
| - connection stack. |
| 161 | + :rtype: :class:`gcloud.datastore.batch.Batch`, or an object |
| 162 | + implementing its API, or ``NoneType`` (if no batch is active). |
| 163 | + :returns: The batch/transaction at the toop of the batch stack. |
164 | 164 | """
|
165 |
| - return self._connection_stack[-1] |
| 165 | + return self._batch_stack.top |
166 | 166 |
|
167 | 167 | def get(self, key, missing=None, deferred=None):
|
168 | 168 | """Retrieve an entity from a single key (if it exists).
|
|
0 commit comments