陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
Quintiq file version 2.0
#parent: #root
Method RollbackOneTransaction
{
  Description:
  [*
    Rollback the transaction when the run is configured for `InOneTransaction`.
    
    This will serialize the run and store it such that it can later be retrieved by the `LibOpt_Optimizer.RecoverLastFailedRun` method.
  *]
  TextBody:
  [*
    if( not this.IsFailed() )
    {
      this.Task( relflush );
      this.OnFinish();
    }
    
    // Store the serialized LibOpt_Run in the AlgorithmStore
    // This way it can later be deserialized and inspected.
    json_builder := this.Serialize();
    json_string := json_builder.AsString();
    
    identifier := LibOpt_Run::AlgorithmStore_OnException_Identifier( this.Optimizer() );
    
    algorithm := LibOpt_Utility::ConstructMathematicalProgramWithoutAnalysis();
    algorithm.StoreString( LibOpt_Suboptimizer::RollbackStorage_Run(), json_string );
    AlgorithmStore::TryRetrieve( identifier );
    AlgorithmStore::Store( identifier, &algorithm );
    
    // Store the RunNr in the AlgorithmStore
    // This way we prevent having duplicate RunNrs in the future.
    identifier := LibOpt_Optimization::AlgorithmStore_RunNr( this.Optimization() );
    
    algorithm := LibOpt_Utility::ConstructMathematicalProgramWithoutAnalysis();
    algorithm.StoreString( attribute( LibOpt_Run, RunNr ).Name(), NumberToString::ISOConverter().Convert( this.RunNr() ) );
    AlgorithmStore::TryRetrieve( identifier );
    AlgorithmStore::Store( identifier, &algorithm );
    
    // Rollback transaction
    LibOpt_Utility::ThrowCleanError( Translations::LibOpt_Optimization_OneTransactionException() );
  *]
  InterfaceProperties { Accessibility: 'Module' }
}