ADF: Using Save Points (Explicit)

You can configure a task flow to capture the state of an ADF application at a particular instance creating what is called a Save Point. This allows you to save application state when, for example, you are creating a new department, and the application state can be restored at a later point.

An explicit save point requires an end user action before a bounded or unbounded task flow creates a save point. For example, an end user clicks a button that invokes a method call activity that, in turn, creates a save point.

In this post, you will learn how to use explicit save point in Oracle ADF 12c (12.1.3).
Download the sample application: ADFSavePointApp.zip.

Create an ADF Fusion Web Application, and call it as ADFSavePointApp.
This application must implement ADF Task Flow with departments data.

adf-using-save-points-explicit1

Configure your application to use save points.
In the Application Resources pane, expand Descriptors > ADF META-INF, and open the adf-config.xml file.
Go to Controller page and click the magnific glass icon near Data Source field, to choose savepoint connection.

adf-using-save-points-explicit2

To use save point, leave the value of the jbo.locking.mode property set to the default value optimistic.

adf-using-save-points-explicit3

A database table named ORADFCSAVPT stores save points. If this database table does not exist, it is created automatically by your ADF application. You may use the following SQL script to create the ORADFCSAVPT database table too.

<MIDDLEWARE_HOME>\oracle_common\common\sql\adfc_create_save_point_table.sql

To create save points, you may use the createSavePoint method exposed by the currentViewPort node of the ADF Controller Objects. The resulting EL expression is similar to the following:

#{controllerContext.currentViewPort.createSavePoint}

I will identify my save points with the departments name, so, I will create a custom method for creating save points.
In the task flow, double-click listSavePoints component.
In the Select Method dialog, click the New button and create a new Managed Bean.

adf-using-save-points-explicit4

In the Select Method dialog, set listSavePoints as method name.

adf-using-save-points-explicit5

Double-click in listSavePoints component to go to bean.
Replace all the file content with the following code:

package br.com.waslleysouza.view.beans;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import oracle.adf.controller.ControllerContext;
import oracle.adf.controller.savepoint.SavePointAttributes;
import oracle.adf.controller.savepoint.SavePointManager;

public class SavePointBean implements Serializable {

  private static final long serialVersionUID = 1L;
    
  private List savePointSelectItems = new ArrayList();

  public SavePointBean() {}

  public List getSavePointSelectItems() {
    return savePointSelectItems;
  }

  public void createSavePoint(String savePointName) {
    ControllerContext cc = ControllerContext.getInstance();
    if (cc != null) {
      SavePointManager mgr = cc.getSavePointManager();
      if (mgr != null) {
        SavePointAttributes spa = new SavePointAttributes(savePointName, savePointName, null);
        String id = mgr.createSavePoint(spa);
        System.out.println("Save point is being set " + id);
      }
    }
  }

  public void listSavePoints() {
    savePointSelectItems.clear();
    ControllerContext cc = ControllerContext.getInstance();
    if (cc != null) {
      SavePointManager mgr = cc.getSavePointManager();
      if (mgr != null) {
        List savePointIdList = mgr.listSavePointIds();
        for (String savePointId : savePointIdList) {
          SavePointAttributes attributes = mgr.getSavePointAttributes(savePointId);
          SelectItem item = new SelectItem(savePointId, attributes.getName());
          savePointSelectItems.add(item);
        }
      }
    }
  }
}

Create the deptView page fragment.
The selectOneChoice component displays all save points.
The button components adds departments and manages save points (Restore and remove).

adf-using-save-points-explicit6

adf-using-save-points-explicit7

Create the deptEditView page fragment.
The button components saves departments and creates save points.

adf-using-save-points-explicit8

adf-using-save-points-explicit9

Click the removeAllSavePoints component and configure it.
It removes all Save Points for the current user.

adf-using-save-points-explicit10

Click the savePointRestore component and configure it.
It restores the save point by id.

adf-using-save-points-explicit11

Click the removeSavePoint component and configure it.
It removes the save point with a given id.

adf-using-save-points-explicit12

Click the createSavePoint component and configure it.
It creates a save point for the current user.

adf-using-save-points-explicit13

Deploy the application and enjoy!
Create a save point.

adf-using-save-points-explicit14

adf-using-save-points-explicit15

adf-using-save-points-explicit16

Restore the save point.

adf-using-save-points-explicit17

Commit the new department (and remove the save point).

adf-using-save-points-explicit18

adf-using-save-points-explicit19

Remove all save points.

adf-using-save-points-explicit20

adf-using-save-points-explicit21

References:
Oracle ADF 12c Documentation
Java API Reference for Oracle ADF 12c

Waslley Souza

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 *