Recover deleted rows without using rollback

Environment (JDeveloper 11.1.1.5.0, ADF BC and ADF Faces)

In many cases developers want to cancel an edit form without using rollback action. Frank Nimphius has implemented this functionality using Java  in this example   006.  How to cancel an edit form, undoing changes in Java. However, this method falls a bit short when a record was deleted and now needs to be recovered. In this example I will explain how to  recover  the deleted rows without using rollback.

In my case I have a table called TEST in my database schema, and I have already created BC (Entity object, View object, Application module). The steps to implement this use case are:

  1. generate the TestImpl class for our TEST entity.
  2. override the remove method in  TestImpl class as shown below:    
    public void remove() {

            refresh(REFRESH_WITH_DB_FORGET_CHANGES);
            super.remove();
        }
  3. generate TestViewImpl  class.
  4. add this method to TestViewImpl class.    
    public void undoDelete(){
    Iterator iterator =
    getEntityDef(0).getAllEntityInstancesIterator(getDBTransaction());
    while (iterator.hasNext()) {
    TestImpl test = (TestImpl)iterator.next();
    if (test.getEntityState() == test.STATUS_DELETED) {
    test.revert();
    }
    }
    executeQuery();
    }
  5. add undoDelete() method to view object client interface, as shown in figure below. The client interface contains the methods from view object class that are available for clients using this object.

    Add client interface

  6. create a page and drag and drop the TestView1 from the data control as ADF table in the page.
  7. add an extra column to the table, then go to the data control, expand TestView1, expand the operation folder, drag and drop removeRowWithKey operation into the newly created column, set the parameter for removeRowWithKey operation to this expression value #{row.rowKeyStr} as shown below.

    removeRowWithKey action

  8. again from the data control, expand TestView1, you should see undoDelete() method as shown below, drag and drop it in the page as a button or a link.

    undoDelete() method

  9. run the page and enjoy with testing.


Advertisements

8 Comments

Filed under ADF

8 responses to “Recover deleted rows without using rollback

  1. Nigel Thomas

    Hi Mohd. Jabr,
    As you had replied to my post in https://forums.oracle.com/forums/message.jspa?messageID=10250371#10250371, I tried out and the method is retrieving the deleted rows using the button action.
    But I need to access the method from a managed bean, well , which is not happening and I am writing this comment here .
    Can you suggest a solution to this problem?
    Thanks,
    Nigel.

    • Mohammad Jabr

      Hello Nigel,
      In step 8, after you add the button to your page, double click on the button and Jdeveloper will prompt you to create an action method in your bean, select your bean or create a new one if not exist, and enter a name for your method.
      you will get something like this in your bean:
      public BindingContainer getBindings()
      {
      return BindingContext.getCurrent().getCurrentBindingsEntry();
      }
      public String undoDelete()
      {
      BindingContainer bindings = getBindings();
      OperationBinding operationBinding = bindings.getOperationBinding("undoDelete");
      Object result = operationBinding.execute();
      if (!operationBinding.getErrors().isEmpty())
      {
      return null;
      }
      return null;
      }

  2. Nigel Thomas

    Hi Jabr,
    I had tried doing as you told, but it is showing some Error in the Page like :

    ADF: Adding the following JSF error message: 1
    java.lang.ArrayIndexOutOfBoundsException: 1
    at oracle.jbo.server.ViewDefImpl.getEntityDef(ViewDefImpl.java:1939)
    at oracle.jbo.server.ViewObjectImpl.getEntityDef(ViewObjectImpl.java:6088)
    at oracle.insurance.viking.questionnaire.model.view.VikQuestionResponseVOImpl.undoDelete(VikQuestionResponseVOImpl.java:24)

    Sorry for messing up your page.

    Can you give any solution to this problem.

    Thanks,
    Nigel.

    • Mohammad Jabr

      you have an exception thrown in
      VikQuestionResponseVOImpl.undoDelete method
      specifically at line# 24.
      you can debug your code to detect the exception cause.

      • Nigel Thomas

        Yes Jabr,That’s the problem. In the line 24 of the undoDelete() the code is :
        Iterator iterator = getEntityDef(1).getAllEntityInstancesIterator(getDBTransaction());

        So it not being able to execute the rest of the lines in the method , since its throwing exception at that line.

  3. Divya

    Thanks a lot, for the post, it helped me solve my long lasting issue with deleted row. 🙂

    Divya.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s