Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Object type change on the fly

Object type change on the fly

From: Petr <petr.novotny_at_seacomp.cz>
Date: 2 Feb 2005 02:28:11 -0800
Message-ID: <3a0fcf7d.0502020228.463fd57d@posting.google.com>


Hi,
I have a following problem and I could not find how to solve it. Lets show it on example.

I have stations (name, type, ...), for example NAME TYPE


X1     PRINTER
X2     AUTOMAT
X3     WEIGHT

Then I have a container records with set of stations (the meaning is what should be done with that container).

I created object types ST_GENERAL, ST_PRINTER under ST_GENERAL, ST_AUTOMAT under ST_GENERAL etc. In all such types I have a member procedure DO_ACTION.

When I got from HW subsystem a message that the container is on some station, I want to do some actions depending on the type of the station type. So for example when I get a message that container is on X1 (type PRINTER), I want to call the member procedure ST_PRINTER.DO_ACTION. My database should not be changed (so do not create object table), so I can use only object views. I created one of the general type ST_GENERAL, so I am able to call the general action. But I did not find a possibility to redefine the type from the ST_GENERAL to the subtype (for example ST_PRINTER) to be able to call the correct action. The only one possibility I found is to create one object view for each type of the stations, and then on the fly over dynamic SQL I can retrieve the object from proper object view, so then it is a type of the derived object correctly.
But this solution is not very nice, as I will need a lot of object view and the list of station types is not fixed now and some of them can be added in future without needs to change some already existing code (just to derive a new class and define the action what should be done).

So is it a possibility that if I have something like

CREATE TYPE ST_GENERAL AS OBJECT (
  Name VARCHAR2(10),
  Type VARCHAR2(10),
  MEMBER PROCEDURE DO_ACTION
) NOT FINAL;

CREATE TYPE ST_PRINTER UNDER ST_GENERAL (   OVERRIDING MEMBER PROCEDURE DO_ACTION
) NOT FINAL;

...

CREATE OR REPLACE VIEW OV_STATIONS of ST_GENERAL WITH OBJECT IDENTIFIER(Name) AS SELECT Name, Type FROM STATIONS;

to do a select from this view something like DECLARE
  vo_Station ST_GENERAL;
BEGIN
  SELECT VALUE(S) INTO vo_Station FROM OV_STATIONS S WHERE S.Name = 'X1';

and not the general one, but the derived action will be called, so generally change the type of the object stored in vo_Station from ST_GENERAL to ST_PRINTER ?

When I tried TREAT function, it does not work, as the object view is based on the general type, so the following treat returns always null

EXECUTE IMMEDIATE 'SELECT TREAT(VALUE(S) AS :type) FROM OV_STATIONS S'   ||' WHERE S.NAME = :name'
  INTO vo_Station USING 'ST_PRINTER', 'X1';

Thanks
Petr Received on Wed Feb 02 2005 - 04:28:11 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US