コード例 #1
0
    def _ConvertCachedResponse(self, stub_method, exec_op_response):
        """Converts the cached response or RPC error.

    Args:
      stub_method: A string, the name of the original method that triggered the
                   retry.
      exec_op_response: A protobuf, the retry response that contains either the
                        RPC error or the cached response.

    Returns:
      A protobuf, the cached response.

    Raises:
      DatabaseError: If the cached response contains SqlException.
      InternalError: If a cached RpcErrorProto exists.
    """
        if exec_op_response.HasField('cached_rpc_error'):
            raise InternalError(
                '%d: %s' % (exec_op_response.cached_rpc_error.error_code,
                            exec_op_response.cached_rpc_error.error_message))
        if not exec_op_response.HasField('cached_payload'):
            raise InternalError('Invalid exec op response for retry request')
        if stub_method == 'Exec':
            response = sql_pb2.ExecResponse()
        elif stub_method == 'ExecOp':
            response = sql_pb2.ExecOpResponse()
        elif stub_method == 'GetMetadata':
            response = sql_pb2.MetadataResponse()
        else:
            raise InternalError('Found unexpected stub_method: %s' %
                                (stub_method))
        response.ParseFromString(exec_op_response.cached_payload)
        if response.HasField('sql_exception'):
            raise _ToDbApiException(response.sql_exception)
        return response
コード例 #2
0
    def _CreateResponse(self, stub_method):
        """Creates the protocol buffer response object for stub_method."""

        if stub_method == 'OpenConnection':
            return sql_pb2.OpenConnectionResponse()
        elif stub_method == 'CloseConnection':
            return sql_pb2.CloseConnectionResponse()
        elif stub_method == 'Exec':
            return sql_pb2.ExecResponse()
        elif stub_method == 'ExecOp':
            return sql_pb2.ExecOpResponse()
        elif stub_method == 'GetMetadata':
            return sql_pb2.MetadataResponse()