home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / mts4.cab / Account.VJ_Account_UpdateReceipt.java < prev    next >
Text File  |  1997-11-14  |  3KB  |  115 lines

  1. // Filename: UpdateReceipt.java
  2. //
  3. // Description: Declaration of UpdateReceipt
  4. //
  5. // This file is provided as part of the Microsoft Transaction Server
  6. // Software Development Kit
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT 
  9. // WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
  10. // INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
  11. // OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR 
  12. // PURPOSE.
  13. //
  14. // Copyright (C) 1997 Microsoft Corporation, All rights reserved
  15.  
  16. package Account;
  17.  
  18. import com.ms.mtx.*;
  19. import com.ms.com.*;
  20. import msado15.*;
  21.  
  22. import accountlib.*;
  23.  
  24.  
  25. public class UpdateReceipt implements IUpdateReceipt {
  26.     
  27.     public static final String CLSID = "c25e3b4a-e902-11d0-b5be-00c04fb957d8";
  28.  
  29.     // Update() performs error handling for TrueUpdate().  If TrueUpdate() throws an 
  30.     // exception, then Update() will call SetAbort() and pass the exception up 
  31.     // to the caller.  Otherwise, Update() will simply call SetComplete() and return.
  32.  
  33.     public int Update () throws ComFailException {
  34.  
  35.         int result;
  36.         boolean bSuccess = false;
  37.  
  38.         // First of all, get the object context
  39.         IObjectContext ctxObject = MTx.GetObjectContext();
  40.  
  41.         try {
  42.             // Call the true function
  43.             result = trueUpdate ();
  44.  
  45.             bSuccess = true;
  46.             return result;
  47.         }
  48.  
  49.         // Upon exit, always call SetComplete if happy, or SetAbort if unhappy.
  50.         // We do this because we never save state across method calls.
  51.         finally {
  52.             if (bSuccess)
  53.                 ctxObject.SetComplete();
  54.             else
  55.                 ctxObject.SetAbort();
  56.         }
  57.     }
  58.  
  59.  
  60.     // trueUpdate() is the function that performs the actual work for the Account class.
  61.     // If an error occurs during execution, it will throw a ComFailException for Update()
  62.     // to handle.
  63.     private int trueUpdate () throws ComFailException {
  64.         
  65.         _Connection adoConn = null;
  66.         _Recordset adoRsReceipt = null;
  67.         Field pField = null;
  68.         Fields pFields = null;
  69.  
  70.         try {
  71.             // Create ADOConnection object and initialize the connection
  72.             adoConn = (_Connection) new Connection();
  73.             String vDSN = "FILEDSN=MTSSamples";
  74.             adoConn.Open (vDSN, null, null, CommandTypeEnum.adCmdUnspecified);
  75.             
  76.             // Obtain the desired recordset with an SQL query
  77.             Variant    vAdoNull = new Variant();
  78.  
  79.             String strSQL = "Update Receipt set NextReceipt = NextReceipt + 100";
  80.             adoConn.Execute (strSQL, vAdoNull, - 1);
  81.  
  82.             strSQL = "Select NextReceipt from Receipt";
  83.             adoRsReceipt = adoConn.Execute (strSQL, vAdoNull, - 1);
  84.             
  85.             // Get the appropriate fields
  86.             pFields = adoRsReceipt.getFields();
  87.             
  88.             // Get the appropriate field
  89.             Variant vField = new Variant();
  90.             Variant lngNextReceipt = new Variant();
  91.             vField.putString ("NextReceipt");
  92.             
  93.             pField = pFields.getItem(vField);
  94.             lngNextReceipt = pField.getValue();
  95.             
  96.             return lngNextReceipt.getInt();
  97.         }
  98.  
  99.         finally {
  100.             // cleanup that needs to occur whether we leave via a return or an exception.
  101.             if (adoRsReceipt != null) {
  102.                 if (adoRsReceipt.getState() == ObjectStateEnum.adStateOpen)
  103.                     adoRsReceipt.Close();
  104.                 ComLib.release (adoRsReceipt);
  105.             }
  106.  
  107.             if (adoConn != null) {
  108.                 if (adoConn.getState() == ObjectStateEnum.adStateOpen)
  109.                     adoConn.Close();
  110.                 ComLib.release (adoConn);
  111.             }
  112.         }
  113.     }
  114. }
  115.