Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Object type change on the fly
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';
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