Skip to main content
Participant
May 8, 2017
Question

Using CFLOCK for data Integrity

  • May 8, 2017
  • 1 reply
  • 531 views

I plan to run the following two processes. In order to maintain data consistency I plan to use CFLOCK. I've never use CFLOCK in the past and not sure if this is going to work in maintaining data integrity. Please advise.

   <cflock scope = "Session" timeout = "30" type = "Exclusive">    

            <cfexecute name="SomeName" arguments ="#PathToFile#  #PathToLogfile#" errorFile="#PathToErrorFileLog#" outputFile="#PathToOutPutFileLog#"

             timeout="300></cfexecute>

       

            <cfquery name="UpdateUserID">

              Update TempTable

              SET UserID = '#session.userid#'

              WHERE NVL(userid,' ') = ' '

           </cfquery>

     </cflock>

cfexecute is inserting data from a text file into a temp table.

There is one column in temp table that is not in the text file and that column is UserId column.

Aftr Oracle sqlldr inserting all data from text file to the temp table, I update userid column in temp table to the session.userid. This way I know who own the data after the process is done.

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
May 16, 2017

sylviam23155084 wrote:

..update userid column in temp table to the session.userid. This way I know who own the data after the process is done.

You apparently want that no two users should be able to access the code simultaneously. If so, then you should perhaps not be using the session lock. A session lock prevents two separate requests in the same user-session from accessing the code simultaneously.

You could use a named lock. For example,

<cflock name = "someUniqueName" timeout = "30" type = "Exclusive">

<cfexecute>

</cfexecute>

<cfquery>

</cfquery>

</cflock>

A good reference is: https://www.raymondcamden.com/2011/05/16/Why-and-how-to-lock-file-operations-in-ColdFusion