Thursday, June 21, 2012

Override EntityImpl Lock


One of the common exception that we face in ADF is :
" JBO-26030: Failed to lock the record, another user holds the lock "
A lot has been written and explained about this , In a simple implementation below is how i resolved this by overriding the lock () method in EntityImpl

Tries 3 times after  a gap of 10 sec for trying to get the lock.

        while ((++tries <= 3) && !islock)
        {
          try
          { super.lock();  islock = true; }
             catch (AlreadyLockedException a)
             { try
                { Thread.sleep(10000); }catch (InterruptedException e){e.printStackTrace();}
                }catch(RowInconsistentException e){
                refresh(REFRESH_WITH_DB_ONLY_IF_UNCHANGED|REFRESH_CONTAINEES);
            }
         }
   
        if (!islock)  throw new AlreadyLockedException(new Exception());

More explanation can be found at :
https://blogs.oracle.com/onesizedoesntfitall/entry/the_case_of_the_phantom