hongji.li
2023-11-07 1a1ba3ad5ed9e4380185aa1ccad20204a0e5f115
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Quintiq file version 2.0
#parent: #root
StaticMethod DoFinalizeDataset (stream[JSON] streamsuccess, LibOpt_Task task, output Boolean hascreatedstream_o) as stream[JSON]
{
  Description:
  [*
    Finalize the dataset copies that were created on this component.
    In `DoFinalizeDatasetCopyDelete` the `DeleteCondition` of each dataset copy is checked and the dataset is deleted if needed.
    In `DoFinalizeDatasetCopyChangeToStandAlone` all the remaining (memory only) dataset copies are converted to stand-alone datasets.
  *]
  TextBody:
  [*
    // evr3 Jun-30-2020 (created)
    // If component X is linked to a previous component by using a TaskTransporterOneTransaction, then DoFinalize is not called when an error occurs during the execution of component X.
    // Therefore, when an error is thrown, all dataset copies that were created before this error are handled in LibOpt_CurrentTransaction::HandleQuillError.
    // If component X is linked to a previous component by using a TaskTransporterReactive, then the DoFinalize method of this component is still executed. 
    // In this case, a dataset that is created on the 'Finalize' component position still needs to be handled.
    // In DoFinalizeDatasetCopyDelete and DoFinalizeDatasetCopyChangeToStandAlone we ensure that we do not double check the dataset copies that were already checked in HandleQuillError.
    
    // For performance reasons, we only want to start a reactive call (and hence a new transaction) 
    // if any LibOpt_SnapshotReplannableCopyDataset (for which HasExecutedDoFinalizeDatasetCopyDelete is still false) exists on this task.
    if( exists( task,
                SnapshotComponent.Children.astype( LibOpt_SnapshotReplannableCopyDataset ), 
                snapshot, 
                not snapshot.IsDatasetDeletedByOptimizer() 
                and not snapshot.HasFailedToCreateDataset()
                and not snapshot.HasExecutedDoFinalizeDatasetCopyDelete()
                )    
       )
    {
      if( not task.Run().InOneTransaction() )
      {
        streamsuccess := streamsuccess
                         ->|task->LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyDelete( false )
                         ->|task->LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyChangeToStandAlone()
                         ->|streamsuccess;
        hascreatedstream_o := true;
      }
      else
      {
        LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyDelete( task, false );   
        // Convert all memory-only datasets that are not deleted to standalone datasets.
        LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyChangeToStandAlone( task );
      }
    }
    
    return streamsuccess;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}