get Child OracleClassType from Parent
get Child OracleClassType from Parent
Hi all. I have a queue with object type A and object B inhereted from A. I put a B instance into my queue as A. So Dequeue method return message with A ObjectPayload type. Is it possible to determine ObjectPayload true type? (B in this example)
how to perform A->B conversation ?
In C#, i'll just write "A as B_Type" and all is OK.
Is it possible to do same conversation with OracleObjects in this example? Any way is good 8 ).
Is it possible to do same conversation with OracleObjects in this example? Any way is good 8 ).
You are right, if you set the ObjectPayload type to B of your OracleQueueMessage object explicitly when making dequeue, it is possible to work with this object as with an object of the B type.
But unfortunately, OracleObject doesn't have functionality that allows to determine the true type of ObjectPayload.
But unfortunately, OracleObject doesn't have functionality that allows to determine the true type of ObjectPayload.
can you post example code please? i can't find the way to perform typecast 8 (.
I try :
and have an "InvalidOperation Exception" on last string.
I try :
Code: Select all
oracleQueue.PayloadTypeName = "A_OBJTYPE";
OracleQueueMessage msg = oracleQueue.Dequeue();
oracleObject Try = new OracleObject("B_OBJTYPE", oracleConnection);
Try = (OracleObject)msg.ObjectPayload.Clone();
string olala = Try[].ToString();
Here is a sample:
Code: Select all
using (OracleConnection oracleConnection = new OracleConnection(connStr)){
oracleConnection.Open();
OracleCommand oracleCommand = new OracleCommand("CREATE OR REPLACE TYPE message
AS OBJECT (nickname VARCHAR2(15), mestext VARCHAR2(80)) not final;", oracleConnection);
oracleCommand.ExecuteNonQuery();
oracleCommand = new OracleCommand("CREATE OR REPLACE TYPE message2
UNDER message(deptid NUMBER);", oracleConnection);
oracleCommand.ExecuteNonQuery();
OracleQueueTable oracleQueueTable = new OracleQueueTable("QUEUE_TABLE_MESSAGE", oracleConnection);
oracleQueueTable.Options.PayloadTypeName = "message";
oracleQueueTable.CreateQueueTable();
OracleQueueAdmin oracleQueueAdmin = new OracleQueueAdmin("MESSAGE_QUEUE",
"QUEUE_TABLE_MESSAGE", oracleConnection);
oracleQueueAdmin.CreateQueue();
oracleQueueAdmin.StartQueue();
OracleQueue oracleEnqueueQueue = new OracleQueue("MESSAGE_QUEUE", oracleConnection);
OracleQueueMessage message1 = new OracleQueueMessage();
OracleObject obj = new OracleObject("message2", oracleConnection);
obj["nickname"] = oracleConnection.UserId;
obj["mestext"] = "Hello, world!";
obj["deptid"] = 35;
message1.ObjectPayload = obj;
oracleEnqueueQueue.Enqueue(message1);
OracleQueue oracleDequeueQueue = new OracleQueue("MESSAGE_QUEUE", oracleConnection);
try {
OracleQueueMessage msg = oracleDequeueQueue.Dequeue();
msg.ObjectPayload = obj;
if (msg != null && msg.ObjectPayload != null) {
int k = Convert.ToInt32(msg.ObjectPayload["deptid"]);
Console.WriteLine("deptid = {0}", k);
}
}
catch (OracleException ex) {
Console.WriteLine("Exception:\n{0}", ex.Message);
}
oracleQueueAdmin.StopQueue();
oracleQueueAdmin.DropQueue();
oracleQueueTable.DropQueueTable();
}
I have a problem with code string:
because it just copy obj to msg.ObjectPayload, erasing all ObjectPayload data.
How i can perform type conversation ?
Code: Select all
msg.ObjectPayload = obj;
How i can perform type conversation ?
I wrote an oracle procedure :
And it raises ORA-06502 error when run on msg.PayloadObject. It seems that Dequeue() method returns object without message2 data.[/code]
Code: Select all
create or replace procedure conv_from_message_to_message2 (
p_pl_sup in message
,p_pl_sub out message2)
is
begin
p_pl_sub := treat(p_pl_sup as message2);
end;