F ADF Equivalents of Common Oracle Forms Triggers

This appendix provides a quick summary of how basic tasks performed with the most common Oracle Forms triggers are accomplished using Oracle ADF.

This appendix includes the following sections:

F.1 Validation and Defaulting (Business Logic)

Table F-1 ADF Equivalents for Oracle Forms Validation and Defaulting Triggers

Forms Trigger ADF Equivalent

WHEN-VALIDATE-RECORD

Execute validation code at the record level

In the custom EntityImpl class for your entity object, write a public method returning a boolean type with a method name like validateXXXX() and have it return true if the validation succeeds or false if the validation fails. Then, add a Method validator for this validation method to your entity object at the entity level. When doing that, you can associate a validation failure message with the rule.

WHEN-VALIDATE-ITEM

Execute validation code at the field level

In the custom EntityImpl class for your entity object, write a public method returning a boolean type and accepting a single argument of the same data type as your attribute, having a method name like validateXXXX(). Have it return true if the validation succeeds or false if the validation fails. Then, add a Method validator for this validation method to the entity object at the attribute level for the appropriate attribute. When doing that, you can associate a validation failure message with the rule.

WHEN-DATABASE-RECORD

Execute code when a row in the data block is marked for insert or update

Override the addToTransactionManager() method of your entity object. Write code after calling the super.

WHEN-CREATE-RECORD

Execute code to populate complex default values when a new record in the data block is created, without changing the modification status of the record

Override the create() method of your entity object and after calling the super, use appropriate setAttrName() methods to set default values for attributes as necessary.

To immediately set a primary key attribute to the value of a sequence, construct an instance of the SequenceImpl helper class and call its getSequenceNumber() method to get the next sequence number. Assign this value to your primary key attribute.

If you want to wait to assign the sequence number until the new record is saved, but still without using a database trigger, you can use this technique in an overridden prepareForDML() method in your entity object.

If instead you want to assign the primary key from a sequence using your own BEFOREINSERTFOREACHROW database trigger, then use the special data type called DBSequence for your primary key attribute instead of the regular Number type.

WHEN-REMOVE-RECORD

Execute code whenever a row is removed from the data block

Override the remove() method of your entity object and write code either before or after calling the super.


F.2 Query Processing

Table F-2 ADF Equivalents for Oracle Forms Query Processing Triggers

Forms Trigger ADF Equivalent

PRE-QUERY

Execute logic before executing a query in a data block, typically to set up values for Query-by-Example criteria in the "example record"

Override the executeQueryForCollection() method on your view object class and write code before calling the super.

ON-COUNT

Override default behavior to count the query hits for a data block

Override the getQueryHitCount() method in your view object and do something instead of calling the super.

POST-QUERY

Execute logic after retrieving each row from the data source for a data block.

Generally instead of using a POST-QUERY style technique to fetch descriptions from other tables based on foreign key values in the current row, in ADF it's more efficient to build a view object that has multiple participating entity objects, joining in all the information you need in the query from the main table, as well as any auxiliary or lookup-value tables. This way, in a single roundtrip to the database you get all the information you need. If you still need a per-fetched-row trigger like POST-QUERY, override the createInstanceFromResultSet() method in your view object class.

ON-LOCK

Override default behavior to attempt to acquire a lock on the current row in the data block

Override the lock() method in your entity object class and do something instead of calling the super.


F.3 Database Connection

Table F-3 ADF Equivalents for Oracle Forms Database Connection Triggers

Forms Trigger ADF Equivalent

POST-LOGON

Execute logic after logging into the database

Override the afterConnect() method on your custom application module. Since application module instances can stay connected while serving different logical client sessions, you can override the prepareSession() method, which is fired after initial login, as well as after any time the application module is accessed by a user that was different from the one that accessed it last time.

PRE-LOGOUT

Execute logic before logging out of the database

Override the beforeDisconnect() method on your custom application module class.


F.4 Transaction "Post" Processing (Record Cache)

Table F-4 ADF Equivalents for Oracle Forms Transactional Triggers

Forms Trigger ADF Equivalent

PRE-COMMIT

Execute code before commencing processing of the changed rows in all data blocks in the transaction

Override the commit() method in a custom DBTransactionImpl class and write code before calling the super.

Note:

For an overview of creating and using a custom DBTransaction implementation, see Section 12.8.4.1, "Creating a Custom Database Transaction Framework Extension Class."

PRE-INSERT

Execute code before a new row in the data block is inserted into the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_INSERT, then write code before calling the super.

ON-INSERT

Override default processing for inserting a new row into the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_INSERT, then write code instead of calling the super.

POST-INSERT

Execute code after new row in the data block is inserted into the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_INSERT, then write code after calling the super.

PRE-DELETE

Execute code before a row removed from the data block is deleted from the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_DELETE, then write code before calling the super.

ON-DELETE

Override default processing for deleting a row removed from the data block from the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_DELETE, then write code instead of calling the super.

POST-DELETE

Execute code after a row removed from the data block is deleted from the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_DELETE, then write code after calling the super.

PRE-UPDATE

Execute code before a row changed in the data block is updated in the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_UPDATE, then write code before calling the super.

ON-UPDATE

Override default processing for updating a row changed in the data block from the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_UPDATE, then write code instead of calling the super.

POST-UPDATE

Execute code after a row changed in the data block is updated in the database during "post" processing

Override the doDML() method in your entity class, and if the operation equals DML_UPDATE, then write code after calling the super.

POST-FORMS-COMMIT

Execute code after Forms has "posted" all necessary rows to the database, but before issuing the data commit to end the transaction

If you want a single block of code for the whole transaction, you can override the doCommit() method in a custom DBTransactionImpl object and write code before calling the super.

To execute entity-specific code before commit for each affected entity in the transaction, override the beforeCommit() method on your entity object, and write code there.

POST-DATABASE-COMMIT

Execute code after database transaction has been committed

Override the commit() method in a custom DBTransactionImpl class, and write code after calling the super.


F.5 Error Handling

Table F-5 ADF Equivalents for Oracle Forms Error Handling Triggers

Forms Trigger ADF Equivalent

ON-ERROR

Override default behavior for handling an error

Install a custom error handler (DCErrorHandler) on the ADF BindingContext.