"Is it possible, like in Oracle Forms, to set an attribute in a PRE-INSERT trigger?"
Sure. Where Oracle Forms offers six different trigger points (a.k.a. event handlers) like PRE-INSERT, ON-INSERT, POST-INSERT, PRE-UPDATE, ON-UPDATE, POST-UPDATE, PRE-DELETE, ON-DELETE, POST-DELETE, where you can associate event handle code in PL/SQL, in BC4J you can accomplish the same thing by overriding the single doDML() method in your entity object. The object-oriented equivalent of Oracle Forms' "do-the-right-thing" built-in procedures (which Forms developers would call in the case that they conditionally wanted to "just do the behavior you were going to do by default before I overrode you") is accomplished in BC4J by just calling the superclass' implementation of the method that you are overridding.
When you override the doDML() method, you are passed by the framework an integer which represents the operation your entity instance (which typically corresponds to a row you your base table) is being asked to perform. The operation contstants are defined in the EntityImpl class as DML_INSERT, DML_UPDATE, and DML_DELETE. So, here's what an overridden doDML() method would look like with comments indicating where you could put code to achieve the same Oracle Forms' style "Trigger Points":
protected void doDML(int operation, TransactionEvent e) { if (operation == DML_INSERT) { /* write PRE-INSERT trigger-like code here */ super.doDML(operation, e); /* Don't call the super and do something else to write ON-INSERT trigger-like code */ /* write POST-INSERT trigger-like code here */ } else if (operation == DML_UPDATE) { /* write PRE-UPDATE trigger-like code here */ super.doDML(operation, e); /* Don't call the super and do something else to write ON-UPDATE trigger-like code here */ /* write POST-UPDATE trigger-like code here */ } else if (operation == DML_DELETE) { /* write PRE-DELETE trigger-like code here */ super.doDML(operation, e); /* Don't call the super and do something else to write ON-DELETE trigger-like code here */ /* write POST-DELETE trigger-like code here */ } }
So, to assign a value to an attribute in a pre-insert trigger, you would do:
protected void doDML(int operation, TransactionEvent e) { if (operation == DML_INSERT) { setIdAttr(...); /* Assuming attribute is called "IdAttr" */ super.doDML(operation, e); } else if (operation == DML_UPDATE) { super.doDML(operation, e); } else if (operation == DML_DELETE) { super.doDML(operation, e); } }
or, more compactly, you can just deal with the exception case like this:
protected void doDML(int operation, TransactionEvent e) { if (operation == DML_INSERT) { setIdAttr(...); /* Assuming attribute is called "IdAttr" */ } super.doDML(operation, e); }
7:22:06 PM
|
|