예제 #1
0
    def commit(self, dataset_id, mutation_pb):
        """Commit dataset mutations in context of current transation (if any).

        Maps the ``DatastoreService.Commit`` protobuf RPC.

        :type dataset_id: string
        :param dataset_id: The dataset in which to perform the changes.

        :type mutation_pb: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
        :param mutation_pb: The protobuf for the mutations being saved.

        :rtype: :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
        :returns': the result protobuf for the mutation.
        """
        request = datastore_pb.CommitRequest()

        if self.transaction():
            request.mode = datastore_pb.CommitRequest.TRANSACTIONAL
            request.transaction = self.transaction().id()
        else:
            request.mode = datastore_pb.CommitRequest.NON_TRANSACTIONAL

        request.mutation.CopyFrom(mutation_pb)
        response = self._rpc(dataset_id, 'commit', request,
                             datastore_pb.CommitResponse)
        return response.mutation_result
예제 #2
0
    def commit(self, dataset_id, mutation_pb):
        request = datastore_pb.CommitRequest()

        if self.transaction():
            request.mode = datastore_pb.CommitRequest.TRANSACTIONAL
            request.transaction = self.transaction().id()
        else:
            request.mode = datastore_pb.CommitRequest.NON_TRANSACTIONAL

        request.mutation.CopyFrom(mutation_pb)
        response = self._rpc(dataset_id, 'commit', request,
                             datastore_pb.CommitResponse)
        return response.mutation_result
    # Set the appropriate value.
    helpers._set_protobuf_value(prop.value, value)


def save_entity_fresh():
    start = time.time()
    result = CONNECTION.commit(DATASET_ID, MUTATION)
    duration = time.time() - start

    key_pb = result.insert_auto_id_key[0]
    check_key_pb(key_pb)
    return duration


COMMIT_REQUEST = datastore_pb.CommitRequest()
COMMIT_REQUEST.mode = datastore_pb.CommitRequest.NON_TRANSACTIONAL
COMMIT_REQUEST.mutation.CopyFrom(MUTATION)


def commit_fresh():
    start = time.time()
    response = CONNECTION._rpc(DATASET_ID, 'commit', COMMIT_REQUEST,
                               datastore_pb.CommitResponse)
    duration = time.time() - start

    key_pb = response.mutation_result.insert_auto_id_key[0]
    check_key_pb(key_pb)
    return duration