get Child OracleClassType from Parent

get Child OracleClassType from Parent

Postby Linkelf » Thu 02 Apr 2009 23:21

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)
Linkelf
 
Posts: 9
Joined: Thu 02 Apr 2009 21:29

Postby Shalex » Fri 03 Apr 2009 11:20

Our components do not allow to get a message of B ObjectPayload type in this situation. It will be A.
Shalex
Devart Team
 
Posts: 7792
Joined: Thu 14 Aug 2008 12:44

how to perform A->B conversation ?

Postby Linkelf » Fri 03 Apr 2009 21:11

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 ).
Linkelf
 
Posts: 9
Joined: Thu 02 Apr 2009 21:29

Postby Shalex » Mon 06 Apr 2009 12:26

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.
Shalex
Devart Team
 
Posts: 7792
Joined: Thu 14 Aug 2008 12:44

Postby Linkelf » Tue 07 Apr 2009 00:10

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.
Linkelf
 
Posts: 9
Joined: Thu 02 Apr 2009 21:29

Postby Shalex » Tue 07 Apr 2009 09:45

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();
}
Shalex
Devart Team
 
Posts: 7792
Joined: Thu 14 Aug 2008 12:44

Postby Linkelf » Wed 22 Apr 2009 23:23

I have a problem with code string:
Code: Select all
msg.ObjectPayload = obj;

because it just copy obj to msg.ObjectPayload, erasing all ObjectPayload data.
How i can perform type conversation ?
Linkelf
 
Posts: 9
Joined: Thu 02 Apr 2009 21:29

Postby Linkelf » Thu 23 Apr 2009 08:47

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]
Linkelf
 
Posts: 9
Joined: Thu 02 Apr 2009 21:29

Postby Shalex » Thu 23 Apr 2009 11:46

Sorry, you are right. There is no way to obtain the message2 object from a table with message type.
Shalex
Devart Team
 
Posts: 7792
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle