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 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 209 by tony, Wed Mar 14 12:48:51 2018 UTC

# Line 1 | Line 1
1 + (*
2 + *  IBX For Lazarus (Firebird Express)
3 + *
4 + *  The contents of this file are subject to the Initial Developer's
5 + *  Public License Version 1.0 (the "License"); you may not use this
6 + *  file except in compliance with the License. You may obtain a copy
7 + *  of the License here:
8 + *
9 + *    http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 + *
11 + *  Software distributed under the License is distributed on an "AS
12 + *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 + *  implied. See the License for the specific language governing rights
14 + *  and limitations under the License.
15 + *
16 + *  The Initial Developer of the Original Code is Tony Whyman.
17 + *
18 + *  The Original Code is (C) 2015 Tony Whyman, MWA Software
19 + *  (http://www.mwasoftware.co.uk).
20 + *
21 + *  All Rights Reserved.
22 + *
23 + *  Contributor(s): ______________________________________.
24 + *
25 + *)
26 +            
27   unit LimboTransactionsUnit;
28  
29   {$mode objfpc}{$H+}
# Line 6 | Line 32 | interface
32  
33   uses
34    Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
35 <  Grids, IBServices;
35 >  ActnList, db, IBXServices, IBDynamicGrid;
36  
37   type
38    { TLimboTransactionsForm }
39  
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;
49      Button1: TButton;
50      Button2: TButton;
51      Button3: TButton;
52      Button4: TButton;
53 <    IBValidationService1: TIBValidationService;
54 <    Label1: TLabel;
55 <    StringGrid1: TStringGrid;
56 <    procedure Button1Click(Sender: TObject);
57 <    procedure Button2Click(Sender: TObject);
58 <    procedure Button3Click(Sender: TObject);
59 <    procedure Button4Click(Sender: TObject);
53 >    Button5: TButton;
54 >    IBDynamicGrid3: TIBDynamicGrid;
55 >    Label38: TLabel;
56 >    Label39: TLabel;
57 >    LimboListSource: TDataSource;
58 >    LimboReport: TMemo;
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);
65 <    procedure StringGrid1EditingDone(Sender: TObject);
65 >    procedure RollbackAllExecute(Sender: TObject);
66    private
67      { private declarations }
68      procedure DoRefresh(Data: PtrInt);
31    function StateToStr(State: TTransactionState): string;
32    function AdviseToStr(Advise: TTransactionAdvise): string;
33    function ActionToStr(anAction: TTransactionAction): string;
34    procedure RunGFix;
69    public
70      { public declarations }
71    end;
# Line 43 | Line 77 | implementation
77  
78   {$R *.lfm}
79  
46 uses Unit1;
47
80   { TLimboTransactionsForm }
81  
82   procedure TLimboTransactionsForm.FormShow(Sender: TObject);
83   begin
84    Application.QueueAsyncCall(@DoRefresh,0);
85 +  LimboReport.Lines.Clear;
86   end;
87  
88 < procedure TLimboTransactionsForm.Button1Click(Sender: TObject);
56 < begin
57 <  IBValidationService1.GlobalAction := CommitGlobal;
58 <  RunGFix;
59 < end;
60 <
61 < procedure TLimboTransactionsForm.Button2Click(Sender: TObject);
88 > procedure TLimboTransactionsForm.RollbackAllExecute(Sender: TObject);
89   begin
90 <  IBValidationService1.GlobalAction := RollbackGlobal;
64 <  RunGFix;
90 >  InLimboList.FixErrors(RollbackGlobal,LimboReport.Lines);
91   end;
92  
93 < procedure TLimboTransactionsForm.Button3Click(Sender: TObject);
93 > procedure TLimboTransactionsForm.ApplySelectedActionExecute(Sender: TObject);
94   begin
95 <  IBValidationService1.GlobalAction := NoGlobalAction;
70 <  RunGFix;
95 >  InLimboList.FixErrors(NoGlobalAction,LimboReport.Lines);
96   end;
97  
98 < procedure TLimboTransactionsForm.Button4Click(Sender: TObject);
98 > procedure TLimboTransactionsForm.Commit2PhaseAllExecute(Sender: TObject);
99   begin
100 <  IBValidationService1.GlobalAction := RecoverTwoPhaseGlobal;
76 <  RunGFix;
100 >  InLimboList.FixErrors(RecoverTwoPhaseGlobal,LimboReport.Lines);
101   end;
102  
103 < procedure TLimboTransactionsForm.StringGrid1EditingDone(Sender: TObject);
103 > procedure TLimboTransactionsForm.CommitAllExecute(Sender: TObject);
104   begin
105 <  with StringGrid1, IBValidationService1 do
82 <  if col = 7 then
83 <  begin
84 <    if Cells[7,row] = 'Commit' then
85 <      LimboTransactionInfo[row-1].Action := CommitAction
86 <    else
87 <      if Cells[7,row] = 'Rollback' then
88 <        LimboTransactionInfo[row-1].Action := RollbackAction
89 <  end;
105 >  InLimboList.FixErrors(CommitGlobal,LimboReport.Lines);
106   end;
107  
108 < procedure TLimboTransactionsForm.DoRefresh(Data: PtrInt);
93 < var i: integer;
108 > procedure TLimboTransactionsForm.CommitAllUpdate(Sender: TObject);
109   begin
110 <  with IBValidationService1 do
96 <  begin
97 <    Active := true;
98 <    ServiceStart;
99 <    FetchLimboTransactionInfo;
100 <    StringGrid1.RowCount := LimboTransactionInfoCount + 1;
101 <    for i := 0 to LimboTransactionInfoCount - 1 do
102 <    with LimboTransactionInfo[i] do
103 <    begin
104 <      StringGrid1.Cells[0,i+1] := IntToStr(ID);
105 <      if MultiDatabase then
106 <        StringGrid1.Cells[1,i+1] := 'Multi DB'
107 <      else
108 <        StringGrid1.Cells[1,i+1] := 'Single DB';
109 <      StringGrid1.Cells[2,i+1] := HostSite;
110 <      StringGrid1.Cells[3,i+1] := RemoteSite;
111 <      StringGrid1.Cells[4,i+1] := RemoteDatabasePath;
112 <      StringGrid1.Cells[5,i+1] := StateToStr(State);
113 <      StringGrid1.Cells[6,i+1] := AdviseToStr(Advise);
114 <      StringGrid1.Cells[7,i+1] := ActionToStr(Action);
115 <    end;
116 <  end;
110 >  (Sender as TAction).Enabled := InLimboList.Active and (InLimboList.RecordCount > 0);
111   end;
112  
113 < function TLimboTransactionsForm.StateToStr(State: TTransactionState): string;
113 > procedure TLimboTransactionsForm.FormClose(Sender: TObject;
114 >  var CloseAction: TCloseAction);
115   begin
116 <  case State of
122 <  LimboState:
123 <    Result := 'Limbo';
124 <  CommitState:
125 <    Result := 'Commit';
126 <  RollbackState:
127 <    Result := 'Rollback';
128 <  else
129 <    Result := 'Unknown';
130 <  end;
116 >  InLimboList.Active := false;
117   end;
118  
119 < function TLimboTransactionsForm.AdviseToStr(Advise: TTransactionAdvise): string;
134 < begin
135 <  case Advise of
136 <  CommitAdvise:
137 <    Result := 'Commit';
138 <  RollbackAdvise:
139 <    Result := 'Rollback';
140 <  else
141 <    Result := 'Unknown';
142 <  end;
143 < end;
144 <
145 < function TLimboTransactionsForm.ActionToStr(anAction: TTransactionAction
146 <  ): string;
147 < begin
148 <  case anAction of
149 <  CommitAction:
150 <    Result := 'Commit';
151 <  RollbackAction:
152 <    Result := 'Rollback';
153 <  end;
154 < end;
155 <
156 < procedure TLimboTransactionsForm.RunGFix;
119 > procedure TLimboTransactionsForm.DoRefresh(Data: PtrInt);
120   begin
121 <  with IBValidationService1 do
122 <  begin
160 <    Form1.Memo1.Lines.Add('Starting Limbo transaction resolution');
161 <    FixLimboTransactionErrors;
162 <    while not Eof do
163 <    begin
164 <      Form1.Memo1.Lines.Add(GetNextLine);
165 <      Application.ProcessMessages;
166 <    end;
167 <    Form1.Memo1.Lines.Add('Limbo Transaction resolution complete');
168 <    Application.QueueAsyncCall(@DoRefresh,0);
169 <  end;
121 >  InLimboList.Active := false;
122 >  InLimboList.Active := true;
123   end;
124  
125   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines