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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Quintiq file version 2.0
#parent: #root
Method RollbackCurrentTransaction (
  String message,
  LibOpt_Error e,
  Boolean logError
)
{
  TextBody:
  [*
    rollback_storage := LibOpt_Utility::ConstructMathematicalProgramWithoutAnalysis();
    
    rollback_storage.StoreString( LibOpt_Suboptimizer::RollbackStorage_HasRollback(), [String] true );
    if( not isnull( this.SnapshotComponent() ) )
    {
      rollback_storage.StoreString( LibOpt_Suboptimizer::RollbackStorage_Snapshot(), this.SnapshotComponent().Serialize().AsString() );
    }
    
    if( not isnull( e ) )
    {
      rollback_storage.StoreString( LibOpt_Task::RollbackStorage_Error(), JSONIO::ExportToString( e, "iso8601", "iso8601", "iso8601", 0 ) );
    }
    
    current_transaction := LibOpt_CurrentTransaction::GetCurrentTransaction( this.Component() );
    last_task := current_transaction.LastTask();
    if( not isnull( last_task ) )
    {
      rollback_storage.StoreString( LibOpt_Task::RollbackStorage_Component(), [String] last_task.Component().Key() );
    }
    
    identifier := LibOpt_Task::AlgorithmStore_Identifier( this );
    AlgorithmStore::TryRetrieve( identifier ); // Remove it from the AlgorithmStore if it is already stored.
    AlgorithmStore::Store( identifier, & rollback_storage );
    
    if( logError )
    {
      //if we have indicated we want to log this error it will be thrown below in the try block
      //and then immediately consumed by the onfailure block
      try
      {
        //create a separate program to undo and throw the error
        progam := LibOpt_Utility::ConstructMathematicalProgramWithoutAnalysis();
        progam.UndoStep( message );
      }
      onfailure
      {
      }
    }
    LibOpt_Utility::ThrowCleanError( message );
  *]
}