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 -> Re: Object type change on the fly

Re: Object type change on the fly

From: <townsend_at_ebmud.com>
Date: 7 Feb 2005 10:22:47 -0800
Message-ID: <1107800567.500369.84620@l41g2000cwc.googlegroups.com>


I'm a bit new to this Object Relational stuff, but it sounds like what you need to do is create an Object View Hierarchy. Querying at the top of the hierarchy returns objects from all levels below that in the view hierarchy. Each level of the hierarchy is based on the subtypes of the top-level type. So you get your most specific member method from the sub-views.
-- Dan
Petr wrote:
> 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';
> -- ?????
> vo_Station.DO_ACTION();
> END;
>
> 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 Mon Feb 07 2005 - 12:22:47 CST

Original text of this message

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