Find Current

Posted by Alex Hart on 14-Apr-2015 06:14

Something I got used to in other languages is using Find Current to change lock status while in a loop (For Each) 

I think it is much cleaner to change the lock status for this one record and then update and release record, rather than having to define a 2nd buffer, finding the same record in 2nd buffer with exclusive lock and update it.

I would like to be able to do something like this:

FOR EACH Customer NO-LOCK:

    <do logic checks>

   FIND CURRENT Customer EXCLUSIVE-LOCK.

   <do updates>

    RELEASE Customer.

END.

All Replies

Posted by James Palmer on 14-Apr-2015 06:19

DEFINE BUFFER lb-Customer for customer.

FOR EACH Customer NO-LOCK:

   <do logic checks>

  do for lb-customer transaction:

     FIND lb-Customer EXCLUSIVE-LOCK where rowid(lb-customer) eq rowid(customer) no-error.

     <do updates>

  end.

END.

No need to release. It doesn't do what you think it does.

Posted by James Palmer on 14-Apr-2015 06:20

The problem with your code is that even if you could do that it would make the transaction scope wrong and you'd have all sorts of problems.

Posted by Alex Hart on 14-Apr-2015 07:17

James thanks for that, but  I only put the code in as an example :) I know what Release and Validate does and understand buffers and know that this is how progress currently works. But it was not a question on how it is currently done within progress, more a discussion on merits of not having to create a 2nd buffer and then do find on a record you already have in a buffer. A lot of other languages i have worked in allow you to just change the lock status of the record you are busy with, without influencing the outer loop, hence the reason I put the release which in other languages also down grades locks. So my code example was more of how I would like it to work, not how it works. It saves on data base retrievals, saves on memory, ...

RELEASE - Verifies that a record complies with mandatory field and unique index definitions. It clears the record from the buffer and unites it to the database if it has been changed.

VALIDATE - Verifies that a record complies with mandatory field and unique index definitions.

Posted by James Palmer on 14-Apr-2015 07:37

Ah sorry I misread your post. *oops*

I'm not sure I'd want what you propose. I think it would muddy the waters in terms of transaction scoping, and would make code inherently less easy to read as you don't see straight away if a buffer is being updated or not.

Posted by Laura Stern on 14-Apr-2015 07:59

Sorry, but I don’t understand what you’re asking for.  You certainly CAN use FIND CURRENT on the existing FOR EACH buffer.  Though of course the lock will be held till the end of the transaction.   So you could do this:

FOR EACH Customer NO-LOCK:

   DO TRANSACTION:

       FIND CURRENT Customer EXCLUSIVE-LOCK.

       <do updates>    

       RELEASE Customer.

   END.

   /* Here the lock is released.  */

   /* Without the RELEASE, the lock will be downgraded to a SHARE-LOCK. */

END.

So what’s the issue?  

Posted by Tim Kuehn on 14-Apr-2015 08:31

Laura - your example is a bit puzzling as I recall running into situations where trying to change a buffer's lock resulted in a compiler complaint about changing the lock status of a query.

Has this been changed in a recent release?

Posted by Laura Stern on 14-Apr-2015 08:35

I just ran this code and it ran fine.  I don't think it's been changed but couldn't swear to that.

Did you mean compiler complaint or runtime?

Posted by ChUIMonster on 14-Apr-2015 08:42

I get:

 FIND cannot be processed for a FOR EACH mode record. (213)

on 10.2b08

[collapse]On 4/14/15 9:36 AM, Laura Stern wrote:
Reply by Laura Stern

I just ran this code and it ran fine.  I don't think it's been changed but couldn't swear to that.

Did you mean compiler complaint or runtime?

Stop receiving emails on this subject.

Flag this post as spam/abuse.



-- 
Tom Bascom
603 396 4886
tom@greenfieldtech.com
[/collapse]

Posted by Tim Kuehn on 14-Apr-2015 08:45

As I recall, I got a compiler complaint. 

I wrote similar code on my 11.5 W7/64 and it compiled. 

Posted by ChUIMonster on 14-Apr-2015 08:47

In what way does your suggested approach "save database retrievals"?  Or any noticeable amount of memory?

My test code gets the same number of locks either way and it takes slightly more "db access" to use FIND CURRENT than to use a stand-alone buffer.  (I faked the FOR EACH with a DO WHILE to get around the compile error using FIND CURRENT -- but both empty loops result in the same db access impact so it shouldn't matter.)


 
Aside from proper transaction scoping and enforcement at compile time (both of which are pretty darned good reasons) I prefer the named buffer approach because it makes it very explicit that that buffer is being used for updates.

I would not, however prefix it with gibberish such as "lb-".  That is a perversion of "hungarian notation" that utterly misses the point of hungarian notation.

http://www.joelonsoftware.com/articles/Wrong.html

http://optionexplicitvba.com/2014/02/17/its-time-to-say-goodbye-to-hungarian-notation/

http://en.wikipedia.org/wiki/Hungarian_notation

It is particularly useless and stupid in OO code.

Even Microsoft now discourages the use of gibberish.


[collapse]On 4/14/15 8:18 AM, Alex Hart wrote:
Reply by Alex Hart

James thanks for that, but  I only put the code in as an example :) I know what Release and Validate does and understand buffers and know that this is how progress currently works. But it was not a question on how it is currently done within progress, more a discussion on merits of not having to create a 2nd buffer and then do find on a record you already have in a buffer. A lot of other languages i have worked in allow you to just change the lock status of the record you are busy with, without influencing the outer loop, hence the reason I put the release which in other languages also down grades locks. So my code example was more of how I would like it to work, not how it works. It saves on data base retrievals, saves on memory, ...

RELEASE - Verifies that a record complies with mandatory field and unique index definitions. It clears the record from the buffer and unites it to the database if it has been changed.

VALIDATE - Verifies that a record complies with mandatory field and unique index definitions.

Stop receiving emails on this subject.

Flag this post as spam/abuse.



-- 
Tom Bascom
603 396 4886
tom@greenfieldtech.com
[/collapse]

Posted by Jeff Ledbetter on 14-Apr-2015 08:52

In the original pseudo-code, wouldn’t the transaction be scoped to the iteration?  What would the intended transaction scope be?
 
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: James Palmer [mailto:bounce-jdpjamesp@community.progress.com]
Sent: Tuesday, April 14, 2015 6:21 AM
To: TU.OE.General@community.progress.com
Subject: RE: [Technical Users - OE General] Find Current
 
Reply by James Palmer

The problem with your code is that even if you could do that it would make the transaction scope wrong and you'd have all sorts of problems.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by James Palmer on 14-Apr-2015 08:54

Apologies Tom. lb- is a bad habit that's hard to break. It's part of our "coding standards".

Posted by Laura Stern on 14-Apr-2015 08:56

Ah.. Indeed.  This was fixed in 11.4.  You will still get this error if you do a "normal" FIND.  But you will no longer get the error with FIND CURRENT.  

Posted by Laura Stern on 14-Apr-2015 08:57

That last post was of course referring to error:  FIND cannot be processed for a FOR EACH mode record. (213)

Posted by Thomas Mercer-Hursh on 14-Apr-2015 09:40

James, just because Tom wants to rant about what his ideas are for good
naming doesn't mean that you need to apologize for having different
idea. Many of us do and have good reasons for why we think that way.

Posted by ChUIMonster on 14-Apr-2015 09:50

Yeah.

Although it is encouraging to see converts :)

Some day you too may see the light.

On 4/14/15 10:41 AM, Thomas Mercer-Hursh wrote:
Reply by Thomas Mercer-Hursh
James, just because Tom wants to rant about what his ideas are for good
naming doesn't mean that you need to apologize for having different
idea. Many of us do and have good reasons for why we think that way.
Stop receiving emails on this subject.

Flag this post as spam/abuse.



-- 
Tom Bascom
603 396 4886
tom@greenfieldtech.com

This thread is closed