home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Documentation / snippets / cflock.cfm < prev    next >
Encoding:
Text File  |  1999-04-12  |  5.3 KB  |  149 lines

  1. <!------------------------------------------------------------- 
  2.     This example shows how CFLOCK can be used to guarantee the
  3.     consistency of data updates to variables in the Application, 
  4.     Server, and Session scopes. You should copy the following code 
  5.     into an Application.cfm file in the snippets directory. 
  6. --------------------------------------------------------------->
  7.     <HTML>
  8.     <HEAD>
  9.         <title>Define Session and Application Variables</title>
  10.     </HEAD>
  11.     
  12.     <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  13.     <BODY  bgcolor="#FFFFD5">
  14.     
  15.     <H3>CFAPPLICATION Example</H3>
  16.     
  17.     <P>CFAPPLICATION defines scoping for a ColdFusion application and 
  18.     enables or disables the storing of application and/or session
  19.     variables. This tag is placed in a special file called
  20.     Application.cfm that is run before any other CF template in a
  21.     directory where the Application.cfm file appears. This is a read-
  22.     only example to ensure that you create your own Application.cfm
  23.     file according to the needs of your site.
  24.  
  25.     <!------------------------------------------------------------- 
  26.     
  27.     <CFAPPLICATION NAME="ETurtle" SESSIONTIMEOUT="60"
  28.     SESSIONMANAGEMENT="yes">
  29.     <!------------------------------------------------------------- 
  30.     Initialize the session and application variables that will be 
  31.     used by E-Turtleneck. Use the session lock for the session variables.
  32.     The member variable sessionID creates the session name for you.
  33.     ---------------------------------------------------------------> 
  34.  
  35.     <CFLOCK Name="#session.sessionID#" timeout="30" Type ="Exclusive">
  36.         <CFIF NOT IsDefined("session.size")>
  37.             <CFSET session.size = "">
  38.         </CFIF>
  39.         <CFIF NOT IsDefined("session.color")>
  40.             <CFSET session.color = "">
  41.         </CFIF>
  42.     </CFLOCK>
  43.     
  44.     <!---------------------------------------------------------------- 
  45.     Use the application lock for the application variable. This
  46.     variable keeps track of the total number of turtlenecks sold. The
  47.     application lock should have the same name as specified in the 
  48.     CFAPPLICATION tag. 
  49.     ------------------------------------------------------------------->
  50.     
  51.     <CFLOCK Name="application.applicationName" Timeout="30"
  52.     Type="Exclusive">
  53.         <CFIF NOT IsDefined("application.number")>
  54.             <CFSET application.number = 1>
  55.         </CFIF>
  56.     </CFLOCK>
  57.     <CFLOCK Name="application.applicationName" Timeout="30" 
  58.     Type ="ReadOnly">
  59.         <CFOUTPUT>
  60.         E-Turtleneck is proud to say that we have sold
  61.         #application.number# turtlenecks to date.
  62.         </CFOUTPUT>
  63.     </CFLOCK>
  64. --------------------------------------------------------------->     
  65. <!--- End of Application.cfm --->
  66.  
  67. <HEAD>
  68. <TITLE>
  69. CFLOCK Example
  70. </TITLE>
  71. </HEAD>
  72.  
  73. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  74. <BODY  bgcolor="#FFFFD5">
  75.  
  76. <H3>CFLOCK Example</H3>
  77. <!---------------------------------------------------------------------
  78. <CFIF IsDefined("form.submit")>
  79.     <!-----------------------------------------------------------------
  80.      Lock session variable sessionID. Note that the sessionID member 
  81.      variable becomes the order number. 
  82.     ------------------------------------------------------------------->
  83.     <CFLOCK Name="#session.sessionID#" timeout="30" Type="ReadOnly">
  84.         <CFOUTPUT>
  85.         Thank you for shopping E-Turtleneck. Today you have
  86.         chosen a turtleneck in size <b>#form.size#</b> and in the color
  87.         <b>#form.color#</b>. Your order number is #session.sessionID#.
  88.         </CFOUTPUT>
  89.     </CFLOCK>
  90.     
  91.     <!----------------------------------------------------------------- 
  92.      Lock session variables to assign form values to them. 
  93.      To lock session variables, you should get the session ID with
  94.      the sessionID member variable. 
  95.     -------------------------------------------------------------------> 
  96.     <CFLOCK Name="#session.sessionID#" timeout="30" Type="Exclusive">
  97.         <CFPARAM Name=session.size Default=#form.size#>
  98.         <CFPARAM Name=session.color Default=#form.color#>
  99.     </CFLOCK>
  100.     
  101.     <!------------------------------------------------------------------ 
  102.     Lock application variable application.number to find the total number 
  103.     of turtlenecks sold. If you do not know the name of the application,
  104.     you can use the member variable applicationName to get it. 
  105.     -------------------------------------------------------------------> 
  106.     <CFLOCK Name="#application.applicationName#" Timeout="30" Type="Exclusive">
  107.         <CFSET application.number = application.number + 1>
  108.     </CFLOCK>
  109.     
  110. <CFELSE><!--- Show the form only if it has not been submitted. --->
  111.  
  112. <FORM ACTION="cflock.cfm" METHOD="POST">
  113.  
  114. <P>Congratulations! You have just selected the longest wearing, most comfortable turtleneck in the world. Please indicate the color and size that you wish to buy.</P> 
  115. <table cellspacing="2" cellpadding="2" border="0">
  116. <tr>
  117.     <td>Select a color.</td>
  118.     <td><SELECT TYPE="Text" NAME="color">
  119.         <OPTION>red
  120.         <OPTION>white
  121.         <OPTION>blue
  122.         <OPTION>turquoise
  123.         <OPTION>black
  124.         <OPTION>forest green
  125.         </SELECT>
  126.     </td>
  127. </tr>
  128. <tr>
  129.     <td>Select a size.</td>
  130.     <td><SELECT TYPE="Text" NAME="size" >
  131.         <OPTION>XXsmall
  132.         <OPTION>Xsmall
  133.         <OPTION>small
  134.         <OPTION>medium
  135.         <OPTION>large
  136.         <OPTION>Xlarge
  137.         </SELECT>
  138.     </td>
  139. </tr>
  140. <tr>
  141.     <td>Press Submit when you are finished making your selection.</td>
  142.     <td><INPUT TYPE="Submit" NAME="submit" VALUE="Submit"> 
  143.     </td>
  144. </tr>
  145. </table>
  146. </FORM>
  147. </CFIF>
  148. ------------------------------------------------------------------->
  149. </HTML>