haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
MethodOverride DeleteCondition (LibOpt_Task task) as Boolean
{
  Description:
  [*
    Conditionally deletes the dataset copy that is attached to the `snapshotcopydataset` snapshot.
    The dataset is deleted if no dataset copy has been created on any downstream component and if no dataset copy has been created after the creation of the `snapshotcopydataset` snapshot on this component.
    Note: All dataset copies that have been created because a `LibOpt_DatasetCopyOnAnyDownstreamCopy` is attached to a component position, are ignored. 
    All dataset copies that have already been deleted (or that will be deleted), are also ignored. 
    
    Extending this method (or subclassing the `LibOpt_DatasetCopyOnAnyDownstreamCopy` type) will break the unit tests. We recommend you to create a new subclass from the `LibOpt_DatasetCopyConditional` type if you want to modify this method.
  *]
  TextBody:
  [*
    snapshotcopydataset := select( task,
                                   SnapshotComponent.Children.astype( LibOpt_SnapshotReplannableCopyDataset ),
                                   snapshot,
                                   snapshot.ComponentPositionName() = this.ComponentPositionName()
                                   );
      
    hascreateddownstreamsnapshot := exists( task.SnapshotComponent().Descendants(),
                                            Elements.astype( LibOpt_SnapshotReplannableCopyDataset ),
                                            snapshot, 
                                            not snapshot.IsDatasetDeleted() 
                                            and not snapshot.IsDatasetDeletedByOptimizer()
                                            and not snapshot.HasToBeDeleted()
                                            // Ignore all snapshots on the current component position that were created before snapshotcopydataset
                                            and ( snapshot.GetComponent() <> task.Component() 
                                                  or snapshot.SequenceNr() > snapshotcopydataset.SequenceNr() )
                                            );
    
    return not hascreateddownstreamsnapshot;
  *]
}