user defined types - Partial Objects In Oracle -
i using flat stored procedures (flat means not contained in objects) in oracle update tables. example have table person columns id, firstname, lastname, address, salary. made flat procedure person_updfirstname , procedure has 2 parameters: id, firstname. inside procedure, find row in person table matches parameter id , update firstname parameter firstname. usual stuff, nothing new.
now, using oracle objects. have object persontype, udt. object has same fields columns in table person. have put of procedures related person table inside persontype object, is, instead of using flat procedures start using member procedures. none of member procedures has parameter, take values fields of object. example, in case of person_updfirstname flat procedure, have member procedure updfirstname. member procedure not take parameter, uses id , firstname fields of object itself, , update person table before.
the problem is, when using flat procedures, passing parameters such id, firstname, in large system hundreds of tables, cannot make mistake in passing parameters stored procedure because number , type of parameters in each stored procedure fixed. using objects, have remember fields of object filled, there no built in check in system. fine long fields in table person non-nullable because throw exception anyways if fields in table nullable, or when comparing values, can have lots of logical errors.
my question is, there built-in way close door of potential errors. have rough solutions not sure:
- some kind of partial objects. member methods should forced take in parameter partial objects. example have partial object personupdfirstnametype, has 1 field firstname , updfirstname member method take parameter. ofcourse cumbersome make separate partial-type each operation on table. don't solution
- i don't pass objects c# oracle procedures, instead pass variables in parameters , manually build (or not build) oracle objects needed.
i have found out way map oracle objects c# classes. this, don't have use orm tool. have add few attributes on c# classes , c# fields of classes , implement few interfaces. so, can pass c# objects oracle procedures , use "." syntax in oracle procedures access fields contains actual data.
i think problem asking general oop problem, not specific particular language. general problem, suppose have class c fields f1, f2, f3, f4, f5 , methods m1, m2, m3. m1 operation on of fields, m2 operation on other fields, m3 operations on fields may acted upon m1 or m2. client code making objects of c , can fill number (including zero) of parameters before calling method. if client code call method before putting values in fields required method. in c#, think handled compiler throwing exceptions if not initialize fields first; can leave fields empty in definition of class such "int i" without putting value in if method called compiler throw exception. there no such support in dbms because of nullable fields. if lets comparing id of table-row against id of object-field , forgot put value in object-field table-row's id compared against null , no row matched , therefore no update happens (suppose want update rows match id, usual update operation).
i want know if there built-in check in system handle such cases.
i don't have idea how have error in compilation time, , don't know of other oo language gives such feature either (how can compiler tell when or attribute initiated ?)
can have exceptions in runtime (somewhat nullpointerexception
or argumentnullexception
).
example:
create or replace type person_o object ( id number, fname varchar2(32), lname varchar2(32), member procedure update_lname ); / create or replace type body person_o member procedure update_lname begin if self.lname null raise_application_error(-20000, 'null attribute'); end if; update persons_table set last_name = self.lname id = self.id; commit; end; end; /
Comments
Post a Comment