12 Replies Latest reply on Jun 18, 2012 11:57 AM by 933071

    Update without No wait

    Sam
      I think ADF by default perform update in NOWAIT mode. So we get below exception when the row is locked :

      "JBO-26030: Failed to lock the record, another user holds the lock."

      I have a requirement where i want to wait for the Lock to be released without any exception.

      I tried making the locking as "Pessimistic" but thats not working .

      Is there a way to override the update behavior ? please suggest.


      -Sam
        • 1. Re: Update without No wait
          John Stegeman
          Sam,

          Pessimistic locking would be a horrible idea for a web application.

          You could try overriding the lock() method for your Entity Object to do something like this (be sure to change to meet your requirements):
            public void lock()
            {
              int tries = 0;
              boolean got_the_lock = false;
              int MAX_TRIES = 5;
          
              while ((++tries <= MAX_TRIES) && !got_the_lock)
              {
                try
                {
                  super.lock();
                  got_the_lock = true;
                }
                catch (AlreadyLockedException t)
                {
                  try
                  {
                    Thread.sleep(2000); //wait for 2 seconds
                  }
                  catch (InterruptedException e)
                  {
                    // ignore
                  }
                }
              }
          
              if (!got_the_lock)
              {
                throw new AlreadyLockedException(new Exception());
              }
            }
          This will try for 10 seconds to get the lock, and if it doesn't get it - it behaves as before.

          John
          1 person found this helpful
          • 2. Re: Update without No wait
            ramandeep singh - oracle
            or you can make locking made optimistic.
            • 3. Re: Update without No wait
              Timo Hahn
              @Ramandeep this is not what the op is asking for as optimistic locking will give you an other error (check Chris Muir's blog [url https://blogs.oracle.com/onesizedoesntfitall/entry/the_case_of_the_phantom]The case of the phantom ADF developer (and other yarns))

              Timo
              • 4. Re: Update without No wait
                ramandeep singh - oracle
                In that case he might get a row is already updated exception yes. But the row would not be locked and he can always handle it by refreshing the state from database.

                See this http://www.avromroyfaderman.com/2008/05/bring-back-the-hobgoblin-dealing-with-rowinconsistentexception/
                {thread:id=2346875}

                But in any case it is always recommended not to use pessimistic locking for a web app.
                • 5. Re: Update without No wait
                  John Stegeman
                  Yes, it would be exceedingly rare to get the "another user holds the lock" error in an optimistic locking situation. The only two cases I can think of:

                  1). Someone else is literally committing a change to the same row a split second before you are (and thus, the record is locked)
                  2). Some other application/session (not your ADF web app) is holding the lock

                  John
                  • 6. Re: Update without No wait
                    Sam
                    John ,

                    Really appreciate your reply.

                    So there is no default settings/behavior available to get this working.

                    My case :
                    Legacy application : Updating a row.
                    ADF/SOA application : Updating same row at the same time.

                    We want ADF/SOA to keep waiting for the lock.
                    Currently i am handling this by my custom code similar to what you have suggested to retry 3 times with an interval of 5 sec.

                    And yes Locking mode at AM -> pessimistic/optimistic doesn't help in this case.

                    Thanks once again.

                    -Sam
                    • 7. Re: Update without No wait
                      ramandeep singh - oracle
                      Tell me how will this work.

                      Your legacy application is updating the same record at x time and you want to update that record from web application at same time ? why?
                      • 8. Re: Update without No wait
                        Sam
                        @Ramandeep Nanda

                        Thats how the applications are working.

                        Legacy application : Dropping data using batch process to transaction DB (issues updates)
                        Web App/SOA : Updates the record while communicating to third party.

                        There are rare scenarios when Legacy application updates the record and before it could commit , the new app also tries to update the same row and we get this exception.

                        -Sam
                        • 9. Re: Update without No wait
                          Sam
                          John,

                          I implemented the way you mentioned with a small modification :

                          catch(RowInconsistentException e)
                          {
                          log("------- Inside RowInconsistentException");
                          refresh(REFRESH_WITH_DB_ONLY_IF_UNCHANGED|REFRESH_CONTAINEES);
                          }

                          This solves my purpose , do you think i am doing it the right way, any repercussions of this ?

                          Thanks again
                          - Sam

                          Edited by: Sam on Mar 28, 2012 12:01 PM
                          • 10. Re: Update without No wait
                            John Stegeman
                            If it does what you want it to, then go for it. However, I'm not convinced it does what you want it to. Here's what it does:

                            If the row in the DB has changed since the user of your app read the row then refresh from the DB; however the [url http://docs.oracle.com/cd/E16162_01/apirefs.1112/e17483/oracle/jbo/Row.html#REFRESH_WITH_DB_ONLY_IF_UNCHANGED]doc for REFRESH_WITH_DB_ONLY_IF_UNCHANGED says:
                            When using this refresh mode, if the locking mode is optimistic, the framework could bring the latest data for unmodified attributes and merge them into the row, while retaining changed attributes as is. However, this could lead to data integrity problems. Thus, for consistency sake and data integrity, we leave the row alone if it was modified even for optimistic locking mode.
                            So, I'd say this doesn't appear to be a great idea

                            John
                            • 11. Re: Update without No wait
                              933071
                              restrict opening of the record from search itself .
                              • 12. Re: Update without No wait
                                933071
                                restrict opening of the record from search itself .