LPARAMETER toDataRec LOCAL lnLastArea lnLastArea = SELECT() SELECT (THIS.cAlias) GATHER NAME toDataRec MEMO SELECT (lnLastArea)The Save should look something like this:
LPARAMETER tlForce LOCAL lnRecNo THIS.ClearError() lnRecNo = RECNO(THIS.cAlias) IF NOT TABLEUPDATE( .T., tlForce, THIS.cAlias ) && Update all records THIS.cError = THIS.GetErrorMessage() THIS.lError = .T. ENDIF IF lnRecNo > 0 AND lnRecNo < RECCOUNT(THIS.cAlias) GOTO (lnRecNo) IN (THIS.cAlias) ENDIF RETURN NOT THIS.lErrorThe business class has a UpdateData() and SaveData() method with code something like this:
LOCAL loRS,llReturn,loDataObject llReturn = .F. THIS.ClearError() DODebug('About to save...') loDataObject = THIS.GetDataObject() IF VARTYPE(loDataObject) = 'O' IF THIS.UpdateRecord() AND THIS.ValidateBusinessRules() IF loDataObject.SAVE() llReturn = .T. THIS.oData = loDataObject.GETRS() ELSE loDataObject.REVERT() ENDIF ENDIF ENDIF RETURN llReturn AND NOT THIS.lErrorUpdateData method – base_business_data
LOCAL llReturn,loDataObject,loRS llReturn = .T. loDataObject = THIS.GetDataObject() *DoDebug('We are in the UpdateRecord method...') IF NOT loDataObject.lEOF loRS = loDataObject.GetRS() IF VARTYPE(THIS.oData) = 'O' ; AND NOT THIS.CompareRS(loRS ,THIS.oData) ; AND (VARTYPE(loRS.ID)='C' OR loRS.ID = THIS.oData.ID) THIS.Set_Dependence() IF PEMSTATUS(THIS.oData,'edit_userid',5) THIS.oData.edit_userid = THIS.cCurrentUser ENDIF IF PEMSTATUS(THIS.oData,'edit_date',5) THIS.oData.edit_Date = DATETIME() ENDIF llReturn = loDataObject.SetRS(THIS.oData) IF THIS.lPopulateArray THIS.PopulateArray() ENDIF ENDIF ENDIF RETURN llReturn AND NOT THIS.lErrorNow the above code only takes into account a single data object being involved which is rarely the case. Here is a sample of a more complex SaveData() method which answers your question about Transactions. My base business class has a BeginTransaction, CommitTransaction and RollbackTransaction method. I included the BeginTransaction code below:
LOCAL llReturn *DoDebug('We are in the save of business object '+THIS.Name) IF THIS.UpdateRecord() LOCAL loTran,loDockTran,loDetail,loEmployee,; loDist,loEmployeeSick,loEmployeeVacation loTran = THIS.GetDataObject() IF NOT EMPTY(THIS.cDataClass_Dist) loDist = EVAL('THIS.o'+THIS.cDataClass_Dist) ENDIF IF NOT EMPTY(THIS.cDataClass_Dock) loDockTran = EVAL('THIS.o'+THIS.cDataClass_Dock) ENDIF IF NOT EMPTY(THIS.cDataClass_Detail) loDetail = EVAL('THIS.o'+THIS.cDataClass_Detail) ENDIF IF NOT EMPTY(THIS.cDataClass_Employee) loEmployee = EVAL('THIS.o'+THIS.cDataClass_Employee) ENDIF IF NOT EMPTY(THIS.cDataClass_Employee_Sick) loEmployeeSick = EVAL('THIS.o'+THIS.cDataClass_Employee_Sick) ENDIF IF NOT EMPTY(THIS.cDataClass_Employee_Vacation) loEmployeeVacation = EVAL('THIS.o'+THIS.cDataClass_Employee_Vacation) ENDIF THIS.BeginTransaction() IF VARTYPE(loTran) = 'O' llReturn = loTran.SAVE() ENDIF IF llReturn AND VARTYPE(loDist) = 'O' llReturn = loDist.SAVE() ENDIF IF llReturn AND VARTYPE(loDockTran) = 'O' llReturn = loDockTran.SAVE() ENDIF IF llReturn AND VARTYPE(loDetail) = 'O' llReturn = loDetail.SAVE() ENDIF IF llReturn AND VARTYPE(loEmployee) = 'O' llReturn = loEmployee.SAVE() ENDIF IF llReturn AND VARTYPE(loEmployeeSick) = 'O' llReturn = loEmployeeSick.SAVE() ENDIF IF llReturn AND VARTYPE(loEmployeeVacation) = 'O' llReturn = loEmployeeVacation.SAVE() ENDIF IF llReturn THIS.oData = loTran.GetRS() IF VARTYPE(loEmployee) = 'O' THIS.oEmployeeData = loEmployee.GetRS() ENDIF THIS.CommitTransaction() ELSE THIS.RollBackTransaction() ENDIF ENDIF RETURN llReturn AND NOT THIS.lErrorThe business class BeginTransaction code iterates through the data objects and calls the BeginTransaction method for each connection used. Depending on the connection class – VFP, Oracle, MS SQL Server the required code is executed for a transaction to begin.
*BeginTransaction method – base_business_class LOCAL lcConnectionsProcessed,llReturn lcConnectionsProcessed = '' llReturn = .f. LOCAL loDataObject WITH THIS FOR EACH loDataObject IN .CONTROLS IF NOT loDataObject.oConnection.NAME + ',' $ lcConnectionsProcessed lcConnectionsProcessed = lcConnectionsProcessed + loDataObject.oConnection.NAME + ',' llReturn = loDataObject.oConnection.BeginTransaction(THIS.DataSessionID) ENDIF ENDFOR ENDWITH RETURN llReturnLots of code I know… It is not meant to be the answer just a sample to give you some ideas.
>business.Save() > >SELECT (calias) >SCATTER NAME THIS.oData MEMO > >if TABLEUPDATE(.t.,.f.,calias) > return .t. >else > **error handle > return .f. >endif > >>