def decode_element(element_tuple): """ Converts a tuple to a path element protobuf object. """ path_element = entity_pb.Path_Element() path_element.set_type(element_tuple[0]) if isinstance(element_tuple[1], int): path_element.set_id(element_tuple[1]) else: path_element.set_name(element_tuple[1]) return path_element
def _Dynamic_TransactionQuery(self, request, response): if not request.has_ancestor(): raise apiproxy_errors.ApplicationError( datastore_pb.Error.BAD_REQUEST, 'No ancestor in transactional query.') app_id = datastore_types.ResolveAppId(None) if (datastore_rpc._GetDatastoreType(app_id) != datastore_rpc.BaseConnection.HIGH_REPLICATION_DATASTORE): raise apiproxy_errors.ApplicationError( datastore_pb.Error.BAD_REQUEST, 'remote_api supports transactional queries only in the ' 'high-replication datastore.') entity_group_key = entity_pb.Reference() entity_group_key.CopyFrom(request.ancestor()) group_path = entity_group_key.mutable_path() root = entity_pb.Path_Element() root.MergeFrom(group_path.element(0)) group_path.clear_element() group_path.add_element().CopyFrom(root) eg_element = group_path.add_element() eg_element.set_type(metadata.EntityGroup.KIND_NAME) eg_element.set_id(metadata.EntityGroup.ID) begin_request = datastore_pb.BeginTransactionRequest() begin_request.set_app(app_id) tx = datastore_pb.Transaction() self.__call('datastore_v3', 'BeginTransaction', begin_request, tx) request.mutable_transaction().CopyFrom(tx) self.__call('datastore_v3', 'RunQuery', request, response.mutable_result()) get_request = datastore_pb.GetRequest() get_request.mutable_transaction().CopyFrom(tx) get_request.add_key().CopyFrom(entity_group_key) get_response = datastore_pb.GetResponse() self.__call('datastore_v3', 'Get', get_request, get_response) entity_group = get_response.entity(0) response.mutable_entity_group_key().CopyFrom(entity_group_key) if entity_group.has_entity(): response.mutable_entity_group().CopyFrom(entity_group.entity()) self.__call('datastore_v3', 'Commit', tx, datastore_pb.CommitResponse())