Vorrei chiamare un metodo PL/SQL sovrascritto. Ecco un esempio:Come chiamare un metodo Super Oracle PL/SQL
-- super class
create or replace type test as object
(
n number,
member procedure proc(SELF in out nocopy test, s varchar2)
)
alter type test not final
/
create or replace type body test is
member procedure proc(SELF in out nocopy test, s varchar2) is
begin
dbms_output.put_line('test1: n='||nvl(self.n, 'null')||' s='||s);
self.n := to_number(s);
end;
end;
/
-- derived class
create or replace type test2 under test
(
overriding member procedure proc(SELF in out nocopy test2, s varchar2)
)
/
Ora voglio richiamare la versione ereditata del metodo proc
. Quando provo a fare un cast esplicito come treat(self as test).proc(s);
non si compila a causa di PLS-00363: l'espressione 'SYS_TREAT' non può essere utilizzato come destinazione di assegnazione
Il corpo di tipo compila quando uso una variabile locale:
create or replace type body test2 is
overriding member procedure proc(SELF in out nocopy test2, s varchar2) is
O test;
begin
O := treat(self as test);
O.proc(s);
end;
end;
/
Ma quando eseguo il mio esempio come questo
declare
obj test2;
begin
obj := test2(0);
obj.proc('1');
end;
... getta ORA-21780: numero massimo di durata degli oggetti superato.
C'è un modo per chiamare test :: proc (senza serializzazione/deserializzazione)?
E ... dopo che proc è stato chiamato, come possono essere riflessi eventuali attributi modificati (ovvero n
) in obj
?
Aggiornamento (Grazie, tbone):
ho cambiato l'organizzazione dei miei metodi che utilizzano metodi di template ('prima' e 'dopo'). Li aggiungo ogni volta che ho bisogno di estendere un metodo.
create or replace type test as object
(
n number,
member procedure proc (SELF in out nocopy test, s varchar2),
member procedure afterProc (SELF in out nocopy test, s varchar2)
member procedure beforeProc(SELF in out nocopy test, s varchar2),
)
not final
/
create or replace type body test is
member procedure proc(SELF in out nocopy test, s varchar2) is
begin
beforeProc(s);
dbms_output.put_line('test1: n='||nvl(n, 'null')||' s='||s);
n := to_number(s);
afterProc(s);
end;
member procedure afterProc (SELF in out nocopy test, s varchar2) is begin null; end;
member procedure beforeProc(SELF in out nocopy test, s varchar2) is begin null; end;
end;
/
da documenti sembra che TREAT sia utilizzato per accedere ai metodi/attributi di sottotipo, non super. Potrei sbagliarmi, ma vedi http://docs.oracle.com/cd/E11882_01/appdev.112/e11822/adobjbas.htm – tbone
sì, hai ragione. I documenti dicono che TREAT può solo accedere al sottotipo. Ma come dovrei usare la super classe? –