Page 1 of 1
get Child OracleClassType from Parent
Posted: Thu 02 Apr 2009 23:21
by Linkelf
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)
Posted: Fri 03 Apr 2009 11:20
by Shalex
Our components do not allow to get a message of B ObjectPayload type in this situation. It will be A.
how to perform A->B conversation ?
Posted: Fri 03 Apr 2009 21:11
by Linkelf
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 ).
Posted: Mon 06 Apr 2009 12:26
by Shalex
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.
Posted: Tue 07 Apr 2009 00:10
by Linkelf
can you post example code please? i can't find the way to perform typecast 8 (.
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();
and have an "InvalidOperation Exception" on last string.
Posted: Tue 07 Apr 2009 09:45
by Shalex
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();
}
Posted: Wed 22 Apr 2009 23:23
by Linkelf
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 ?
Posted: Thu 23 Apr 2009 08:47
by Linkelf
I wrote an oracle procedure :
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;
And it raises ORA-06502 error when run on msg.PayloadObject. It seems that Dequeue() method returns object without message2 data.[/code]
Posted: Thu 23 Apr 2009 11:46
by Shalex
Sorry, you are right. There is no way to obtain the message2 object from a table with message type.