1

我需要在 c# 的 oracle 高级队列中使用 UDT 执行入队和出队消息。我正在使用以下代码。

UDT:

CREATE OR REPLACE TYPE APPS_GLOBAL.db_Message_type2 as object ( text VARCHAR2(4000 CHAR), text1 number);

C#:

' [OracleCustomTypeMapping("APPS_GLOBAL.DB_MESSAGE_TYPE2")] 类 db_Message_type2 : IOracleCustomType, INullable { private string _text; 私人十进制_text1;私人布尔_isNull;

    public db_Message_type2()
    {
        _text = "iDontKnow";
        _text1 = 30;
    }

    public db_Message_type2(string text, decimal text1)
    {
        _text = text;
        _text1 = text1;
    }

    [OracleObjectMapping("text")]
    public string text
    {
        get { return this._text; }
        set { this._text = value; }
    }

    [OracleObjectMapping("text1")]
    public decimal text1
    {
        get { return this._text1; }
        set { this._text1 = value; }
    }

    public bool IsNull { get { return this._isNull; } }
    public void FromCustomObject(OracleConnection con, IntPtr pUdt)
    {
        OracleUdt.SetValue(con, pUdt, "text", this._text);
        OracleUdt.SetValue(con, pUdt, "text1", this._text1);
    }

    public void ToCustomObject(OracleConnection con, IntPtr pUdt)
    {
        text = (string)OracleUdt.GetValue(con, pUdt, "text");
        text1 = (decimal)OracleUdt.GetValue(con, pUdt, "text1");
    }

    public static db_Message_type2 Null
    {
        get { return new db_Message_type2 { _isNull = true }; }
    }
}

'

[OracleCustomTypeMappingAttribute("APPS_GLOBAL.DB_MESSAGE_TYPE2")]
public class QueueMessageTypeFactory : IOracleCustomTypeFactory
{
    public IOracleCustomType CreateObject()
    {
        var result = new db_Message_type2("iDontKnow anything about AQ", 50);
        return result;
    }
}



class Program
{
    static void Main(string[] args)
    {
        EnqueueUDT();
        Console.ReadLine();
    }

    static void EnqueueUDT()
    {
        try
        {
            string _connstring = "myConnectionString";

            OracleConnection _connObj = new OracleConnection(_connstring);

            _connObj.Open();

            OracleTransaction _txn = _connObj.BeginTransaction();
            OracleAQQueue _queueObj = new OracleAQQueue("APPS_GLOBAL.db_temp_adv_queue3", _connObj, OracleAQMessageType.Udt, "APPS_GLOBAL.DB_MESSAGE_TYPE2");

            OracleAQMessage _msg = new OracleAQMessage();

            _msg.Payload = new db_Message_type2 { text = "Custom", text1 = 5 };

            // Enqueue the message
            //_queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.Immediate;
            //_queueObj.EnqueueOptions.DeliveryMode = OracleAQMessageDeliveryMode.Persistent;

            //_queueObj.Enqueue(_msg);
            _queueObj.Enqueue(_msg, new OracleAQEnqueueOptions { DeliveryMode = OracleAQMessageDeliveryMode.Persistent, Visibility = OracleAQVisibilityMode.Immediate });

            _txn.Commit();
            _queueObj.Dispose();
            _connObj.Close();
            _connObj.Dispose();
            _connObj = null;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
        }
    }
}

我无法理解我在哪里做错了。

4

0 回答 0