Kbase P24492: How to update parent and children records in one transaction.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Unverified
GOAL:
How to update parent and children records in one transaction.
FIX:
The following details one possible solution in case you need to update one record in an SDO, and at the same time commit the changes for several children records in a related SDO.
Let's assume we have an SDO on table customer (h_SDOcust), which is linked via a Data SmartLink to another SDO, on table order (h_SDOorder). A CommitPanel is already linked to the main SDO (h_SDOcust), and you want that any time you press Commit in the CommitPanel, not only all pending modifications for the SDO on table customer is committed, but also all modifications on table order.
All the following code changes have to be done on the main SDO.
1) Write an endTransactionValidate procedure, that will RUN commitTransaction in the related SDO's.
PROCEDURE endTransactionValidate:
DEFINE VARIABLE cDataTargets AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hTarget AS HANDLE NO-UNDO.
{get DataTarget cDataTargets}.
DO iCount = 1 TO NUM-ENTRIES(cDataTargets):
ASSIGN hTarget = WIDGET-HANDLE(ENTRY(iCount, cDataTargets)).
/* Among Data Targets there might be objects other than SDO's;
put the NO-ERROR clause so that we fail silently in those cases */
RUN commitTransaction IN hTarget NO-ERROR.
END.
END PROCEDURE.
2) Write an override for undoTransaction, so that it will RUN undoTransaction for all related SDO's.
PROCEDURE undoTransaction:
DEFINE VARIABLE cDataTargets AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hTarget AS HANDLE NO-UNDO.
/* Code placed here will execute PRIOR to standard behavior. */
RUN SUPER.
/* Code placed here will execute AFTER standard behavior. */
{get DataTarget cDataTargets}.
DO iCount = 1 TO NUM-ENTRIES(cDataTargets):
ASSIGN hTarget = WIDGET-HANDLE(ENTRY(iCount, cDataTargets)).
/* Among Data Targets there might be objects other than SDO's;
put the NO-ERROR clause so that we fail silently in those cases */
RUN undoTransaction IN hTarget NO-ERROR.
END.
END PROCEDURE.
3) Write an override for initializeObject, and set the AutoCommit attribute to FALSE for both SDO's.
PROCEDURE initializeObject:
DEFINE VARIABLE cDataTargets AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hTarget AS HANDLE NO-UNDO.
/* Code placed here will execute PRIOR to standard behavior. */
RUN SUPER.
/* Code placed here will execute AFTER standard behavior. */
{get DataTarget cDataTargets}.
DO iCount = 1 TO NUM-ENTRIES(cDataTargets):
ASSIGN hTarget = WIDGET-HANDLE(ENTRY(iCount, cDataTargets)).
/* Among Data Targets there might be objects other than SDO's;
put the NO-ERROR clause so that we fail silently in those cases */
DYNAMIC-FUNCTION('setAutoCommit' IN hTarget, FALSE) NO-ERROR.
END.
END PROCEDURE.
At this point, when you press Commit or Undo in the CommitPanel, the action will be propagated to the secondary SDO (h_SDOorder).