ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/examples/services/LimboTransactionsUnit.pas
(Generate patch)

Comparing ibx/trunk/examples/services/LimboTransactionsUnit.pas (file contents):
Revision 147 by tony, Mon Feb 26 11:14:30 2018 UTC vs.
Revision 209 by tony, Wed Mar 14 12:48:51 2018 UTC

# Line 32 | Line 32 | interface
32  
33   uses
34    Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
35 <  Grids, ActnList, db, memds, IBServices, IBDynamicGrid;
35 >  ActnList, db, IBXServices, IBDynamicGrid;
36  
37   type
38    { TLimboTransactionsForm }
# Line 40 | Line 40 | type
40    TLimboTransactionsForm = class(TForm)
41      ApplySelectedAction: TAction;
42      Commit2PhaseAll: TAction;
43 +
44 +      IBXLimboTransactionResolutionService1: TIBXLimboTransactionResolutionService;
45 +      InLimboList: TIBXServicesLimboTransactionsList;
46      RollbackAll: TAction;
47      CommitAll: TAction;
48      ActionList1: TActionList;
# Line 49 | Line 52 | type
52      Button4: TButton;
53      Button5: TButton;
54      IBDynamicGrid3: TIBDynamicGrid;
52    InLimboList: TMemDataset;
55      Label38: TLabel;
56      Label39: TLabel;
57      LimboListSource: TDataSource;
58      LimboReport: TMemo;
57    LimboTransactionValidation: TIBValidationService;
59      procedure ApplySelectedActionExecute(Sender: TObject);
60      procedure Commit2PhaseAllExecute(Sender: TObject);
61      procedure CommitAllExecute(Sender: TObject);
62      procedure CommitAllUpdate(Sender: TObject);
63      procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
64      procedure FormShow(Sender: TObject);
64    procedure InLimboListAfterOpen(DataSet: TDataSet);
65    procedure InLimboListBeforeClose(DataSet: TDataSet);
66    procedure InLimboListBeforePost(DataSet: TDataSet);
65      procedure RollbackAllExecute(Sender: TObject);
66    private
67      { private declarations }
70    FLoadingLimboTr: boolean;
68      procedure DoRefresh(Data: PtrInt);
72    procedure RunGFix;
69    public
70      { public declarations }
71    end;
# Line 81 | Line 77 | implementation
77  
78   {$R *.lfm}
79  
84 uses MainFormUnit;
85
80   { TLimboTransactionsForm }
81  
82   procedure TLimboTransactionsForm.FormShow(Sender: TObject);
# Line 91 | Line 85 | begin
85    LimboReport.Lines.Clear;
86   end;
87  
94 procedure TLimboTransactionsForm.InLimboListAfterOpen(DataSet: TDataSet);
95
96 function TypeToStr(MultiDatabase: boolean): string;
97 begin
98  if MultiDatabase then
99    Result := 'Multi DB'
100  else
101    Result := 'Single DB';
102 end;
103
104 function StateToStr(State: TTransactionState): string;
105 begin
106  case State of
107  LimboState:
108    Result := 'Limbo';
109  CommitState:
110    Result := 'Commit';
111  RollbackState:
112    Result := 'Rollback';
113  else
114    Result := 'Unknown';
115  end;
116 end;
117
118 function AdviseToStr(Advise: TTransactionAdvise): string;
119 begin
120  case Advise of
121  CommitAdvise:
122    Result := 'Commit';
123  RollbackAdvise:
124    Result := 'Rollback';
125  else
126    Result := 'Unknown';
127  end;
128 end;
129
130 function ActionToStr(anAction: IBServices.TTransactionAction): string;
131 begin
132  case anAction of
133  CommitAction:
134    Result := 'Commit';
135  RollbackAction:
136    Result := 'Rollback';
137  end;
138 end;
139
140 var i: integer;
141 begin
142  if FLoadingLimboTr then Exit;
143  FLoadingLimboTr := true;
144  with LimboTransactionValidation do
145  try
146    Active := true;
147    ServiceStart;
148    FetchLimboTransactionInfo;
149    for i := 0 to LimboTransactionInfoCount - 1 do
150    with LimboTransactionInfo[i] do
151    begin
152      InLimboList.Append;
153      InLimboList.FieldByName('TransactionID').AsInteger := ID;
154      InLimboList.FieldByName('TransactionType').AsString := TypeToStr(MultiDatabase);
155      InLimboList.FieldByName('HostSite').AsString := HostSite;
156      InLimboList.FieldByName('RemoteSite').AsString := RemoteSite;
157      InLimboList.FieldByName('DatabasePath').AsString := RemoteDatabasePath;
158      InLimboList.FieldByName('State').AsString := StateToStr(State);
159      InLimboList.FieldByName('RecommendedAction').AsString := AdviseToStr(Advise);
160      InLimboList.FieldByName('RequestedAction').AsString := ActionToStr(Action);
161      InLimboList.Post;
162    end;
163  finally
164    FLoadingLimboTr := false;
165  end;
166 end;
167
168 procedure TLimboTransactionsForm.InLimboListBeforeClose(DataSet: TDataSet);
169 begin
170  InLimboList.Clear(false);
171 end;
172
173 procedure TLimboTransactionsForm.InLimboListBeforePost(DataSet: TDataSet);
174 var i: integer;
175 begin
176  if FLoadingLimboTr then Exit;
177  with LimboTransactionValidation do
178  for i := 0 to LimboTransactionInfoCount - 1 do
179    with LimboTransactionInfo[i] do
180    begin
181      if ID = InLimboList.FieldByName('TransactionID').AsInteger then
182      begin
183       if InLimboList.FieldByName('RequestedAction').AsString = 'Commit' then
184         Action := CommitAction
185       else
186         if InLimboList.FieldByName('RequestedAction').AsString = 'Rollback' then
187           Action := RollbackAction;
188       break;
189      end;
190    end;
191 end;
192
88   procedure TLimboTransactionsForm.RollbackAllExecute(Sender: TObject);
89   begin
90 <  LimboTransactionValidation.GlobalAction := RollbackGlobal;
196 <  RunGFix;
90 >  InLimboList.FixErrors(RollbackGlobal,LimboReport.Lines);
91   end;
92  
93   procedure TLimboTransactionsForm.ApplySelectedActionExecute(Sender: TObject);
94   begin
95 <  LimboTransactionValidation.GlobalAction := NoGlobalAction;
202 <  RunGFix;
95 >  InLimboList.FixErrors(NoGlobalAction,LimboReport.Lines);
96   end;
97  
98   procedure TLimboTransactionsForm.Commit2PhaseAllExecute(Sender: TObject);
99   begin
100 <  LimboTransactionValidation.GlobalAction := RecoverTwoPhaseGlobal;
208 <  RunGFix;
100 >  InLimboList.FixErrors(RecoverTwoPhaseGlobal,LimboReport.Lines);
101   end;
102  
103   procedure TLimboTransactionsForm.CommitAllExecute(Sender: TObject);
104   begin
105 <  LimboTransactionValidation.GlobalAction := CommitGlobal;
214 <  RunGFix;
105 >  InLimboList.FixErrors(CommitGlobal,LimboReport.Lines);
106   end;
107  
108   procedure TLimboTransactionsForm.CommitAllUpdate(Sender: TObject);
# Line 231 | Line 122 | begin
122    InLimboList.Active := true;
123   end;
124  
234 procedure TLimboTransactionsForm.RunGFix;
235 begin
236  if not InLimboList.Active then
237    raise Exception.Create('Limbo Transactions List not available');
238
239  with InLimboList do
240    if State = dsEdit then Post;
241  LimboReport.Lines.Clear;
242
243  with LimboTransactionValidation do
244  begin
245    LimboReport.Lines.Add('Starting Limbo transaction resolution');
246    FixLimboTransactionErrors;
247    while not Eof do
248    begin
249      LimboReport.Lines.Add(GetNextLine);
250      Application.ProcessMessages;
251    end;
252    LimboReport.Lines.Add('Limbo Transaction resolution complete');
253    Application.QueueAsyncCall(@DoRefresh,0);
254  end;
255 end;
256
125   end.
126  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines