Create Framework Extension Class in ADF

Tweet about this on TwitterShare on Facebook0Share on LinkedIn7Share on Google+0

Create Framework Extension Class of some base classes is a good practice when you are building ADF applications. Some reasons to create Framework Extension Classes are:

  • Coding a generic functionality. For example, create a method that call Database Sequence and all Entity Objects may use it.
  • Change how a built-in feature works. For example, change the doDML() method to update a deleted flag when an Entity Row is removed (Logical Delete).
  • Workaround a bug.

A common set of customized framework base classes are:

  • public class CustomEntityImpl extends EntityImpl
  • public class CustomEntityDefImpl extends EntityDefImpl
  • public class CustomViewObjectImpl extends ViewObjectImpl
  • public class CustomViewRowImpl extends ViewRowImpl
  • public class CustomApplicationModuleImpl extends ApplicationModuleImpl
  • public class CustomDBTransactionImpl extends DBTransactionImpl2
  • public class CustomDatabaseTransactionFactoryImpl extends DatabaseTransactionFactory

You also may create the following customized framework base classes, but rarely you will override anything in these classes.

  • public class CustomViewDefImpl extends ViewDefImpl
  • public class CustomEntityCache extends EntityCache
  • public class CustomApplicationModuleDefImpl extends ApplicationModuleDefImpl

Create Framework Extension Class

Let’s change the doDML() method to update a deleted flag when an Entity Row is removed (Logical Delete). For this, we will need to create the CustomEntityImpl Framework Extension Class that extends EntityImpl.
Download the sample application: ADFFrameworkExtensionClassApp.zip.

In the Applications window, right-click the Model project and choose New > From Gallery.
In the New Gallery, choose General > Java > Class and click OK.
In the Create Java Class dialog, specify the following values and click OK.

  • Name: CustomEntityImpl
  • Package: br.com.waslleysouza.model.adfbc.base
  • Extends: oracle.jbo.server.EntityImpl

create-framework-extension-class-adf1

In the CustomEntityImpl class, we will override two methods:

  • remove(): To set the deleted flag before calling the super.remove() method.
  • doDML(): To force the Entity Object to be updated instead of deleted.

Replace the content of Java class with the following code:

package br.com.waslleysouza.model.adfbc.base;

import oracle.jbo.server.EntityImpl;
import oracle.jbo.server.TransactionEvent;

public abstract class CustomEntityImpl extends EntityImpl {
  @Override
  public void remove() {
    setDeleted("Y");
    super.remove();
  }

  @Override
  protected void doDML(int operation, TransactionEvent transactionEvent) {
    if (operation == DML_DELETE) {
      operation = DML_UPDATE;
    }
    super.doDML(operation, transactionEvent);
  }

  public abstract void setDeleted(String value);
}

create-framework-extension-class-adf2

Add a new DELETED column to the COUNTRIES table.

ALTER TABLE COUNTRIES ADD (DELETED CHAR(1));

It is necessary to syncronize the Countries Entity Object with Database.
In the Applications window, right-click the Countries Entity Object and choose Syncronize with Database.
Click the Syncronize All button, and then click Yes.

create-framework-extension-class-adf3

To implement the setDeleted() method, we will need to generate the CountriesImpl class.
In the Applications window, and double-click the Countries Entity Object.
Click the Java navigation tab and then click the Edit Java Classes button.
In the Select Java Options dialog, select these options: Generate Entity Object Class and Accessors.

create-framework-extension-class-adf4

Click the Classes Extend button.
In the Override Base Classes dialog, replace the content of Row field:

br.com.waslleysouza.model.adfbc.base.CustomEntityImpl

create-framework-extension-class-adf5

As you can see, the setDeleted() method was created.

create-framework-extension-class-adf6

Just like that!
Now, if you run the Oracle ADF Model Tester and delete any country, the DELETED column is updated.

create-framework-extension-class-adf7

create-framework-extension-class-adf8

Bonus

You may change the preferences and define the Framework Extension Classes for all New Components.
These preferences do not affect any existing components in the project.

create-framework-extension-class-adf9

Tweet about this on TwitterShare on Facebook0Share on LinkedIn7Share on Google+0

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.

Leave a Reply

Your email address will not be published. Required fields are marked *